|
51 | 51 | import io.netty.util.internal.EmptyArrays; |
52 | 52 | import io.netty.util.internal.PlatformDependent; |
53 | 53 | import io.netty.util.internal.StringUtil; |
54 | | -import io.netty.util.internal.SystemPropertyUtil; |
55 | 54 | import io.netty.util.internal.logging.InternalLogger; |
56 | 55 | import io.netty.util.internal.logging.InternalLoggerFactory; |
57 | 56 | import org.conscrypt.OpenSSLProvider; |
@@ -4462,10 +4461,9 @@ public void testMasterKeyLogging(final SSLEngineTestParam param) throws Exceptio |
4462 | 4461 | * The JDK SSL engine master key retrieval relies on being able to set field access to true. |
4463 | 4462 | * That is not available in JDK9+ |
4464 | 4463 | */ |
4465 | | - assumeFalse(sslServerProvider() == SslProvider.JDK); |
4466 | | - |
4467 | | - String originalSystemPropertyValue = SystemPropertyUtil.get(SslMasterKeyHandler.SYSTEM_PROP_KEY); |
4468 | | - System.setProperty(SslMasterKeyHandler.SYSTEM_PROP_KEY, Boolean.TRUE.toString()); |
| 4464 | + if (sslServerProvider() == SslProvider.JDK) { |
| 4465 | + assumeTrue(SslMasterKeyHandler.isSunSslEngineAvailable()); |
| 4466 | + } |
4469 | 4467 |
|
4470 | 4468 | SelfSignedCertificate ssc = CachedSelfSignedCertificate.getCachedCertificate(); |
4471 | 4469 | serverSslCtx = wrapContext(param, SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) |
@@ -4475,23 +4473,28 @@ public void testMasterKeyLogging(final SSLEngineTestParam param) throws Exceptio |
4475 | 4473 | .ciphers(param.ciphers()) |
4476 | 4474 | .build()); |
4477 | 4475 |
|
4478 | | - try { |
4479 | | - sb = new ServerBootstrap(); |
4480 | | - sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); |
4481 | | - sb.channel(NioServerSocketChannel.class); |
| 4476 | + sb = new ServerBootstrap(); |
| 4477 | + sb.group(new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())); |
| 4478 | + sb.channel(NioServerSocketChannel.class); |
4482 | 4479 |
|
4483 | | - final Promise<SecretKey> promise = sb.config().group().next().newPromise(); |
4484 | | - serverChannel = sb.childHandler(new ChannelInitializer<Channel>() { |
4485 | | - @Override |
4486 | | - protected void initChannel(Channel ch) { |
4487 | | - ch.config().setAllocator(new TestByteBufAllocator(ch.config().getAllocator(), param.type())); |
| 4480 | + final Promise<SecretKey> promise = sb.config().group().next().newPromise(); |
| 4481 | + serverChannel = sb.childHandler(new ChannelInitializer<Channel>() { |
| 4482 | + @Override |
| 4483 | + protected void initChannel(Channel ch) { |
| 4484 | + ch.config().setAllocator(new TestByteBufAllocator(ch.config().getAllocator(), param.type())); |
4488 | 4485 |
|
4489 | | - SslHandler sslHandler = !param.delegate() ? |
4490 | | - serverSslCtx.newHandler(ch.alloc()) : |
4491 | | - serverSslCtx.newHandler(ch.alloc(), delegatingExecutor); |
| 4486 | + SslHandler sslHandler = !param.delegate() ? |
| 4487 | + serverSslCtx.newHandler(ch.alloc()) : |
| 4488 | + serverSslCtx.newHandler(ch.alloc(), delegatingExecutor); |
4492 | 4489 |
|
4493 | 4490 | ch.pipeline().addLast(sslHandler); |
4494 | 4491 | ch.pipeline().addLast(new SslMasterKeyHandler() { |
| 4492 | + |
| 4493 | + @Override |
| 4494 | + protected boolean masterKeyHandlerEnabled() { |
| 4495 | + return true; |
| 4496 | + } |
| 4497 | + |
4495 | 4498 | @Override |
4496 | 4499 | protected void accept(SecretKey masterKey, SSLSession session) { |
4497 | 4500 | promise.setSuccess(masterKey); |
@@ -4501,25 +4504,18 @@ protected void accept(SecretKey masterKey, SSLSession session) { |
4501 | 4504 | } |
4502 | 4505 | }).bind(new InetSocketAddress(0)).get(); |
4503 | 4506 |
|
4504 | | - int port = ((InetSocketAddress) serverChannel.localAddress()).getPort(); |
| 4507 | + int port = ((InetSocketAddress) serverChannel.localAddress()).getPort(); |
4505 | 4508 |
|
4506 | | - SSLContext sslContext = SSLContext.getInstance("TLS"); |
4507 | | - sslContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null); |
4508 | | - try (Socket socket = sslContext.getSocketFactory().createSocket(NetUtil.LOCALHOST, port)) { |
4509 | | - OutputStream out = socket.getOutputStream(); |
4510 | | - out.write(1); |
4511 | | - out.flush(); |
| 4509 | + SSLContext sslContext = SSLContext.getInstance("TLS"); |
| 4510 | + sslContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null); |
| 4511 | + try (Socket socket = sslContext.getSocketFactory().createSocket(NetUtil.LOCALHOST, port)) { |
| 4512 | + OutputStream out = socket.getOutputStream(); |
| 4513 | + out.write(1); |
| 4514 | + out.flush(); |
4512 | 4515 |
|
4513 | | - assertTrue(promise.await(10, TimeUnit.SECONDS)); |
4514 | | - SecretKey key = promise.get(); |
4515 | | - assertEquals(48, key.getEncoded().length, "AES secret key must be 48 bytes"); |
4516 | | - } |
4517 | | - } finally { |
4518 | | - if (originalSystemPropertyValue != null) { |
4519 | | - System.setProperty(SslMasterKeyHandler.SYSTEM_PROP_KEY, originalSystemPropertyValue); |
4520 | | - } else { |
4521 | | - System.clearProperty(SslMasterKeyHandler.SYSTEM_PROP_KEY); |
4522 | | - } |
| 4516 | + assertTrue(promise.await(10, TimeUnit.SECONDS)); |
| 4517 | + SecretKey key = promise.get(); |
| 4518 | + assertEquals(48, key.getEncoded().length, "AES secret key must be 48 bytes"); |
4523 | 4519 | } |
4524 | 4520 | } |
4525 | 4521 |
|
|