[#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.
This commit is contained in:
Norman Maurer 2014-09-26 20:53:54 +02:00
parent 89d4c50c30
commit eef2ad7cd2
2 changed files with 4 additions and 5 deletions

View File

@ -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.HttpPostRequestEncoder;
import io.netty.handler.codec.http.multipart.InterfaceHttpData; import io.netty.handler.codec.http.multipart.InterfaceHttpData;
import io.netty.handler.ssl.SslContext; 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.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -85,8 +85,7 @@ public final class HttpUploadClient {
final boolean ssl = "https".equalsIgnoreCase(scheme); final boolean ssl = "https".equalsIgnoreCase(scheme);
final SslContext sslCtx; final SslContext sslCtx;
if (ssl) { if (ssl) {
SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
} else { } else {
sslCtx = null; sslCtx = null;
} }

View File

@ -34,6 +34,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.codec.http.websocketx.WebSocketVersion;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.handler.ssl.util.SelfSignedCertificate;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -82,8 +83,7 @@ public final class WebSocketClient {
final boolean ssl = "wss".equalsIgnoreCase(scheme); final boolean ssl = "wss".equalsIgnoreCase(scheme);
final SslContext sslCtx; final SslContext sslCtx;
if (ssl) { if (ssl) {
SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
} else { } else {
sslCtx = null; sslCtx = null;
} }