GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SSL test: Don't depend on property value in test (#16346) (#16361) · netty/netty@9ab6332

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src/test/java/io/netty/handler/ssl
    • SSLEngineTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java‎

Copy file name to clipboardExpand all lines: handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java
+30-34Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import io.netty.util.internal.EmptyArrays;
5252
import io.netty.util.internal.PlatformDependent;
5353
import io.netty.util.internal.StringUtil;
54-
import io.netty.util.internal.SystemPropertyUtil;
5554
import io.netty.util.internal.logging.InternalLogger;
5655
import io.netty.util.internal.logging.InternalLoggerFactory;
5756
import org.conscrypt.OpenSSLProvider;
@@ -4462,10 +4461,9 @@ public void testMasterKeyLogging(final SSLEngineTestParam param) throws Exceptio
44624461
* The JDK SSL engine master key retrieval relies on being able to set field access to true.
44634462
* That is not available in JDK9+
44644463
*/
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+
}
44694467

44704468
SelfSignedCertificate ssc = CachedSelfSignedCertificate.getCachedCertificate();
44714469
serverSslCtx = wrapContext(param, SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
@@ -4475,23 +4473,28 @@ public void testMasterKeyLogging(final SSLEngineTestParam param) throws Exceptio
44754473
.ciphers(param.ciphers())
44764474
.build());
44774475

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);
44824479

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()));
44884485

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);
44924489

44934490
ch.pipeline().addLast(sslHandler);
44944491
ch.pipeline().addLast(new SslMasterKeyHandler() {
4492+
4493+
@Override
4494+
protected boolean masterKeyHandlerEnabled() {
4495+
return true;
4496+
}
4497+
44954498
@Override
44964499
protected void accept(SecretKey masterKey, SSLSession session) {
44974500
promise.setSuccess(masterKey);
@@ -4501,25 +4504,18 @@ protected void accept(SecretKey masterKey, SSLSession session) {
45014504
}
45024505
}).bind(new InetSocketAddress(0)).get();
45034506

4504-
int port = ((InetSocketAddress) serverChannel.localAddress()).getPort();
4507+
int port = ((InetSocketAddress) serverChannel.localAddress()).getPort();
45054508

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();
45124515

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");
45234519
}
45244520
}
45254521

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.