25 |
25 |
26 package jdk.internal.net.http; |
26 package jdk.internal.net.http; |
27 |
27 |
28 import java.net.InetSocketAddress; |
28 import java.net.InetSocketAddress; |
29 import java.util.Arrays; |
29 import java.util.Arrays; |
|
30 import java.util.ArrayDeque; |
30 import java.util.List; |
31 import java.util.List; |
31 import java.util.concurrent.CompletableFuture; |
32 import java.util.concurrent.CompletableFuture; |
32 import javax.net.ssl.SNIHostName; |
33 import javax.net.ssl.SNIHostName; |
33 import javax.net.ssl.SSLContext; |
34 import javax.net.ssl.SSLContext; |
34 import javax.net.ssl.SSLEngine; |
35 import javax.net.ssl.SSLEngine; |
87 return getConnectionFlow().getALPN(); |
88 return getConnectionFlow().getALPN(); |
88 } |
89 } |
89 |
90 |
90 final SSLEngine getEngine() { return engine; } |
91 final SSLEngine getEngine() { return engine; } |
91 |
92 |
|
93 private static boolean contains(String[] rr, String target) { |
|
94 for (String s : rr) |
|
95 if (target.equalsIgnoreCase(s)) |
|
96 return true; |
|
97 return false; |
|
98 } |
|
99 |
92 private static SSLParameters createSSLParameters(HttpClientImpl client, |
100 private static SSLParameters createSSLParameters(HttpClientImpl client, |
93 ServerName serverName, |
101 ServerName serverName, |
94 String[] alpn) { |
102 String[] alpn) { |
95 SSLParameters sslp = client.sslParameters(); |
103 SSLParameters sslp = client.sslParameters(); |
96 SSLParameters sslParameters = Utils.copySSLParameters(sslp); |
104 SSLParameters sslParameters = Utils.copySSLParameters(sslp); |
|
105 // filter out unwanted protocols, if h2 only |
|
106 if (alpn != null && alpn.length != 0 && !contains(alpn, "http/1.1")) { |
|
107 ArrayDeque<String> l = new ArrayDeque<>(); |
|
108 for (String proto : sslParameters.getProtocols()) { |
|
109 if (!proto.startsWith("SSL") && !proto.endsWith("v1.1") && !proto.endsWith("v1")) { |
|
110 l.add(proto); |
|
111 } |
|
112 } |
|
113 String[] a1 = l.toArray(new String[0]); |
|
114 sslParameters.setProtocols(a1); |
|
115 } |
|
116 |
97 if (!disableHostnameVerification) |
117 if (!disableHostnameVerification) |
98 sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); |
118 sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); |
99 if (alpn != null) { |
119 if (alpn != null) { |
100 Log.logSSL("AbstractAsyncSSLConnection: Setting application protocols: {0}", |
120 Log.logSSL("AbstractAsyncSSLConnection: Setting application protocols: {0}", |
101 Arrays.toString(alpn)); |
121 Arrays.toString(alpn)); |
110 } |
130 } |
111 } |
131 } |
112 return sslParameters; |
132 return sslParameters; |
113 } |
133 } |
114 |
134 |
|
135 |
115 private static SSLEngine createEngine(SSLContext context, String serverName, int port, |
136 private static SSLEngine createEngine(SSLContext context, String serverName, int port, |
116 SSLParameters sslParameters) { |
137 SSLParameters sslParameters) { |
117 SSLEngine engine = context.createSSLEngine(serverName, port); |
138 SSLEngine engine = context.createSSLEngine(serverName, port); |
118 engine.setUseClientMode(true); |
139 engine.setUseClientMode(true); |
|
140 |
119 engine.setSSLParameters(sslParameters); |
141 engine.setSSLParameters(sslParameters); |
120 return engine; |
142 return engine; |
121 } |
143 } |
122 |
144 |
123 @Override |
145 @Override |