@@ -3100,3 +3100,89 @@ int test_tls13_plaintext_alert(void)
31003100 return EXPECT_RESULT ();
31013101}
31023102
3103+ /* Test that wolfSSL_set1_sigalgs_list() is honored in TLS 1.3
3104+ */
3105+ int test_tls13_cert_req_sigalgs (void )
3106+ {
3107+ EXPECT_DECLS ;
3108+ #if defined(WOLFSSL_TLS13 ) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
3109+ !defined(NO_CERTS ) && !defined(NO_RSA ) && defined(WC_RSA_PSS ) && \
3110+ defined(HAVE_ECC ) && !defined(NO_WOLFSSL_CLIENT ) && \
3111+ !defined(NO_WOLFSSL_SERVER ) && defined(OPENSSL_EXTRA ) && \
3112+ !defined(NO_FILESYSTEM )
3113+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
3114+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
3115+ struct test_memio_ctx test_ctx ;
3116+
3117+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
3118+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
3119+ wolfTLSv1_3_client_method , wolfTLSv1_3_server_method ), 0 );
3120+
3121+ /* Server: require client cert and load ECC client cert for verification */
3122+ if (EXPECT_SUCCESS ()) {
3123+ wolfSSL_set_verify (ssl_s ,
3124+ WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT , NULL );
3125+ ExpectIntEQ (wolfSSL_CTX_load_verify_locations (ctx_s ,
3126+ cliEccCertFile , 0 ), WOLFSSL_SUCCESS );
3127+ }
3128+
3129+ /* Server: restrict CertificateRequest to RSA-PSS+SHA256 only */
3130+ if (EXPECT_SUCCESS ()) {
3131+ ExpectIntEQ (wolfSSL_set1_sigalgs_list (ssl_s , "RSA-PSS+SHA256" ),
3132+ WOLFSSL_SUCCESS );
3133+ }
3134+
3135+ /* Client: load ECC cert/key */
3136+ if (EXPECT_SUCCESS ()) {
3137+ ExpectIntEQ (wolfSSL_use_certificate_file (ssl_c , cliEccCertFile ,
3138+ CERT_FILETYPE ), WOLFSSL_SUCCESS );
3139+ ExpectIntEQ (wolfSSL_use_PrivateKey_file (ssl_c , cliEccKeyFile ,
3140+ CERT_FILETYPE ), WOLFSSL_SUCCESS );
3141+ }
3142+
3143+ /* Handshake must fail: ECC client cannot match RSA-PSS+SHA256 */
3144+ ExpectIntNE (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
3145+
3146+ wolfSSL_free (ssl_c ); ssl_c = NULL ;
3147+ wolfSSL_free (ssl_s ); ssl_s = NULL ;
3148+ wolfSSL_CTX_free (ctx_c ); ctx_c = NULL ;
3149+ wolfSSL_CTX_free (ctx_s ); ctx_s = NULL ;
3150+
3151+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
3152+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
3153+ wolfTLSv1_3_client_method , wolfTLSv1_3_server_method ), 0 );
3154+
3155+ /* Server: require client cert and load RSA client cert for verification */
3156+ if (EXPECT_SUCCESS ()) {
3157+ wolfSSL_set_verify (ssl_s ,
3158+ WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT , NULL );
3159+ ExpectIntEQ (wolfSSL_CTX_load_verify_locations (ctx_s ,
3160+ cliCertFile , 0 ), WOLFSSL_SUCCESS );
3161+ }
3162+
3163+ /* Server: restrict CertificateRequest to RSA-PSS+SHA256 only */
3164+ if (EXPECT_SUCCESS ()) {
3165+ ExpectIntEQ (wolfSSL_set1_sigalgs_list (ssl_s , "RSA-PSS+SHA256" ),
3166+ WOLFSSL_SUCCESS );
3167+ }
3168+
3169+ /* Client: load RSA cert/key */
3170+ if (EXPECT_SUCCESS ()) {
3171+ ExpectIntEQ (wolfSSL_use_certificate_file (ssl_c , cliCertFile ,
3172+ CERT_FILETYPE ), WOLFSSL_SUCCESS );
3173+ ExpectIntEQ (wolfSSL_use_PrivateKey_file (ssl_c , cliKeyFile ,
3174+ CERT_FILETYPE ), WOLFSSL_SUCCESS );
3175+ }
3176+
3177+ /* Handshake must succeed: RSA client satisfies RSA-PSS+SHA256 */
3178+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
3179+
3180+ wolfSSL_free (ssl_c ); ssl_c = NULL ;
3181+ wolfSSL_free (ssl_s ); ssl_s = NULL ;
3182+ wolfSSL_CTX_free (ctx_c ); ctx_c = NULL ;
3183+ wolfSSL_CTX_free (ctx_s ); ctx_s = NULL ;
3184+ #endif
3185+
3186+ return EXPECT_RESULT ();
3187+ }
3188+
0 commit comments