-
Notifications
You must be signed in to change notification settings - Fork 901
20251114-WOLFSSL_BLIND_PRIVATE_KEY-thread-safety #9436
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?
20251114-WOLFSSL_BLIND_PRIVATE_KEY-thread-safety #9436
Conversation
This comment was marked as spam.
This comment was marked as spam.
|
Jenkins retest this please: PRB-generic-config-parser aborted |
| void wolfssl_priv_der_blind_toggle(DerBuffer* key, const DerBuffer* mask) | ||
| { | ||
| if (key != NULL) { | ||
| xorbuf(key->buffer, mask->buffer, mask->length); | ||
| } | ||
| } |
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.
If key is null checked then mask should be too.
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.
it's incumbent code. not bothering to bikeshed it for present purposes.
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.
While this area is being touched, we can add a null check. It shouldn't have any affect (if it does we're already in trouble).
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.
(fixed it anyway)
src/internal.c
Outdated
| ret = (DerBuffer *)XMALLOC(sizeof(*key) + key->length, key->heap, | ||
| DYNAMIC_TYPE_TMP_BUFFER); | ||
| if (ret == NULL) | ||
| return NULL; | ||
| XMEMCPY(ret, key, sizeof(*key)); | ||
| ret->buffer = (byte *)ret + sizeof(*key); |
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.
This kind of extra allocation at the end of DerBuffer is an anti-pattern. There should be an explicit field at the end of the struct to let us know that the structure stores data at the end.
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.
Ok I guess that is what AllocDer does. We should consider just moving buffer to the end and changing it to buffer[] (save the space from the pointer).
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.
that sounds like the right idea. I thought of checking for an existing allocator but never got around to it -- will fix.
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.
(fixed)
| DerBuffer *wolfssl_priv_der_unblind(const DerBuffer* key, const DerBuffer* mask) | ||
| { | ||
| DerBuffer *ret; | ||
| if (key == NULL) | ||
| return NULL; | ||
| if (mask->length > key->length) | ||
| return NULL; | ||
| ret = (DerBuffer *)XMALLOC(sizeof(*key) + key->length, key->heap, | ||
| DYNAMIC_TYPE_TMP_BUFFER); | ||
| if (ret == NULL) | ||
| return NULL; | ||
| XMEMCPY(ret, key, sizeof(*key)); | ||
| ret->buffer = (byte *)ret + sizeof(*key); | ||
| xorbufout(ret->buffer, key->buffer, mask->buffer, mask->length); | ||
| return ret; | ||
| } | ||
|
|
||
| void wolfssl_priv_der_unblind_free(DerBuffer* key) | ||
| { | ||
| if (key != NULL) { | ||
| void *heap = key->heap; | ||
| ForceZero(key->buffer, key->length); | ||
| ForceZero(key, sizeof(*key)); | ||
| XFREE(key, heap, DYNAMIC_TYPE_TMP_BUFFER); | ||
| } | ||
| } |
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.
Also you should be using AllocDer and FreeDer.
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.
✔️
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.
(fixed)
| } | ||
|
|
||
| void wolfssl_priv_der_unblind(DerBuffer* key, DerBuffer* mask) | ||
| void wolfssl_priv_der_blind_toggle(DerBuffer* key, const DerBuffer* mask) |
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.
I think I'd prefer wolfssl_der_key_xor_mask.
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.
xor isn't the point here (blinding could be implemented with barrel shifts or other ops), and we're not gonna bikeshed the terminology for present purposes.
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.
I don't like the "toggle" part of the name. Maybe "apply" would be better but I won't block the pr over this.
…,altPrivateKeyMask} in WOLFSSL_BLIND_PRIVATE_KEY code paths: * rename wolfssl_priv_der_unblind() to wolfssl_priv_der_blind_toggle(), * add wolfssl_priv_der_unblind() that allocates a temp copy, * add wolfssl_priv_der_unblind_free(), * in wolfssl_priv_der_blind_toggle(), make mask a const arg; restore const attribute to ctx arg to wolfSSL_CTX_get0_privatekey(), and add explanatory comment.
…wolfssl_priv_der_unblind_free() to use AllocDer() and FreeDer().
e82110b to
c29abcc
Compare
fix races around
WOLFSSL_CTX.{privateKey,privateKeyMask,altPrivateKey,altPrivateKeyMask}inWOLFSSL_BLIND_PRIVATE_KEYcode paths:wolfssl_priv_der_unblind()towolfssl_priv_der_blind_toggle(),wolfssl_priv_der_unblind()that allocates a temp copy,wolfssl_priv_der_unblind_free(),wolfssl_priv_der_blind_toggle(), makemaskaconstarg;restore
constattribute toctxarg towolfSSL_CTX_get0_privatekey(), and add explanatory comment.tested with
wolfssl-multi-test.sh ... check-source-text clang-tidy-all-sp-allAlso ran
clang-tidy-all-sp-allwithLIBWOLFSSL_CONFIGURE_ARGS_OVERRIDE=CFLAGS=-DWOLFSSL_BLIND_PRIVATE_KEY, which is analytically clean, but crashes, unrelated to this PR: