2141 // hostname or IP address instead.
2142
2143 // Get the original hostname via jdk.internal.misc.SharedSecrets
2144 InetAddress inetAddress = getInetAddress();
2145 if (inetAddress == null) { // not connected
2146 return;
2147 }
2148
2149 JavaNetInetAddressAccess jna =
2150 SharedSecrets.getJavaNetInetAddressAccess();
2151 String originalHostname = jna.getOriginalHostName(inetAddress);
2152 if ((originalHostname != null) &&
2153 (originalHostname.length() != 0)) {
2154
2155 host = originalHostname;
2156 if (!noSniUpdate && serverNames.isEmpty() && !noSniExtension) {
2157 serverNames =
2158 Utilities.addToSNIServerNameList(serverNames, host);
2159
2160 if (!roleIsServer &&
2161 (handshaker != null) && !handshaker.started()) {
2162 handshaker.setSNIServerNames(serverNames);
2163 }
2164 }
2165
2166 return;
2167 }
2168
2169 // No explicitly specified hostname, no server name indication.
2170 if (!trustNameService) {
2171 // The local name service is not trustworthy, use IP address.
2172 host = inetAddress.getHostAddress();
2173 } else {
2174 // Use the underlying reverse host name resolution service.
2175 host = getInetAddress().getHostName();
2176 }
2177 }
2178
2179 // ONLY used by HttpsClient to setup the URI specified hostname
2180 //
2181 // Please NOTE that this method MUST be called before calling to
2182 // SSLSocket.setSSLParameters(). Otherwise, the {@code host} parameter
2183 // may override SNIHostName in the customized server name indication.
2184 public synchronized void setHost(String host) {
2185 this.host = host;
2186 this.serverNames =
2187 Utilities.addToSNIServerNameList(this.serverNames, this.host);
2188
2189 if (!roleIsServer && (handshaker != null) && !handshaker.started()) {
2190 handshaker.setSNIServerNames(serverNames);
2191 }
2192 }
2193
2194 /**
2195 * Gets an input stream to read from the peer on the other side.
2196 * Data read from this stream was always integrity protected in
2197 * transit, and will usually have been confidentiality protected.
2198 */
2199 @Override
2200 public synchronized InputStream getInputStream() throws IOException {
2201 if (isClosed()) {
2202 throw new SocketException("Socket is closed");
2203 }
2204
2205 /*
2206 * Can't call isConnected() here, because the Handshakers
2207 * do some initialization before we actually connect.
2208 */
2209 if (connectionState == cs_START) {
2621 outputRecord.changePacketSize(maximumPacketSize);
2622 } else {
2623 // use the implicit maximum packet size.
2624 maximumPacketSize = outputRecord.getMaxPacketSize();
2625 }
2626
2627 List<SNIServerName> sniNames = params.getServerNames();
2628 if (sniNames != null) {
2629 noSniExtension = sniNames.isEmpty();
2630 serverNames = sniNames;
2631 }
2632
2633 Collection<SNIMatcher> matchers = params.getSNIMatchers();
2634 if (matchers != null) {
2635 noSniMatcher = matchers.isEmpty();
2636 sniMatchers = matchers;
2637 }
2638
2639 applicationProtocols = params.getApplicationProtocols();
2640
2641 if ((handshaker != null) && !handshaker.started()) {
2642 handshaker.setIdentificationProtocol(identificationProtocol);
2643 handshaker.setAlgorithmConstraints(algorithmConstraints);
2644 handshaker.setMaximumPacketSize(maximumPacketSize);
2645 handshaker.setApplicationProtocols(applicationProtocols);
2646 if (roleIsServer) {
2647 handshaker.setSNIMatchers(sniMatchers);
2648 handshaker.setUseCipherSuitesOrder(preferLocalCipherSuites);
2649 } else {
2650 handshaker.setSNIServerNames(serverNames);
2651 }
2652 }
2653 }
2654
2655 @Override
2656 public synchronized String getApplicationProtocol() {
2657 return applicationProtocol;
2658 }
2659
2660 @Override
2661 public synchronized String getHandshakeApplicationProtocol() {
|
2141 // hostname or IP address instead.
2142
2143 // Get the original hostname via jdk.internal.misc.SharedSecrets
2144 InetAddress inetAddress = getInetAddress();
2145 if (inetAddress == null) { // not connected
2146 return;
2147 }
2148
2149 JavaNetInetAddressAccess jna =
2150 SharedSecrets.getJavaNetInetAddressAccess();
2151 String originalHostname = jna.getOriginalHostName(inetAddress);
2152 if ((originalHostname != null) &&
2153 (originalHostname.length() != 0)) {
2154
2155 host = originalHostname;
2156 if (!noSniUpdate && serverNames.isEmpty() && !noSniExtension) {
2157 serverNames =
2158 Utilities.addToSNIServerNameList(serverNames, host);
2159
2160 if (!roleIsServer &&
2161 (handshaker != null) && !handshaker.activated()) {
2162 handshaker.setSNIServerNames(serverNames);
2163 }
2164 }
2165
2166 return;
2167 }
2168
2169 // No explicitly specified hostname, no server name indication.
2170 if (!trustNameService) {
2171 // The local name service is not trustworthy, use IP address.
2172 host = inetAddress.getHostAddress();
2173 } else {
2174 // Use the underlying reverse host name resolution service.
2175 host = getInetAddress().getHostName();
2176 }
2177 }
2178
2179 // ONLY used by HttpsClient to setup the URI specified hostname
2180 //
2181 // Please NOTE that this method MUST be called before calling to
2182 // SSLSocket.setSSLParameters(). Otherwise, the {@code host} parameter
2183 // may override SNIHostName in the customized server name indication.
2184 public synchronized void setHost(String host) {
2185 this.host = host;
2186 this.serverNames =
2187 Utilities.addToSNIServerNameList(this.serverNames, this.host);
2188
2189 if (!roleIsServer && (handshaker != null) && !handshaker.activated()) {
2190 handshaker.setSNIServerNames(serverNames);
2191 }
2192 }
2193
2194 /**
2195 * Gets an input stream to read from the peer on the other side.
2196 * Data read from this stream was always integrity protected in
2197 * transit, and will usually have been confidentiality protected.
2198 */
2199 @Override
2200 public synchronized InputStream getInputStream() throws IOException {
2201 if (isClosed()) {
2202 throw new SocketException("Socket is closed");
2203 }
2204
2205 /*
2206 * Can't call isConnected() here, because the Handshakers
2207 * do some initialization before we actually connect.
2208 */
2209 if (connectionState == cs_START) {
2621 outputRecord.changePacketSize(maximumPacketSize);
2622 } else {
2623 // use the implicit maximum packet size.
2624 maximumPacketSize = outputRecord.getMaxPacketSize();
2625 }
2626
2627 List<SNIServerName> sniNames = params.getServerNames();
2628 if (sniNames != null) {
2629 noSniExtension = sniNames.isEmpty();
2630 serverNames = sniNames;
2631 }
2632
2633 Collection<SNIMatcher> matchers = params.getSNIMatchers();
2634 if (matchers != null) {
2635 noSniMatcher = matchers.isEmpty();
2636 sniMatchers = matchers;
2637 }
2638
2639 applicationProtocols = params.getApplicationProtocols();
2640
2641 if ((handshaker != null) && !handshaker.activated()) {
2642 handshaker.setIdentificationProtocol(identificationProtocol);
2643 handshaker.setAlgorithmConstraints(algorithmConstraints);
2644 handshaker.setMaximumPacketSize(maximumPacketSize);
2645 handshaker.setApplicationProtocols(applicationProtocols);
2646 if (roleIsServer) {
2647 handshaker.setSNIMatchers(sniMatchers);
2648 handshaker.setUseCipherSuitesOrder(preferLocalCipherSuites);
2649 } else {
2650 handshaker.setSNIServerNames(serverNames);
2651 }
2652 }
2653 }
2654
2655 @Override
2656 public synchronized String getApplicationProtocol() {
2657 return applicationProtocol;
2658 }
2659
2660 @Override
2661 public synchronized String getHandshakeApplicationProtocol() {
|