author | apetcher |
Tue, 22 May 2018 14:12:14 -0400 | |
branch | JDK-8171279-XDH-TLS-branch |
changeset 56591 | 35891b3c2e28 |
parent 56589 | bafd8be2f970 |
child 56855 | ee6aa4c74a4b |
permissions | -rw-r--r-- |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
1 |
/* |
56542 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
4 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
10 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
15 |
* accompanied this code). |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
16 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
20 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
23 |
* questions. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
24 |
*/ |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
25 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
26 |
package sun.security.ssl; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
27 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
28 |
import java.io.IOException; |
56542 | 29 |
import java.nio.ByteBuffer; |
30 |
import java.security.AccessController; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
31 |
import java.security.AlgorithmConstraints; |
56542 | 32 |
import java.security.AlgorithmParameters; |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
33 |
import java.security.CryptoPrimitive; |
56542 | 34 |
import java.security.NoSuchAlgorithmException; |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
35 |
import java.security.spec.AlgorithmParameterSpec; |
56542 | 36 |
import java.security.spec.ECGenParameterSpec; |
37 |
import java.security.spec.ECParameterSpec; |
|
38 |
import java.security.spec.InvalidParameterSpecException; |
|
56589
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
39 |
import java.security.spec.NamedParameterSpec; |
56542 | 40 |
import java.text.MessageFormat; |
41 |
import java.util.ArrayList; |
|
42 |
import java.util.Collections; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
43 |
import java.util.EnumSet; |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
44 |
import java.util.HashMap; |
56542 | 45 |
import java.util.LinkedList; |
46 |
import java.util.List; |
|
47 |
import java.util.Locale; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
48 |
import java.util.Map; |
56542 | 49 |
import javax.crypto.spec.DHParameterSpec; |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
50 |
import javax.net.ssl.SSLProtocolException; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
51 |
import sun.security.action.GetPropertyAction; |
56542 | 52 |
import static sun.security.ssl.SSLExtension.CH_SUPPORTED_GROUPS; |
53 |
import static sun.security.ssl.SSLExtension.EE_SUPPORTED_GROUPS; |
|
54 |
import sun.security.ssl.SSLExtension.ExtensionConsumer; |
|
55 |
import sun.security.ssl.SSLExtension.SSLExtensionSpec; |
|
56 |
import sun.security.ssl.SSLHandshake.HandshakeMessage; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
57 |
|
56542 | 58 |
/** |
59 |
* Pack of the "supported_groups" extensions [RFC 4492/7919]. |
|
60 |
*/ |
|
61 |
final class SupportedGroupsExtension { |
|
62 |
static final HandshakeProducer chNetworkProducer = |
|
63 |
new CHSupportedGroupsProducer(); |
|
64 |
static final ExtensionConsumer chOnLoadConcumer = |
|
65 |
new CHSupportedGroupsConsumer(); |
|
66 |
static final SSLStringize sgsStringize = |
|
67 |
new SupportedGroupsStringize(); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
68 |
|
56542 | 69 |
static final HandshakeProducer eeNetworkProducer = |
70 |
new EESupportedGroupsProducer(); |
|
71 |
static final ExtensionConsumer eeOnLoadConcumer = |
|
72 |
new EESupportedGroupsConsumer(); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
73 |
|
56542 | 74 |
/** |
75 |
* The "supported_groups" extension. |
|
76 |
*/ |
|
77 |
static final class SupportedGroupsSpec implements SSLExtensionSpec { |
|
78 |
final int[] namedGroupsIds; |
|
79 |
||
80 |
private SupportedGroupsSpec(int[] namedGroupsIds) { |
|
81 |
this.namedGroupsIds = namedGroupsIds; |
|
82 |
} |
|
83 |
||
84 |
private SupportedGroupsSpec(List<NamedGroup> namedGroups) { |
|
85 |
this.namedGroupsIds = new int[namedGroups.size()]; |
|
86 |
int i = 0; |
|
87 |
for (NamedGroup ng : namedGroups) { |
|
88 |
namedGroupsIds[i++] = ng.id; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
89 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
90 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
91 |
|
56542 | 92 |
private SupportedGroupsSpec(ByteBuffer m) throws IOException { |
93 |
if (m.remaining() < 2) { // 2: the length of the list |
|
94 |
throw new SSLProtocolException( |
|
95 |
"Invalid supported_groups extension: insufficient data"); |
|
96 |
} |
|
97 |
||
98 |
byte[] ngs = Record.getBytes16(m); |
|
99 |
if (m.hasRemaining()) { |
|
100 |
throw new SSLProtocolException( |
|
101 |
"Invalid supported_groups extension: unknown extra data"); |
|
102 |
} |
|
103 |
||
104 |
if ((ngs == null) || (ngs.length == 0) || (ngs.length % 2 != 0)) { |
|
105 |
throw new SSLProtocolException( |
|
106 |
"Invalid supported_groups extension: incomplete data"); |
|
107 |
} |
|
108 |
||
109 |
int[] ids = new int[ngs.length / 2]; |
|
110 |
for (int i = 0, j = 0; i < ngs.length;) { |
|
111 |
ids[j++] = ((ngs[i++] & 0xFF) << 8) | (ngs[i++] & 0xFF); |
|
112 |
} |
|
113 |
||
114 |
this.namedGroupsIds = ids; |
|
115 |
} |
|
116 |
||
117 |
@Override |
|
118 |
public String toString() { |
|
119 |
MessageFormat messageFormat = new MessageFormat( |
|
120 |
"\"versions\": '['{0}']'", Locale.ENGLISH); |
|
121 |
||
122 |
if (namedGroupsIds == null || namedGroupsIds.length == 0) { |
|
123 |
Object[] messageFields = { |
|
124 |
"<no supported named group specified>" |
|
125 |
}; |
|
126 |
return messageFormat.format(messageFields); |
|
127 |
} else { |
|
128 |
StringBuilder builder = new StringBuilder(512); |
|
129 |
boolean isFirst = true; |
|
130 |
for (int ngid : namedGroupsIds) { |
|
131 |
if (isFirst) { |
|
132 |
isFirst = false; |
|
133 |
} else { |
|
134 |
builder.append(", "); |
|
135 |
} |
|
136 |
||
137 |
builder.append(NamedGroup.nameOf(ngid)); |
|
138 |
} |
|
139 |
||
140 |
Object[] messageFields = { |
|
141 |
builder.toString() |
|
142 |
}; |
|
143 |
||
144 |
return messageFormat.format(messageFields); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
private static final |
|
150 |
class SupportedGroupsStringize implements SSLStringize { |
|
151 |
@Override |
|
152 |
public String toString(ByteBuffer buffer) { |
|
153 |
try { |
|
154 |
return (new SupportedGroupsSpec(buffer)).toString(); |
|
155 |
} catch (IOException ioe) { |
|
156 |
// For debug logging only, so please swallow exceptions. |
|
157 |
return ioe.getMessage(); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
static enum NamedGroupType { |
|
163 |
NAMED_GROUP_ECDHE, // Elliptic Curve Groups (ECDHE) |
|
164 |
NAMED_GROUP_FFDHE, // Finite Field Groups (DHE) |
|
165 |
NAMED_GROUP_XDH, // Finite Field Groups (XDH) |
|
166 |
NAMED_GROUP_ARBITRARY, // arbitrary prime and curves (ECDHE) |
|
167 |
NAMED_GROUP_NONE; // Not predefined named group |
|
168 |
||
169 |
boolean isSupported(List<CipherSuite> cipherSuites) { |
|
170 |
for (CipherSuite cs : cipherSuites) { |
|
171 |
if (cs.keyExchange == null || cs.keyExchange.groupType == this) { |
|
172 |
return true; |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
return false; |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
static enum NamedGroup { |
|
181 |
// Elliptic Curves (RFC 4492) |
|
182 |
// |
|
183 |
// See sun.security.util.CurveDB for the OIDs |
|
184 |
// NIST K-163 |
|
185 |
SECT163_K1 (0x0001, "sect163k1", "1.3.132.0.1", true, |
|
186 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
187 |
SECT163_R1 (0x0002, "sect163r1", "1.3.132.0.2", false, |
|
188 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
189 |
||
190 |
// NIST B-163 |
|
191 |
SECT163_R2 (0x0003, "sect163r2", "1.3.132.0.15", true, |
|
192 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
193 |
SECT193_R1 (0x0004, "sect193r1", "1.3.132.0.24", false, |
|
194 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
195 |
SECT193_R2 (0x0005, "sect193r2", "1.3.132.0.25", false, |
|
196 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
197 |
||
198 |
// NIST K-233 |
|
199 |
SECT233_K1 (0x0006, "sect233k1", "1.3.132.0.26", true, |
|
200 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
201 |
||
202 |
// NIST B-233 |
|
203 |
SECT233_R1 (0x0007, "sect233r1", "1.3.132.0.27", true, |
|
204 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
205 |
SECT239_K1 (0x0008, "sect239k1", "1.3.132.0.3", false, |
|
206 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
207 |
||
208 |
// NIST K-283 |
|
209 |
SECT283_K1 (0x0009, "sect283k1", "1.3.132.0.16", true, |
|
210 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
211 |
||
212 |
// NIST B-283 |
|
213 |
SECT283_R1 (0x000A, "sect283r1", "1.3.132.0.17", true, |
|
214 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
215 |
||
216 |
// NIST K-409 |
|
217 |
SECT409_K1 (0x000B, "sect409k1", "1.3.132.0.36", true, |
|
218 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
219 |
||
220 |
// NIST B-409 |
|
221 |
SECT409_R1 (0x000C, "sect409r1", "1.3.132.0.37", true, |
|
222 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
223 |
||
224 |
// NIST K-571 |
|
225 |
SECT571_K1 (0x000D, "sect571k1", "1.3.132.0.38", true, |
|
226 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
227 |
||
228 |
// NIST B-571 |
|
229 |
SECT571_R1 (0x000E, "sect571r1", "1.3.132.0.39", true, |
|
230 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
231 |
SECP160_K1 (0x000F, "secp160k1", "1.3.132.0.9", false, |
|
232 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
233 |
SECP160_R1 (0x0010, "secp160r1", "1.3.132.0.8", false, |
|
234 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
235 |
SECP160_R2 (0x0011, "secp160r2", "1.3.132.0.30", false, |
|
236 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
237 |
SECP192_K1 (0x0012, "secp192k1", "1.3.132.0.31", false, |
|
238 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
239 |
||
240 |
// NIST P-192 |
|
241 |
SECP192_R1 (0x0013, "secp192r1", "1.2.840.10045.3.1.1", true, |
|
242 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
243 |
SECP224_K1 (0x0014, "secp224k1", "1.3.132.0.32", false, |
|
244 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
245 |
// NIST P-224 |
|
246 |
SECP224_R1 (0x0015, "secp224r1", "1.3.132.0.33", true, |
|
247 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
248 |
SECP256_K1 (0x0016, "secp256k1", "1.3.132.0.10", false, |
|
249 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
250 |
||
251 |
// NIST P-256 |
|
252 |
SECP256_R1 (0x0017, "secp256r1", "1.2.840.10045.3.1.7", true, |
|
253 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
254 |
||
255 |
// NIST P-384 |
|
256 |
SECP384_R1 (0x0018, "secp384r1", "1.3.132.0.34", true, |
|
257 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
258 |
||
259 |
// NIST P-521 |
|
260 |
SECP521_R1 (0x0019, "secp521r1", "1.3.132.0.35", true, |
|
261 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
262 |
||
263 |
// x25519 and x448 |
|
264 |
X25519 (0x001D, "x25519", true, "x25519", |
|
56591 | 265 |
ProtocolVersion.PROTOCOLS_OF_13), |
56542 | 266 |
X448 (0x001E, "x448", true, "x448", |
56591 | 267 |
ProtocolVersion.PROTOCOLS_OF_13), |
56542 | 268 |
|
269 |
// Finite Field Diffie-Hellman Ephemeral Parameters (RFC 7919) |
|
270 |
FFDHE_2048 (0x0100, "ffdhe2048", true, |
|
271 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
272 |
FFDHE_3072 (0x0101, "ffdhe3072", true, |
|
273 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
274 |
FFDHE_4096 (0x0102, "ffdhe4096", true, |
|
275 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
276 |
FFDHE_6144 (0x0103, "ffdhe6144", true, |
|
277 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
278 |
FFDHE_8192 (0x0104, "ffdhe8192", true, |
|
279 |
ProtocolVersion.PROTOCOLS_TO_13), |
|
280 |
||
281 |
// Elliptic Curves (RFC 4492) |
|
282 |
// |
|
283 |
// arbitrary prime and characteristic-2 curves |
|
284 |
ARBITRARY_PRIME (0xFF01, "arbitrary_explicit_prime_curves", |
|
285 |
ProtocolVersion.PROTOCOLS_TO_12), |
|
286 |
ARBITRARY_CHAR2 (0xFF02, "arbitrary_explicit_char2_curves", |
|
287 |
ProtocolVersion.PROTOCOLS_TO_12); |
|
288 |
||
289 |
final int id; // hash + signature |
|
290 |
final NamedGroupType type; // group type |
|
291 |
final String name; // literal name |
|
292 |
final String oid; // object identifier of the named group |
|
293 |
final String algorithm; // signature algorithm |
|
294 |
final boolean isFips; // can be used in FIPS mode? |
|
295 |
final ProtocolVersion[] supportedProtocols; |
|
296 |
||
297 |
// Constructor used for Elliptic Curve Groups (ECDHE) |
|
298 |
private NamedGroup(int id, String name, String oid, boolean isFips, |
|
299 |
ProtocolVersion[] supportedProtocols) { |
|
300 |
this.id = id; |
|
301 |
this.type = NamedGroupType.NAMED_GROUP_ECDHE; |
|
302 |
this.name = name; |
|
303 |
this.oid = oid; |
|
304 |
this.algorithm = "EC"; |
|
305 |
this.isFips = isFips; |
|
306 |
this.supportedProtocols = supportedProtocols; |
|
307 |
} |
|
308 |
||
309 |
// Constructor used for Elliptic Curve Groups (XDH) |
|
310 |
private NamedGroup(int id, String name, |
|
311 |
boolean isFips, String algorithm, |
|
312 |
ProtocolVersion[] supportedProtocols) { |
|
313 |
this.id = id; |
|
314 |
this.type = NamedGroupType.NAMED_GROUP_XDH; |
|
315 |
this.name = name; |
|
316 |
this.oid = null; |
|
317 |
this.algorithm = algorithm; |
|
318 |
this.isFips = isFips; |
|
319 |
this.supportedProtocols = supportedProtocols; |
|
320 |
} |
|
321 |
||
322 |
// Constructor used for Finite Field Diffie-Hellman Groups (FFDHE) |
|
323 |
private NamedGroup(int id, String name, boolean isFips, |
|
324 |
ProtocolVersion[] supportedProtocols) { |
|
325 |
this.id = id; |
|
326 |
this.type = NamedGroupType.NAMED_GROUP_FFDHE; |
|
327 |
this.name = name; |
|
328 |
this.oid = null; |
|
329 |
this.algorithm = "DiffieHellman"; |
|
330 |
this.isFips = isFips; |
|
331 |
this.supportedProtocols = supportedProtocols; |
|
332 |
} |
|
333 |
||
334 |
// Constructor used for arbitrary prime and curves (ECDHE) |
|
335 |
private NamedGroup(int id, String name, |
|
336 |
ProtocolVersion[] supportedProtocols) { |
|
337 |
this.id = id; |
|
338 |
this.type = NamedGroupType.NAMED_GROUP_ARBITRARY; |
|
339 |
this.name = name; |
|
340 |
this.oid = null; |
|
341 |
this.algorithm = "EC"; |
|
342 |
this.isFips = false; |
|
343 |
this.supportedProtocols = supportedProtocols; |
|
344 |
} |
|
345 |
||
346 |
static NamedGroup valueOf(int id) { |
|
347 |
for (NamedGroup group : NamedGroup.values()) { |
|
348 |
if (group.id == id) { |
|
349 |
return group; |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
return null; |
|
354 |
} |
|
355 |
||
356 |
static NamedGroup valueOf(ECParameterSpec params) { |
|
357 |
String oid = JsseJce.getNamedCurveOid(params); |
|
358 |
if ((oid != null) && (!oid.isEmpty())) { |
|
359 |
for (NamedGroup group : NamedGroup.values()) { |
|
360 |
if ((group.type == NamedGroupType.NAMED_GROUP_ECDHE) && |
|
361 |
oid.equals(group.oid)) { |
|
362 |
return group; |
|
363 |
} |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
364 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
365 |
} |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
366 |
|
56542 | 367 |
return null; |
368 |
} |
|
369 |
||
370 |
static NamedGroup valueOf(DHParameterSpec params) { |
|
371 |
for (Map.Entry<NamedGroup, AlgorithmParameters> me : |
|
372 |
SupportedGroups.namedGroupParams.entrySet()) { |
|
373 |
NamedGroup ng = me.getKey(); |
|
374 |
if (ng.type != NamedGroupType.NAMED_GROUP_FFDHE) { |
|
375 |
continue; |
|
376 |
} |
|
377 |
||
378 |
DHParameterSpec ngParams = null; |
|
379 |
AlgorithmParameters aps = me.getValue(); |
|
380 |
try { |
|
381 |
ngParams = aps.getParameterSpec(DHParameterSpec.class); |
|
382 |
} catch (InvalidParameterSpecException ipse) { |
|
383 |
// should be unlikely |
|
384 |
} |
|
385 |
||
386 |
if (ngParams == null) { |
|
387 |
continue; |
|
388 |
} |
|
389 |
||
390 |
if (ngParams.getP().equals(params.getP()) && |
|
391 |
ngParams.getG().equals(params.getG())) { |
|
392 |
return ng; |
|
393 |
} |
|
43693
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
394 |
} |
56542 | 395 |
|
396 |
return null; |
|
397 |
} |
|
398 |
||
399 |
static NamedGroup nameOf(String name) { |
|
400 |
for (NamedGroup group : NamedGroup.values()) { |
|
401 |
if (group.name.equals(name)) { |
|
402 |
return group; |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
return null; |
|
407 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
408 |
|
56542 | 409 |
static String nameOf(int id) { |
410 |
for (NamedGroup group : NamedGroup.values()) { |
|
411 |
if (group.id == id) { |
|
412 |
return group.name; |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
return "UNDEFINED-NAMED-GROUP(" + id + ")"; |
|
417 |
} |
|
418 |
||
419 |
boolean isAvailable(List<ProtocolVersion> protocolVersions) { |
|
420 |
for (ProtocolVersion pv : supportedProtocols) { |
|
421 |
if (protocolVersions.contains(pv)) { |
|
422 |
return true; |
|
423 |
} |
|
424 |
} |
|
425 |
return false; |
|
426 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
427 |
|
56542 | 428 |
boolean isAvailable(ProtocolVersion protocolVersion) { |
429 |
for (ProtocolVersion pv : supportedProtocols) { |
|
430 |
if (protocolVersion == pv) { |
|
431 |
return true; |
|
432 |
} |
|
433 |
} |
|
434 |
return false; |
|
435 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
436 |
|
56542 | 437 |
boolean isSupported(List<CipherSuite> cipherSuites) { |
438 |
for (CipherSuite cs : cipherSuites) { |
|
439 |
boolean isMatch = isAvailable(cs.supportedProtocols); |
|
440 |
if (isMatch && (cs.keyExchange == null || |
|
441 |
cs.keyExchange.groupType == type)) { |
|
442 |
return true; |
|
443 |
} |
|
444 |
} |
|
445 |
return false; |
|
446 |
} |
|
447 |
||
448 |
// lazy loading of parameters |
|
449 |
AlgorithmParameters getParameters() { |
|
450 |
return SupportedGroups.namedGroupParams.get(this); |
|
451 |
} |
|
452 |
||
453 |
AlgorithmParameterSpec getParameterSpec() { |
|
454 |
if (this.type == NamedGroupType.NAMED_GROUP_ECDHE) { |
|
455 |
return SupportedGroups.getECGenParamSpec(this); |
|
456 |
} else if (this.type == NamedGroupType.NAMED_GROUP_FFDHE) { |
|
457 |
return SupportedGroups.getDHParameterSpec(this); |
|
56589
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
458 |
} else if (this.type == NamedGroupType.NAMED_GROUP_XDH) { |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
459 |
return new NamedParameterSpec(this.algorithm); |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
460 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
461 |
|
56542 | 462 |
return null; |
463 |
} |
|
464 |
} |
|
465 |
||
466 |
static class SupportedGroups { |
|
467 |
// To switch off the supported_groups extension for DHE cipher suite. |
|
468 |
static final boolean enableFFDHE = |
|
469 |
Utilities.getBooleanProperty("jsse.enableFFDHE", true); |
|
470 |
||
471 |
// cache to speed up the parameters construction |
|
472 |
static final Map<NamedGroup, |
|
473 |
AlgorithmParameters> namedGroupParams = new HashMap<>(); |
|
474 |
||
475 |
// the supported named groups |
|
476 |
static final NamedGroup[] supportedNamedGroups; |
|
477 |
||
478 |
static { |
|
479 |
boolean requireFips = SunJSSE.isFIPS(); |
|
480 |
||
481 |
// The value of the System Property defines a list of enabled named |
|
482 |
// groups in preference order, separated with comma. For example: |
|
483 |
// |
|
484 |
// jdk.tls.namedGroups="secp521r1, secp256r1, ffdhe2048" |
|
485 |
// |
|
486 |
// If the System Property is not defined or the value is empty, the |
|
487 |
// default groups and preferences will be used. |
|
488 |
String property = AccessController.doPrivileged( |
|
489 |
new GetPropertyAction("jdk.tls.namedGroups")); |
|
490 |
if (property != null && property.length() != 0) { |
|
491 |
// remove double quote marks from beginning/end of the property |
|
492 |
if (property.length() > 1 && property.charAt(0) == '"' && |
|
493 |
property.charAt(property.length() - 1) == '"') { |
|
494 |
property = property.substring(1, property.length() - 1); |
|
495 |
} |
|
496 |
} |
|
497 |
||
498 |
ArrayList<NamedGroup> groupList; |
|
499 |
if (property != null && property.length() != 0) { |
|
500 |
String[] groups = property.split(","); |
|
501 |
groupList = new ArrayList<>(groups.length); |
|
502 |
for (String group : groups) { |
|
503 |
group = group.trim(); |
|
504 |
if (!group.isEmpty()) { |
|
505 |
NamedGroup namedGroup = NamedGroup.nameOf(group); |
|
506 |
if (namedGroup != null && |
|
507 |
(!requireFips || namedGroup.isFips)) { |
|
508 |
if (isAvailableGroup(namedGroup)) { |
|
509 |
groupList.add(namedGroup); |
|
510 |
} |
|
511 |
} // ignore unknown groups |
|
512 |
} |
|
513 |
} |
|
514 |
||
515 |
if (groupList.isEmpty()) { |
|
516 |
throw new IllegalArgumentException( |
|
517 |
"System property jdk.tls.namedGroups(" + |
|
518 |
property + ") contains no supported named groups"); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
519 |
} |
56542 | 520 |
} else { // default groups |
521 |
NamedGroup[] groups; |
|
522 |
if (requireFips) { |
|
523 |
groups = new NamedGroup[] { |
|
524 |
// only NIST curves in FIPS mode |
|
525 |
NamedGroup.SECP256_R1, |
|
526 |
NamedGroup.SECP384_R1, |
|
527 |
NamedGroup.SECP521_R1, |
|
528 |
NamedGroup.SECT283_K1, |
|
529 |
NamedGroup.SECT283_R1, |
|
530 |
NamedGroup.SECT409_K1, |
|
531 |
NamedGroup.SECT409_R1, |
|
532 |
NamedGroup.SECT571_K1, |
|
533 |
NamedGroup.SECT571_R1, |
|
534 |
||
535 |
// FFDHE 2048 |
|
536 |
NamedGroup.FFDHE_2048, |
|
537 |
NamedGroup.FFDHE_3072, |
|
538 |
NamedGroup.FFDHE_4096, |
|
539 |
NamedGroup.FFDHE_6144, |
|
540 |
NamedGroup.FFDHE_8192, |
|
541 |
}; |
|
542 |
} else { |
|
543 |
groups = new NamedGroup[] { |
|
544 |
// NIST curves first |
|
545 |
NamedGroup.SECP256_R1, |
|
546 |
NamedGroup.SECP384_R1, |
|
547 |
NamedGroup.SECP521_R1, |
|
548 |
NamedGroup.SECT283_K1, |
|
549 |
NamedGroup.SECT283_R1, |
|
550 |
NamedGroup.SECT409_K1, |
|
551 |
NamedGroup.SECT409_R1, |
|
552 |
NamedGroup.SECT571_K1, |
|
553 |
NamedGroup.SECT571_R1, |
|
554 |
||
555 |
// non-NIST curves |
|
556 |
NamedGroup.SECP256_K1, |
|
557 |
||
56589
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
558 |
// XDH |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
559 |
NamedGroup.X25519, |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
560 |
NamedGroup.X448, |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
561 |
|
56542 | 562 |
// FFDHE 2048 |
563 |
NamedGroup.FFDHE_2048, |
|
564 |
NamedGroup.FFDHE_3072, |
|
565 |
NamedGroup.FFDHE_4096, |
|
566 |
NamedGroup.FFDHE_6144, |
|
567 |
NamedGroup.FFDHE_8192, |
|
568 |
}; |
|
569 |
} |
|
570 |
||
571 |
groupList = new ArrayList<>(groups.length); |
|
572 |
for (NamedGroup group : groups) { |
|
573 |
if (isAvailableGroup(group)) { |
|
574 |
groupList.add(group); |
|
575 |
} |
|
576 |
} |
|
577 |
||
578 |
if (groupList.isEmpty() && |
|
579 |
SSLLogger.isOn && SSLLogger.isOn("ssl")) { |
|
580 |
SSLLogger.warning("No default named groups"); |
|
581 |
} |
|
582 |
} |
|
583 |
||
584 |
supportedNamedGroups = new NamedGroup[groupList.size()]; |
|
585 |
int i = 0; |
|
586 |
for (NamedGroup namedGroup : groupList) { |
|
587 |
supportedNamedGroups[i++] = namedGroup; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
588 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
589 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
590 |
|
56542 | 591 |
// check whether the group is supported by the underlying providers |
592 |
private static boolean isAvailableGroup(NamedGroup namedGroup) { |
|
593 |
AlgorithmParameters params = null; |
|
594 |
AlgorithmParameterSpec spec = null; |
|
595 |
if (namedGroup.type == NamedGroupType.NAMED_GROUP_ECDHE) { |
|
596 |
if (namedGroup.oid != null) { |
|
597 |
try { |
|
598 |
params = JsseJce.getAlgorithmParameters("EC"); |
|
599 |
spec = new ECGenParameterSpec(namedGroup.oid); |
|
600 |
} catch (NoSuchAlgorithmException e) { |
|
601 |
return false; |
|
602 |
} |
|
603 |
} |
|
604 |
} else if (namedGroup.type == NamedGroupType.NAMED_GROUP_FFDHE) { |
|
605 |
try { |
|
606 |
params = JsseJce.getAlgorithmParameters("DiffieHellman"); |
|
607 |
spec = getFFDHEDHParameterSpec(namedGroup); |
|
608 |
} catch (NoSuchAlgorithmException e) { |
|
609 |
return false; |
|
610 |
} |
|
56589
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
611 |
} else if (namedGroup.type == NamedGroupType.NAMED_GROUP_XDH) { |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
612 |
try { |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
613 |
JsseJce.getKeyAgreement(namedGroup.algorithm); |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
614 |
// no parameters |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
615 |
return true; |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
616 |
} catch (NoSuchAlgorithmException e) { |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
617 |
return false; |
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
618 |
} |
56542 | 619 |
} // Otherwise, unsupported. |
620 |
||
621 |
if ((params != null) && (spec != null)) { |
|
622 |
try { |
|
623 |
params.init(spec); |
|
624 |
} catch (InvalidParameterSpecException e) { |
|
625 |
return false; |
|
626 |
} |
|
627 |
||
628 |
// cache the parameters |
|
629 |
namedGroupParams.put(namedGroup, params); |
|
630 |
||
631 |
return true; |
|
632 |
} |
|
633 |
||
634 |
return false; |
|
43693
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
635 |
} |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
636 |
|
56542 | 637 |
private static DHParameterSpec getFFDHEDHParameterSpec( |
638 |
NamedGroup namedGroup) { |
|
639 |
DHParameterSpec spec = null; |
|
640 |
switch (namedGroup) { |
|
641 |
case FFDHE_2048: |
|
642 |
spec = PredefinedDHParameterSpecs.ffdheParams.get(2048); |
|
643 |
break; |
|
644 |
case FFDHE_3072: |
|
645 |
spec = PredefinedDHParameterSpecs.ffdheParams.get(3072); |
|
646 |
break; |
|
647 |
case FFDHE_4096: |
|
648 |
spec = PredefinedDHParameterSpecs.ffdheParams.get(4096); |
|
649 |
break; |
|
650 |
case FFDHE_6144: |
|
651 |
spec = PredefinedDHParameterSpecs.ffdheParams.get(6144); |
|
652 |
break; |
|
653 |
case FFDHE_8192: |
|
654 |
spec = PredefinedDHParameterSpecs.ffdheParams.get(8192); |
|
655 |
} |
|
656 |
||
657 |
return spec; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
658 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
659 |
|
56542 | 660 |
private static DHParameterSpec getPredefinedDHParameterSpec( |
661 |
NamedGroup namedGroup) { |
|
662 |
DHParameterSpec spec = null; |
|
663 |
switch (namedGroup) { |
|
664 |
case FFDHE_2048: |
|
665 |
spec = PredefinedDHParameterSpecs.definedParams.get(2048); |
|
666 |
break; |
|
667 |
case FFDHE_3072: |
|
668 |
spec = PredefinedDHParameterSpecs.definedParams.get(3072); |
|
669 |
break; |
|
670 |
case FFDHE_4096: |
|
671 |
spec = PredefinedDHParameterSpecs.definedParams.get(4096); |
|
672 |
break; |
|
673 |
case FFDHE_6144: |
|
674 |
spec = PredefinedDHParameterSpecs.definedParams.get(6144); |
|
675 |
break; |
|
676 |
case FFDHE_8192: |
|
677 |
spec = PredefinedDHParameterSpecs.definedParams.get(8192); |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
678 |
} |
56542 | 679 |
|
680 |
return spec; |
|
681 |
} |
|
682 |
||
683 |
static ECGenParameterSpec getECGenParamSpec(NamedGroup namedGroup) { |
|
684 |
if (namedGroup.type != NamedGroupType.NAMED_GROUP_ECDHE) { |
|
685 |
throw new RuntimeException( |
|
686 |
"Not a named EC group: " + namedGroup); |
|
687 |
} |
|
688 |
||
689 |
AlgorithmParameters params = namedGroupParams.get(namedGroup); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
690 |
try { |
56542 | 691 |
return params.getParameterSpec(ECGenParameterSpec.class); |
692 |
} catch (InvalidParameterSpecException ipse) { |
|
693 |
// should be unlikely |
|
694 |
return new ECGenParameterSpec(namedGroup.oid); |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
695 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
696 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
697 |
|
56542 | 698 |
static DHParameterSpec getDHParameterSpec(NamedGroup namedGroup) { |
699 |
if (namedGroup.type != NamedGroupType.NAMED_GROUP_FFDHE) { |
|
700 |
throw new RuntimeException( |
|
701 |
"Not a named DH group: " + namedGroup); |
|
702 |
} |
|
703 |
||
704 |
AlgorithmParameters params = namedGroupParams.get(namedGroup); |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
705 |
try { |
56542 | 706 |
return params.getParameterSpec(DHParameterSpec.class); |
707 |
} catch (InvalidParameterSpecException ipse) { |
|
708 |
// should be unlikely |
|
709 |
return getPredefinedDHParameterSpec(namedGroup); |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
// Is there any supported group permitted by the constraints? |
|
714 |
static boolean isActivatable( |
|
715 |
AlgorithmConstraints constraints, NamedGroupType type) { |
|
716 |
||
717 |
boolean hasFFDHEGroups = false; |
|
718 |
for (NamedGroup namedGroup : supportedNamedGroups) { |
|
719 |
if (namedGroup.type == type) { |
|
720 |
if (constraints.permits( |
|
721 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
722 |
namedGroup.algorithm, |
|
723 |
namedGroupParams.get(namedGroup))) { |
|
724 |
||
725 |
return true; |
|
726 |
} |
|
727 |
||
728 |
if (!hasFFDHEGroups && |
|
729 |
(type == NamedGroupType.NAMED_GROUP_FFDHE)) { |
|
730 |
hasFFDHEGroups = true; |
|
731 |
} |
|
732 |
} |
|
733 |
} |
|
734 |
||
735 |
// For compatibility, if no FFDHE groups are defined, the non-FFDHE |
|
736 |
// compatible mode (using DHE cipher suite without FFDHE extension) |
|
737 |
// is allowed. |
|
738 |
// |
|
739 |
// Note that the constraints checking on DHE parameters will be |
|
740 |
// performed during key exchanging in a handshake. |
|
741 |
return !hasFFDHEGroups && type == NamedGroupType.NAMED_GROUP_FFDHE; |
|
742 |
} |
|
743 |
||
744 |
// Is the named group permitted by the constraints? |
|
745 |
static boolean isActivatable( |
|
746 |
AlgorithmConstraints constraints, NamedGroup namedGroup) { |
|
747 |
if (!isSupported(namedGroup)) { |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
748 |
return false; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
749 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
750 |
|
56542 | 751 |
return constraints.permits( |
752 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
753 |
namedGroup.algorithm, |
|
754 |
namedGroupParams.get(namedGroup)); |
|
755 |
} |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
756 |
|
56542 | 757 |
// Is there any supported group permitted by the constraints? |
758 |
static boolean isSupported(NamedGroup namedGroup) { |
|
759 |
for (NamedGroup group : supportedNamedGroups) { |
|
760 |
if (namedGroup.id == group.id) { |
|
761 |
return true; |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
return false; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
766 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
767 |
|
56542 | 768 |
static NamedGroup getPreferredGroup( |
769 |
ProtocolVersion negotiatedProtocol, |
|
770 |
AlgorithmConstraints constraints, NamedGroupType type, |
|
771 |
List<NamedGroup> requestedNamedGroups) { |
|
772 |
for (NamedGroup namedGroup : requestedNamedGroups) { |
|
773 |
if ((namedGroup.type == type) && |
|
774 |
namedGroup.isAvailable(negotiatedProtocol) && |
|
775 |
constraints.permits( |
|
776 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
777 |
namedGroup.algorithm, |
|
778 |
namedGroupParams.get(namedGroup))) { |
|
779 |
return namedGroup; |
|
780 |
} |
|
781 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
782 |
|
56542 | 783 |
return null; |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
784 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
785 |
|
56542 | 786 |
static NamedGroup getPreferredGroup( |
787 |
ProtocolVersion negotiatedProtocol, |
|
788 |
AlgorithmConstraints constraints, NamedGroupType type) { |
|
789 |
for (NamedGroup namedGroup : supportedNamedGroups) { |
|
790 |
if ((namedGroup.type == type) && |
|
791 |
namedGroup.isAvailable(negotiatedProtocol) && |
|
792 |
constraints.permits( |
|
793 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
794 |
namedGroup.algorithm, |
|
795 |
namedGroupParams.get(namedGroup))) { |
|
796 |
return namedGroup; |
|
797 |
} |
|
798 |
} |
|
799 |
||
800 |
return null; |
|
801 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
802 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
803 |
|
56542 | 804 |
/** |
805 |
* Network data producer of a "supported_groups" extension in |
|
806 |
* the ClientHello handshake message. |
|
807 |
*/ |
|
808 |
private static final class CHSupportedGroupsProducer |
|
809 |
extends SupportedGroups implements HandshakeProducer { |
|
810 |
// Prevent instantiation of this class. |
|
811 |
private CHSupportedGroupsProducer() { |
|
812 |
// blank |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
813 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
814 |
|
56542 | 815 |
@Override |
816 |
public byte[] produce(ConnectionContext context, |
|
817 |
HandshakeMessage message) throws IOException { |
|
818 |
// The producing happens in client side only. |
|
819 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
820 |
|
56542 | 821 |
// Is it a supported and enabled extension? |
822 |
if (!chc.sslConfig.isAvailable(CH_SUPPORTED_GROUPS)) { |
|
823 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
824 |
SSLLogger.fine( |
|
825 |
"Ignore unavailable supported_groups extension"); |
|
826 |
} |
|
827 |
return null; |
|
828 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
829 |
|
56542 | 830 |
// Produce the extension. |
831 |
ArrayList<NamedGroup> namedGroups = |
|
832 |
new ArrayList<>(SupportedGroups.supportedNamedGroups.length); |
|
833 |
for (NamedGroup ng : SupportedGroups.supportedNamedGroups) { |
|
834 |
if ((!SupportedGroups.enableFFDHE) && |
|
835 |
(ng.type == NamedGroupType.NAMED_GROUP_FFDHE)) { |
|
836 |
continue; |
|
837 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
838 |
|
56542 | 839 |
if (ng.isAvailable(chc.activeProtocols) && |
840 |
ng.isSupported(chc.activeCipherSuites) && |
|
841 |
chc.algorithmConstraints.permits( |
|
842 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
843 |
ng.algorithm, namedGroupParams.get(ng))) { |
|
844 |
namedGroups.add(ng); |
|
845 |
} else if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
846 |
SSLLogger.fine( |
|
847 |
"Ignore inactive or disabled named group: " + ng.name); |
|
848 |
} |
|
849 |
} |
|
850 |
||
851 |
if (namedGroups.isEmpty()) { |
|
852 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
853 |
SSLLogger.warning("no available named group"); |
|
854 |
} |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
855 |
|
56542 | 856 |
return null; |
857 |
} |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
858 |
|
56542 | 859 |
int vectorLen = namedGroups.size() << 1; |
860 |
byte[] extData = new byte[vectorLen + 2]; |
|
861 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
862 |
Record.putInt16(m, vectorLen); |
|
863 |
for (NamedGroup namedGroup : namedGroups) { |
|
864 |
Record.putInt16(m, namedGroup.id); |
|
865 |
} |
|
866 |
||
867 |
// Update the context. |
|
868 |
chc.clientRequestedNamedGroups = |
|
869 |
Collections.<NamedGroup>unmodifiableList(namedGroups); |
|
870 |
chc.handshakeExtensions.put(CH_SUPPORTED_GROUPS, |
|
871 |
new SupportedGroupsSpec(namedGroups)); |
|
872 |
||
873 |
return extData; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
874 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
875 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
876 |
|
56542 | 877 |
/** |
878 |
* Network data producer of a "supported_groups" extension in |
|
879 |
* the ClientHello handshake message. |
|
880 |
*/ |
|
881 |
private static final |
|
882 |
class CHSupportedGroupsConsumer implements ExtensionConsumer { |
|
883 |
// Prevent instantiation of this class. |
|
884 |
private CHSupportedGroupsConsumer() { |
|
885 |
// blank |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
886 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
887 |
|
56542 | 888 |
@Override |
889 |
public void consume(ConnectionContext context, |
|
890 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
891 |
// The comsuming happens in server side only. |
|
892 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
893 |
|
56542 | 894 |
// Is it a supported and enabled extension? |
895 |
if (!shc.sslConfig.isAvailable(CH_SUPPORTED_GROUPS)) { |
|
896 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
897 |
SSLLogger.fine( |
|
898 |
"Ignore unavailable supported_groups extension"); |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
899 |
} |
56542 | 900 |
return; // ignore the extension |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
901 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
902 |
|
56542 | 903 |
// Parse the extension. |
904 |
SupportedGroupsSpec spec; |
|
905 |
try { |
|
906 |
spec = new SupportedGroupsSpec(buffer); |
|
907 |
} catch (IOException ioe) { |
|
908 |
shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
|
909 |
return; // fatal() always throws, make the compiler happy. |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
910 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
911 |
|
56542 | 912 |
// Update the context. |
913 |
List<NamedGroup> knownNamedGroups = new LinkedList<>(); |
|
914 |
for (int id : spec.namedGroupsIds) { |
|
915 |
NamedGroup ng = NamedGroup.valueOf(id); |
|
916 |
if (ng != null) { |
|
917 |
knownNamedGroups.add(ng); |
|
918 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
919 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
920 |
|
56542 | 921 |
shc.clientRequestedNamedGroups = knownNamedGroups; |
922 |
shc.handshakeExtensions.put(CH_SUPPORTED_GROUPS, spec); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
923 |
|
56542 | 924 |
// No impact on session resumption. |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
925 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
926 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
927 |
|
56542 | 928 |
/** |
929 |
* Network data producer of a "supported_groups" extension in |
|
930 |
* the EncryptedExtensions handshake message. |
|
931 |
*/ |
|
932 |
private static final class EESupportedGroupsProducer |
|
933 |
extends SupportedGroups implements HandshakeProducer { |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
934 |
|
56542 | 935 |
// Prevent instantiation of this class. |
936 |
private EESupportedGroupsProducer() { |
|
937 |
// blank |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
938 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
939 |
|
56542 | 940 |
@Override |
941 |
public byte[] produce(ConnectionContext context, |
|
942 |
HandshakeMessage message) throws IOException { |
|
943 |
// The producing happens in server side only. |
|
944 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
945 |
||
946 |
// Is it a supported and enabled extension? |
|
947 |
if (!shc.sslConfig.isAvailable(EE_SUPPORTED_GROUPS)) { |
|
948 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
949 |
SSLLogger.fine( |
|
950 |
"Ignore unavailable supported_groups extension"); |
|
951 |
} |
|
952 |
return null; |
|
953 |
} |
|
954 |
||
955 |
// Produce the extension. |
|
956 |
// |
|
957 |
// Contains all groups the server supports, regardless of whether |
|
958 |
// they are currently supported by the client. |
|
959 |
ArrayList<NamedGroup> namedGroups = new ArrayList<>( |
|
960 |
SupportedGroups.supportedNamedGroups.length); |
|
961 |
for (NamedGroup ng : SupportedGroups.supportedNamedGroups) { |
|
962 |
if ((!SupportedGroups.enableFFDHE) && |
|
963 |
(ng.type == NamedGroupType.NAMED_GROUP_FFDHE)) { |
|
964 |
continue; |
|
965 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
966 |
|
56542 | 967 |
if (ng.isAvailable(shc.activeProtocols) && |
968 |
ng.isSupported(shc.activeCipherSuites) && |
|
969 |
shc.algorithmConstraints.permits( |
|
970 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
971 |
ng.algorithm, namedGroupParams.get(ng))) { |
|
972 |
namedGroups.add(ng); |
|
973 |
} else if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
974 |
SSLLogger.fine( |
|
975 |
"Ignore inactive or disabled named group: " + ng.name); |
|
976 |
} |
|
977 |
} |
|
978 |
||
979 |
if (namedGroups.isEmpty()) { |
|
980 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
981 |
SSLLogger.warning("no available named group"); |
|
982 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
983 |
|
56542 | 984 |
return null; |
985 |
} |
|
986 |
||
987 |
int vectorLen = namedGroups.size() << 1; |
|
988 |
byte[] extData = new byte[vectorLen + 2]; |
|
989 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
990 |
Record.putInt16(m, vectorLen); |
|
991 |
for (NamedGroup namedGroup : namedGroups) { |
|
992 |
Record.putInt16(m, namedGroup.id); |
|
993 |
} |
|
994 |
||
995 |
// Update the context. |
|
996 |
shc.conContext.serverRequestedNamedGroups = |
|
997 |
Collections.<NamedGroup>unmodifiableList(namedGroups); |
|
998 |
SupportedGroupsSpec spec = new SupportedGroupsSpec(namedGroups); |
|
999 |
shc.handshakeExtensions.put(EE_SUPPORTED_GROUPS, spec); |
|
1000 |
||
1001 |
return extData; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
1002 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
1003 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
1004 |
|
56542 | 1005 |
private static final |
1006 |
class EESupportedGroupsConsumer implements ExtensionConsumer { |
|
1007 |
// Prevent instantiation of this class. |
|
1008 |
private EESupportedGroupsConsumer() { |
|
1009 |
// blank |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
1010 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
1011 |
|
56542 | 1012 |
@Override |
1013 |
public void consume(ConnectionContext context, |
|
1014 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
1015 |
// The comsuming happens in client side only. |
|
1016 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
1017 |
||
1018 |
// Is it a supported and enabled extension? |
|
1019 |
if (!chc.sslConfig.isAvailable(EE_SUPPORTED_GROUPS)) { |
|
1020 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
1021 |
SSLLogger.fine( |
|
1022 |
"Ignore unavailable supported_groups extension"); |
|
1023 |
} |
|
1024 |
return; // ignore the extension |
|
1025 |
} |
|
1026 |
||
1027 |
// Parse the extension. |
|
1028 |
SupportedGroupsSpec spec; |
|
1029 |
try { |
|
1030 |
spec = new SupportedGroupsSpec(buffer); |
|
1031 |
} catch (IOException ioe) { |
|
1032 |
chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
|
1033 |
return; // fatal() always throws, make the compiler happy. |
|
1034 |
} |
|
1035 |
||
1036 |
// Update the context. |
|
1037 |
List<NamedGroup> knownNamedGroups = |
|
1038 |
new ArrayList<>(spec.namedGroupsIds.length); |
|
1039 |
for (int id : spec.namedGroupsIds) { |
|
1040 |
NamedGroup ng = NamedGroup.valueOf(id); |
|
1041 |
if (ng != null) { |
|
1042 |
knownNamedGroups.add(ng); |
|
1043 |
} |
|
1044 |
} |
|
1045 |
||
1046 |
chc.conContext.serverRequestedNamedGroups = knownNamedGroups; |
|
1047 |
chc.handshakeExtensions.put(EE_SUPPORTED_GROUPS, spec); |
|
1048 |
||
1049 |
// No impact on session resumption. |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
1050 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
1051 |
} |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
1052 |
} |