diff --git a/tests/api.c b/tests/api.c index 200971d73..754597961 100644 --- a/tests/api.c +++ b/tests/api.c @@ -34627,6 +34627,194 @@ static int test_wc_CreateEncryptedPKCS8Key(void) return EXPECT_RESULT(); } +static int test_wc_DecryptedPKCS8Key(void) +{ + EXPECT_DECLS; +#if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \ + && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \ + !defined(NO_ASN_CRYPT) + static byte badPkcs5RsaEnc[] = { + 0x30, 0x82, 0x05, 0x2d, 0x30, 0x57, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, + 0x0d, 0x30, 0x4a, 0x30, 0x29, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x05, 0x0c, + 0x30, 0x1c, 0x04, 0x09, 0xad, 0x8f, 0xb7, 0x90, + 0x43, 0xd9, 0x3f, 0xe5, 0x02, 0x02, 0x04, 0x02, + 0x02, 0x04, 0x80, 0x30, 0x0c, 0x06, 0x08, 0x2a, + 0xbc, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x09, 0x05, + 0x00, 0x30, 0x1d, 0x06, 0x09, 0x60, 0x86, 0x48, + 0x01, 0x65, 0x03, 0x04, 0x01, 0x2a, 0x04, 0x10, + 0x90, 0xf9, 0xa4, 0xd7, 0xf2, 0xae, 0x58, 0xd6, + 0xe1, 0x7c, 0x60, 0x7b, 0x84, 0xc0, 0x8c, 0x44, + 0x04, 0x50, 0xc8, 0xd0, 0x03, 0xa7, 0x79, 0xa9, + 0x11, 0x8b, 0xbd, 0xd6, 0xcb, 0xd9, 0x9e, 0xd7, + 0x2d, 0xac, 0x2c, 0xb8, 0xc9, 0x5f, 0xe7, 0x8b, + 0x36, 0x26, 0x26, 0x23, 0x2a, 0x21, 0x25, 0x6f, + 0xd0, 0x52, 0xd3, 0xeb, 0xff, 0x1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0x90, + 0x9b, 0x38, 0x41, 0xd3, 0x13, 0xd0, 0xfa, 0xec, + 0x0f, 0x65, 0xe9, 0x02, 0x90, 0x39, 0xa8, 0xe4, + 0xd4, 0x52, 0xa6, 0x1f, 0x7a, 0x54, 0x00, 0x19, + 0x13, 0x94, 0xae, 0x7a, 0xf2, 0xa7, 0xce, 0xf5, + 0x29, 0x78, 0x66, 0x1c, 0x03, 0x26, 0x65, 0xe8, + 0x03, 0x8e, 0x97, 0x67, 0x20, 0x61, 0x4c, 0xbd, + 0xa0, 0xb3, 0x88, 0x10, 0x8b, 0x74, 0x40, 0x8d, + 0xc6, 0xe6, 0x26, 0x32, 0x0f, 0x01, 0x47, 0x35, + 0xb3, 0x86, 0x87, 0xa9, 0x6d, 0xf8, 0xf8, 0x9f, + 0xca, 0x30, 0x69, 0xf7, 0x5d, 0x89, 0x3f, 0xf5, + 0x1d, 0xd5, 0x26, 0xd7, 0xef, 0x43, 0x26, 0x06, + 0x26, 0x7b, 0xf0, 0xdd, 0x86, 0xa6, 0x58, 0x71, + 0xd6, 0xcb, 0x45, 0xb4, 0x4f, 0x52, 0xd7, 0xf1, + 0xae, 0x06, 0xad, 0xc7, 0x94, 0x17, 0xe8, 0x44, + 0x59, 0x02, 0xe1, 0x22, 0x9e, 0x59, 0xa6, 0xcc, + 0x3b, 0x20, 0x5b, 0x95, 0xf1, 0x34, 0x31, 0x52, + 0x7e, 0x6d, 0xff, 0x4b, 0x45, 0x9a, 0xff, 0xba, + 0x1a, 0x41, 0x48, 0x20, 0x49, 0xb8, 0x62, 0xef, + 0x82, 0xca, 0x14, 0x7e, 0x14, 0xfa, 0x49, 0x3f, + 0xfb, 0x5e, 0xb1, 0x60, 0x30, 0x94, 0x4c, 0xee, + 0x4b, 0x78, 0xa2, 0x79, 0xb2, 0xa1, 0xbd, 0xb1, + 0x94, 0x24, 0xd6, 0x9c, 0xf0, 0x41, 0x3b, 0xc6, + 0xf2, 0x30, 0x8c, 0x8a, 0xdd, 0x2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0x92, 0x35, 0xdd, 0xb7, 0xb8, 0x2e, 0xd8, + 0xb3, 0xe9, 0x62, 0x8e, 0xe2, 0x5e, 0x16, 0xd4, + 0xed, 0xf4, 0xd3, 0xc1, 0xba, 0x5d, 0x49, 0xce, + 0x78, 0x5c, 0xf5, 0xbb, 0xad, 0x61, 0x1f, 0x64, + 0x52, 0x22, 0xb4, 0xa3, 0x07, 0x18, 0x3d, 0xd3, + 0x9d, 0xec, 0xe6, 0x9e, 0xb5, 0xad, 0x0c, 0xd3, + 0x3b, 0xb6, 0xeb, 0xcd, 0x9c, 0x69, 0x45, 0xf2, + 0x07, 0x24, 0xe9, 0xd7, 0xe0, 0xe7, 0x62, 0xe5, + 0x01, 0x34, 0x24, 0x4e, 0xf6, 0x32, 0xe8, 0x42, + 0x97, 0x3e, 0x14, 0xaf, 0xbc, 0x26, 0xbd, 0x73, + 0xc5, 0xde, 0x5a, 0x8e, 0x65, 0x61, 0x97, 0x81, + 0x31, 0x52, 0xa3, 0xbd, 0x9b, 0x9e, 0xda, 0xdd, + 0x37, 0x15, 0x30, 0xfb, 0x3b, 0x59, 0x0c, 0x91, + 0x8b, 0x54, 0x49, 0x68, 0xc6, 0x41, 0x38, 0x77, + 0x1c, 0x00, 0xb2, 0xc3, 0x37, 0xe2, 0x50, 0x67, + 0xeb, 0x49, 0xa4, 0xde, 0x04, 0x1e, 0xf5, 0xcc, + 0x49, 0x24, 0x5a, 0x8d, 0x94, 0x33, 0xbf, 0x55, + 0xf8, 0x70, 0x7d, 0x1e, 0x5b, 0xe3, 0x74, 0x6b, + 0x34, 0xb3, 0xf6, 0x8a, 0x47, 0xf9, 0x2f, 0xc9, + 0xcb, 0x6a, 0x80, 0x89, 0xf2, 0x19, 0x24, 0x5b, + 0xdf, 0x04, 0x9a, 0x53, 0x1c, 0x9f, 0x71, 0xea, + 0x01, 0xd3, 0xe9, 0x14, 0x87, 0xee, 0x2a, 0x62, + 0x53, 0x19, 0x74, 0x64, 0x19, 0x03, 0x00, 0xd6, + 0xa1, 0xcb, 0xdf, 0x59, 0x77, 0x6b, 0xa9, 0x25, + 0x32, 0xff, 0xe9, 0xa9, 0x41, 0x06, 0x0c, 0x06, + 0xd4, 0xae, 0xfb, 0x58, 0x20, 0x2e, 0xe3, 0xe0, + 0xce, 0x53, 0xea, 0x03, 0xcb, 0x3f, 0x64, 0xe9, + 0xd9, 0xc1, 0x0e, 0xf8, 0xec, 0x97, 0xee, 0x05, + 0x42, 0x41, 0x61, 0xcc, 0x75, 0x13, 0x8d, 0x88, + 0x62, 0x84, 0xa1, 0x3c, 0xa3, 0x30, 0xce, 0x12, + 0xf1, 0x84, 0xee, 0x26, 0x08, 0x04, 0xae, 0x67, + 0x56, 0xa0, 0x84, 0x91, 0x8a, 0xbd, 0xc4, 0xba, + 0x07, 0xb3, 0x06, 0xe7, 0xc8, 0x12, 0xae, 0x56, + 0x46, 0xcd, 0x8d, 0x5c, 0x91, 0x05, 0x90, 0x11, + 0x37, 0xef, 0xe0, 0x3e, 0xf3, 0xc6, 0x95, 0x13, + 0xeb, 0x2f, 0xe4, 0x3e, 0xfc, 0xe4, 0xc0, 0x61, + 0xfb, 0x1b, 0x74, 0x78, 0xe9, 0x6b, 0x7d, 0xe4, + 0xa2, 0xc4, 0x6d, 0x26, 0x6d, 0xc0, 0x06, 0xba, + 0x9f, 0x7e, 0x7d, 0x5e, 0x7f, 0xfa, 0x66, 0x08, + 0xd9, 0x70, 0x39, 0x05, 0xfa, 0x10, 0xfd, 0x5f, + 0xaa, 0xc4, 0x9d, 0x02, 0xd4, 0xf8, 0x0f, 0x3f, + 0xd3, 0xbe, 0xaa, 0x86, 0x4a, 0x0f, 0x8e, 0x23, + 0x02, 0xbf, 0x48, 0x26, 0x93, 0x5f, 0xc2, 0xc5, + 0x05, 0xca, 0xa1, 0x6d, 0x96, 0xd1, 0x3a, 0x30, + 0x66, 0xe1, 0x97, 0x1d, 0x4c, 0xb0, 0x93, 0xd7, + 0x8d, 0x3c, 0xc0, 0xf9, 0x2b, 0x81, 0x0d, 0xd7, + 0x68, 0x49, 0x18, 0xab, 0xdc, 0x4b, 0xa0, 0x7b, + 0x30, 0x6e, 0x7c, 0x81, 0x2a, 0xe5, 0x64, 0x6c, + 0xd8, 0xd5, 0xc9, 0x10, 0x59, 0x01, 0x13, 0x7e, + 0xfe, 0x03, 0xef, 0x3c, 0x69, 0x51, 0x3e, 0xb2, + 0xfe, 0x43, 0xef, 0xce, 0x4c, 0x06, 0x1f, 0xb1, + 0xb7, 0x47, 0x8e, 0x96, 0xb7, 0xde, 0x4a, 0x2c, + 0x46, 0xd2, 0x66, 0xdc, 0x00, 0x6b, 0xa9, 0xf7, + 0xe7, 0xd5, 0xe7, 0xff, 0xa6, 0x60, 0x8d, 0x97, + 0x03, 0x90, 0x5f, 0xa1, 0x0f, 0xd5, 0xfa, 0xac, + 0x49, 0xd0, 0x2d, 0x4f, 0x80, 0xf3, 0xfd, 0x3b, + 0xea, 0xa8, 0x64, 0xa0, 0xf8, 0xe2, 0x30, 0x2b, + 0xf4, 0x80, 0x2c, 0x50, 0x5c, 0xaa, 0x16, 0xd9, + 0x6d, 0x13, 0xa3, 0x06, 0x6e, 0x19, 0x71, 0xd4, + 0xcb, 0x09, 0x3d, 0x78, 0xd3, 0xcc, 0x0f, 0x92, + 0xb8, 0x10, 0xdd, 0x76, 0x88, 0x97, 0x1b, 0x7f, + 0xf0, 0x5c, 0xfb, 0x97, 0x66, 0x3e, 0x7f, 0x66, + 0xf9, 0xa4, 0xd5, 0x29, 0xb5, 0x54, 0x8a, 0xaa, + 0xfc, 0xe2, 0xdb, 0xb7, + }; + const char password[] = "password"; + word32 passwordSz = (word32)XSTRLEN(password); + + /* Decrypt the encrypted PKCS8 key we just made. */ + ExpectIntEQ(wc_DecryptPKCS8Key(badPkcs5RsaEnc, sizeof(badPkcs5RsaEnc), + password, (int)passwordSz), ASN_PARSE_E); +#endif + return EXPECT_RESULT(); +} + static int test_wc_GetPkcs8TraditionalOffset(void) { EXPECT_DECLS; @@ -52128,6 +52316,7 @@ TEST_CASE testCases[] = { /* wolfCrypt ASN tests */ TEST_DECL(test_ToTraditional), TEST_DECL(test_wc_CreateEncryptedPKCS8Key), + TEST_DECL(test_wc_DecryptedPKCS8Key), TEST_DECL(test_wc_GetPkcs8TraditionalOffset), /* Certificate */ diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index cde672635..066543903 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -10030,7 +10030,7 @@ enum { int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) { #ifndef WOLFSSL_ASN_TEMPLATE - word32 inOutIdx = 0, seqEnd, oid, shaOid = 0; + word32 inOutIdx = 0, seqEnd, oid, shaOid = 0, seqPkcs5End = sz; int ret = 0, first, second, length = 0, version, saltSz, id = 0; int iterations = 0, keySz = 0; #ifdef WOLFSSL_SMALL_STACK @@ -10062,6 +10062,7 @@ int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) if (GetSequence(input, &inOutIdx, &length, sz) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); } + seqPkcs5End = inOutIdx + length; if (GetAlgoId(input, &inOutIdx, &oid, oidKdfType, sz) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); @@ -10079,7 +10080,7 @@ int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) * DEFAULT items. */ seqEnd = inOutIdx + (word32)length; - ret = GetOctetString(input, &inOutIdx, &saltSz, sz); + ret = GetOctetString(input, &inOutIdx, &saltSz, seqEnd); if (ret < 0) goto exit_dc; @@ -10097,7 +10098,7 @@ int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) XMEMCPY(salt, &input[inOutIdx], (size_t)saltSz); inOutIdx += (word32)saltSz; - if (GetShortInt(input, &inOutIdx, &iterations, sz) < 0) { + if (GetShortInt(input, &inOutIdx, &iterations, seqEnd) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); } @@ -10105,19 +10106,19 @@ int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) if (seqEnd > inOutIdx) { word32 localIdx = inOutIdx; - if (GetASNTag(input, &localIdx, &tag, sz) < 0) { + if (GetASNTag(input, &localIdx, &tag, seqEnd) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); } if (tag == ASN_INTEGER && - GetShortInt(input, &inOutIdx, &keySz, sz) < 0) { + GetShortInt(input, &inOutIdx, &keySz, seqEnd) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); } } /* DEFAULT HMAC is SHA-1 */ if (seqEnd > inOutIdx) { - if (GetAlgoId(input, &inOutIdx, &oid, oidHmacType, sz) < 0) { + if (GetAlgoId(input, &inOutIdx, &oid, oidHmacType, seqEnd) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); } @@ -10133,7 +10134,7 @@ int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) if (version == PKCS5v2) { /* get encryption algo */ - if (GetAlgoId(input, &inOutIdx, &oid, oidBlkType, sz) < 0) { + if (GetAlgoId(input, &inOutIdx, &oid, oidBlkType, seqPkcs5End) < 0) { ERROR_OUT(ASN_PARSE_E, exit_dc); } @@ -10144,7 +10145,7 @@ int DecryptContent(byte* input, word32 sz, const char* password, int passwordSz) if (shaOid == 0) shaOid = oid; - ret = GetOctetString(input, &inOutIdx, &length, sz); + ret = GetOctetString(input, &inOutIdx, &length, seqPkcs5End); if (ret < 0) goto exit_dc; @@ -10215,9 +10216,10 @@ exit_dc: idx = dataASN[PKCS8DECASN_IDX_ENCALGO_OID].data.oid.length; /* Second last byte: 1 (PKCS #12 PBE Id) or 5 (PKCS #5) * Last byte: Alg or PBES2 */ - ret = CheckAlgo(dataASN[PKCS8DECASN_IDX_ENCALGO_OID].data.oid.data[idx - 2], - dataASN[PKCS8DECASN_IDX_ENCALGO_OID].data.oid.data[idx - 1], - &id, &version, NULL); + ret = CheckAlgo( + dataASN[PKCS8DECASN_IDX_ENCALGO_OID].data.oid.data[idx - 2], + dataASN[PKCS8DECASN_IDX_ENCALGO_OID].data.oid.data[idx - 1], &id, + &version, NULL); } if (ret == 0) { /* Get the parameters data. */ @@ -10241,7 +10243,8 @@ exit_dc: 0, params, &pIdx, sz); if (ret == 0) { /* Get the salt data. */ - GetASN_GetRef(&dataASN[PBES1PARAMSASN_IDX_SALT], &salt, &saltSz); + GetASN_GetRef(&dataASN[PBES1PARAMSASN_IDX_SALT], &salt, + &saltSz); } } else { @@ -10250,17 +10253,22 @@ exit_dc: /* Initialize for PBES2 parameters. Put iterations in var; match * KDF, HMAC and cipher, and copy CBC into buffer. */ XMEMSET(dataASN, 0, sizeof(*dataASN) * pbes2ParamsASN_Length); - GetASN_ExpBuffer(&dataASN[PBES2PARAMSASN_IDX_KDF_OID], pbkdf2Oid, sizeof(pbkdf2Oid)); - GetASN_Int32Bit(&dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_ITER], &iterations); - GetASN_OID(&dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_PRF_OID], oidHmacType); + GetASN_ExpBuffer(&dataASN[PBES2PARAMSASN_IDX_KDF_OID], pbkdf2Oid, + sizeof(pbkdf2Oid)); + GetASN_Int32Bit(&dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_ITER], + &iterations); + GetASN_OID(&dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_PRF_OID], + oidHmacType); GetASN_OID(&dataASN[PBES2PARAMSASN_IDX_ENCS_OID], oidBlkType); - GetASN_Buffer(&dataASN[PBES2PARAMSASN_IDX_ENCS_PARAMS], cbcIv, &ivSz); + GetASN_Buffer(&dataASN[PBES2PARAMSASN_IDX_ENCS_PARAMS], cbcIv, + &ivSz); /* Parse the PBES2 parameters */ ret = GetASN_Items(pbes2ParamsASN, dataASN, pbes2ParamsASN_Length, 0, params, &pIdx, sz); if (ret == 0) { /* Get the salt data. */ - GetASN_GetRef(&dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_SALT], &salt, &saltSz); + GetASN_GetRef(&dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_SALT], + &salt, &saltSz); /* Get the digest and encryption algorithm id. */ shaOid = dataASN[PBES2PARAMSASN_IDX_PBKDF2_PARAMS_PRF_OID].data.oid.sum; /* Default HMAC-SHA1 */ id = (int)dataASN[PBES2PARAMSASN_IDX_ENCS_OID].data.oid.sum;