11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2929import java .util .AbstractMap .SimpleImmutableEntry ;
3030import java .util .Arrays ;
3131import java .util .HashMap ;
32+ import java .util .List ;
3233import java .util .Map ;
3334import sun .security .ssl .SupportedGroupsExtension .SupportedGroups ;
3435import sun .security .ssl .X509Authentication .X509Possession ;
3536
3637final class SSLKeyExchange implements SSLKeyAgreementGenerator ,
3738 SSLHandshakeBinding {
38- private final SSLAuthentication authentication ;
39+ private final List < SSLAuthentication > authentication ;
3940 private final SSLKeyAgreement keyAgreement ;
4041
41- SSLKeyExchange (X509Authentication authentication ,
42+ SSLKeyExchange (List < X509Authentication > authentication ,
4243 SSLKeyAgreement keyAgreement ) {
43- this .authentication = authentication ;
44+ if (authentication != null ) {
45+ this .authentication = List .copyOf (authentication );
46+ } else {
47+ this .authentication = null ;
48+ }
4449 this .keyAgreement = keyAgreement ;
4550 }
4651
4752 SSLPossession [] createPossessions (HandshakeContext context ) {
4853 // authentication
4954 SSLPossession authPossession = null ;
5055 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+
5265 if (authPossession == null ) {
5366 return new SSLPossession [0 ];
5467 } else if (context instanceof ServerHandshakeContext ) {
@@ -109,12 +122,14 @@ public SSLKeyDerivation createKeyDerivation(
109122 @ Override
110123 public SSLHandshake [] getRelatedHandshakers (
111124 HandshakeContext handshakeContext ) {
112- SSLHandshake [] auHandshakes ;
125+ SSLHandshake [] auHandshakes = null ;
113126 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+ }
118133 }
119134
120135 SSLHandshake [] kaHandshakes =
@@ -136,12 +151,14 @@ public SSLHandshake[] getRelatedHandshakers(
136151 @ Override
137152 public Map .Entry <Byte , HandshakeProducer >[] getHandshakeProducers (
138153 HandshakeContext handshakeContext ) {
139- Map .Entry <Byte , HandshakeProducer >[] auProducers ;
154+ Map .Entry <Byte , HandshakeProducer >[] auProducers = null ;
140155 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+ }
145162 }
146163
147164 Map .Entry <Byte , HandshakeProducer >[] kaProducers =
@@ -163,12 +180,14 @@ public Map.Entry<Byte, HandshakeProducer>[] getHandshakeProducers(
163180 @ Override
164181 public Map .Entry <Byte , SSLConsumer >[] getHandshakeConsumers (
165182 HandshakeContext handshakeContext ) {
166- Map .Entry <Byte , SSLConsumer >[] auConsumers ;
183+ Map .Entry <Byte , SSLConsumer >[] auConsumers = null ;
167184 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+ }
172191 }
173192
174193 Map .Entry <Byte , SSLConsumer >[] kaConsumers =
@@ -247,37 +266,37 @@ static SSLKeyExchange valueOf(NamedGroup namedGroup) {
247266
248267 private static class SSLKeyExRSA {
249268 private static SSLKeyExchange KE = new SSLKeyExchange (
250- X509Authentication .RSA , T12KeyAgreement .RSA );
269+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .RSA );
251270 }
252271
253272 private static class SSLKeyExRSAExport {
254273 private static SSLKeyExchange KE = new SSLKeyExchange (
255- X509Authentication .RSA , T12KeyAgreement .RSA_EXPORT );
274+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .RSA_EXPORT );
256275 }
257276
258277 private static class SSLKeyExDHEDSS {
259278 private static SSLKeyExchange KE = new SSLKeyExchange (
260- X509Authentication .DSA , T12KeyAgreement .DHE );
279+ List . of ( X509Authentication .DSA ) , T12KeyAgreement .DHE );
261280 }
262281
263282 private static class SSLKeyExDHEDSSExport {
264283 private static SSLKeyExchange KE = new SSLKeyExchange (
265- X509Authentication .DSA , T12KeyAgreement .DHE_EXPORT );
284+ List . of ( X509Authentication .DSA ) , T12KeyAgreement .DHE_EXPORT );
266285 }
267286
268287 private static class SSLKeyExDHERSA {
269288 private static SSLKeyExchange KE = new SSLKeyExchange (
270- X509Authentication .RSA , T12KeyAgreement .DHE );
289+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .DHE );
271290 }
272291
273292 private static class SSLKeyExDHERSAOrPSS {
274293 private static SSLKeyExchange KE = new SSLKeyExchange (
275- X509Authentication .RSA_OR_PSS , T12KeyAgreement .DHE );
294+ List . of ( X509Authentication .RSA_OR_PSS ) , T12KeyAgreement .DHE );
276295 }
277296
278297 private static class SSLKeyExDHERSAExport {
279298 private static SSLKeyExchange KE = new SSLKeyExchange (
280- X509Authentication .RSA , T12KeyAgreement .DHE_EXPORT );
299+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .DHE_EXPORT );
281300 }
282301
283302 private static class SSLKeyExDHANON {
@@ -292,27 +311,28 @@ private static class SSLKeyExDHANONExport {
292311
293312 private static class SSLKeyExECDHECDSA {
294313 private static SSLKeyExchange KE = new SSLKeyExchange (
295- X509Authentication .EC , T12KeyAgreement .ECDH );
314+ List . of ( X509Authentication .EC ) , T12KeyAgreement .ECDH );
296315 }
297316
298317 private static class SSLKeyExECDHRSA {
299318 private static SSLKeyExchange KE = new SSLKeyExchange (
300- X509Authentication .EC , T12KeyAgreement .ECDH );
319+ List . of ( X509Authentication .EC ) , T12KeyAgreement .ECDH );
301320 }
302321
303322 private static class SSLKeyExECDHEECDSA {
304323 private static SSLKeyExchange KE = new SSLKeyExchange (
305- X509Authentication .EC , T12KeyAgreement .ECDHE );
324+ List .of (X509Authentication .EC , X509Authentication .EDDSA ),
325+ T12KeyAgreement .ECDHE );
306326 }
307327
308328 private static class SSLKeyExECDHERSA {
309329 private static SSLKeyExchange KE = new SSLKeyExchange (
310- X509Authentication .RSA , T12KeyAgreement .ECDHE );
330+ List . of ( X509Authentication .RSA ) , T12KeyAgreement .ECDHE );
311331 }
312332
313333 private static class SSLKeyExECDHERSAOrPSS {
314334 private static SSLKeyExchange KE = new SSLKeyExchange (
315- X509Authentication .RSA_OR_PSS , T12KeyAgreement .ECDHE );
335+ List . of ( X509Authentication .RSA_OR_PSS ) , T12KeyAgreement .ECDHE );
316336 }
317337
318338 private static class SSLKeyExECDHANON {
0 commit comments