|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
47 | 47 | import javax.security.auth.x500.X500Principal; |
48 | 48 |
|
49 | 49 | import javax.net.ssl.*; |
| 50 | +import sun.net.util.IPAddressUtil; |
50 | 51 | import sun.net.www.http.HttpClient; |
51 | 52 | import sun.net.www.protocol.http.AuthenticatorKeys; |
52 | 53 | import sun.net.www.protocol.http.HttpURLConnection; |
@@ -577,7 +578,13 @@ public void afterConnect() throws IOException, UnknownHostException { |
577 | 578 | SSLParameters paramaters = s.getSSLParameters(); |
578 | 579 | paramaters.setEndpointIdentificationAlgorithm("HTTPS"); |
579 | 580 | // 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". |
581 | 588 | paramaters.setServerNames(List.of(new SNIHostName(host))); |
582 | 589 | } |
583 | 590 | s.setSSLParameters(paramaters); |
|
0 commit comments