-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix multiple issues with WOLFSSL_CHECK_SIG_FAULTS + HAVE_PK_CALLBACKS. #11000
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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -94,7 +94,11 @@ jobs: | |||||||||||||||
| {"name": "sm4-all-modes", "minutes": 1.5, | ||||||||||||||||
| "configure": ["--enable-sm2", "--enable-sm3", "--enable-sm4-ecb", | ||||||||||||||||
| "--enable-sm4-cbc", "--enable-sm4-ctr", "--enable-sm4-gcm", | ||||||||||||||||
| "--enable-sm4-ccm", "--enable-sha3"]} | ||||||||||||||||
| "--enable-sm4-ccm", "--enable-sha3"]}, | ||||||||||||||||
| {"name": "sm-faultharden", "minutes": 1.5, | ||||||||||||||||
| "configure": ["--enable-sm2", "--enable-sm3", "--enable-sm4-ecb", | ||||||||||||||||
| "--enable-sm4-cbc", "--enable-sm4-ctr", "--enable-sm4-gcm", | ||||||||||||||||
| "--enable-sm4-ccm", "--enable-sha3", "--enable-faultharden"]} | ||||||||||||||||
|
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] New sm-faultharden CI config omits PK callbacks, so the SM2 + HAVE_PK_CALLBACKS code this PR fixes is still never compiled The core compile-level defect this PR fixes is at Verified locally (macOS arm64, PR head Building master with this PR's exact Only the And the other half of the gap is confirmed too - So neither new entry compiles the SM2 + PK-callbacks intersection, and the type error this PR Suggestion:
Suggested change
|
||||||||||||||||
| ] | ||||||||||||||||
| EOF | ||||||||||||||||
| .github/scripts/parallel-make-check.py \ | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36519,15 +36519,20 @@ int SendCertificateVerify(WOLFSSL* ssl) | |
| #ifdef HAVE_PK_CALLBACKS | ||
| buffer tmp; | ||
|
|
||
| tmp.length = ssl->buffers.key->length; | ||
| tmp.buffer = ssl->buffers.key->buffer; | ||
| /* Private key may be held by the PK callback. */ | ||
| tmp.length = ssl->buffers.key ? | ||
| ssl->buffers.key->length : 0; | ||
| tmp.buffer = ssl->buffers.key ? | ||
| ssl->buffers.key->buffer : NULL; | ||
| #endif | ||
|
|
||
| ret = Sm3wSm2Verify(ssl, | ||
| /* Sm2wSm3Sign() was given the handshake messages and | ||
| * not the digest - verify over the same data. */ | ||
| ret = Sm2wSm3Verify(ssl, | ||
| TLS12_SM2_SIG_ID, TLS12_SM2_SIG_ID_SZ, | ||
| ssl->buffers.sig.buffer, ssl->buffers.sig.length, | ||
| ssl->buffers.digest.buffer, | ||
| ssl->buffers.digest.length, key, | ||
| ssl->hsHashes->messages, | ||
| ssl->hsHashes->length, key, | ||
| #ifdef HAVE_PK_CALLBACKS | ||
| &tmp | ||
| #else | ||
|
|
@@ -36541,8 +36546,11 @@ int SendCertificateVerify(WOLFSSL* ssl) | |
| #ifdef HAVE_PK_CALLBACKS | ||
| buffer tmp; | ||
|
|
||
| tmp.length = ssl->buffers.key->length; | ||
| tmp.buffer = ssl->buffers.key->buffer; | ||
| /* Private key may be held by the PK callback. */ | ||
| tmp.length = ssl->buffers.key ? | ||
| ssl->buffers.key->length : 0; | ||
| tmp.buffer = ssl->buffers.key ? | ||
| ssl->buffers.key->buffer : NULL; | ||
| #endif | ||
|
|
||
| ret = EccVerify(ssl, | ||
|
|
@@ -38584,6 +38592,16 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl) | |
| #ifdef WOLFSSL_CHECK_SIG_FAULTS | ||
| { | ||
| ecc_key* key = (ecc_key*)ssl->hsKey; | ||
| #ifdef HAVE_PK_CALLBACKS | ||
| buffer tmp; | ||
|
|
||
| /* Private key may be held by the PK | ||
| * callback. */ | ||
| tmp.length = ssl->buffers.key ? | ||
|
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] Fault check still runs without usable key material when the private key is held by a PK callback, so the handshake fails The PR guards When the private key is supplied only through a PK callback, Three outcomes, depending on build and application:
So the crash is genuinely fixed, but the feature combination still does not produce a working handshake. Verified locally (macOS arm64, PR head Server side, ECC client-auth handshake, built Address No crash, but the handshake still fails: the self-check hands the verify callback a zero-length key. Worth deciding whether the check should simply be skipped when there is no local key to re-verify with. Recommendation: Skip the sig-fault self-check when there is no local key material, rather than calling EccVerify with a NULL key - e.g. gate the block on If instead the intended contract is that |
||
| ssl->buffers.key->length : 0; | ||
| tmp.buffer = ssl->buffers.key ? | ||
| ssl->buffers.key->buffer : NULL; | ||
| #endif | ||
|
|
||
| #if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3) | ||
| if (ssl->options.sigAlgo == sm2_sa_algo) { | ||
|
|
@@ -38595,7 +38613,7 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl) | |
| ssl->buffers.sig.length, | ||
| key, | ||
| #ifdef HAVE_PK_CALLBACKS | ||
| ssl->buffers.key | ||
| &tmp | ||
| #else | ||
| NULL | ||
| #endif | ||
|
|
@@ -38604,13 +38622,6 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl) | |
| else | ||
| #endif /* WOLFSSL_SM2 */ | ||
| { | ||
| #ifdef HAVE_PK_CALLBACKS | ||
| buffer tmp; | ||
|
|
||
| tmp.length = ssl->buffers.key->length; | ||
| tmp.buffer = ssl->buffers.key->buffer; | ||
| #endif | ||
|
|
||
| ret = EccVerify(ssl, | ||
| args->output + LENGTH_SZ + args->idx, | ||
| args->sigSz, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10720,8 +10720,11 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl) | |||||||||||||||||
| #ifdef HAVE_PK_CALLBACKS | ||||||||||||||||||
| buffer tmp; | ||||||||||||||||||
|
|
||||||||||||||||||
| tmp.length = ssl->buffers.key->length; | ||||||||||||||||||
| tmp.buffer = ssl->buffers.key->buffer; | ||||||||||||||||||
| /* Private key may be held by the PK callback. */ | ||||||||||||||||||
| tmp.length = ssl->buffers.key ? | ||||||||||||||||||
| ssl->buffers.key->length : 0; | ||||||||||||||||||
| tmp.buffer = ssl->buffers.key ? | ||||||||||||||||||
| ssl->buffers.key->buffer : NULL; | ||||||||||||||||||
|
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. 🔵 [Low] Dual-algorithm alt-key site left with the unguarded dereference pattern Three of the four (Anchored on the changed hunk; the alt-key copy itself is roughly 20 lines below, at Suggestion:
Suggested change
|
||||||||||||||||||
| #endif | ||||||||||||||||||
| ret = EccVerify(ssl, sigOut, args->sigLen, | ||||||||||||||||||
| args->sigData, args->sigDataSz, | ||||||||||||||||||
|
|
||||||||||||||||||
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.
🟡 [Medium] No test exercises the NULL private-key scenario the PR fixes; CI additions give compile coverage only
💡 SUGGEST
testThe crash being fixed only happens when
ssl->buffers.key == NULL, i.e. when the private key lives entirely in the PK callback (SendCertificateVerify()src/internal.c:36258-36265 andSendTls13CertificateVerify()src/tls13.c:10188-10195 take thewolfSSL_CTX_IsPrivatePkSet()path and never callDecodePrivateKey()). In-tree, that state is only produced whenTEST_PK_PRIVKEYis defined:examples/client/client.c:3671-3675andexamples/server/server.c:3023skip loading the private key only under#if defined(HAVE_PK_CALLBACKS) && defined(TEST_PK_PRIVKEY), andtests/suites.c:687,815only append-Punder the same macro.grep -rn 'TEST_PK_PRIVKEY' .github/returns nothing, so no CI config defines it. Consequentlyall-faulthardenrunsscripts/pkcallbacks.testwith the key loaded (ssl->buffers.key != NULL) and never reaches the NULL branch the PR adds — the new configs prove only that the code compiles. The PR checklist claims "added tests", but the diff adds build configurations, not a test of the fixed behaviour. Note that adding such a config will also requiremyEccVerify()inwolfssl/test.h:3369-3394to be taught to handlekey == NULL, keySz == 0(it currently callswc_EccPublicKeyDecode(key, &idx, &myKey, keySz)unconditionally), which is itself evidence that this path has never been run.Verified locally (macOS arm64, PR head
d4ea9dd08, wolfsm sources installed):Confirmed both directions.
make checkon this PR with--enable-sm2 --enable-sm3 --enable-faultharden --enable-pkcallbackspasses 6/6 includingscripts/pkcallbacks.test- but only becauseTEST_PK_PRIVKEYis undefined, so the key is loaded andssl->buffers.key != NULL. Rebuilding withCPPFLAGS=-DTEST_PK_PRIVKEYand running an ECC handshake reaches the new branch and fails:This is exactly the
myEccVerify()gap predicted above, and it confirms a runtime config would have caught something the compile-only configs cannot.Suggestion: