<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi all,<div class=""><br class=""></div><div class="">I think I found another bug in the the SSL implementation (well really in the TrustManager related part) which leads to a NPE. I was able to reproduce this on Java8 and Java11 (ea28) but I am sure it also exists on 9 and 10. </div><div class=""><br class=""></div><div class="">While trying to write some test code for netty I did something stupid while creating the SSLEngine by passing a hostname as parameter for the server which then ended up in an NPE during handshake. I would argue we should not fail with a NPE.</div><div class=""><br class=""></div><div class="">Basically something like:</div><div class=""><br class=""></div><div class="">SSLEngine serverEngine = serverCtx.createSSLEngine("localhost", -1);</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I think this is caused by <font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" size="2" class=""><span style="caret-color: rgb(36, 41, 46);" class="">sun.security.ssl.X509TrustManagerImpl.checkIdentity(…)</span></font> missing a null check for the hostname before calling <font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" size="2" class=""><span style="caret-color: rgb(36, 41, 46);" class="">sun.security.util.HostnameChecker.match(…)</span></font></div><div class=""><br class=""></div><div class="">A full reproduce (which I extracted from my netty testcase)  can be found here (there is a README.md which explains how to run it):</div><div class=""><br class=""></div><div class=""><a href="https://github.com/normanmaurer/jdk_ssl_npe_reproducer" class="">https://github.com/normanmaurer/jdk_ssl_npe_reproducer</a></div><div class=""><br class=""></div><div class="">The stack I see is:</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; word-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; caret-color: rgb(36, 41, 46); color: rgb(36, 41, 46); margin-bottom: 0px !important;" class=""><code style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; padding: 0px; margin: 0px; background-color: transparent; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal; border: 0px; display: inline; overflow: visible; line-height: inherit; word-wrap: normal;" class="">Exception in thread "main" java.lang.RuntimeException: Delegated task threw Exception/Error
        at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1527)
        at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:535)
        at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1214)
        at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1186)
        at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
        at JDKSslReproducer.handshake(JDKSslReproducer.java:76)
        at JDKSslReproducer.main(JDKSslReproducer.java:51)
Caused by: java.lang.NullPointerException
        at sun.net.util.IPAddressUtil.textToNumericFormatV4(IPAddressUtil.java:49)
        at sun.net.util.IPAddressUtil.isIPv4LiteralAddress(IPAddressUtil.java:241)
        at sun.security.util.HostnameChecker.isIpAddress(HostnameChecker.java:125)
        at sun.security.util.HostnameChecker.match(HostnameChecker.java:93)
        at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455)
        at sun.security.ssl.AbstractTrustManagerWrapper.checkAdditionalTrust(SSLContextImpl.java:1068)
        at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:1007)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1601)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
        at sun.security.ssl.Handshaker$1.run(Handshaker.java:992)
        at sun.security.ssl.Handshaker$1.run(Handshaker.java:989)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1467)
        at JDKSslReproducer.runDelegatedTasks(JDKSslReproducer.java:131)
        at JDKSslReproducer.handshake(JDKSslReproducer.java:99)
        ... 1 more</code></pre><div class=""><br class=""></div></div><div class="">This only happens if a X509Trustmanager is used (not the Extended version) and when  setE<span style="background-color: rgb(255, 255, 255);" class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre;" class="">ndpointIdentificationAlgorithm(…) is used on the </span></font></span><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre;" class="">client-side.</span></font></div><div class=""><font color="#24292e" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="caret-color: rgb(36, 41, 46); white-space: pre;" class=""><br class=""></span></font></div><div class="">Please let me know if you agree this is a bug and I am happy to open a bug for it.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks</div><div class="">Norman</div><div class=""><br class=""></div></body></html>