Skip to content

Commit 34916c8

Browse files
committed
ASN: improve handling of ASN.1 parsing/encoding
ToTraditionalInline_ex2 original ASN code: - Now return 0 when no OCTECT_STRING data found. - Change callers to accept 0 as a valid returnb value. SizeASN_Items: - Change encoded size to word32 as won't be negative. - Change callers to supply a pointer to a word32 instead of integer. Fix casting due to change of parameter type. ASN_LEN_ENC_LEN: Function to calculate the length of the encoded ASN.1 length. GetLength_ex: - Change minLen to word32 - Change length to word32 and change negative check appropriately for different type. GetASNHeader_ex: - If not checking lengths in GetLength_ex, check it here. DecodeObjectId: - Ensure no overflow in calculation. _RsaPrivateKeyDecode (original) - Clear RSA integers on failure (will be done in free anyway). wc_CreatePKCS8Key (original): - safe check of overflow. DecryptContent (templare): - Parse will fail if OID not recognized, and recognized OIDs are 9/10 bytes long - but check idx is 9/10 anyway so we know we can read 2 end bytes of data. wc_RsaPublicKeyDecode_ex (original): - Fix calculation of seqEndIdx and use it to bound modulus and exponent. DecodePolicyOID - enusre inSz is not too long. - Ensure no overflow in calculation. SetOidValue (orginal): - Safe check of inSz and oidSz. SetAltNames (original): - Improve length checks FlattenAltNames: - Check for overflow. - Better length check. ParseCRL_CertList (original): - overflow check
1 parent 9d3cc6e commit 34916c8

5 files changed

Lines changed: 253 additions & 186 deletions

File tree

src/pk_ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3581,7 +3581,7 @@ int wolfSSL_EC_KEY_LoadDer_ex(WOLFSSL_EC_KEY* key, const unsigned char* derBuf,
35813581
* have a PKCS8 header then do not error out.
35823582
*/
35833583
if ((ret = ToTraditionalInline_ex((const byte*)derBuf, &idx,
3584-
(word32)derSz, &algId)) > 0) {
3584+
(word32)derSz, &algId)) >= 0) {
35853585
WOLFSSL_MSG("Found PKCS8 header");
35863586
key->pkcs8HeaderSz = (word16)idx;
35873587
res = 1;

src/pk_rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ int wolfSSL_RSA_LoadDer_ex(WOLFSSL_RSA* rsa, const unsigned char* derBuf,
924924
* have a PKCS8 header then do not error out. */
925925
res = ToTraditionalInline_ex((const byte*)derBuf, &idx, (word32)derSz,
926926
&algId);
927-
if (res > 0) {
927+
if (res >= 0) {
928928
/* Store size of PKCS#8 header for encoding. */
929929
WOLFSSL_MSG("Found PKCS8 header");
930930
rsa->pkcs8HeaderSz = (word16)idx;

0 commit comments

Comments
 (0)