-
Notifications
You must be signed in to change notification settings - Fork 987
Bugfix- wolf ssl add0 chain cert not incrementing certchain and causing TLS1.3 to fail #10517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3693,6 +3693,52 @@ static int test_wolfSSL_CTX_add1_chain_cert(void) | |
| return EXPECT_RESULT(); | ||
| } | ||
|
|
||
| static int test_wolfSSL_add0_chain_cert_increments_count(void) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] Test verifies the counter but not the end-to-end chain-send behavior it fixes The new test directly asserts Fix: Consider adding a parallel assertion via |
||
| { | ||
| EXPECT_DECLS; | ||
| #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \ | ||
| defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_TLS) && \ | ||
| !defined(NO_WOLFSSL_CLIENT) | ||
| WOLFSSL_CTX* ctx = NULL; | ||
| WOLFSSL* ssl = NULL; | ||
| const char* chainCerts[] = { | ||
| "./certs/intermediate/ca-int2-cert.pem", | ||
| "./certs/intermediate/ca-int-cert.pem", | ||
| "./certs/ca-cert.pem", | ||
| NULL | ||
| }; | ||
| const char** cert; | ||
| WOLFSSL_X509* x509 = NULL; | ||
| int expectedCnt = 0; | ||
|
|
||
| ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())); | ||
| ExpectNotNull(ssl = wolfSSL_new(ctx)); | ||
|
|
||
| ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file( | ||
| "./certs/intermediate/client-int-cert.pem", WOLFSSL_FILETYPE_PEM)); | ||
| ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 1); | ||
| /* Leaf -> ssl->buffers.certificate, not chain. certChainCnt unchanged. */ | ||
| if (ssl != NULL) { | ||
| ExpectIntEQ(ssl->buffers.certChainCnt, 0); | ||
| } | ||
| x509 = NULL; | ||
| for (cert = chainCerts; EXPECT_SUCCESS() && *cert != NULL; cert++) { | ||
| ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert, | ||
| WOLFSSL_FILETYPE_PEM)); | ||
| ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 1); | ||
| x509 = NULL; | ||
| expectedCnt++; | ||
| if (ssl != NULL) { | ||
| ExpectIntEQ(ssl->buffers.certChainCnt, expectedCnt); | ||
| } | ||
| } | ||
|
|
||
| SSL_free(ssl); | ||
| SSL_CTX_free(ctx); | ||
| #endif | ||
| return EXPECT_RESULT(); | ||
| } | ||
|
|
||
| /* Test that wolfssl_add_to_chain rejects sizes that would overflow word32. | ||
| * ZD #21241 */ | ||
| static int test_wolfSSL_add_to_chain_overflow(void) | ||
|
|
@@ -40634,6 +40680,7 @@ TEST_CASE testCases[] = { | |
| TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex), | ||
| TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format), | ||
| TEST_DECL(test_wolfSSL_CTX_add1_chain_cert), | ||
| TEST_DECL(test_wolfSSL_add0_chain_cert_increments_count), | ||
| TEST_DECL(test_wolfSSL_add_to_chain_overflow), | ||
| TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format), | ||
| TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ [Info] Increment is unconditional while CTX equivalent guards it with WOLFSSL_TLS13
The new
ssl->buffers.certChainCnt++;is unconditional, whereas the analogous CTX helperwolfssl_ctx_add_to_chain(src/ssl_load.c:4968-4971) wrapsctx->certChainCnt++;in#ifdef WOLFSSL_TLS13. This is a minor stylistic inconsistency, not a bug: thecertChainCntmember is always defined (under#ifndef NO_CERTS, wolfssl/internal.h:5029), so the unconditional increment always compiles, and the count is consumed both by TLS 1.3 (SendTls13Certificate) and by the non-TLS1.3 OCSP-multi path (MIN(cnt, certChainCnt + 1)at src/internal.c:26269). The unconditional form here is arguably more correct than the CTX version because it keeps the count accurate even in non-TLS1.3 builds. No change required; flagging only for awareness of the divergence between the two helpers.Fix: Leave as-is (unconditional is fine and slightly more correct). Optionally note the divergence, or align the CTX helper to also increment unconditionally in a follow-up for consistency.