Skip to content

Commit f4295a4

Browse files
committed
BCJSSE: Strip trailing dot from hostname for SNI, endpointID checks
1 parent dbd3462 commit f4295a4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

tls/src/main/java/org/bouncycastle/jsse/provider/JsseUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,19 @@ private static String stripOuterChars(String s, char openChar, char closeChar)
937937
return s;
938938
}
939939

940+
static String stripTrailingDot(String s)
941+
{
942+
if (s != null && s.endsWith("."))
943+
{
944+
int sLast = s.length() - 1;
945+
if (sLast >= 0 && s.charAt(sLast) == '.')
946+
{
947+
return s.substring(0, sLast);
948+
}
949+
}
950+
return s;
951+
}
952+
940953
static boolean useCompatibilityMode()
941954
{
942955
return provTlsUseCompatibilityMode;

tls/src/main/java/org/bouncycastle/jsse/provider/ProvTlsClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ protected Vector<ServerName> getSNIServerNames()
174174
List<BCSNIServerName> sniServerNames = sslParameters.getServerNames();
175175
if (null == sniServerNames)
176176
{
177-
String peerHostSNI = manager.getPeerHostSNI();
177+
/*
178+
* A fully qualified domain name (FQDN) may contain a trailing dot. We remove it for the
179+
* purpose of SNI and endpoint ID checks (e.g. SNIHostName doesn't permit it).
180+
*/
181+
String peerHostSNI = JsseUtils.stripTrailingDot(manager.getPeerHostSNI());
178182

179183
/*
180184
* TODO[jsse] Consider removing the restriction that the name must contain a '.'

tls/src/main/java/org/bouncycastle/jsse/provider/ProvX509TrustManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ private static void checkEndpointID(X509Certificate certificate, String endpoint
427427
BCExtendedSSLSession sslSession) throws CertificateException
428428
{
429429
String peerHost = sslSession.getPeerHost();
430+
431+
/*
432+
* A fully qualified domain name (FQDN) may contain a trailing dot. We remove it for the purpose of
433+
* SNI and endpoint ID checks (e.g. SNIHostName doesn't permit it).
434+
*/
435+
peerHost = JsseUtils.stripTrailingDot(peerHost);
436+
430437
if (checkServerTrusted)
431438
{
432439
BCSNIHostName sniHostName = JsseUtils.getSNIHostName(sslSession.getRequestedServerNames());

0 commit comments

Comments
 (0)