1
1
/*
2
- * Copyright (c) 2015, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2020 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
29
29
import java .util .AbstractMap .SimpleImmutableEntry ;
30
30
import java .util .Arrays ;
31
31
import java .util .HashMap ;
32
+ import java .util .List ;
32
33
import java .util .Map ;
33
34
import sun .security .ssl .SupportedGroupsExtension .SupportedGroups ;
34
35
import sun .security .ssl .X509Authentication .X509Possession ;
35
36
36
37
final class SSLKeyExchange implements SSLKeyAgreementGenerator ,
37
38
SSLHandshakeBinding {
38
- private final SSLAuthentication authentication ;
39
+ private final List < SSLAuthentication > authentication ;
39
40
private final SSLKeyAgreement keyAgreement ;
40
41
41
- SSLKeyExchange (X509Authentication authentication ,
42
+ SSLKeyExchange (List < X509Authentication > authentication ,
42
43
SSLKeyAgreement keyAgreement ) {
43
- this .authentication = authentication ;
44
+ if (authentication != null ) {
45
+ this .authentication = List .copyOf (authentication );
46
+ } else {
47
+ this .authentication = null ;
48
+ }
44
49
this .keyAgreement = keyAgreement ;
45
50
}
46
51
47
52
SSLPossession [] createPossessions (HandshakeContext context ) {
48
53
// authentication
49
54
SSLPossession authPossession = null ;
50
55
if (authentication != null ) {
51
- authPossession = authentication .createPossession (context );
56
+ // Loop through potential authentication types and end at
57
+ // the first non-null possession.
58
+ for (SSLAuthentication authType : authentication ) {
59
+ if ((authPossession = authType .createPossession (context ))
60
+ != null ) {
61
+ break ;
62
+ }
63
+ }
64
+
52
65
if (authPossession == null ) {
53
66
return new SSLPossession [0 ];
54
67
} else if (context instanceof ServerHandshakeContext ) {
@@ -109,12 +122,14 @@ public SSLKeyDerivation createKeyDerivation(
109
122
@ Override
110
123
public SSLHandshake [] getRelatedHandshakers (
111
124
HandshakeContext handshakeContext ) {
112
- SSLHandshake [] auHandshakes ;
125
+ SSLHandshake [] auHandshakes = null ;
113
126
if (authentication != null ) {
114
- auHandshakes =
115
- authentication .getRelatedHandshakers (handshakeContext );
116
- } else {
117
- auHandshakes = null ;
127
+ for (SSLAuthentication authType : authentication ) {
128
+ auHandshakes = authType .getRelatedHandshakers (handshakeContext );
129
+ if (auHandshakes != null && auHandshakes .length > 0 ) {
130
+ break ;
131
+ }
132
+ }
118
133
}
119
134
120
135
SSLHandshake [] kaHandshakes =
@@ -136,12 +151,14 @@ public SSLHandshake[] getRelatedHandshakers(
136
151
@ Override
137
152
public Map .Entry <Byte , HandshakeProducer >[] getHandshakeProducers (
138
153
HandshakeContext handshakeContext ) {
139
- Map .Entry <Byte , HandshakeProducer >[] auProducers ;
154
+ Map .Entry <Byte , HandshakeProducer >[] auProducers = null ;
140
155
if (authentication != null ) {
141
- auProducers =
142
- authentication .getHandshakeProducers (handshakeContext );
143
- } else {
144
- auProducers = null ;
156
+ for (SSLAuthentication authType : authentication ) {
157
+ auProducers = authType .getHandshakeProducers (handshakeContext );
158
+ if (auProducers != null && auProducers .length > 0 ) {
159
+ break ;
160
+ }
161
+ }
145
162
}
146
163
147
164
Map .Entry <Byte , HandshakeProducer >[] kaProducers =
@@ -163,12 +180,14 @@ public Map.Entry<Byte, HandshakeProducer>[] getHandshakeProducers(
163
180
@ Override
164
181
public Map .Entry <Byte , SSLConsumer >[] getHandshakeConsumers (
165
182
HandshakeContext handshakeContext ) {
166
- Map .Entry <Byte , SSLConsumer >[] auConsumers ;
183
+ Map .Entry <Byte , SSLConsumer >[] auConsumers = null ;
167
184
if (authentication != null ) {
168
- auConsumers =
169
- authentication .getHandshakeConsumers (handshakeContext );
170
- } else {
171
- auConsumers = null ;
185
+ for (SSLAuthentication authType : authentication ) {
186
+ auConsumers = authType .getHandshakeConsumers (handshakeContext );
187
+ if (auConsumers != null && auConsumers .length > 0 ) {
188
+ break ;
189
+ }
190
+ }
172
191
}
173
192
174
193
Map .Entry <Byte , SSLConsumer >[] kaConsumers =
@@ -247,37 +266,37 @@ static SSLKeyExchange valueOf(NamedGroup namedGroup) {
247
266
248
267
private static class SSLKeyExRSA {
249
268
private static SSLKeyExchange KE = new SSLKeyExchange (
250
- X509Authentication .RSA , T12KeyAgreement .RSA );
269
+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .RSA );
251
270
}
252
271
253
272
private static class SSLKeyExRSAExport {
254
273
private static SSLKeyExchange KE = new SSLKeyExchange (
255
- X509Authentication .RSA , T12KeyAgreement .RSA_EXPORT );
274
+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .RSA_EXPORT );
256
275
}
257
276
258
277
private static class SSLKeyExDHEDSS {
259
278
private static SSLKeyExchange KE = new SSLKeyExchange (
260
- X509Authentication .DSA , T12KeyAgreement .DHE );
279
+ List . of ( X509Authentication .DSA ) , T12KeyAgreement .DHE );
261
280
}
262
281
263
282
private static class SSLKeyExDHEDSSExport {
264
283
private static SSLKeyExchange KE = new SSLKeyExchange (
265
- X509Authentication .DSA , T12KeyAgreement .DHE_EXPORT );
284
+ List . of ( X509Authentication .DSA ) , T12KeyAgreement .DHE_EXPORT );
266
285
}
267
286
268
287
private static class SSLKeyExDHERSA {
269
288
private static SSLKeyExchange KE = new SSLKeyExchange (
270
- X509Authentication .RSA , T12KeyAgreement .DHE );
289
+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .DHE );
271
290
}
272
291
273
292
private static class SSLKeyExDHERSAOrPSS {
274
293
private static SSLKeyExchange KE = new SSLKeyExchange (
275
- X509Authentication .RSA_OR_PSS , T12KeyAgreement .DHE );
294
+ List . of ( X509Authentication .RSA_OR_PSS ) , T12KeyAgreement .DHE );
276
295
}
277
296
278
297
private static class SSLKeyExDHERSAExport {
279
298
private static SSLKeyExchange KE = new SSLKeyExchange (
280
- X509Authentication .RSA , T12KeyAgreement .DHE_EXPORT );
299
+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .DHE_EXPORT );
281
300
}
282
301
283
302
private static class SSLKeyExDHANON {
@@ -292,27 +311,28 @@ private static class SSLKeyExDHANONExport {
292
311
293
312
private static class SSLKeyExECDHECDSA {
294
313
private static SSLKeyExchange KE = new SSLKeyExchange (
295
- X509Authentication .EC , T12KeyAgreement .ECDH );
314
+ List . of ( X509Authentication .EC ) , T12KeyAgreement .ECDH );
296
315
}
297
316
298
317
private static class SSLKeyExECDHRSA {
299
318
private static SSLKeyExchange KE = new SSLKeyExchange (
300
- X509Authentication .EC , T12KeyAgreement .ECDH );
319
+ List . of ( X509Authentication .EC ) , T12KeyAgreement .ECDH );
301
320
}
302
321
303
322
private static class SSLKeyExECDHEECDSA {
304
323
private static SSLKeyExchange KE = new SSLKeyExchange (
305
- X509Authentication .EC , T12KeyAgreement .ECDHE );
324
+ List .of (X509Authentication .EC , X509Authentication .EDDSA ),
325
+ T12KeyAgreement .ECDHE );
306
326
}
307
327
308
328
private static class SSLKeyExECDHERSA {
309
329
private static SSLKeyExchange KE = new SSLKeyExchange (
310
- X509Authentication .RSA , T12KeyAgreement .ECDHE );
330
+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .ECDHE );
311
331
}
312
332
313
333
private static class SSLKeyExECDHERSAOrPSS {
314
334
private static SSLKeyExchange KE = new SSLKeyExchange (
315
- X509Authentication .RSA_OR_PSS , T12KeyAgreement .ECDHE );
335
+ List . of ( X509Authentication .RSA_OR_PSS ) , T12KeyAgreement .ECDHE );
316
336
}
317
337
318
338
private static class SSLKeyExECDHANON {
0 commit comments