From 2d6d1fa1390ac8c3febb7b176660b1f181d8effe Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 26 Sep 2014 20:53:54 +0200 Subject: [PATCH] [#2939] Fix SslContext usage in the examples for client side Motivation: We incorrectly used SslContext.newServerContext() in some places where a we needed a client context. Modifications: Use SslContext.newClientContext() when using ssl on the client side. Result: Working ssl client examples. --- .../java/io/netty/example/http/upload/HttpUploadClient.java | 5 ++--- .../example/http/websocketx/client/WebSocketClient.java | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java index f4f1af4621..4c69312b06 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java @@ -36,7 +36,7 @@ import io.netty.handler.codec.http.multipart.HttpDataFactory; import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder; import io.netty.handler.codec.http.multipart.InterfaceHttpData; import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.util.SelfSignedCertificate; +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import java.io.File; import java.io.FileNotFoundException; @@ -85,8 +85,7 @@ public final class HttpUploadClient { final boolean ssl = "https".equalsIgnoreCase(scheme); final SslContext sslCtx; if (ssl) { - SelfSignedCertificate ssc = new SelfSignedCertificate(); - sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); + sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); } else { sslCtx = null; } diff --git a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java index b706b07e68..d08b8c3fdc 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java +++ b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java @@ -35,6 +35,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.ssl.util.SelfSignedCertificate; import java.io.BufferedReader; @@ -83,8 +84,7 @@ public final class WebSocketClient { final boolean ssl = "wss".equalsIgnoreCase(scheme); final SslContext sslCtx; if (ssl) { - SelfSignedCertificate ssc = new SelfSignedCertificate(); - sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); + sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); } else { sslCtx = null; }