Skip to content

Commit 2fb41a2

Browse files
committed
test: tls13: add wolfSSL_set1_sigalgs_list test
1 parent 1d9afa4 commit 2fb41a2

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

tests/api/test_tls13.c

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

tests/api/test_tls13.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ int test_tls13_duplicate_extension(void);
3838
int test_key_share_mismatch(void);
3939
int test_tls13_middlebox_compat_empty_session_id(void);
4040
int test_tls13_plaintext_alert(void);
41+
int test_tls13_cert_req_sigalgs(void);
4142

4243
#define TEST_TLS13_DECLS \
4344
TEST_DECL_GROUP("tls13", test_tls13_apis), \
@@ -53,6 +54,7 @@ int test_tls13_plaintext_alert(void);
5354
TEST_DECL_GROUP("tls13", test_tls13_duplicate_extension), \
5455
TEST_DECL_GROUP("tls13", test_key_share_mismatch), \
5556
TEST_DECL_GROUP("tls13", test_tls13_middlebox_compat_empty_session_id), \
56-
TEST_DECL_GROUP("tls13", test_tls13_plaintext_alert)
57+
TEST_DECL_GROUP("tls13", test_tls13_plaintext_alert), \
58+
TEST_DECL_GROUP("tls13", test_tls13_cert_req_sigalgs)
5759

5860
#endif /* WOLFCRYPT_TEST_TLS13_H */

0 commit comments

Comments
 (0)