Skip to content

Commit 20eeba3

Browse files
committed
test: tls13: add wolfSSL_set1_sigalgs_list test
1 parent d72fcb1 commit 20eeba3

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

tests/api/test_tls13.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+

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)