Skip to content

Commit 7da9153

Browse files
serchermyankelev
authored andcommitted
8369950: TLS connection to IPv6 address fails with BCJSSE due to IllegalArgumentException
Co-authored-by: Mikhail Yankelevich <myankelevich@openjdk.org> Reviewed-by: djelinski, vyazici, dfuchs, myankelevich
1 parent 5f083ab commit 7da9153

File tree

2 files changed

+388
-2
lines changed

2 files changed

+388
-2
lines changed

src/java.base/share/classes/sun/net/www/protocol/https/HttpsClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,7 @@
4444
import java.util.StringTokenizer;
4545

4646
import javax.net.ssl.*;
47+
import sun.net.util.IPAddressUtil;
4748
import sun.net.www.http.HttpClient;
4849
import sun.net.www.protocol.http.AuthCacheImpl;
4950
import sun.net.www.protocol.http.HttpURLConnection;
@@ -471,7 +472,13 @@ public void afterConnect() throws IOException, UnknownHostException {
471472
SSLParameters parameters = s.getSSLParameters();
472473
parameters.setEndpointIdentificationAlgorithm("HTTPS");
473474
// host has been set previously for SSLSocketImpl
474-
if (!(s instanceof SSLSocketImpl)) {
475+
if (!(s instanceof SSLSocketImpl) &&
476+
!IPAddressUtil.isIPv4LiteralAddress(host) &&
477+
!(host.charAt(0) == '[' && host.charAt(host.length() - 1) == ']' &&
478+
IPAddressUtil.isIPv6LiteralAddress(host.substring(1, host.length() - 1))
479+
)) {
480+
// Fully qualified DNS hostname of the server, as per section 3, RFC 6066
481+
// Literal IPv4 and IPv6 addresses are not permitted in "HostName".
475482
parameters.setServerNames(List.of(new SNIHostName(host)));
476483
}
477484
s.setSSLParameters(parameters);

0 commit comments

Comments
 (0)