Skip to content

Commit

Permalink
Fixes #6159 - Jetty with Conscrypt unable to handle any HTTPS request…
Browse files Browse the repository at this point in the history
…s when connected by IP rather than hostname.

Added null guard for `ExtendedSSLSession.getRequestedServerNames()`
which should never return null, but it does when using Conscrypt.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed May 7, 2021
1 parent d3576a8 commit 1c34222
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import javax.net.ssl.ExtendedSSLSession;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIMatcher;
import javax.net.ssl.SNIServerName;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession;
Expand Down Expand Up @@ -115,12 +117,16 @@ protected String chooseServerAlias(String keyType, Principal[] issuers, Collecti
String host = null;
if (session instanceof ExtendedSSLSession)
{
host = ((ExtendedSSLSession)session).getRequestedServerNames().stream()
.findAny()
.filter(SNIHostName.class::isInstance)
.map(SNIHostName.class::cast)
.map(SNIHostName::getAsciiName)
.orElse(null);
List<SNIServerName> serverNames = ((ExtendedSSLSession)session).getRequestedServerNames();
if (serverNames != null)
{
host = serverNames.stream()
.findAny()
.filter(SNIHostName.class::isInstance)
.map(SNIHostName.class::cast)
.map(SNIHostName::getAsciiName)
.orElse(null);
}
}
if (host == null)
{
Expand Down

0 comments on commit 1c34222

Please sign in to comment.