Skip to content

Commit 443aa6a

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 a631611 commit 443aa6a

4 files changed

Lines changed: 251 additions & 186 deletions

File tree

src/pk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ int wolfSSL_RSA_LoadDer_ex(WOLFSSL_RSA* rsa, const unsigned char* derBuf,
18291829
* have a PKCS8 header then do not error out. */
18301830
res = ToTraditionalInline_ex((const byte*)derBuf, &idx, (word32)derSz,
18311831
&algId);
1832-
if (res > 0) {
1832+
if (res >= 0) {
18331833
/* Store size of PKCS#8 header for encoding. */
18341834
WOLFSSL_MSG("Found PKCS8 header");
18351835
rsa->pkcs8HeaderSz = (word16)idx;
@@ -12452,7 +12452,7 @@ int wolfSSL_EC_KEY_LoadDer_ex(WOLFSSL_EC_KEY* key, const unsigned char* derBuf,
1245212452
* have a PKCS8 header then do not error out.
1245312453
*/
1245412454
if ((ret = ToTraditionalInline_ex((const byte*)derBuf, &idx,
12455-
(word32)derSz, &algId)) > 0) {
12455+
(word32)derSz, &algId)) >= 0) {
1245612456
WOLFSSL_MSG("Found PKCS8 header");
1245712457
key->pkcs8HeaderSz = (word16)idx;
1245812458
res = 1;

src/ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8654,7 +8654,7 @@ static WOLFSSL_EVP_PKEY* _d2i_PublicKey(int type, WOLFSSL_EVP_PKEY** out,
86548654
/* Check if input buffer has PKCS8 header. In the case that it does not
86558655
* have a PKCS8 header then do not error out. */
86568656
if ((ret = ToTraditionalInline_ex((const byte*)(*in), &idx,
8657-
(word32)inSz, &algId)) > 0) {
8657+
(word32)inSz, &algId)) >= 0) {
86588658
WOLFSSL_MSG("Found PKCS8 header");
86598659
pkcs8HeaderSz = (word16)idx;
86608660

0 commit comments

Comments
 (0)