-
Notifications
You must be signed in to change notification settings - Fork 1k
Block cert modification in callbacks based on new flag #11203
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 |
|---|---|---|
|
|
@@ -2677,6 +2677,12 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff, long sz, | |
| if ((ret == 0) && (sz < 0)) { | ||
| ret = BAD_FUNC_ARG; | ||
| } | ||
| /* Sessions made from this context hold these and the chain by pointer. */ | ||
| if ((ret == 0) && (ssl == NULL) && ((type == CERT_TYPE) || | ||
| (type == PRIVATEKEY_TYPE) || (type == ALT_PRIVATEKEY_TYPE) || | ||
| userChain)) { | ||
| ret = CheckCtxCertLoad(ctx); | ||
| } | ||
|
|
||
| #ifdef WOLFSSL_SMALL_STACK | ||
| if (ret == 0) { | ||
|
|
@@ -4464,6 +4470,10 @@ int wolfSSL_CTX_use_PrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id, | |
| return 0; | ||
| } | ||
|
|
||
| if (CheckCtxCertLoad(ctx) != 0) { | ||
|
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. Alternate private-key Id/Label setters bypass the new callback guard · Logic errors The guard was added to Related known finding #13391 (similar but distinct): Both affect CTX primary/alternate key ID/label replacement setters in ssl_load.c, but this frees an aliased alternate-key buffer during a callback due to a missing guard, while #13391 retains a stale blinding mask after replacement. The configurations, faulting state, and fixes differ. Fix: Add the same
Contributor
Author
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. fixed |
||
| return 0; | ||
| } | ||
|
|
||
| /* Dispose of old private key and allocate and copy in id. */ | ||
| FreeDer(&ctx->privateKey); | ||
| if (AllocCopyDer(&ctx->privateKey, id, (word32)sz, PRIVATEKEY_TYPE, | ||
|
|
@@ -4542,6 +4552,10 @@ int wolfSSL_CTX_use_PrivateKey_Label(WOLFSSL_CTX* ctx, const char* label, | |
|
|
||
| sz = (word32)XSTRLEN(label) + 1; | ||
|
|
||
| if (CheckCtxCertLoad(ctx) != 0) { | ||
| return 0; | ||
| } | ||
|
|
||
| /* Dispose of old private key and allocate and copy in label. */ | ||
| FreeDer(&ctx->privateKey); | ||
| if (AllocCopyDer(&ctx->privateKey, (const byte*)label, (word32)sz, | ||
|
|
@@ -4582,6 +4596,9 @@ int wolfSSL_CTX_use_AltPrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id, | |
| if ((ctx == NULL) || (id == NULL) || (sz < 0)) { | ||
| ret = 0; | ||
| } | ||
| if ((ret == 1) && (CheckCtxCertLoad(ctx) != 0)) { | ||
| ret = 0; | ||
| } | ||
|
|
||
| if (ret == 1) { | ||
| FreeDer(&ctx->altPrivateKey); | ||
|
|
@@ -4632,6 +4649,9 @@ int wolfSSL_CTX_use_AltPrivateKey_Label(WOLFSSL_CTX* ctx, const char* label, | |
| if ((ctx == NULL) || (label == NULL)) { | ||
| ret = 0; | ||
| } | ||
| if ((ret == 1) && (CheckCtxCertLoad(ctx) != 0)) { | ||
| ret = 0; | ||
| } | ||
|
|
||
| if (ret == 1) { | ||
| sz = (word32)XSTRLEN(label) + 1; | ||
|
|
@@ -5207,6 +5227,11 @@ static int wolfssl_ctx_add_to_chain(WOLFSSL_CTX* ctx, const byte* der, | |
| { | ||
| int res; | ||
|
|
||
| /* Sessions made from this context hold the chain by pointer. */ | ||
| if (CheckCtxCertLoad(ctx) != 0) { | ||
| return 0; | ||
| } | ||
|
|
||
| /* Add chain to DER buffer. */ | ||
| res = wolfssl_add_to_chain(&ctx->certChain, 1, der, (word32)derSz, | ||
| ctx->heap); | ||
|
|
@@ -5299,6 +5324,10 @@ int wolfSSL_CTX_use_certificate(WOLFSSL_CTX *ctx, WOLFSSL_X509 *x) | |
| res = 0; | ||
| } | ||
|
|
||
| if ((res == 1) && (CheckCtxCertLoad(ctx) != 0)) { | ||
| res = 0; | ||
| } | ||
|
|
||
| if (res == 1) { | ||
| /* Replace certificate buffer with one holding the new certificate. */ | ||
| FreeDer(&ctx->certificate); | ||
|
|
@@ -5386,6 +5415,11 @@ int wolfSSL_CTX_add1_chain_cert(WOLFSSL_CTX* ctx, WOLFSSL_X509* x509) | |
| ret = 0; | ||
| } | ||
|
|
||
| /* Sessions made from this context hold the chain by pointer. */ | ||
| if ((ret == 1) && (CheckCtxCertLoad(ctx) != 0)) { | ||
| ret = 0; | ||
| } | ||
|
|
||
| /* Check if we already have set a certificate. */ | ||
| if ((ret == 1) && (ctx->certificate == NULL)) { | ||
| /* Use the certificate. */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.