From b44fe3fd686d9fecc90902d4587ab4c84423111f Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 11 May 2015 10:33:35 -0700 Subject: [PATCH] Add missing SslContextBuilder.forServer(KeyManagerFactory) Motivation: keyManager() is required on server-side, and so there is a forServer() method for each override of keyManager(). However, one of the forServer() overrides was missing, which meant that if you wanted to use a KeyManagerFactory you were forced to provide garbage configuration just to get past null checks. Modifications: Add missing override. Result: No hacks to use SslContextBuilder on server-side with KeyManagerFactory. Resolves #3775 --- .../main/java/io/netty/handler/ssl/SslContext.java | 2 +- .../java/io/netty/handler/ssl/SslContextBuilder.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/SslContext.java b/handler/src/main/java/io/netty/handler/ssl/SslContext.java index 890b36242b..0865890f40 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslContext.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslContext.java @@ -76,7 +76,7 @@ import java.util.List; *
  * // In your {@link ChannelInitializer}:
  * {@link ChannelPipeline} p = channel.pipeline();
- * {@link SslContext} sslCtx = {@link #newBuilderForClient() SslContext.newBuilderForClient()}.build();
+ * {@link SslContext} sslCtx = {@link SslContextBuilder#forClient() SslContextBuilder.forClient()}.build();
  * p.addLast("ssl", {@link #newEngine(ByteBufAllocator, String, int) sslCtx.newEngine(channel.alloc(), host, port)});
  * ...
  * 
diff --git a/handler/src/main/java/io/netty/handler/ssl/SslContextBuilder.java b/handler/src/main/java/io/netty/handler/ssl/SslContextBuilder.java index fcc840e6ca..a0d3caf45d 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslContextBuilder.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslContextBuilder.java @@ -39,6 +39,7 @@ public final class SslContextBuilder { * * @param keyCertChainFile an X.509 certificate chain file in PEM format * @param keyFile a PKCS#8 private key file in PEM format + * @see #keyManager(File, File) */ public static SslContextBuilder forServer(File keyCertChainFile, File keyFile) { return new SslContextBuilder(true).keyManager(keyCertChainFile, keyFile); @@ -51,12 +52,23 @@ public final class SslContextBuilder { * @param keyFile a PKCS#8 private key file in PEM format * @param keyPassword the password of the {@code keyFile}, or {@code null} if it's not * password-protected + * @see #keyManager(File, File, String) */ public static SslContextBuilder forServer( File keyCertChainFile, File keyFile, String keyPassword) { return new SslContextBuilder(true).keyManager(keyCertChainFile, keyFile, keyPassword); } + /** + * Creates a builder for new server-side {@link SslContext}. + * + * @param keyManagerFactory non-{@code null} factory for server's private key + * @see #keyManager(KeyManagerFactory) + */ + public static SslContextBuilder forServer(KeyManagerFactory keyManagerFactory) { + return new SslContextBuilder(true).keyManager(keyManagerFactory); + } + private final boolean forServer; private SslProvider provider; private File trustCertChainFile;