GeezerVison is showing github.com — Swap to SslContextBuilder in examples · netty/netty@2927cdd
File treeExpand file treeCollapse file tree Open diff view settings example/src/main/java/io/netty/example
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: example/src/main/java/io/netty/example/http2/client/Http2Client.java +14-13Lines changed: 14 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 33 | 33 | import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; | 34 | 34 | import io.netty.handler.ssl.OpenSsl; | 35 | 35 | import io.netty.handler.ssl.SslContext; | | 36 | +import io.netty.handler.ssl.SslContextBuilder; | 36 | 37 | import io.netty.handler.ssl.SslProvider; | 37 | 38 | import io.netty.handler.ssl.SupportedCipherSuiteFilter; | 38 | 39 | import io.netty.handler.ssl.util.InsecureTrustManagerFactory; | @@ -64,19 +65,19 @@ public static void main(String[] args) throws Exception { | 64 | 65 | final SslContext sslCtx; | 65 | 66 | if (SSL) { | 66 | 67 | SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; | 67 | | - sslCtx = SslContext.newClientContext(provider, | 68 | | - null, InsecureTrustManagerFactory.INSTANCE, | 69 | | - Http2SecurityUtil.CIPHERS, | 70 | | - /* NOTE: the following filter may not include all ciphers required by the HTTP/2 specification | 71 | | - * Please refer to the HTTP/2 specification for cipher requirements. */ | 72 | | - SupportedCipherSuiteFilter.INSTANCE, | 73 | | - new ApplicationProtocolConfig( | 74 | | - Protocol.ALPN, | 75 | | - SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | 76 | | - SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | 77 | | - SelectedProtocol.HTTP_2.protocolName(), | 78 | | - SelectedProtocol.HTTP_1_1.protocolName()), | 79 | | - 0, 0); | | 68 | + sslCtx = SslContextBuilder.forClient() | | 69 | + .sslProvider(provider) | | 70 | + /* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification. | | 71 | + * Please refer to the HTTP/2 specification for cipher requirements. */ | | 72 | + .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) | | 73 | + .trustManager(InsecureTrustManagerFactory.INSTANCE) | | 74 | + .applicationProtocolConfig(new ApplicationProtocolConfig( | | 75 | + Protocol.ALPN, | | 76 | + SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | | 77 | + SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | | 78 | + SelectedProtocol.HTTP_2.protocolName(), | | 79 | + SelectedProtocol.HTTP_1_1.protocolName())) | | 80 | + .build(); | 80 | 81 | } else { | 81 | 82 | sslCtx = null; | 82 | 83 | } | |
Collapse file Copy file name to clipboardExpand all lines: example/src/main/java/io/netty/example/http2/server/Http2Server.java +13-13Lines changed: 13 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 32 | 32 | import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; | 33 | 33 | import io.netty.handler.ssl.OpenSsl; | 34 | 34 | import io.netty.handler.ssl.SslContext; | | 35 | +import io.netty.handler.ssl.SslContextBuilder; | 35 | 36 | import io.netty.handler.ssl.SslProvider; | 36 | 37 | import io.netty.handler.ssl.SupportedCipherSuiteFilter; | 37 | 38 | import io.netty.handler.ssl.util.SelfSignedCertificate; | @@ -52,19 +53,18 @@ public static void main(String[] args) throws Exception { | 52 | 53 | if (SSL) { | 53 | 54 | SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; | 54 | 55 | SelfSignedCertificate ssc = new SelfSignedCertificate(); | 55 | | - sslCtx = SslContext.newServerContext(provider, | 56 | | - ssc.certificate(), ssc.privateKey(), null, | 57 | | - Http2SecurityUtil.CIPHERS, | 58 | | - /* NOTE: the following filter may not include all ciphers required by the HTTP/2 specification | 59 | | - * Please refer to the HTTP/2 specification for cipher requirements. */ | 60 | | - SupportedCipherSuiteFilter.INSTANCE, | 61 | | - new ApplicationProtocolConfig( | 62 | | - Protocol.ALPN, | 63 | | - SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | 64 | | - SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | 65 | | - SelectedProtocol.HTTP_2.protocolName(), | 66 | | - SelectedProtocol.HTTP_1_1.protocolName()), | 67 | | - 0, 0); | | 56 | + sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) | | 57 | + .sslProvider(provider) | | 58 | + /* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification. | | 59 | + * Please refer to the HTTP/2 specification for cipher requirements. */ | | 60 | + .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) | | 61 | + .applicationProtocolConfig(new ApplicationProtocolConfig( | | 62 | + Protocol.ALPN, | | 63 | + SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | | 64 | + SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, | | 65 | + SelectedProtocol.HTTP_2.protocolName(), | | 66 | + SelectedProtocol.HTTP_1_1.protocolName())) | | 67 | + .build(); | 68 | 68 | } else { | 69 | 69 | sslCtx = null; | 70 | 70 | } | |
Collapse file Copy file name to clipboardExpand all lines: example/src/main/java/io/netty/example/memcache/binary/MemcacheClient.java +3-15Lines changed: 3 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 26 | 26 | import io.netty.channel.socket.nio.NioSocketChannel; | 27 | 27 | import io.netty.handler.codec.memcache.binary.BinaryMemcacheClientCodec; | 28 | 28 | import io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator; | 29 | | -import io.netty.handler.codec.spdy.SpdyOrHttpChooser.SelectedProtocol; | 30 | | -import io.netty.handler.ssl.ApplicationProtocolConfig; | 31 | | -import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol; | 32 | | -import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBehavior; | 33 | | -import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; | 34 | | -import io.netty.handler.ssl.IdentityCipherSuiteFilter; | 35 | 29 | import io.netty.handler.ssl.SslContext; | | 30 | +import io.netty.handler.ssl.SslContextBuilder; | 36 | 31 | import io.netty.handler.ssl.util.InsecureTrustManagerFactory; | 37 | 32 |
| 38 | 33 | import java.io.BufferedReader; | @@ -51,15 +46,8 @@ public static void main(String[] args) throws Exception { | 51 | 46 | // Configure SSL. | 52 | 47 | final SslContext sslCtx; | 53 | 48 | if (SSL) { | 54 | | - sslCtx = SslContext.newClientContext( | 55 | | - null, InsecureTrustManagerFactory.INSTANCE, null, | 56 | | - IdentityCipherSuiteFilter.INSTANCE, | 57 | | - new ApplicationProtocolConfig( | 58 | | - Protocol.ALPN, | 59 | | - SelectorFailureBehavior.FATAL_ALERT, | 60 | | - SelectedListenerFailureBehavior.FATAL_ALERT, | 61 | | - SelectedProtocol.HTTP_1_1.protocolName()), | 62 | | - 0, 0); | | 49 | + sslCtx = SslContextBuilder.forClient() | | 50 | + .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); | 63 | 51 | } else { | 64 | 52 | sslCtx = null; | 65 | 53 | } | |
|