Skip to content

Commit 8c33581

Browse files
committed
backport 7da91533aaf2033cedee6e2a56fb693f26909df5
1 parent 9dee91e commit 8c33581

2 files changed

Lines changed: 388 additions & 2 deletions

File tree

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, 2021, 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
@@ -47,6 +47,7 @@
4747
import javax.security.auth.x500.X500Principal;
4848

4949
import javax.net.ssl.*;
50+
import sun.net.util.IPAddressUtil;
5051
import sun.net.www.http.HttpClient;
5152
import sun.net.www.protocol.http.AuthenticatorKeys;
5253
import sun.net.www.protocol.http.HttpURLConnection;
@@ -577,7 +578,13 @@ public void afterConnect() throws IOException, UnknownHostException {
577578
SSLParameters paramaters = s.getSSLParameters();
578579
paramaters.setEndpointIdentificationAlgorithm("HTTPS");
579580
// host has been set previously for SSLSocketImpl
580-
if (!(s instanceof SSLSocketImpl)) {
581+
if (!(s instanceof SSLSocketImpl)&&
582+
!IPAddressUtil.isIPv4LiteralAddress(host) &&
583+
!(host.charAt(0) == '[' && host.charAt(host.length() - 1) == ']' &&
584+
IPAddressUtil.isIPv6LiteralAddress(host.substring(1, host.length() - 1))
585+
)) {
586+
// Fully qualified DNS hostname of the server, as per section 3, RFC 6066
587+
// Literal IPv4 and IPv6 addresses are not permitted in "HostName".
581588
paramaters.setServerNames(List.of(new SNIHostName(host)));
582589
}
583590
s.setSSLParameters(paramaters);

0 commit comments

Comments
 (0)