Skip to content

Commit 2d6d1fa

Browse files
committed
[netty#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.
1 parent fc273cc commit 2d6d1fa

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
3737
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
3838
import io.netty.handler.ssl.SslContext;
39-
import io.netty.handler.ssl.util.SelfSignedCertificate;
39+
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
4040

4141
import java.io.File;
4242
import java.io.FileNotFoundException;
@@ -85,8 +85,7 @@ public static void main(String[] args) throws Exception {
8585
final boolean ssl = "https".equalsIgnoreCase(scheme);
8686
final SslContext sslCtx;
8787
if (ssl) {
88-
SelfSignedCertificate ssc = new SelfSignedCertificate();
89-
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
88+
sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
9089
} else {
9190
sslCtx = null;
9291
}

example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
3636
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
3737
import io.netty.handler.ssl.SslContext;
38+
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
3839
import io.netty.handler.ssl.util.SelfSignedCertificate;
3940

4041
import java.io.BufferedReader;
@@ -83,8 +84,7 @@ public static void main(String[] args) throws Exception {
8384
final boolean ssl = "wss".equalsIgnoreCase(scheme);
8485
final SslContext sslCtx;
8586
if (ssl) {
86-
SelfSignedCertificate ssc = new SelfSignedCertificate();
87-
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
87+
sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
8888
} else {
8989
sslCtx = null;
9090
}

0 commit comments

Comments
 (0)