|
1 | 1 | /* |
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. |
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 |
|
44 | 44 | import java.util.StringTokenizer; |
45 | 45 |
|
46 | 46 | import javax.net.ssl.*; |
| 47 | +import sun.net.util.IPAddressUtil; |
47 | 48 | import sun.net.www.http.HttpClient; |
48 | 49 | import sun.net.www.protocol.http.AuthCacheImpl; |
49 | 50 | import sun.net.www.protocol.http.HttpURLConnection; |
@@ -471,7 +472,13 @@ public void afterConnect() throws IOException, UnknownHostException { |
471 | 472 | SSLParameters parameters = s.getSSLParameters(); |
472 | 473 | parameters.setEndpointIdentificationAlgorithm("HTTPS"); |
473 | 474 | // 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". |
475 | 482 | parameters.setServerNames(List.of(new SNIHostName(host))); |
476 | 483 | } |
477 | 484 | s.setSSLParameters(parameters); |
|
0 commit comments