@@ -593,20 +593,21 @@ TEST(SSLTest, ClientHello) {
593593 0x0a , 0x00 , 0x08 , 0x00 , 0x06 , 0x00 , 0x1d , 0x00 , 0x17 , 0x00 , 0x18 , 0x00 ,
594594 0x0b , 0x00 , 0x02 , 0x01 , 0x00 , 0x00 , 0x23 , 0x00 , 0x00 }},
595595 {TLS1_2_VERSION,
596- {0x16 , 0x03 , 0x01 , 0x00 , 0x88 , 0x01 , 0x00 , 0x00 , 0x84 , 0x03 , 0x03 , 0x00 ,
596+ {0x16 , 0x03 , 0x01 , 0x00 , 0x8e , 0x01 , 0x00 , 0x00 , 0x8a , 0x03 , 0x03 , 0x00 ,
597597 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
598598 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
599599 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x22 , 0xcc , 0xa9 ,
600600 0xcc , 0xa8 , 0xc0 , 0x2b , 0xc0 , 0x2f , 0xc0 , 0x2c , 0xc0 , 0x30 , 0xc0 , 0x09 ,
601601 0xc0 , 0x13 , 0xc0 , 0x27 , 0xc0 , 0x0a , 0xc0 , 0x14 , 0xc0 , 0x28 , 0x00 , 0x9c ,
602- 0x00 , 0x9d , 0x00 , 0x2f , 0x00 , 0x3c , 0x00 , 0x35 , 0x01 , 0x00 , 0x00 , 0x39 ,
602+ 0x00 , 0x9d , 0x00 , 0x2f , 0x00 , 0x3c , 0x00 , 0x35 , 0x01 , 0x00 , 0x00 , 0x3f ,
603603 0x00 , 0x17 , 0x00 , 0x00 , 0xff , 0x01 , 0x00 , 0x01 , 0x00 , 0x00 , 0x0a , 0x00 ,
604604 0x08 , 0x00 , 0x06 , 0x00 , 0x1d , 0x00 , 0x17 , 0x00 , 0x18 , 0x00 , 0x0b , 0x00 ,
605- 0x02 , 0x01 , 0x00 , 0x00 , 0x23 , 0x00 , 0x00 , 0x00 , 0x0d , 0x00 , 0x16 , 0x00 ,
606- 0x14 , 0x04 , 0x03 , 0x08 , 0x04 , 0x04 , 0x01 , 0x05 , 0x03 , 0x08 , 0x05 , 0x05 ,
607- 0x01 , 0x06 , 0x03 , 0x08 , 0x06 , 0x06 , 0x01 , 0x02 , 0x01 }},
605+ 0x02 , 0x01 , 0x00 , 0x00 , 0x23 , 0x00 , 0x00 , 0x00 , 0x0d , 0x00 , 0x1c , 0x00 ,
606+ 0x1a , 0x04 , 0x03 , 0x08 , 0x04 , 0x04 , 0x01 , 0x05 , 0x03 , 0x08 , 0x05 , 0x05 ,
607+ 0x01 , 0x06 , 0x03 , 0x08 , 0x06 , 0x06 , 0x01 , 0x09 , 0x04 , 0x09 , 0x05 , 0x09 ,
608+ 0x06 , 0x02 , 0x01 }},
608609 {TLS1_3_VERSION,
609- {0x16 , 0x03 , 0x01 , 0x05 , 0xb5 , 0x01 , 0x00 , 0x05 , 0xb1 , 0x03 , 0x03 , 0x00 ,
610+ {0x16 , 0x03 , 0x01 , 0x05 , 0xbb , 0x01 , 0x00 , 0x05 , 0xb7 , 0x03 , 0x03 , 0x00 ,
610611 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
611612 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
612613 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -616,13 +617,13 @@ TEST(SSLTest, ClientHello) {
616617 0xcc , 0xa9 , 0xcc , 0xa8 , 0xc0 , 0x2b , 0xc0 , 0x2f , 0xc0 , 0x2c , 0xc0 , 0x30 ,
617618 0xc0 , 0x09 , 0xc0 , 0x13 , 0xc0 , 0x27 , 0xc0 , 0x0a , 0xc0 , 0x14 , 0xc0 , 0x28 ,
618619 0x00 , 0x9c , 0x00 , 0x9d , 0x00 , 0x2f , 0x00 , 0x3c , 0x00 , 0x35 , 0x01 , 0x00 ,
619- 0x05 , 0x40 , 0x00 , 0x17 , 0x00 , 0x00 , 0xff , 0x01 , 0x00 , 0x01 , 0x00 , 0x00 ,
620+ 0x05 , 0x46 , 0x00 , 0x17 , 0x00 , 0x00 , 0xff , 0x01 , 0x00 , 0x01 , 0x00 , 0x00 ,
620621 0x0a , 0x00 , 0x0e , 0x00 , 0x0c , 0x11 , 0xec , 0x11 , 0xeb , 0x11 , 0xed , 0x00 ,
621622 0x1d , 0x00 , 0x17 , 0x00 , 0x18 , 0x00 , 0x0b , 0x00 , 0x02 , 0x01 , 0x00 , 0x00 ,
622- 0x23 , 0x00 , 0x00 , 0x00 , 0x0d , 0x00 , 0x16 , 0x00 , 0x14 , 0x04 , 0x03 , 0x08 ,
623+ 0x23 , 0x00 , 0x00 , 0x00 , 0x0d , 0x00 , 0x1c , 0x00 , 0x1a , 0x04 , 0x03 , 0x08 ,
623624 0x04 , 0x04 , 0x01 , 0x05 , 0x03 , 0x08 , 0x05 , 0x05 , 0x01 , 0x06 , 0x03 , 0x08 ,
624- 0x06 , 0x06 , 0x01 , 0x02 , 0x01 , 0x00 , 0x33 , 0x04 , 0xea , 0x04 , 0xe8 , 0x11 ,
625- 0xec , 0x04 , 0xc0 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
625+ 0x06 , 0x06 , 0x01 , 0x09 , 0x04 , 0x09 , 0x05 , 0x09 , 0x06 , 0x02 , 0x01 , 0x00 ,
626+ 0x33 , 0x04 , 0xea , 0x04 , 0xe8 , 0x11 , 0xec , 0x04 , 0xc0 , 0x00 , 0x00 , 0x00 ,
626627 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
627628 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
628629 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -723,12 +724,12 @@ TEST(SSLTest, ClientHello) {
723724 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
724725 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
725726 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
726- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x1d , 0x00 , 0x20 , 0x00 ,
727727 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
728+ 0x00 , 0x00 , 0x1d , 0x00 , 0x20 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
728729 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
729- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x2d , 0x00 , 0x02 , 0x01 ,
730- 0x01 , 0x00 , 0x2b , 0x00 , 0x09 , 0x08 , 0x03 , 0x04 , 0x03 , 0x03 , 0x03 , 0x02 ,
731- 0x03 , 0x01 }},
730+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
731+ 0x00 , 0x00 , 0x2d , 0x00 , 0x02 , 0x01 , 0x01 , 0x00 , 0x2b , 0x00 , 0x09 , 0x08 ,
732+ 0x03 , 0x04 , 0x03 , 0x03 , 0x03 , 0x02 , 0x03 , 0x01 }},
732733 };
733734
734735 for (const auto &t : kTests ) {
@@ -757,7 +758,7 @@ TEST(SSLTest, ClientHello) {
757758 1 + 3 + // handshake message header
758759 2 ; // client_version
759760
760- constexpr size_t kKeyShare1Offset = 195 ;
761+ constexpr size_t kKeyShare1Offset = 201 ;
761762 constexpr size_t kKeyShare1Size = 32 + MLKEM768_PUBLIC_KEY_BYTES;
762763 constexpr size_t kKeyShare2Offset = kKeyShare1Offset + kKeyShare1Size
763764 + 2 // KeyShare 2 IANA ID
@@ -1934,6 +1935,111 @@ TEST_P(MultipleCertificateSlotTest, MissingPrivateKey) {
19341935}
19351936
19361937
1938+ // ML-DSA TLS 1.3 signature-scheme tests (draft-ietf-tls-mldsa). These
1939+ // exercise the plumbing in ssl_privkey.cc / ssl_cipher.cc that wires
1940+ // EVP_PKEY_PQDSA into TLS 1.3 handshake signing and verification.
1941+
1942+ struct MLDSATestParams {
1943+ const char name[16 ];
1944+ uint16_t sigalg;
1945+ bssl::UniquePtr<X509> (*certificate)();
1946+ bssl::UniquePtr<EVP_PKEY> (*key)();
1947+ };
1948+
1949+ static const MLDSATestParams kMLDSATests [] = {
1950+ {" MLDSA44" , SSL_SIGN_MLDSA44, GetMLDSA44TestCertificate,
1951+ GetMLDSA44TestKey},
1952+ {" MLDSA65" , SSL_SIGN_MLDSA65, GetMLDSA65TestCertificate,
1953+ GetMLDSA65TestKey},
1954+ {" MLDSA87" , SSL_SIGN_MLDSA87, GetMLDSA87TestCertificate,
1955+ GetMLDSA87TestKey},
1956+ };
1957+
1958+ class MLDSAHandshakeTest : public testing ::TestWithParam<MLDSATestParams> {};
1959+
1960+ INSTANTIATE_TEST_SUITE_P (
1961+ MLDSA, MLDSAHandshakeTest, testing::ValuesIn(kMLDSATests ),
1962+ [](const testing::TestParamInfo<MLDSATestParams> &info) {
1963+ return info.param .name ;
1964+ });
1965+
1966+ TEST_P (MLDSAHandshakeTest, HandshakeSucceeds) {
1967+ bssl::UniquePtr<SSL_CTX> client_ctx (SSL_CTX_new (TLS_method ()));
1968+ bssl::UniquePtr<SSL_CTX> server_ctx (
1969+ CreateContextWithCertificate (TLS_method (), GetParam ().certificate (),
1970+ GetParam ().key ()));
1971+ ASSERT_TRUE (client_ctx);
1972+ ASSERT_TRUE (server_ctx);
1973+ ASSERT_TRUE (SSL_CTX_set_min_proto_version (client_ctx.get (), TLS1_3_VERSION));
1974+ ASSERT_TRUE (SSL_CTX_set_max_proto_version (client_ctx.get (), TLS1_3_VERSION));
1975+ ASSERT_TRUE (SSL_CTX_set_min_proto_version (server_ctx.get (), TLS1_3_VERSION));
1976+ ASSERT_TRUE (SSL_CTX_set_max_proto_version (server_ctx.get (), TLS1_3_VERSION));
1977+
1978+ const uint16_t sigalgs[] = {GetParam ().sigalg };
1979+ ASSERT_TRUE (SSL_CTX_set_signing_algorithm_prefs (server_ctx.get (), sigalgs,
1980+ OPENSSL_ARRAY_SIZE (sigalgs)));
1981+ ASSERT_TRUE (SSL_CTX_set_verify_algorithm_prefs (client_ctx.get (), sigalgs,
1982+ OPENSSL_ARRAY_SIZE (sigalgs)));
1983+
1984+ bssl::UniquePtr<SSL> client, server;
1985+ ASSERT_TRUE (ConnectClientAndServer (&client, &server, client_ctx.get (),
1986+ server_ctx.get ()));
1987+ EXPECT_EQ (SSL_get_peer_signature_algorithm (client.get ()), GetParam ().sigalg );
1988+ }
1989+
1990+ TEST_P (MLDSAHandshakeTest, RejectedInTLS12) {
1991+ // ML-DSA is only defined for TLS 1.3. Forcing a TLS 1.2 handshake with an
1992+ // ML-DSA sigalg preference must not succeed.
1993+ bssl::UniquePtr<SSL_CTX> client_ctx (SSL_CTX_new (TLS_method ()));
1994+ bssl::UniquePtr<SSL_CTX> server_ctx (
1995+ CreateContextWithCertificate (TLS_method (), GetParam ().certificate (),
1996+ GetParam ().key ()));
1997+ ASSERT_TRUE (client_ctx);
1998+ ASSERT_TRUE (server_ctx);
1999+ ASSERT_TRUE (SSL_CTX_set_min_proto_version (client_ctx.get (), TLS1_2_VERSION));
2000+ ASSERT_TRUE (SSL_CTX_set_max_proto_version (client_ctx.get (), TLS1_2_VERSION));
2001+ ASSERT_TRUE (SSL_CTX_set_min_proto_version (server_ctx.get (), TLS1_2_VERSION));
2002+ ASSERT_TRUE (SSL_CTX_set_max_proto_version (server_ctx.get (), TLS1_2_VERSION));
2003+
2004+ const uint16_t sigalgs[] = {GetParam ().sigalg };
2005+ ASSERT_TRUE (SSL_CTX_set_signing_algorithm_prefs (server_ctx.get (), sigalgs,
2006+ OPENSSL_ARRAY_SIZE (sigalgs)));
2007+ ASSERT_TRUE (SSL_CTX_set_verify_algorithm_prefs (client_ctx.get (), sigalgs,
2008+ OPENSSL_ARRAY_SIZE (sigalgs)));
2009+
2010+ bssl::UniquePtr<SSL> client, server;
2011+ EXPECT_FALSE (ConnectClientAndServer (&client, &server, client_ctx.get (),
2012+ server_ctx.get ()));
2013+ }
2014+
2015+ TEST (MLDSAHandshakeTest, CrossVariantMismatchFails) {
2016+ // Server has an MLDSA-44 cert/key, but the client only advertises
2017+ // MLDSA-65 / MLDSA-87 for verification. No common sigalg => handshake
2018+ // must fail.
2019+ bssl::UniquePtr<SSL_CTX> client_ctx (SSL_CTX_new (TLS_method ()));
2020+ bssl::UniquePtr<SSL_CTX> server_ctx (CreateContextWithCertificate (
2021+ TLS_method (), GetMLDSA44TestCertificate (), GetMLDSA44TestKey ()));
2022+ ASSERT_TRUE (client_ctx);
2023+ ASSERT_TRUE (server_ctx);
2024+ ASSERT_TRUE (SSL_CTX_set_min_proto_version (client_ctx.get (), TLS1_3_VERSION));
2025+ ASSERT_TRUE (SSL_CTX_set_max_proto_version (client_ctx.get (), TLS1_3_VERSION));
2026+ ASSERT_TRUE (SSL_CTX_set_min_proto_version (server_ctx.get (), TLS1_3_VERSION));
2027+ ASSERT_TRUE (SSL_CTX_set_max_proto_version (server_ctx.get (), TLS1_3_VERSION));
2028+
2029+ const uint16_t server_sigalgs[] = {SSL_SIGN_MLDSA44};
2030+ ASSERT_TRUE (SSL_CTX_set_signing_algorithm_prefs (
2031+ server_ctx.get (), server_sigalgs, OPENSSL_ARRAY_SIZE (server_sigalgs)));
2032+
2033+ const uint16_t client_sigalgs[] = {SSL_SIGN_MLDSA65, SSL_SIGN_MLDSA87};
2034+ ASSERT_TRUE (SSL_CTX_set_verify_algorithm_prefs (
2035+ client_ctx.get (), client_sigalgs, OPENSSL_ARRAY_SIZE (client_sigalgs)));
2036+
2037+ bssl::UniquePtr<SSL> client, server;
2038+ EXPECT_FALSE (ConnectClientAndServer (&client, &server, client_ctx.get (),
2039+ server_ctx.get ()));
2040+ }
2041+
2042+
19372043struct MultiTransferReadWriteTestParams {
19382044 const char suite[50 ];
19392045 bool tls13;
0 commit comments