Fix parsing of PBKDF2 parameters.
The OPTIONAL prf field is an AlgorithmIdentifier, not an OID. I messed this up in the recent rewrite. Fix the parsing and add a test, produced by commenting out the logic in OpenSSL to omit the field for hmacWithSHA1. (We don't currently support any other PBKDF2, or I'd just add a test for that.) Change-Id: I7d258bb01b93cd203a6fc1b8cccbddfdbc4dbbad Reviewed-on: https://boringssl-review.googlesource.com/14330 Reviewed-by: Steven Valdez <svaldez@google.com> Commit-Queue: Steven Valdez <svaldez@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
7179e53ea6
commit
f35e8384a8
@ -235,7 +235,7 @@ int PKCS5_pbe2_decrypt_init(const struct pbe_suite *suite, EVP_CIPHER_CTX *ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse the KDF parameters. */
|
||||
/* Parse the KDF parameters. See RFC 8018, appendix A.2. */
|
||||
CBS pbkdf2_params, salt;
|
||||
uint64_t iterations;
|
||||
if (!CBS_get_asn1(&kdf, &pbkdf2_params, CBS_ASN1_SEQUENCE) ||
|
||||
@ -267,8 +267,9 @@ int PKCS5_pbe2_decrypt_init(const struct pbe_suite *suite, EVP_CIPHER_CTX *ctx,
|
||||
}
|
||||
|
||||
if (CBS_len(&pbkdf2_params) != 0) {
|
||||
CBS prf;
|
||||
if (!CBS_get_asn1(&pbkdf2_params, &prf, CBS_ASN1_OBJECT) ||
|
||||
CBS alg_id, prf;
|
||||
if (!CBS_get_asn1(&pbkdf2_params, &alg_id, CBS_ASN1_SEQUENCE) ||
|
||||
!CBS_get_asn1(&alg_id, &prf, CBS_ASN1_OBJECT) ||
|
||||
CBS_len(&pbkdf2_params) != 0) {
|
||||
OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_DECODE_ERROR);
|
||||
return 0;
|
||||
@ -280,6 +281,15 @@ int PKCS5_pbe2_decrypt_init(const struct pbe_suite *suite, EVP_CIPHER_CTX *ctx,
|
||||
OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_UNSUPPORTED_PRF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* hmacWithSHA1 has a NULL parameter. */
|
||||
CBS null;
|
||||
if (!CBS_get_asn1(&alg_id, &null, CBS_ASN1_NULL) ||
|
||||
CBS_len(&null) != 0 ||
|
||||
CBS_len(&alg_id) != 0) {
|
||||
OPENSSL_PUT_ERROR(PKCS8, PKCS8_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse the encryption scheme parameters. Note OpenSSL does not match the
|
||||
|
@ -143,6 +143,31 @@ static const uint8_t kEmptyPasswordOpenSSL[] = {
|
||||
0xed,
|
||||
};
|
||||
|
||||
// kExplicitHMACWithSHA1 is a PBES2-encrypted private key with an explicit
|
||||
// hmacWithSHA1 AlgorithmIdentifier in the PBKDF2 parameters.
|
||||
static const uint8_t kExplicitHMACWithSHA1[] = {
|
||||
0x30, 0x81, 0xec, 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, 0x08, 0x90,
|
||||
0xcd, 0x1e, 0x47, 0x1d, 0xff, 0x4c, 0xa8, 0x02, 0x02, 0x08, 0x00, 0x30,
|
||||
0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x07, 0x05,
|
||||
0x00, 0x30, 0x1d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04,
|
||||
0x01, 0x02, 0x04, 0x10, 0x34, 0xe7, 0x5b, 0x9b, 0xf9, 0x17, 0xcf, 0x15,
|
||||
0x59, 0x7c, 0xfd, 0xc1, 0xac, 0xed, 0x6f, 0xdd, 0x04, 0x81, 0x90, 0xe3,
|
||||
0xd7, 0xfc, 0xbe, 0xe6, 0xe8, 0x92, 0xc1, 0xa2, 0x57, 0x42, 0x4b, 0xf1,
|
||||
0x35, 0x6c, 0x4f, 0x58, 0x61, 0x14, 0x30, 0x4e, 0xa3, 0x8d, 0x4f, 0xde,
|
||||
0x2d, 0x0b, 0xa2, 0x62, 0x4b, 0xee, 0x9f, 0xc4, 0xeb, 0x89, 0x33, 0x76,
|
||||
0x3f, 0x0c, 0x20, 0xad, 0x75, 0x29, 0x42, 0xbc, 0xbd, 0x83, 0x46, 0x1d,
|
||||
0x5c, 0xae, 0xec, 0x10, 0x05, 0xbb, 0xd3, 0x98, 0xc9, 0x5a, 0x5e, 0x0a,
|
||||
0x95, 0x12, 0x1e, 0x65, 0x93, 0xdd, 0xdd, 0x51, 0xd5, 0x56, 0xc2, 0xa9,
|
||||
0xf9, 0x43, 0x0f, 0x68, 0x8a, 0x14, 0x40, 0xe5, 0x62, 0x9e, 0x0d, 0xd7,
|
||||
0x67, 0x62, 0xf4, 0x49, 0xb1, 0x62, 0x22, 0x42, 0xb1, 0xe1, 0xb2, 0x1d,
|
||||
0x37, 0x3e, 0x95, 0x52, 0xe9, 0x61, 0x89, 0xc7, 0x62, 0xcc, 0xb1, 0x44,
|
||||
0x40, 0xef, 0x89, 0xc8, 0xc4, 0x0e, 0xae, 0xa8, 0xf9, 0x17, 0x42, 0x2b,
|
||||
0x8c, 0x0b, 0x26, 0xf6, 0x07, 0x00, 0xab, 0x25, 0x2b, 0x64, 0xcf, 0xc3,
|
||||
0x68, 0xf9, 0x5e, 0x01, 0x66, 0x59, 0x5f, 0x3f, 0x05, 0x57, 0xcd,
|
||||
};
|
||||
|
||||
static bool TestDecrypt(const uint8_t *der, size_t der_len,
|
||||
const char *password) {
|
||||
const uint8_t *data = der;
|
||||
@ -222,6 +247,8 @@ int main(int argc, char **argv) {
|
||||
!TestDecrypt(kNullPassword, sizeof(kNullPassword), NULL) ||
|
||||
!TestDecrypt(kNullPasswordNSS, sizeof(kNullPasswordNSS), NULL) ||
|
||||
!TestDecrypt(kEmptyPasswordOpenSSL, sizeof(kEmptyPasswordOpenSSL), "") ||
|
||||
!TestDecrypt(kExplicitHMACWithSHA1, sizeof(kExplicitHMACWithSHA1),
|
||||
"foo") ||
|
||||
!TestRoundTrip(NID_pbe_WithSHA1And3_Key_TripleDES_CBC, nullptr,
|
||||
"password", nullptr, 0, 10) ||
|
||||
// Vary the salt
|
||||
|
Loading…
Reference in New Issue
Block a user