-
Notifications
You must be signed in to change notification settings - Fork 959
Fix partial chain verification #10170
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -785,6 +785,42 @@ static int test_wolfSSL_X509_STORE_CTX_ex11(X509_STORE_test_data *testData) | |||||
| return EXPECT_RESULT(); | ||||||
| } | ||||||
|
|
||||||
| static int test_wolfSSL_X509_STORE_CTX_ex_partial_chain_neg( | ||||||
|
Contributor
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. 🟡 [Medium] No test for mixed trusted-store + untrusted-chain with partial chain The new negative test verifies that partial-chain fails when no certificate is trusted (empty store + untrusted intermediates). However, there is no corresponding test for the mixed scenario: a store that contains some trusted intermediates combined with additional untrusted intermediates provided via the chain argument. This scenario exercises the Suggestion:
Suggested change
|
||||||
| X509_STORE_test_data *testData) | ||||||
| { | ||||||
| EXPECT_DECLS; | ||||||
| X509_STORE* store = NULL; | ||||||
| X509_STORE_CTX* ctx = NULL; | ||||||
| STACK_OF(X509)* untrusted = NULL; | ||||||
|
|
||||||
| /* Negative partial-chain test: with X509_V_FLAG_PARTIAL_CHAIN set, the | ||||||
| * intermediates are supplied ONLY as untrusted (passed through the | ||||||
| * X509_STORE_CTX_init "chain" argument and never added to the store). | ||||||
| * No certificate in the chain is in the store, so verification must | ||||||
| * fail. Pre-fix, wolfSSL_X509_verify_cert would incorrectly accept | ||||||
| * this chain because its partial-chain fallback only checked that some | ||||||
| * intermediate had been temporarily loaded into the CertManager, not | ||||||
| * that any chain certificate was actually trusted. */ | ||||||
| ExpectNotNull(store = X509_STORE_new()); | ||||||
| /* Intentionally do NOT add x509CaInt, x509CaInt2, or x509Ca. */ | ||||||
| ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_PARTIAL_CHAIN), 1); | ||||||
|
|
||||||
| ExpectNotNull(untrusted = sk_X509_new_null()); | ||||||
| ExpectIntGT(sk_X509_push(untrusted, testData->x509CaInt2), 0); | ||||||
| ExpectIntGT(sk_X509_push(untrusted, testData->x509CaInt), 0); | ||||||
|
|
||||||
| ExpectNotNull(ctx = X509_STORE_CTX_new()); | ||||||
| ExpectIntEQ(X509_STORE_CTX_init(ctx, store, testData->x509Leaf, untrusted), | ||||||
| 1); | ||||||
| /* Must NOT verify: partial-chain does not relax the trust requirement. */ | ||||||
| ExpectIntNE(X509_verify_cert(ctx), 1); | ||||||
embhorn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| X509_STORE_CTX_free(ctx); | ||||||
| X509_STORE_free(store); | ||||||
| sk_X509_free(untrusted); | ||||||
| return EXPECT_RESULT(); | ||||||
| } | ||||||
|
|
||||||
| #ifdef HAVE_ECC | ||||||
| static int test_wolfSSL_X509_STORE_CTX_ex12(void) | ||||||
| { | ||||||
|
|
@@ -870,6 +906,7 @@ int test_wolfSSL_X509_STORE_CTX_ex(void) | |||||
| ExpectIntEQ(test_wolfSSL_X509_STORE_CTX_ex9(&testData), 1); | ||||||
| ExpectIntEQ(test_wolfSSL_X509_STORE_CTX_ex10(&testData), 1); | ||||||
| ExpectIntEQ(test_wolfSSL_X509_STORE_CTX_ex11(&testData), 1); | ||||||
| ExpectIntEQ(test_wolfSSL_X509_STORE_CTX_ex_partial_chain_neg(&testData), 1); | ||||||
| #ifdef HAVE_ECC | ||||||
| ExpectIntEQ(test_wolfSSL_X509_STORE_CTX_ex12(), 1); | ||||||
| #endif | ||||||
|
|
||||||
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.
🔵 [Low] Unused variable
ndeclared at function scope🔧 NIT
styleThe variable
int nis declared at the top ofX509StoreCertIsTrustedbut is only used inside theif (store != NULL && store->trusted != NULL)block. While this follows C89 declaration-at-top style (common in the wolfSSL codebase), declaringnat the top and only assigning it conditionally may produce compiler warnings about uninitialized use on some static analysis tools. This is purely cosmetic since the usage is correct.Recommendation: No action needed — this follows the existing C89-style convention in the codebase. If you want to silence picky analyzers, initialize
n = 0at declaration.