author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58637 | d66bdf0e2dfe |
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 |
/* |
53734
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
53064
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, 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; |
50768 | 29 |
import java.nio.ByteBuffer; |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
30 |
import java.security.AlgorithmConstraints; |
50768 | 31 |
import java.text.MessageFormat; |
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Collections; |
|
34 |
import java.util.LinkedList; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Locale; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
37 |
import javax.net.ssl.SSLProtocolException; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
38 |
import sun.security.action.GetPropertyAction; |
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
39 |
import sun.security.ssl.NamedGroup.NamedGroupSpec; |
50768 | 40 |
import static sun.security.ssl.SSLExtension.CH_SUPPORTED_GROUPS; |
41 |
import static sun.security.ssl.SSLExtension.EE_SUPPORTED_GROUPS; |
|
42 |
import sun.security.ssl.SSLExtension.ExtensionConsumer; |
|
43 |
import sun.security.ssl.SSLExtension.SSLExtensionSpec; |
|
44 |
import sun.security.ssl.SSLHandshake.HandshakeMessage; |
|
55353 | 45 |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
46 |
|
50768 | 47 |
/** |
48 |
* Pack of the "supported_groups" extensions [RFC 4492/7919]. |
|
49 |
*/ |
|
50 |
final class SupportedGroupsExtension { |
|
51 |
static final HandshakeProducer chNetworkProducer = |
|
52 |
new CHSupportedGroupsProducer(); |
|
53 |
static final ExtensionConsumer chOnLoadConsumer = |
|
54 |
new CHSupportedGroupsConsumer(); |
|
55 |
static final SSLStringizer sgsStringizer = |
|
56 |
new SupportedGroupsStringizer(); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
57 |
|
50768 | 58 |
static final HandshakeProducer eeNetworkProducer = |
59 |
new EESupportedGroupsProducer(); |
|
60 |
static final ExtensionConsumer eeOnLoadConsumer = |
|
61 |
new EESupportedGroupsConsumer(); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
62 |
|
50768 | 63 |
/** |
64 |
* The "supported_groups" extension. |
|
65 |
*/ |
|
66 |
static final class SupportedGroupsSpec implements SSLExtensionSpec { |
|
67 |
final int[] namedGroupsIds; |
|
68 |
||
69 |
private SupportedGroupsSpec(int[] namedGroupsIds) { |
|
70 |
this.namedGroupsIds = namedGroupsIds; |
|
71 |
} |
|
72 |
||
73 |
private SupportedGroupsSpec(List<NamedGroup> namedGroups) { |
|
74 |
this.namedGroupsIds = new int[namedGroups.size()]; |
|
75 |
int i = 0; |
|
76 |
for (NamedGroup ng : namedGroups) { |
|
77 |
namedGroupsIds[i++] = ng.id; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
78 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
79 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
80 |
|
50768 | 81 |
private SupportedGroupsSpec(ByteBuffer m) throws IOException { |
82 |
if (m.remaining() < 2) { // 2: the length of the list |
|
83 |
throw new SSLProtocolException( |
|
84 |
"Invalid supported_groups extension: insufficient data"); |
|
85 |
} |
|
86 |
||
87 |
byte[] ngs = Record.getBytes16(m); |
|
88 |
if (m.hasRemaining()) { |
|
89 |
throw new SSLProtocolException( |
|
90 |
"Invalid supported_groups extension: unknown extra data"); |
|
91 |
} |
|
92 |
||
93 |
if ((ngs == null) || (ngs.length == 0) || (ngs.length % 2 != 0)) { |
|
94 |
throw new SSLProtocolException( |
|
95 |
"Invalid supported_groups extension: incomplete data"); |
|
96 |
} |
|
97 |
||
98 |
int[] ids = new int[ngs.length / 2]; |
|
99 |
for (int i = 0, j = 0; i < ngs.length;) { |
|
100 |
ids[j++] = ((ngs[i++] & 0xFF) << 8) | (ngs[i++] & 0xFF); |
|
101 |
} |
|
102 |
||
103 |
this.namedGroupsIds = ids; |
|
104 |
} |
|
105 |
||
106 |
@Override |
|
107 |
public String toString() { |
|
108 |
MessageFormat messageFormat = new MessageFormat( |
|
109 |
"\"versions\": '['{0}']'", Locale.ENGLISH); |
|
110 |
||
111 |
if (namedGroupsIds == null || namedGroupsIds.length == 0) { |
|
112 |
Object[] messageFields = { |
|
113 |
"<no supported named group specified>" |
|
114 |
}; |
|
115 |
return messageFormat.format(messageFields); |
|
116 |
} else { |
|
117 |
StringBuilder builder = new StringBuilder(512); |
|
118 |
boolean isFirst = true; |
|
119 |
for (int ngid : namedGroupsIds) { |
|
120 |
if (isFirst) { |
|
121 |
isFirst = false; |
|
122 |
} else { |
|
123 |
builder.append(", "); |
|
124 |
} |
|
125 |
||
126 |
builder.append(NamedGroup.nameOf(ngid)); |
|
127 |
} |
|
128 |
||
129 |
Object[] messageFields = { |
|
130 |
builder.toString() |
|
131 |
}; |
|
132 |
||
133 |
return messageFormat.format(messageFields); |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
private static final |
|
139 |
class SupportedGroupsStringizer implements SSLStringizer { |
|
140 |
@Override |
|
141 |
public String toString(ByteBuffer buffer) { |
|
142 |
try { |
|
143 |
return (new SupportedGroupsSpec(buffer)).toString(); |
|
144 |
} catch (IOException ioe) { |
|
145 |
// For debug logging only, so please swallow exceptions. |
|
146 |
return ioe.getMessage(); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
static class SupportedGroups { |
|
152 |
// To switch off the supported_groups extension for DHE cipher suite. |
|
153 |
static final boolean enableFFDHE = |
|
154 |
Utilities.getBooleanProperty("jsse.enableFFDHE", true); |
|
155 |
||
156 |
// the supported named groups |
|
157 |
static final NamedGroup[] supportedNamedGroups; |
|
158 |
||
159 |
static { |
|
160 |
// The value of the System Property defines a list of enabled named |
|
161 |
// groups in preference order, separated with comma. For example: |
|
162 |
// |
|
163 |
// jdk.tls.namedGroups="secp521r1, secp256r1, ffdhe2048" |
|
164 |
// |
|
165 |
// If the System Property is not defined or the value is empty, the |
|
166 |
// default groups and preferences will be used. |
|
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
50768
diff
changeset
|
167 |
String property = GetPropertyAction |
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
50768
diff
changeset
|
168 |
.privilegedGetProperty("jdk.tls.namedGroups"); |
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
51733
diff
changeset
|
169 |
if (property != null && !property.isEmpty()) { |
50768 | 170 |
// remove double quote marks from beginning/end of the property |
171 |
if (property.length() > 1 && property.charAt(0) == '"' && |
|
172 |
property.charAt(property.length() - 1) == '"') { |
|
173 |
property = property.substring(1, property.length() - 1); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
ArrayList<NamedGroup> groupList; |
|
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
51733
diff
changeset
|
178 |
if (property != null && !property.isEmpty()) { |
50768 | 179 |
String[] groups = property.split(","); |
180 |
groupList = new ArrayList<>(groups.length); |
|
181 |
for (String group : groups) { |
|
182 |
group = group.trim(); |
|
183 |
if (!group.isEmpty()) { |
|
184 |
NamedGroup namedGroup = NamedGroup.nameOf(group); |
|
53734
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
53064
diff
changeset
|
185 |
if (namedGroup != null) { |
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
186 |
if (namedGroup.isAvailable) { |
50768 | 187 |
groupList.add(namedGroup); |
188 |
} |
|
189 |
} // ignore unknown groups |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
if (groupList.isEmpty()) { |
|
194 |
throw new IllegalArgumentException( |
|
195 |
"System property jdk.tls.namedGroups(" + |
|
196 |
property + ") contains no supported named groups"); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
197 |
} |
50768 | 198 |
} else { // default groups |
53734
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
53064
diff
changeset
|
199 |
NamedGroup[] groups = new NamedGroup[] { |
55353 | 200 |
|
201 |
// Primary XDH (RFC 7748) curves |
|
202 |
NamedGroup.X25519, |
|
203 |
||
58637 | 204 |
// Primary NIST Suite B curves |
50768 | 205 |
NamedGroup.SECP256_R1, |
206 |
NamedGroup.SECP384_R1, |
|
207 |
NamedGroup.SECP521_R1, |
|
55353 | 208 |
|
209 |
// Secondary XDH curves |
|
210 |
NamedGroup.X448, |
|
211 |
||
212 |
// FFDHE (RFC 7919) |
|
50768 | 213 |
NamedGroup.FFDHE_2048, |
214 |
NamedGroup.FFDHE_3072, |
|
215 |
NamedGroup.FFDHE_4096, |
|
216 |
NamedGroup.FFDHE_6144, |
|
217 |
NamedGroup.FFDHE_8192, |
|
218 |
}; |
|
219 |
||
220 |
groupList = new ArrayList<>(groups.length); |
|
221 |
for (NamedGroup group : groups) { |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
222 |
if (group.isAvailable) { |
50768 | 223 |
groupList.add(group); |
224 |
} |
|
225 |
} |
|
226 |
||
227 |
if (groupList.isEmpty() && |
|
228 |
SSLLogger.isOn && SSLLogger.isOn("ssl")) { |
|
229 |
SSLLogger.warning("No default named groups"); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
supportedNamedGroups = new NamedGroup[groupList.size()]; |
|
234 |
int i = 0; |
|
235 |
for (NamedGroup namedGroup : groupList) { |
|
236 |
supportedNamedGroups[i++] = namedGroup; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
237 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
238 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
239 |
|
50768 | 240 |
// Is there any supported group permitted by the constraints? |
241 |
static boolean isActivatable( |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
242 |
AlgorithmConstraints constraints, NamedGroupSpec type) { |
50768 | 243 |
|
244 |
boolean hasFFDHEGroups = false; |
|
245 |
for (NamedGroup namedGroup : supportedNamedGroups) { |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
246 |
if (namedGroup.isAvailable && namedGroup.spec == type) { |
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
247 |
if (namedGroup.isPermitted(constraints)) { |
50768 | 248 |
return true; |
249 |
} |
|
250 |
||
251 |
if (!hasFFDHEGroups && |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
252 |
(type == NamedGroupSpec.NAMED_GROUP_FFDHE)) { |
50768 | 253 |
hasFFDHEGroups = true; |
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
// For compatibility, if no FFDHE groups are defined, the non-FFDHE |
|
259 |
// compatible mode (using DHE cipher suite without FFDHE extension) |
|
260 |
// is allowed. |
|
261 |
// |
|
262 |
// Note that the constraints checking on DHE parameters will be |
|
263 |
// performed during key exchanging in a handshake. |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
264 |
return !hasFFDHEGroups && type == NamedGroupSpec.NAMED_GROUP_FFDHE; |
50768 | 265 |
} |
266 |
||
267 |
// Is the named group permitted by the constraints? |
|
268 |
static boolean isActivatable( |
|
269 |
AlgorithmConstraints constraints, NamedGroup namedGroup) { |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
270 |
if (!namedGroup.isAvailable || !isSupported(namedGroup)) { |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
271 |
return false; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
272 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
273 |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
274 |
return namedGroup.isPermitted(constraints); |
50768 | 275 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
276 |
|
51733 | 277 |
// Is the named group supported? |
50768 | 278 |
static boolean isSupported(NamedGroup namedGroup) { |
279 |
for (NamedGroup group : supportedNamedGroups) { |
|
280 |
if (namedGroup.id == group.id) { |
|
281 |
return true; |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
return false; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
286 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
287 |
|
50768 | 288 |
static NamedGroup getPreferredGroup( |
289 |
ProtocolVersion negotiatedProtocol, |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
290 |
AlgorithmConstraints constraints, NamedGroupSpec[] types, |
50768 | 291 |
List<NamedGroup> requestedNamedGroups) { |
292 |
for (NamedGroup namedGroup : requestedNamedGroups) { |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
293 |
if ((NamedGroupSpec.arrayContains(types, namedGroup.spec)) && |
50768 | 294 |
namedGroup.isAvailable(negotiatedProtocol) && |
51733 | 295 |
isSupported(namedGroup) && |
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
296 |
namedGroup.isPermitted(constraints)) { |
50768 | 297 |
return namedGroup; |
298 |
} |
|
299 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
300 |
|
50768 | 301 |
return null; |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
302 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
303 |
|
50768 | 304 |
static NamedGroup getPreferredGroup( |
305 |
ProtocolVersion negotiatedProtocol, |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
306 |
AlgorithmConstraints constraints, NamedGroupSpec[] types) { |
50768 | 307 |
for (NamedGroup namedGroup : supportedNamedGroups) { |
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
308 |
if ((NamedGroupSpec.arrayContains(types, namedGroup.spec)) && |
50768 | 309 |
namedGroup.isAvailable(negotiatedProtocol) && |
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
310 |
namedGroup.isPermitted(constraints)) { |
50768 | 311 |
return namedGroup; |
312 |
} |
|
313 |
} |
|
314 |
||
315 |
return null; |
|
316 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
317 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
318 |
|
50768 | 319 |
/** |
320 |
* Network data producer of a "supported_groups" extension in |
|
321 |
* the ClientHello handshake message. |
|
322 |
*/ |
|
323 |
private static final class CHSupportedGroupsProducer |
|
324 |
extends SupportedGroups implements HandshakeProducer { |
|
325 |
// Prevent instantiation of this class. |
|
326 |
private CHSupportedGroupsProducer() { |
|
327 |
// blank |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
328 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
329 |
|
50768 | 330 |
@Override |
331 |
public byte[] produce(ConnectionContext context, |
|
332 |
HandshakeMessage message) throws IOException { |
|
333 |
// The producing happens in client side only. |
|
334 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
335 |
|
50768 | 336 |
// Is it a supported and enabled extension? |
337 |
if (!chc.sslConfig.isAvailable(CH_SUPPORTED_GROUPS)) { |
|
338 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
339 |
SSLLogger.fine( |
|
340 |
"Ignore unavailable supported_groups extension"); |
|
341 |
} |
|
342 |
return null; |
|
343 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
344 |
|
50768 | 345 |
// Produce the extension. |
346 |
ArrayList<NamedGroup> namedGroups = |
|
347 |
new ArrayList<>(SupportedGroups.supportedNamedGroups.length); |
|
348 |
for (NamedGroup ng : SupportedGroups.supportedNamedGroups) { |
|
349 |
if ((!SupportedGroups.enableFFDHE) && |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
350 |
(ng.spec == NamedGroupSpec.NAMED_GROUP_FFDHE)) { |
50768 | 351 |
continue; |
352 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
353 |
|
50768 | 354 |
if (ng.isAvailable(chc.activeProtocols) && |
355 |
ng.isSupported(chc.activeCipherSuites) && |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
356 |
ng.isPermitted(chc.algorithmConstraints)) { |
50768 | 357 |
namedGroups.add(ng); |
358 |
} else if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
359 |
SSLLogger.fine( |
|
360 |
"Ignore inactive or disabled named group: " + ng.name); |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
if (namedGroups.isEmpty()) { |
|
365 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
366 |
SSLLogger.warning("no available named group"); |
|
367 |
} |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
368 |
|
50768 | 369 |
return null; |
370 |
} |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
371 |
|
50768 | 372 |
int vectorLen = namedGroups.size() << 1; |
373 |
byte[] extData = new byte[vectorLen + 2]; |
|
374 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
375 |
Record.putInt16(m, vectorLen); |
|
376 |
for (NamedGroup namedGroup : namedGroups) { |
|
377 |
Record.putInt16(m, namedGroup.id); |
|
378 |
} |
|
379 |
||
380 |
// Update the context. |
|
381 |
chc.clientRequestedNamedGroups = |
|
382 |
Collections.<NamedGroup>unmodifiableList(namedGroups); |
|
383 |
chc.handshakeExtensions.put(CH_SUPPORTED_GROUPS, |
|
384 |
new SupportedGroupsSpec(namedGroups)); |
|
385 |
||
386 |
return extData; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
387 |
} |
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 |
|
50768 | 390 |
/** |
391 |
* Network data producer of a "supported_groups" extension in |
|
392 |
* the ClientHello handshake message. |
|
393 |
*/ |
|
394 |
private static final |
|
395 |
class CHSupportedGroupsConsumer implements ExtensionConsumer { |
|
396 |
// Prevent instantiation of this class. |
|
397 |
private CHSupportedGroupsConsumer() { |
|
398 |
// blank |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
399 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
400 |
|
50768 | 401 |
@Override |
402 |
public void consume(ConnectionContext context, |
|
403 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
404 |
// The consuming happens in server side only. |
|
405 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
406 |
|
50768 | 407 |
// Is it a supported and enabled extension? |
408 |
if (!shc.sslConfig.isAvailable(CH_SUPPORTED_GROUPS)) { |
|
409 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
410 |
SSLLogger.fine( |
|
411 |
"Ignore unavailable supported_groups extension"); |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
412 |
} |
50768 | 413 |
return; // ignore the extension |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
414 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
415 |
|
50768 | 416 |
// Parse the extension. |
417 |
SupportedGroupsSpec spec; |
|
418 |
try { |
|
419 |
spec = new SupportedGroupsSpec(buffer); |
|
420 |
} catch (IOException ioe) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
53018
diff
changeset
|
421 |
throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
422 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
423 |
|
50768 | 424 |
// Update the context. |
425 |
List<NamedGroup> knownNamedGroups = new LinkedList<>(); |
|
426 |
for (int id : spec.namedGroupsIds) { |
|
427 |
NamedGroup ng = NamedGroup.valueOf(id); |
|
428 |
if (ng != null) { |
|
429 |
knownNamedGroups.add(ng); |
|
430 |
} |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
431 |
} |
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
432 |
|
50768 | 433 |
shc.clientRequestedNamedGroups = knownNamedGroups; |
434 |
shc.handshakeExtensions.put(CH_SUPPORTED_GROUPS, spec); |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
435 |
|
50768 | 436 |
// 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
|
437 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
438 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
439 |
|
50768 | 440 |
/** |
441 |
* Network data producer of a "supported_groups" extension in |
|
442 |
* the EncryptedExtensions handshake message. |
|
443 |
*/ |
|
444 |
private static final class EESupportedGroupsProducer |
|
445 |
extends SupportedGroups implements HandshakeProducer { |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
446 |
|
50768 | 447 |
// Prevent instantiation of this class. |
448 |
private EESupportedGroupsProducer() { |
|
449 |
// blank |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
450 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
451 |
|
50768 | 452 |
@Override |
453 |
public byte[] produce(ConnectionContext context, |
|
454 |
HandshakeMessage message) throws IOException { |
|
455 |
// The producing happens in server side only. |
|
456 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
457 |
||
458 |
// Is it a supported and enabled extension? |
|
459 |
if (!shc.sslConfig.isAvailable(EE_SUPPORTED_GROUPS)) { |
|
460 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
461 |
SSLLogger.fine( |
|
462 |
"Ignore unavailable supported_groups extension"); |
|
463 |
} |
|
464 |
return null; |
|
465 |
} |
|
466 |
||
467 |
// Produce the extension. |
|
468 |
// |
|
469 |
// Contains all groups the server supports, regardless of whether |
|
470 |
// they are currently supported by the client. |
|
471 |
ArrayList<NamedGroup> namedGroups = new ArrayList<>( |
|
472 |
SupportedGroups.supportedNamedGroups.length); |
|
473 |
for (NamedGroup ng : SupportedGroups.supportedNamedGroups) { |
|
474 |
if ((!SupportedGroups.enableFFDHE) && |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
475 |
(ng.spec == NamedGroupSpec.NAMED_GROUP_FFDHE)) { |
50768 | 476 |
continue; |
477 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
478 |
|
50768 | 479 |
if (ng.isAvailable(shc.activeProtocols) && |
480 |
ng.isSupported(shc.activeCipherSuites) && |
|
57718
a93b7b28f644
8226374: Restrict TLS signature schemes and named groups
xuelei
parents:
55353
diff
changeset
|
481 |
ng.isPermitted(shc.algorithmConstraints)) { |
50768 | 482 |
namedGroups.add(ng); |
483 |
} else if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
484 |
SSLLogger.fine( |
|
485 |
"Ignore inactive or disabled named group: " + ng.name); |
|
486 |
} |
|
487 |
} |
|
488 |
||
489 |
if (namedGroups.isEmpty()) { |
|
490 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
491 |
SSLLogger.warning("no available named group"); |
|
492 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
493 |
|
50768 | 494 |
return null; |
495 |
} |
|
496 |
||
497 |
int vectorLen = namedGroups.size() << 1; |
|
498 |
byte[] extData = new byte[vectorLen + 2]; |
|
499 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
500 |
Record.putInt16(m, vectorLen); |
|
501 |
for (NamedGroup namedGroup : namedGroups) { |
|
502 |
Record.putInt16(m, namedGroup.id); |
|
503 |
} |
|
504 |
||
505 |
// Update the context. |
|
506 |
shc.conContext.serverRequestedNamedGroups = |
|
507 |
Collections.<NamedGroup>unmodifiableList(namedGroups); |
|
508 |
SupportedGroupsSpec spec = new SupportedGroupsSpec(namedGroups); |
|
509 |
shc.handshakeExtensions.put(EE_SUPPORTED_GROUPS, spec); |
|
510 |
||
511 |
return extData; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
512 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
513 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
514 |
|
50768 | 515 |
private static final |
516 |
class EESupportedGroupsConsumer implements ExtensionConsumer { |
|
517 |
// Prevent instantiation of this class. |
|
518 |
private EESupportedGroupsConsumer() { |
|
519 |
// blank |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
520 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
521 |
|
50768 | 522 |
@Override |
523 |
public void consume(ConnectionContext context, |
|
524 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
525 |
// The consuming happens in client side only. |
|
526 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
527 |
||
528 |
// Is it a supported and enabled extension? |
|
529 |
if (!chc.sslConfig.isAvailable(EE_SUPPORTED_GROUPS)) { |
|
530 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
531 |
SSLLogger.fine( |
|
532 |
"Ignore unavailable supported_groups extension"); |
|
533 |
} |
|
534 |
return; // ignore the extension |
|
535 |
} |
|
536 |
||
537 |
// Parse the extension. |
|
538 |
SupportedGroupsSpec spec; |
|
539 |
try { |
|
540 |
spec = new SupportedGroupsSpec(buffer); |
|
541 |
} catch (IOException ioe) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
53018
diff
changeset
|
542 |
throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
50768 | 543 |
} |
544 |
||
545 |
// Update the context. |
|
546 |
List<NamedGroup> knownNamedGroups = |
|
547 |
new ArrayList<>(spec.namedGroupsIds.length); |
|
548 |
for (int id : spec.namedGroupsIds) { |
|
549 |
NamedGroup ng = NamedGroup.valueOf(id); |
|
550 |
if (ng != null) { |
|
551 |
knownNamedGroups.add(ng); |
|
552 |
} |
|
553 |
} |
|
554 |
||
555 |
chc.conContext.serverRequestedNamedGroups = knownNamedGroups; |
|
556 |
chc.handshakeExtensions.put(EE_SUPPORTED_GROUPS, spec); |
|
557 |
||
558 |
// No impact on session resumption. |
|
45064
b1b45177051b
8140436: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
xuelei
parents:
43693
diff
changeset
|
559 |
} |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
37814
diff
changeset
|
560 |
} |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
561 |
} |