author | apetcher |
Thu, 16 Aug 2018 13:16:18 -0400 | |
branch | JDK-8171279-XDH-TLS-branch |
changeset 56855 | ee6aa4c74a4b |
parent 56589 | bafd8be2f970 |
child 56856 | 74041d6dcf9d |
permissions | -rw-r--r-- |
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
1 |
/* |
56542 | 2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
4 |
* |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
10 |
* |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
15 |
* accompanied this code). |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
16 |
* |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
20 |
* |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
23 |
* questions. |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
24 |
*/ |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
25 |
|
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
26 |
package sun.security.ssl; |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
27 |
|
56542 | 28 |
import java.io.IOException; |
29 |
import java.util.AbstractMap.SimpleImmutableEntry; |
|
30 |
import java.util.Arrays; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.Map; |
|
56855 | 33 |
import java.util.Optional; |
56542 | 34 |
import sun.security.ssl.DHKeyExchange.DHEPossession; |
35 |
import sun.security.ssl.ECDHKeyExchange.ECDHEPossession; |
|
56589
bafd8be2f970
Initial working XDH support in TLS. I should try to refactor the code a bit.
apetcher
parents:
56542
diff
changeset
|
36 |
import sun.security.ssl.XDHKeyExchange.XDHEPossession; |
56542 | 37 |
import sun.security.ssl.SupportedGroupsExtension.NamedGroup; |
38 |
import sun.security.ssl.SupportedGroupsExtension.NamedGroupType; |
|
56855 | 39 |
import sun.security.ssl.SupportedGroupsExtension.NamedGroupFunctions; |
56542 | 40 |
import sun.security.ssl.SupportedGroupsExtension.SupportedGroups; |
41 |
import sun.security.ssl.X509Authentication.X509Possession; |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
42 |
|
56542 | 43 |
final class SSLKeyExchange implements SSLKeyAgreement { |
44 |
private final SSLAuthentication authentication; |
|
45 |
private final SSLKeyAgreement keyAgreement; |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
46 |
|
56542 | 47 |
SSLKeyExchange(X509Authentication authentication, |
48 |
SSLKeyAgreement keyAgreement) { |
|
49 |
this.authentication = authentication; |
|
50 |
this.keyAgreement = keyAgreement; |
|
51 |
} |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
52 |
|
56542 | 53 |
SSLPossession[] createPossessions(HandshakeContext context) { |
54 |
// authentication |
|
55 |
SSLPossession authPossession = null; |
|
56 |
if (authentication != null) { |
|
57 |
authPossession = authentication.createPossession(context); |
|
58 |
if (authPossession == null) { |
|
59 |
return new SSLPossession[0]; |
|
60 |
} else if (context instanceof ServerHandshakeContext) { |
|
61 |
// The authentication information may be used further for |
|
62 |
// key agreement parameters negotiation. |
|
63 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
64 |
shc.interimAuthn = authPossession; |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
65 |
} |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
66 |
} |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
67 |
|
56542 | 68 |
// key agreement |
69 |
SSLPossession kaPossession; |
|
70 |
if (keyAgreement == T12KeyAgreement.RSA_EXPORT) { |
|
71 |
// a special case |
|
72 |
X509Possession x509Possession = (X509Possession)authPossession; |
|
73 |
if (JsseJce.getRSAKeyLength( |
|
74 |
x509Possession.popCerts[0].getPublicKey()) > 512) { |
|
75 |
kaPossession = keyAgreement.createPossession(context); |
|
76 |
||
77 |
if (kaPossession == null) { |
|
78 |
return new SSLPossession[0]; |
|
79 |
} else { |
|
80 |
return authentication != null ? |
|
81 |
new SSLPossession[] {authPossession, kaPossession} : |
|
82 |
new SSLPossession[] {kaPossession}; |
|
83 |
} |
|
84 |
} else { |
|
85 |
return authentication != null ? |
|
86 |
new SSLPossession[] {authPossession} : |
|
87 |
new SSLPossession[0]; |
|
88 |
} |
|
89 |
} else { |
|
90 |
kaPossession = keyAgreement.createPossession(context); |
|
91 |
if (kaPossession == null) { |
|
92 |
// special cases |
|
93 |
if (keyAgreement == T12KeyAgreement.RSA || |
|
94 |
keyAgreement == T12KeyAgreement.ECDH) { |
|
95 |
return authentication != null ? |
|
96 |
new SSLPossession[] {authPossession} : |
|
97 |
new SSLPossession[0]; |
|
98 |
} else { |
|
99 |
return new SSLPossession[0]; |
|
100 |
} |
|
101 |
} else { |
|
102 |
return authentication != null ? |
|
103 |
new SSLPossession[] {authPossession, kaPossession} : |
|
104 |
new SSLPossession[] {kaPossession}; |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
@Override |
|
110 |
public SSLPossession createPossession(HandshakeContext handshakeContext) { |
|
111 |
// Please call createPossessions() so that the SSLAuthentication |
|
112 |
// is counted. |
|
113 |
throw new UnsupportedOperationException( |
|
114 |
"SSLKeyExchange.createPossessions() should be used instead"); |
|
115 |
} |
|
116 |
||
117 |
@Override |
|
118 |
public SSLKeyDerivation createKeyDerivation( |
|
119 |
HandshakeContext handshakeContext) throws IOException { |
|
120 |
return keyAgreement.createKeyDerivation(handshakeContext); |
|
121 |
} |
|
122 |
||
123 |
@Override |
|
124 |
public SSLHandshake[] getRelatedHandshakers( |
|
125 |
HandshakeContext handshakeContext) { |
|
126 |
SSLHandshake[] auHandshakes; |
|
127 |
if (authentication != null) { |
|
128 |
auHandshakes = |
|
129 |
authentication.getRelatedHandshakers(handshakeContext); |
|
130 |
} else { |
|
131 |
auHandshakes = null; |
|
132 |
} |
|
133 |
||
134 |
SSLHandshake[] kaHandshakes = |
|
135 |
keyAgreement.getRelatedHandshakers(handshakeContext); |
|
136 |
||
137 |
if (auHandshakes == null || auHandshakes.length == 0) { |
|
138 |
return kaHandshakes; |
|
139 |
} else if (kaHandshakes == null || kaHandshakes.length == 0) { |
|
140 |
return auHandshakes; |
|
141 |
} else { |
|
142 |
SSLHandshake[] producers = Arrays.copyOf( |
|
143 |
auHandshakes, auHandshakes.length + kaHandshakes.length); |
|
144 |
System.arraycopy(kaHandshakes, 0, |
|
145 |
producers, auHandshakes.length, kaHandshakes.length); |
|
146 |
return producers; |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
@Override |
|
151 |
public Map.Entry<Byte, HandshakeProducer>[] getHandshakeProducers( |
|
152 |
HandshakeContext handshakeContext) { |
|
153 |
Map.Entry<Byte, HandshakeProducer>[] auProducers; |
|
154 |
if (authentication != null) { |
|
155 |
auProducers = |
|
156 |
authentication.getHandshakeProducers(handshakeContext); |
|
157 |
} else { |
|
158 |
auProducers = null; |
|
159 |
} |
|
160 |
||
161 |
Map.Entry<Byte, HandshakeProducer>[] kaProducers = |
|
162 |
keyAgreement.getHandshakeProducers(handshakeContext); |
|
163 |
||
164 |
if (auProducers == null || auProducers.length == 0) { |
|
165 |
return kaProducers; |
|
166 |
} else if (kaProducers == null || kaProducers.length == 0) { |
|
167 |
return auProducers; |
|
168 |
} else { |
|
169 |
Map.Entry<Byte, HandshakeProducer>[] producers = Arrays.copyOf( |
|
170 |
auProducers, auProducers.length + kaProducers.length); |
|
171 |
System.arraycopy(kaProducers, 0, |
|
172 |
producers, auProducers.length, kaProducers.length); |
|
173 |
return producers; |
|
174 |
} |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
175 |
} |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
176 |
|
56542 | 177 |
@Override |
178 |
public Map.Entry<Byte, SSLConsumer>[] getHandshakeConsumers( |
|
179 |
HandshakeContext handshakeContext) { |
|
180 |
Map.Entry<Byte, SSLConsumer>[] auConsumers; |
|
181 |
if (authentication != null) { |
|
182 |
auConsumers = |
|
183 |
authentication.getHandshakeConsumers(handshakeContext); |
|
184 |
} else { |
|
185 |
auConsumers = null; |
|
186 |
} |
|
187 |
||
188 |
Map.Entry<Byte, SSLConsumer>[] kaConsumers = |
|
189 |
keyAgreement.getHandshakeConsumers(handshakeContext); |
|
190 |
||
191 |
if (auConsumers == null || auConsumers.length == 0) { |
|
192 |
return kaConsumers; |
|
193 |
} else if (kaConsumers == null || kaConsumers.length == 0) { |
|
194 |
return auConsumers; |
|
195 |
} else { |
|
196 |
Map.Entry<Byte, SSLConsumer>[] producers = Arrays.copyOf( |
|
197 |
auConsumers, auConsumers.length + kaConsumers.length); |
|
198 |
System.arraycopy(kaConsumers, 0, |
|
199 |
producers, auConsumers.length, kaConsumers.length); |
|
200 |
return producers; |
|
201 |
} |
|
202 |
} |
|
203 |
||
204 |
// SSL 3.0 - (D)TLS 1.2 |
|
205 |
static SSLKeyExchange valueOf( |
|
206 |
CipherSuite.KeyExchange keyExchange) { |
|
207 |
if (keyExchange == null) { |
|
208 |
return null; |
|
209 |
} |
|
210 |
||
211 |
switch (keyExchange) { |
|
212 |
case K_RSA: |
|
213 |
return SSLKeyExRSA.KE; |
|
214 |
case K_RSA_EXPORT: |
|
215 |
return SSLKeyExRSAExport.KE; |
|
216 |
case K_DHE_DSS: |
|
217 |
return SSLKeyExDHEDSS.KE; |
|
218 |
case K_DHE_DSS_EXPORT: |
|
219 |
return SSLKeyExDHEDSSExport.KE; |
|
220 |
case K_DHE_RSA: |
|
221 |
return SSLKeyExDHERSA.KE; |
|
222 |
case K_DHE_RSA_EXPORT: |
|
223 |
return SSLKeyExDHERSAExport.KE; |
|
224 |
case K_DH_ANON: |
|
225 |
return SSLKeyExDHANON.KE; |
|
226 |
case K_DH_ANON_EXPORT: |
|
227 |
return SSLKeyExDHANONExport.KE; |
|
228 |
case K_ECDH_ECDSA: |
|
229 |
return SSLKeyExECDHECDSA.KE; |
|
230 |
case K_ECDH_RSA: |
|
231 |
return SSLKeyExECDHRSA.KE; |
|
232 |
case K_ECDHE_ECDSA: |
|
233 |
return SSLKeyExECDHEECDSA.KE; |
|
234 |
case K_ECDHE_RSA: |
|
235 |
return SSLKeyExECDHERSA.KE; |
|
236 |
case K_ECDH_ANON: |
|
237 |
return SSLKeyExECDHANON.KE; |
|
238 |
} |
|
239 |
||
240 |
return null; |
|
241 |
} |
|
242 |
||
243 |
// TLS 1.3 |
|
244 |
static SSLKeyExchange valueOf(NamedGroup namedGroup) { |
|
245 |
SSLKeyAgreement ka = T13KeyAgreement.valueOf(namedGroup); |
|
246 |
if (ka != null) { |
|
247 |
return new SSLKeyExchange( |
|
248 |
null, T13KeyAgreement.valueOf(namedGroup)); |
|
249 |
} |
|
250 |
||
251 |
return null; |
|
252 |
} |
|
253 |
||
254 |
private static class SSLKeyExRSA { |
|
255 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
256 |
X509Authentication.RSA, T12KeyAgreement.RSA); |
|
257 |
} |
|
258 |
||
259 |
private static class SSLKeyExRSAExport { |
|
260 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
261 |
X509Authentication.RSA, T12KeyAgreement.RSA_EXPORT); |
|
262 |
} |
|
263 |
||
264 |
private static class SSLKeyExDHEDSS { |
|
265 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
266 |
X509Authentication.DSA, T12KeyAgreement.DHE); |
|
267 |
} |
|
268 |
||
269 |
private static class SSLKeyExDHEDSSExport { |
|
270 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
271 |
X509Authentication.DSA, T12KeyAgreement.DHE_EXPORT); |
|
272 |
} |
|
273 |
||
274 |
private static class SSLKeyExDHERSA { |
|
275 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
276 |
X509Authentication.RSA, T12KeyAgreement.DHE); |
|
277 |
} |
|
278 |
||
279 |
private static class SSLKeyExDHERSAExport { |
|
280 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
281 |
X509Authentication.RSA, T12KeyAgreement.DHE_EXPORT); |
|
282 |
} |
|
283 |
||
284 |
private static class SSLKeyExDHANON { |
|
285 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
286 |
null, T12KeyAgreement.DHE); |
|
287 |
} |
|
288 |
||
289 |
private static class SSLKeyExDHANONExport { |
|
290 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
291 |
null, T12KeyAgreement.DHE_EXPORT); |
|
292 |
} |
|
293 |
||
294 |
private static class SSLKeyExECDHECDSA { |
|
295 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
296 |
X509Authentication.EC, T12KeyAgreement.ECDH); |
|
297 |
} |
|
298 |
||
299 |
private static class SSLKeyExECDHRSA { |
|
300 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
301 |
X509Authentication.EC, T12KeyAgreement.ECDH); |
|
302 |
} |
|
303 |
||
304 |
private static class SSLKeyExECDHEECDSA { |
|
305 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
306 |
X509Authentication.EC, T12KeyAgreement.ECDHE); |
|
307 |
} |
|
308 |
||
309 |
private static class SSLKeyExECDHERSA { |
|
310 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
311 |
X509Authentication.RSA, T12KeyAgreement.ECDHE); |
|
312 |
} |
|
313 |
||
314 |
private static class SSLKeyExECDHANON { |
|
315 |
private static SSLKeyExchange KE = new SSLKeyExchange( |
|
316 |
null, T12KeyAgreement.ECDHE); |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
317 |
} |
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
318 |
|
56542 | 319 |
private enum T12KeyAgreement implements SSLKeyAgreement { |
320 |
RSA ("rsa", null, |
|
321 |
RSAKeyExchange.kaGenerator), |
|
322 |
RSA_EXPORT ("rsa_export", RSAKeyExchange.poGenerator, |
|
323 |
RSAKeyExchange.kaGenerator), |
|
324 |
DHE ("dhe", DHKeyExchange.poGenerator, |
|
325 |
DHKeyExchange.kaGenerator), |
|
326 |
DHE_EXPORT ("dhe_export", DHKeyExchange.poExportableGenerator, |
|
327 |
DHKeyExchange.kaGenerator), |
|
328 |
ECDH ("ecdh", null, |
|
329 |
ECDHKeyExchange.ecdhKAGenerator), |
|
330 |
ECDHE ("ecdhe", ECDHKeyExchange.poGenerator, |
|
331 |
ECDHKeyExchange.ecdheKAGenerator); |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
332 |
|
56542 | 333 |
final String name; |
334 |
final SSLPossessionGenerator possessionGenerator; |
|
335 |
final SSLKeyAgreementGenerator keyAgreementGenerator; |
|
336 |
||
337 |
T12KeyAgreement(String name, |
|
338 |
SSLPossessionGenerator possessionGenerator, |
|
339 |
SSLKeyAgreementGenerator keyAgreementGenerator) { |
|
340 |
this.name = name; |
|
341 |
this.possessionGenerator = possessionGenerator; |
|
342 |
this.keyAgreementGenerator = keyAgreementGenerator; |
|
343 |
} |
|
344 |
||
345 |
@Override |
|
346 |
public SSLPossession createPossession(HandshakeContext context) { |
|
347 |
if (possessionGenerator != null) { |
|
348 |
return possessionGenerator.createPossession(context); |
|
349 |
} |
|
350 |
||
351 |
return null; |
|
352 |
} |
|
353 |
||
354 |
@Override |
|
355 |
public SSLKeyDerivation createKeyDerivation( |
|
356 |
HandshakeContext context) throws IOException { |
|
357 |
return keyAgreementGenerator.createKeyDerivation(context); |
|
358 |
} |
|
359 |
||
360 |
@Override |
|
361 |
public SSLHandshake[] getRelatedHandshakers( |
|
362 |
HandshakeContext handshakeContext) { |
|
363 |
if (!handshakeContext.negotiatedProtocol.useTLS13PlusSpec()) { |
|
364 |
if (this.possessionGenerator != null) { |
|
365 |
return new SSLHandshake[] { |
|
366 |
SSLHandshake.SERVER_KEY_EXCHANGE |
|
367 |
}; |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
return new SSLHandshake[0]; |
|
372 |
} |
|
373 |
||
374 |
@Override |
|
375 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
376 |
public Map.Entry<Byte, HandshakeProducer>[] getHandshakeProducers( |
|
377 |
HandshakeContext handshakeContext) { |
|
378 |
if (handshakeContext.negotiatedProtocol.useTLS13PlusSpec()) { |
|
379 |
return (Map.Entry<Byte, HandshakeProducer>[])(new Map.Entry[0]); |
|
380 |
} |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
381 |
|
56542 | 382 |
if (handshakeContext.sslConfig.isClientMode) { |
383 |
switch (this) { |
|
384 |
case RSA: |
|
385 |
case RSA_EXPORT: |
|
386 |
return (Map.Entry<Byte, |
|
387 |
HandshakeProducer>[])(new Map.Entry[] { |
|
388 |
new SimpleImmutableEntry<>( |
|
389 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
390 |
RSAClientKeyExchange.rsaHandshakeProducer |
|
391 |
) |
|
392 |
}); |
|
393 |
||
394 |
case DHE: |
|
395 |
case DHE_EXPORT: |
|
396 |
return (Map.Entry<Byte, |
|
397 |
HandshakeProducer>[])(new Map.Entry[] { |
|
398 |
new SimpleImmutableEntry<Byte, HandshakeProducer>( |
|
399 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
400 |
DHClientKeyExchange.dhHandshakeProducer |
|
401 |
) |
|
402 |
}); |
|
403 |
||
404 |
case ECDH: |
|
405 |
return (Map.Entry<Byte, |
|
406 |
HandshakeProducer>[])(new Map.Entry[] { |
|
407 |
new SimpleImmutableEntry<>( |
|
408 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
409 |
ECDHClientKeyExchange.ecdhHandshakeProducer |
|
410 |
) |
|
411 |
}); |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
412 |
|
56542 | 413 |
case ECDHE: |
414 |
return (Map.Entry<Byte, |
|
415 |
HandshakeProducer>[])(new Map.Entry[] { |
|
416 |
new SimpleImmutableEntry<>( |
|
417 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
418 |
ECDHClientKeyExchange.ecdheHandshakeProducer |
|
419 |
) |
|
420 |
}); |
|
421 |
} |
|
422 |
} else { |
|
423 |
switch (this) { |
|
424 |
case RSA_EXPORT: |
|
425 |
return (Map.Entry<Byte, |
|
426 |
HandshakeProducer>[])(new Map.Entry[] { |
|
427 |
new SimpleImmutableEntry<>( |
|
428 |
SSLHandshake.SERVER_KEY_EXCHANGE.id, |
|
429 |
RSAServerKeyExchange.rsaHandshakeProducer |
|
430 |
) |
|
431 |
}); |
|
432 |
||
433 |
case DHE: |
|
434 |
case DHE_EXPORT: |
|
435 |
return (Map.Entry<Byte, |
|
436 |
HandshakeProducer>[])(new Map.Entry[] { |
|
437 |
new SimpleImmutableEntry<>( |
|
438 |
SSLHandshake.SERVER_KEY_EXCHANGE.id, |
|
439 |
DHServerKeyExchange.dhHandshakeProducer |
|
440 |
) |
|
441 |
}); |
|
442 |
||
443 |
case ECDHE: |
|
444 |
return (Map.Entry<Byte, |
|
445 |
HandshakeProducer>[])(new Map.Entry[] { |
|
446 |
new SimpleImmutableEntry<>( |
|
447 |
SSLHandshake.SERVER_KEY_EXCHANGE.id, |
|
448 |
ECDHServerKeyExchange.ecdheHandshakeProducer |
|
449 |
) |
|
450 |
}); |
|
451 |
} |
|
452 |
} |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
453 |
|
56542 | 454 |
return (Map.Entry<Byte, HandshakeProducer>[])(new Map.Entry[0]); |
455 |
} |
|
456 |
||
457 |
@Override |
|
458 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
459 |
public Map.Entry<Byte, SSLConsumer>[] getHandshakeConsumers( |
|
460 |
HandshakeContext handshakeContext) { |
|
461 |
if (handshakeContext.negotiatedProtocol.useTLS13PlusSpec()) { |
|
462 |
return (Map.Entry<Byte, SSLConsumer>[])(new Map.Entry[0]); |
|
463 |
} |
|
464 |
||
465 |
if (handshakeContext.sslConfig.isClientMode) { |
|
466 |
switch (this) { |
|
467 |
case RSA_EXPORT: |
|
468 |
return (Map.Entry<Byte, |
|
469 |
SSLConsumer>[])(new Map.Entry[] { |
|
470 |
new SimpleImmutableEntry<>( |
|
471 |
SSLHandshake.SERVER_KEY_EXCHANGE.id, |
|
472 |
RSAServerKeyExchange.rsaHandshakeConsumer |
|
473 |
) |
|
474 |
}); |
|
475 |
||
476 |
case DHE: |
|
477 |
case DHE_EXPORT: |
|
478 |
return (Map.Entry<Byte, |
|
479 |
SSLConsumer>[])(new Map.Entry[] { |
|
480 |
new SimpleImmutableEntry<>( |
|
481 |
SSLHandshake.SERVER_KEY_EXCHANGE.id, |
|
482 |
DHServerKeyExchange.dhHandshakeConsumer |
|
483 |
) |
|
484 |
}); |
|
485 |
||
486 |
case ECDHE: |
|
487 |
return (Map.Entry<Byte, |
|
488 |
SSLConsumer>[])(new Map.Entry[] { |
|
489 |
new SimpleImmutableEntry<>( |
|
490 |
SSLHandshake.SERVER_KEY_EXCHANGE.id, |
|
491 |
ECDHServerKeyExchange.ecdheHandshakeConsumer |
|
492 |
) |
|
493 |
}); |
|
494 |
} |
|
495 |
} else { |
|
496 |
switch (this) { |
|
497 |
case RSA: |
|
498 |
case RSA_EXPORT: |
|
499 |
return (Map.Entry<Byte, |
|
500 |
SSLConsumer>[])(new Map.Entry[] { |
|
501 |
new SimpleImmutableEntry<>( |
|
502 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
503 |
RSAClientKeyExchange.rsaHandshakeConsumer |
|
504 |
) |
|
505 |
}); |
|
506 |
||
507 |
case DHE: |
|
508 |
case DHE_EXPORT: |
|
509 |
return (Map.Entry<Byte, |
|
510 |
SSLConsumer>[])(new Map.Entry[] { |
|
511 |
new SimpleImmutableEntry<>( |
|
512 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
513 |
DHClientKeyExchange.dhHandshakeConsumer |
|
514 |
) |
|
515 |
}); |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
516 |
|
56542 | 517 |
case ECDH: |
518 |
return (Map.Entry<Byte, |
|
519 |
SSLConsumer>[])(new Map.Entry[] { |
|
520 |
new SimpleImmutableEntry<>( |
|
521 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
522 |
ECDHClientKeyExchange.ecdhHandshakeConsumer |
|
523 |
) |
|
524 |
}); |
|
525 |
||
526 |
case ECDHE: |
|
527 |
return (Map.Entry<Byte, |
|
528 |
SSLConsumer>[])(new Map.Entry[] { |
|
529 |
new SimpleImmutableEntry<>( |
|
530 |
SSLHandshake.CLIENT_KEY_EXCHANGE.id, |
|
531 |
ECDHClientKeyExchange.ecdheHandshakeConsumer |
|
532 |
) |
|
533 |
}); |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
return (Map.Entry<Byte, SSLConsumer>[])(new Map.Entry[0]); |
|
538 |
} |
|
539 |
} |
|
540 |
||
541 |
private static final class T13KeyAgreement implements SSLKeyAgreement { |
|
542 |
private final NamedGroup namedGroup; |
|
543 |
static final Map<NamedGroup, T13KeyAgreement> |
|
544 |
supportedKeyShares = new HashMap<>(); |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
545 |
|
56542 | 546 |
static { |
547 |
for (NamedGroup namedGroup : |
|
548 |
SupportedGroups.supportedNamedGroups) { |
|
549 |
supportedKeyShares.put( |
|
550 |
namedGroup, new T13KeyAgreement(namedGroup)); |
|
551 |
} |
|
552 |
} |
|
553 |
||
554 |
private T13KeyAgreement(NamedGroup namedGroup) { |
|
555 |
this.namedGroup = namedGroup; |
|
556 |
} |
|
557 |
||
558 |
static T13KeyAgreement valueOf(NamedGroup namedGroup) { |
|
559 |
return supportedKeyShares.get(namedGroup); |
|
560 |
} |
|
561 |
||
562 |
@Override |
|
563 |
public SSLPossession createPossession(HandshakeContext hc) { |
|
56855 | 564 |
|
565 |
Optional<NamedGroupFunctions> ngf = namedGroup.getFunctions(); |
|
566 |
if (ngf.isEmpty()) { |
|
567 |
return null; |
|
56542 | 568 |
} |
56855 | 569 |
return ngf.get().createPossession(hc.sslContext.getSecureRandom()); |
56542 | 570 |
} |
571 |
||
572 |
@Override |
|
573 |
public SSLKeyDerivation createKeyDerivation( |
|
574 |
HandshakeContext hc) throws IOException { |
|
56855 | 575 |
|
576 |
Optional<NamedGroupFunctions> ngf = namedGroup.getFunctions(); |
|
577 |
if (ngf.isEmpty()) { |
|
578 |
return null; |
|
56542 | 579 |
} |
56855 | 580 |
return ngf.get().createKeyDerivation(hc); |
56542 | 581 |
|
582 |
} |
|
583 |
} |
|
30905
bba6fefdd660
8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff
changeset
|
584 |
} |