-
Notifications
You must be signed in to change notification settings - Fork 867
Fix bug in ParseCRL_Extensions #8587
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?
Conversation
Using a mp_int is heavy weight for a 20 byte number - can allocate up to 1KB for storage of 20 bytes. |
Jenkins retest this please |
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.
Looks good. Still on fence about backwards compatibility, but okay for now. Over to @SparkiDev
550ca10
to
70a54ff
Compare
Jenkins retest this please PRB-generic-config-parser error:
|
Jenkins Retest this please |
@@ -645,12 +703,17 @@ static int AddCRL(WOLFSSL_CRL* crl, DecodedCRL* dcrl, const byte* buff, | |||
|
|||
for (curr = crl->crlList; curr != NULL; curr = curr->next) { | |||
if (XMEMCMP(curr->issuerHash, crle->issuerHash, CRL_DIGEST_SIZE) == 0) { | |||
if (crle->crlNumber <= curr->crlNumber) { | |||
ret = CompareCRLnumber(crle, curr); | |||
if (ret == -1 || ret == 0) { |
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.
Can you please use the MP_ defines for the checks? Perhaps also update the code comments on CompareCRLnumber. Why is MP_LT allowed? can you please add a code comment?
/** Result of comparison is that the first number is greater than second. */
#define MP_GT 1
/** Result of comparison is they are equal. */
#define MP_EQ 0
/** Result of comparison is that the first number is less than second. */
#define MP_LT (-1)
@@ -6429,7 +6429,7 @@ static int X509PrintSerial_ex(WOLFSSL_BIO* bio, byte* serial, int sz, | |||
/* if serial can fit into byte then print on the same line */ | |||
else { | |||
if ((scratchLen = XSNPRINTF( | |||
scratch, MAX_WIDTH, " %d (0x%x)\n", serial[0], serial[0])) | |||
scratch, MAX_WIDTH, " %d (0x%x)\n", (char)serial[0], serial[0])) |
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 line is over 80 chars now.
else if (length == 1) { | ||
dcrl->crlNumber = buf[idx]; | ||
} | ||
mp_free(m); |
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.
Maybe not call this if ret == MP_INIT_E
?
#endif | ||
int crlNumber; /* CRL number extension */ | ||
byte crlNumberSet:1; /* CRL number set indicator */ |
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.
Multi-test reports this bit-field issue, however there must be a way to make this work. Perhaps it needs to be unsigned int. Not sure (see other uses to solve)
[allcryptonly-gcc-c89] [14 of 39] [e7860a7e85]
configure... real 0m5.702s user 0m3.401s sys 0m2.671s
In file included from ./wolfssl/ssl.h:45,
from ./wolfssl/openssl/ssl.h:39,
from ./wolfssl/openssl/aes.h:44,
from conftest.c:73:
./wolfssl/wolfcrypt/asn.h:2705:13: error: type of bit-field 'extAuthKeyIdSet' is a GCC extension [-Werror=pedantic]
2705 | byte extAuthKeyIdSet:1; /* Auth key identifier set indicator */
| ^~~~~~~~~~~~~~~
./wolfssl/wolfcrypt/asn.h:2707:13: error: type of bit-field 'crlNumberSet' is a GCC extension [-Werror=pedantic]
2707 | byte crlNumberSet:1; /* CRL number set indicator */
| ^~~~~~~~~~~~
cc1: all warnings being treated as errors
mp_int* curr_num = (mp_int*)XMALLOC(sizeof(*curr_num), NULL, | ||
DYNAMIC_TYPE_BIGINT); | ||
if (prev_num == NULL || curr_num == NULL) { | ||
return MEMORY_E; |
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 will leak if prev_num
was allocated but curr_num
failed.
#ifdef WOLFSSL_SMALL_STACK | ||
XFREE(prev_num, NULL, DYNAMIC_TYPE_BIGINT); | ||
XFREE(curr_num, NULL, DYNAMIC_TYPE_BIGINT); | ||
#endif | ||
return BAD_FUNC_ARG; |
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 would be nice to refactor this func to use an if (ret == 0)
cascade, with smallstack cleanup once at the end.
{ | ||
int result = 0; | ||
#ifdef WOLFSSL_SMALL_STACK | ||
mp_int* prev_num = (mp_int*)XMALLOC(sizeof(*prev_num), NULL, |
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.
Regarding @SparkiDev 's concern about allocing gobs of memory just to process 20 octets of MPI: It's possible to right-size-allocate the MPI containers with existing macros. You'd use DECL_MP_INT_SIZE()
, NEW_MP_INT_SIZE()
. INIT_MP_INT_SIZE()
, and FREE_MP_INT_SIZE()
. These exist with all MPI back ends, though they only right-size on SP and heapmath, not TFM (doesn't matter).
Description
CRL_NUMBER_OID
case inParseCRL_Extensions()
NO_BIG_INT
is definedFixes #8574 and wolfSSL/wolfCLU#174
Also fixes zd#19611
Testing
Tested using wolfCLU with the CRL files provided in #8574 and wolfSSL/wolfCLU#174
Build wolfSSL with
./configure --enable-wolfclu --enable-crl
Then run wolfCLU with
./wolfssl crl -in crl_extention_test.pem -text
Checklist