@@ -19618,17 +19618,31 @@ var testMultipleCertSlotsAlgorithms = []struct {
1961819618 {"ECDSA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 0, testCertECDSAP256, CurveP256},
1961919619}
1962019620
19621- // TODO: Add more failure test cases.
1962219621func addMultipleCertSlotTests() {
1962319622 var allAlgorithms []signatureAlgorithm
1962419623 for _, alg := range testMultipleCertSlotsAlgorithms {
1962519624 if alg.id != 0 {
1962619625 allAlgorithms = append(allAlgorithms, alg.id)
1962719626 }
1962819627 }
19628+ multipleCertsFlag := "-multiple-certs-slot"
19629+ rsaCertSlot := []string{
19630+ multipleCertsFlag, path.Join(*resourceDir, getShimCertificate(testCertRSA)) + "," + path.Join(*resourceDir, getShimKey(testCertRSA)),
19631+ }
19632+ ecdsaCertSlot := []string{
19633+ multipleCertsFlag, path.Join(*resourceDir, getShimCertificate(testCertECDSAP256)) + "," + path.Join(*resourceDir, getShimKey(testCertECDSAP256)),
19634+ }
19635+ ed25519CertSlot := []string{
19636+ multipleCertsFlag, path.Join(*resourceDir, getShimCertificate(testCertEd25519)) + "," + path.Join(*resourceDir, getShimKey(testCertEd25519)),
19637+ }
19638+ certificateSlotFlags := []string{
19639+ rsaCertSlot[0], rsaCertSlot[1],
19640+ ecdsaCertSlot[0], ecdsaCertSlot[1],
19641+ ed25519CertSlot[0], ed25519CertSlot[1],
19642+ }
1962919643
19630- // TODO: add client tests to verify we don't support multiple certs on the client end.
19631- prefix := "Server- "
19644+ signError := ":NO_COMMON_SIGNATURE_ALGORITHMS:"
19645+ signLocalError := "remote error: handshake failure "
1963219646
1963319647 // Make sure each signature algorithm works.
1963419648 for _, alg := range testMultipleCertSlotsAlgorithms {
@@ -19637,6 +19651,7 @@ func addMultipleCertSlotTests() {
1963719651 continue
1963819652 }
1963919653
19654+ prefix := "Server-"
1964019655 var shouldFail bool
1964119656 // ecdsa_sha1 does not exist in TLS 1.3.
1964219657 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
@@ -19672,17 +19687,14 @@ func addMultipleCertSlotTests() {
1967219687 VerifySignatureAlgorithms: allAlgorithms,
1967319688 },
1967419689 flags: append(
19675- []string{
19676- "-multiple-certs-slot", path.Join(*resourceDir, getShimCertificate(testCertRSA)) + "," + path.Join(*resourceDir, getShimKey(testCertRSA)),
19677- "-multiple-certs-slot", path.Join(*resourceDir, getShimCertificate(testCertECDSAP256)) + "," + path.Join(*resourceDir, getShimKey(testCertECDSAP256)),
19678- "-multiple-certs-slot", path.Join(*resourceDir, getShimCertificate(testCertEd25519)) + "," + path.Join(*resourceDir, getShimKey(testCertEd25519)),
19679- },
19690+ certificateSlotFlags,
1968019691 curveFlags...,
1968119692 ),
1968219693 expectations: connectionExpectations{
1968319694 peerSignatureAlgorithm: alg.id,
1968419695 },
1968519696 }
19697+
1968619698 if alg.id != 0 {
1968719699 strictAlgTest.flags = append(strictAlgTest.flags, "-signing-prefs", strconv.Itoa(int(alg.id)))
1968819700 }
@@ -19692,8 +19704,41 @@ func addMultipleCertSlotTests() {
1969219704 strictAlgTest.config.CipherSuites = []uint16{alg.cipher}
1969319705 }
1969419706
19707+ // Extend the original test, but force it to use the early certificate callback instead.
19708+ // Expected behavior should be the same.
19709+ strictAlgCallbackTest := strictAlgTest
19710+ strictAlgCallbackTest.name = prefix + "Multiple-Cert-Strict-Alg-Callback" + suffix
19711+ strictAlgCallbackTest.flags = append(strictAlgCallbackTest.flags, "-use-early-callback")
19712+
19713+ // Verify that we don't support multiple certificate slots on the client side. The client should be
19714+ // configured with the last certificate set (ED25519 in this case).
19715+ prefix = "Client-"
19716+ strictAlgClientTest := testCase{
19717+ testType: clientTest,
19718+ name: prefix + "Multiple-Cert-Strict-Alg" + suffix,
19719+ config: Config{
19720+ MaxVersion: ver.version,
19721+ VerifySignatureAlgorithms: []signatureAlgorithm{alg.id},
19722+ ClientAuth: RequireAnyClientCert,
19723+ Certificates: []Certificate{rsaCertificate, ecdsaP256Certificate, ed25519Certificate},
19724+ },
19725+ flags: append(
19726+ certificateSlotFlags,
19727+ curveFlags...,
19728+ ),
19729+ }
19730+ if alg.id != signatureEd25519 {
19731+ // ED25519 is the last certificate set in |certificateSlotFlags|. We don't support multiple certificate
19732+ // slots on the client side, so the client should only be configured to use ED25519.
19733+ strictAlgClientTest.shouldFail = true
19734+ strictAlgClientTest.expectedError = signError
19735+ strictAlgClientTest.expectedLocalError = signLocalError
19736+ }
19737+
1969519738 if !shouldFail {
1969619739 testCases = append(testCases, strictAlgTest)
19740+ testCases = append(testCases, strictAlgCallbackTest)
19741+ testCases = append(testCases, strictAlgClientTest)
1969719742 }
1969819743 }
1969919744 }
@@ -19704,27 +19749,94 @@ func addMultipleCertSlotTests() {
1970419749 // ED25519 signature algorithm should be prioritized if supported.
1970519750 ed25519PriorityTest := testCase{
1970619751 testType: serverTest,
19707- name: prefix + " Multiple-Cert-ED25519-Priority" + suffix,
19752+ name: "Server- Multiple-Cert-ED25519-Priority" + suffix,
1970819753 config: Config{
1970919754 MaxVersion: ver.version,
1971019755 VerifySignatureAlgorithms: allAlgorithms,
1971119756 },
1971219757 flags: append(
19713- []string{
19714- "-multiple-certs-slot", path.Join(*resourceDir, getShimCertificate(testCertRSA)) + "," + path.Join(*resourceDir, getShimKey(testCertRSA)),
19715- "-multiple-certs-slot", path.Join(*resourceDir, getShimCertificate(testCertECDSAP256)) + "," + path.Join(*resourceDir, getShimKey(testCertECDSAP256)),
19716- "-multiple-certs-slot", path.Join(*resourceDir, getShimCertificate(testCertEd25519)) + "," + path.Join(*resourceDir, getShimKey(testCertEd25519)),
19717- },
19758+ certificateSlotFlags,
1971819759 flagInts("-curves", []int{int(CurveX25519), int(CurveP256)})...,
1971919760 ),
1972019761 expectations: connectionExpectations{
1972119762 peerSignatureAlgorithm: signatureEd25519,
1972219763 },
1972319764 }
1972419765
19766+ // Below tests verify that multiple certificates only works because we have a valid cert.
19767+
19768+ // Connection shouldn't be accepted without RSA cert.
19769+ noRSACertTest := testCase{
19770+ testType: serverTest,
19771+ name: "Server-Multiple-Cert-No-RSA" + suffix,
19772+ config: Config{
19773+ MaxVersion: ver.version,
19774+ VerifySignatureAlgorithms: allAlgorithms,
19775+ },
19776+ flags: []string{
19777+ ecdsaCertSlot[0], ecdsaCertSlot[1],
19778+ ed25519CertSlot[0], ed25519CertSlot[1],
19779+ "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
19780+ },
19781+ shouldFail: true,
19782+ expectedError: signError,
19783+ expectedLocalError: signLocalError,
19784+ }
19785+ // RSA support in TLS1.2 and lower is indicated with |mask_k| in |ssl_get_compatible_server_ciphers|.
19786+ // We do not have a valid public or private RSA key set up, so this fails early.
19787+ if ver.version <= VersionTLS12 {
19788+ noRSACertTest.expectedError = ":NO_SHARED_CIPHER:"
19789+ }
19790+
19791+ // Connection shouldn't be accepted without ECDSA cert.
19792+ noECDSACertTest := testCase{
19793+ testType: serverTest,
19794+ name: "Server-Multiple-Cert-No-ECDSA" + suffix,
19795+ config: Config{
19796+ MaxVersion: ver.version,
19797+ VerifySignatureAlgorithms: allAlgorithms,
19798+ },
19799+ flags: []string{
19800+ rsaCertSlot[0], rsaCertSlot[1],
19801+ ed25519CertSlot[0], ed25519CertSlot[1],
19802+ "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
19803+ },
19804+ shouldFail: true,
19805+ expectedError: signError,
19806+ expectedLocalError: signLocalError,
19807+ }
19808+
19809+ // Connection shouldn't be accepted without ED25519 cert.
19810+ noED25519CertTest := testCase{
19811+ testType: serverTest,
19812+ name: "Server-Multiple-Cert-No-ED25519" + suffix,
19813+ config: Config{
19814+ MaxVersion: ver.version,
19815+ VerifySignatureAlgorithms: allAlgorithms,
19816+ },
19817+ flags: []string{
19818+ rsaCertSlot[0], rsaCertSlot[1],
19819+ ecdsaCertSlot[0], ecdsaCertSlot[1],
19820+ "-signing-prefs", strconv.Itoa(int(signatureEd25519)),
19821+ },
19822+ shouldFail: true,
19823+ expectedError: signError,
19824+ expectedLocalError: signLocalError,
19825+ }
19826+
19827+ if ver.version <= VersionTLS12 {
19828+ noRSACertTest.config.CipherSuites = []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA}
19829+ noECDSACertTest.config.CipherSuites = []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA}
19830+ noED25519CertTest.config.CipherSuites = []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}
19831+ }
19832+
19833+ // ED25519 is only supported in TLS1.2 and above.
1972519834 if ver.version >= VersionTLS12 {
1972619835 testCases = append(testCases, ed25519PriorityTest)
19836+ testCases = append(testCases, noED25519CertTest)
1972719837 }
19838+ testCases = append(testCases, noRSACertTest)
19839+ testCases = append(testCases, noECDSACertTest)
1972819840 }
1972919841}
1973019842
0 commit comments