author | ascarpino |
Wed, 08 Feb 2017 12:08:28 -0800 | |
changeset 43701 | fe8c324ba97c |
parent 43693 | e340c8d10cbb |
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 |
/* |
43693
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
2 |
* Copyright (c) 2006, 2017, 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; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
29 |
import java.security.spec.ECParameterSpec; |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
30 |
import java.security.spec.ECGenParameterSpec; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
31 |
import java.security.spec.InvalidParameterSpecException; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
32 |
import java.security.AlgorithmParameters; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
33 |
import java.security.AlgorithmConstraints; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
34 |
import java.security.CryptoPrimitive; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
35 |
import java.security.AccessController; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
36 |
import java.util.EnumSet; |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
37 |
import java.util.HashMap; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
38 |
import java.util.Map; |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
39 |
import java.util.ArrayList; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
40 |
import javax.net.ssl.SSLProtocolException; |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
41 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
42 |
import sun.security.action.GetPropertyAction; |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
43 |
|
37814
844e590a011a
8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents:
32649
diff
changeset
|
44 |
final class EllipticCurvesExtension extends HelloExtension { |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
45 |
|
43693
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
46 |
/* Class and subclass dynamic debugging support */ |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
47 |
private static final Debug debug = Debug.getInstance("ssl"); |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
48 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
49 |
private static final int ARBITRARY_PRIME = 0xff01; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
50 |
private static final int ARBITRARY_CHAR2 = 0xff02; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
51 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
52 |
// speed up the searching |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
53 |
private static final Map<String, Integer> oidToIdMap = new HashMap<>(); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
54 |
private static final Map<Integer, String> idToOidMap = new HashMap<>(); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
55 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
56 |
// speed up the parameters construction |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
57 |
private static final Map<Integer, |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
58 |
AlgorithmParameters> idToParams = new HashMap<>(); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
59 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
60 |
// the supported elliptic curves |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
61 |
private static final int[] supportedCurveIds; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
62 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
63 |
// the curves of the extension |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
64 |
private final int[] curveIds; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
65 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
66 |
// See sun.security.util.CurveDB for the OIDs |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
67 |
private static enum NamedEllipticCurve { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
68 |
T163_K1(1, "sect163k1", "1.3.132.0.1", true), // NIST K-163 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
69 |
T163_R1(2, "sect163r1", "1.3.132.0.2", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
70 |
T163_R2(3, "sect163r2", "1.3.132.0.15", true), // NIST B-163 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
71 |
T193_R1(4, "sect193r1", "1.3.132.0.24", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
72 |
T193_R2(5, "sect193r2", "1.3.132.0.25", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
73 |
T233_K1(6, "sect233k1", "1.3.132.0.26", true), // NIST K-233 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
74 |
T233_R1(7, "sect233r1", "1.3.132.0.27", true), // NIST B-233 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
75 |
T239_K1(8, "sect239k1", "1.3.132.0.3", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
76 |
T283_K1(9, "sect283k1", "1.3.132.0.16", true), // NIST K-283 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
77 |
T283_R1(10, "sect283r1", "1.3.132.0.17", true), // NIST B-283 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
78 |
T409_K1(11, "sect409k1", "1.3.132.0.36", true), // NIST K-409 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
79 |
T409_R1(12, "sect409r1", "1.3.132.0.37", true), // NIST B-409 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
80 |
T571_K1(13, "sect571k1", "1.3.132.0.38", true), // NIST K-571 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
81 |
T571_R1(14, "sect571r1", "1.3.132.0.39", true), // NIST B-571 |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
82 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
83 |
P160_K1(15, "secp160k1", "1.3.132.0.9", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
84 |
P160_R1(16, "secp160r1", "1.3.132.0.8", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
85 |
P160_R2(17, "secp160r2", "1.3.132.0.30", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
86 |
P192_K1(18, "secp192k1", "1.3.132.0.31", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
87 |
P192_R1(19, "secp192r1", "1.2.840.10045.3.1.1", true), // NIST P-192 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
88 |
P224_K1(20, "secp224k1", "1.3.132.0.32", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
89 |
P224_R1(21, "secp224r1", "1.3.132.0.33", true), // NIST P-224 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
90 |
P256_K1(22, "secp256k1", "1.3.132.0.10", false), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
91 |
P256_R1(23, "secp256r1", "1.2.840.10045.3.1.7", true), // NIST P-256 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
92 |
P384_R1(24, "secp384r1", "1.3.132.0.34", true), // NIST P-384 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
93 |
P521_R1(25, "secp521r1", "1.3.132.0.35", true); // NIST P-521 |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
94 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
95 |
int id; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
96 |
String name; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
97 |
String oid; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
98 |
boolean isFips; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
99 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
100 |
NamedEllipticCurve(int id, String name, String oid, boolean isFips) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
101 |
this.id = id; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
102 |
this.name = name; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
103 |
this.oid = oid; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
104 |
this.isFips = isFips; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
105 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
106 |
if (oidToIdMap.put(oid, id) != null || |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
107 |
idToOidMap.put(id, oid) != null) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
108 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
109 |
throw new RuntimeException( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
110 |
"Duplicate named elliptic curve definition: " + name); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
111 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
112 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
113 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
114 |
static NamedEllipticCurve getCurve(String name, boolean requireFips) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
115 |
for (NamedEllipticCurve curve : NamedEllipticCurve.values()) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
116 |
if (curve.name.equals(name) && (!requireFips || curve.isFips)) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
117 |
return curve; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
118 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
119 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
120 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
121 |
return null; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
122 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
123 |
} |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
124 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
125 |
static { |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
126 |
boolean requireFips = SunJSSE.isFIPS(); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
127 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
128 |
// hack code to initialize NamedEllipticCurve |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
129 |
NamedEllipticCurve nec = |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
130 |
NamedEllipticCurve.getCurve("secp256r1", false); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
131 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
132 |
// The value of the System Property defines a list of enabled named |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
133 |
// curves in preference order, separated with comma. For example: |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
134 |
// |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
135 |
// jdk.tls.namedGroups="secp521r1, secp256r1, secp384r1" |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
136 |
// |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
137 |
// If the System Property is not defined or the value is empty, the |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
138 |
// default curves and preferences will be used. |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
139 |
String property = AccessController.doPrivileged( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
140 |
new GetPropertyAction("jdk.tls.namedGroups")); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
141 |
if (property != null && property.length() != 0) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
142 |
// remove double quote marks from beginning/end of the property |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
143 |
if (property.length() > 1 && property.charAt(0) == '"' && |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
144 |
property.charAt(property.length() - 1) == '"') { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
145 |
property = property.substring(1, property.length() - 1); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
146 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
147 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
148 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
149 |
ArrayList<Integer> idList; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
150 |
if (property != null && property.length() != 0) { // customized curves |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
151 |
String[] curves = property.split(","); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
152 |
idList = new ArrayList<>(curves.length); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
153 |
for (String curve : curves) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
154 |
curve = curve.trim(); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
155 |
if (!curve.isEmpty()) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
156 |
NamedEllipticCurve namedCurve = |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
157 |
NamedEllipticCurve.getCurve(curve, requireFips); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
158 |
if (namedCurve != null) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
159 |
if (isAvailableCurve(namedCurve.id)) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
160 |
idList.add(namedCurve.id); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
161 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
162 |
} // ignore unknown curves |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
163 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
164 |
} |
43693
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
165 |
if (idList.isEmpty() && JsseJce.isEcAvailable()) { |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
166 |
throw new IllegalArgumentException( |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
167 |
"System property jdk.tls.namedGroups(" + property + ") " + |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
168 |
"contains no supported elliptic curves"); |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
169 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
170 |
} else { // default curves |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
171 |
int[] ids; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
172 |
if (requireFips) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
173 |
ids = new int[] { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
174 |
// only NIST curves in FIPS mode |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
175 |
23, 24, 25, 9, 10, 11, 12, 13, 14, |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
176 |
}; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
177 |
} else { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
178 |
ids = new int[] { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
179 |
// NIST curves first |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
180 |
23, 24, 25, 9, 10, 11, 12, 13, 14, |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
181 |
// non-NIST curves |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
182 |
22, |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
183 |
}; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
184 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
185 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
186 |
idList = new ArrayList<>(ids.length); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
187 |
for (int curveId : ids) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
188 |
if (isAvailableCurve(curveId)) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
189 |
idList.add(curveId); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
190 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
191 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
192 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
193 |
|
43693
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
194 |
if (debug != null && idList.isEmpty()) { |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
195 |
Debug.log( |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
196 |
"Initialized [jdk.tls.namedGroups|default] list contains " + |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
197 |
"no available elliptic curves. " + |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
198 |
(property != null ? "(" + property + ")" : "[Default]")); |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
199 |
} |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
200 |
|
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
201 |
supportedCurveIds = new int[idList.size()]; |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
202 |
int i = 0; |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
203 |
for (Integer id : idList) { |
e340c8d10cbb
8173783: IllegalArgumentException: jdk.tls.namedGroups
coffeys
parents:
41473
diff
changeset
|
204 |
supportedCurveIds[i++] = id; |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
205 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
206 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
207 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
208 |
// check whether the curve is supported by the underlying providers |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
209 |
private static boolean isAvailableCurve(int curveId) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
210 |
String oid = idToOidMap.get(curveId); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
211 |
if (oid != null) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
212 |
AlgorithmParameters params = null; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
213 |
try { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
214 |
params = JsseJce.getAlgorithmParameters("EC"); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
215 |
params.init(new ECGenParameterSpec(oid)); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
216 |
} catch (Exception e) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
217 |
return false; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
218 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
219 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
220 |
// cache the parameters |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
221 |
idToParams.put(curveId, params); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
222 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
223 |
return true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
224 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
225 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
226 |
return false; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
227 |
} |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
228 |
|
37814
844e590a011a
8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents:
32649
diff
changeset
|
229 |
private EllipticCurvesExtension(int[] curveIds) { |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
230 |
super(ExtensionType.EXT_ELLIPTIC_CURVES); |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
231 |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
232 |
this.curveIds = curveIds; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
233 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
234 |
|
37814
844e590a011a
8156502: Use short name of SupportedEllipticCurvesExtension.java
xuelei
parents:
32649
diff
changeset
|
235 |
EllipticCurvesExtension(HandshakeInStream s, int len) |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
236 |
throws IOException { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
237 |
super(ExtensionType.EXT_ELLIPTIC_CURVES); |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
238 |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
239 |
int k = s.getInt16(); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
240 |
if (((len & 1) != 0) || (k + 2 != len)) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
241 |
throw new SSLProtocolException("Invalid " + type + " extension"); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
242 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
243 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
244 |
// Note: unknown curves will be ignored later. |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
245 |
curveIds = new int[k >> 1]; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
246 |
for (int i = 0; i < curveIds.length; i++) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
247 |
curveIds[i] = s.getInt16(); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
248 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
249 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
250 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
251 |
// get the preferred active curve |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
252 |
static int getActiveCurves(AlgorithmConstraints constraints) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
253 |
return getPreferredCurve(supportedCurveIds, constraints); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
254 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
255 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
256 |
static boolean hasActiveCurves(AlgorithmConstraints constraints) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
257 |
return getActiveCurves(constraints) >= 0; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
258 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
259 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
260 |
static EllipticCurvesExtension createExtension( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
261 |
AlgorithmConstraints constraints) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
262 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
263 |
ArrayList<Integer> idList = new ArrayList<>(supportedCurveIds.length); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
264 |
for (int curveId : supportedCurveIds) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
265 |
if (constraints.permits( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
266 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
267 |
"EC", idToParams.get(curveId))) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
268 |
idList.add(curveId); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
269 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
270 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
271 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
272 |
if (!idList.isEmpty()) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
273 |
int[] ids = new int[idList.size()]; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
274 |
int i = 0; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
275 |
for (Integer id : idList) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
276 |
ids[i++] = id; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
277 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
278 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
279 |
return new EllipticCurvesExtension(ids); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
280 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
281 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
282 |
return null; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
283 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
284 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
285 |
// get the preferred activated curve |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
286 |
int getPreferredCurve(AlgorithmConstraints constraints) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
287 |
return getPreferredCurve(curveIds, constraints); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
288 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
289 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
290 |
// get a preferred activated curve |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
291 |
private static int getPreferredCurve(int[] curves, |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
292 |
AlgorithmConstraints constraints) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
293 |
for (int curveId : curves) { |
41473
bf73db8c61e0
8167472: Chrome interop regression with JDK-8148516
xuelei
parents:
39563
diff
changeset
|
294 |
if (isSupported(curveId) && constraints.permits( |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
295 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
296 |
"EC", idToParams.get(curveId))) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
297 |
return curveId; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
298 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
299 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
300 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
301 |
return -1; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
302 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
303 |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
304 |
boolean contains(int index) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
305 |
for (int curveId : curveIds) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
306 |
if (index == curveId) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
307 |
return true; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
308 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
309 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
310 |
return false; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
311 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
312 |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14342
diff
changeset
|
313 |
@Override |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
314 |
int length() { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
315 |
return 6 + (curveIds.length << 1); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
316 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
317 |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14342
diff
changeset
|
318 |
@Override |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
319 |
void send(HandshakeOutStream s) throws IOException { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
320 |
s.putInt16(type.id); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
321 |
int k = curveIds.length << 1; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
322 |
s.putInt16(k + 2); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
323 |
s.putInt16(k); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
324 |
for (int curveId : curveIds) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
325 |
s.putInt16(curveId); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
326 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
327 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
328 |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14342
diff
changeset
|
329 |
@Override |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
330 |
public String toString() { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
331 |
StringBuilder sb = new StringBuilder(); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
332 |
sb.append("Extension " + type + ", curve names: {"); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
333 |
boolean first = true; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
334 |
for (int curveId : curveIds) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
335 |
if (first) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
336 |
first = false; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
337 |
} else { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
338 |
sb.append(", "); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
339 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
340 |
// first check if it is a known named curve, then try other cases. |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
341 |
String curveName = getCurveName(curveId); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
342 |
if (curveName != null) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
343 |
sb.append(curveName); |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
344 |
} else if (curveId == ARBITRARY_PRIME) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
345 |
sb.append("arbitrary_explicit_prime_curves"); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
346 |
} else if (curveId == ARBITRARY_CHAR2) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
347 |
sb.append("arbitrary_explicit_char2_curves"); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
348 |
} else { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
349 |
sb.append("unknown curve " + curveId); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
350 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
351 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
352 |
sb.append("}"); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
353 |
return sb.toString(); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
354 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
355 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
356 |
// Test whether the given curve is supported. |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
357 |
static boolean isSupported(int index) { |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
358 |
for (int curveId : supportedCurveIds) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
359 |
if (index == curveId) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
360 |
return true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
361 |
} |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
362 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
363 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
364 |
return false; |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
365 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
366 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
367 |
static int getCurveIndex(ECParameterSpec params) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
368 |
String oid = JsseJce.getNamedCurveOid(params); |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
369 |
if (oid == null) { |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
370 |
return -1; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
371 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
372 |
Integer n = oidToIdMap.get(oid); |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
373 |
return (n == null) ? -1 : n; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
374 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
375 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
376 |
static String getCurveOid(int index) { |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
377 |
return idToOidMap.get(index); |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
378 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
379 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
380 |
static ECGenParameterSpec getECGenParamSpec(int index) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
381 |
AlgorithmParameters params = idToParams.get(index); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
382 |
try { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
383 |
return params.getParameterSpec(ECGenParameterSpec.class); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
384 |
} catch (InvalidParameterSpecException ipse) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
385 |
// should be unlikely |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
386 |
String curveOid = getCurveOid(index); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
387 |
return new ECGenParameterSpec(curveOid); |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
388 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
389 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
390 |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
391 |
private static String getCurveName(int index) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
392 |
for (NamedEllipticCurve namedCurve : NamedEllipticCurve.values()) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
393 |
if (namedCurve.id == index) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
394 |
return namedCurve.name; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
395 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
396 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
397 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
398 |
return null; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
399 |
} |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
400 |
} |