* Try to decrypt the given blob with multiple passwords using the given
* pkcs5 object.
*/
-static private_key_t *decrypt_private_key(pkcs5_t *pkcs5, chunk_t blob)
+static private_key_t *decrypt_private_key(key_type_t type, pkcs5_t *pkcs5,
+ chunk_t blob)
{
enumerator_t *enumerator;
shared_key_t *shared;
{
continue;
}
- private_key = parse_private_key(decrypted);
+ /* do a quick check to validate whether the password was correct */
+ if (!is_asn1(decrypted))
+ {
+ chunk_clear(&decrypted);
+ continue;
+ }
+ private_key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY,
+ type, BUILD_BLOB_ASN1_DER,
+ decrypted, BUILD_END);
if (private_key)
{
chunk_clear(&decrypted);
* Load an encrypted private key from an ASN.1 encoded blob
* Schemes per PKCS#5 (RFC 2898)
*/
-static private_key_t *parse_encrypted_private_key(chunk_t blob)
+static private_key_t *parse_encrypted_private_key(key_type_t type, chunk_t blob)
{
asn1_parser_t *parser;
chunk_t object;
}
case EPKINFO_ENCRYPTED_DATA:
{
- key = decrypt_private_key(pkcs5, object);
+ key = decrypt_private_key(type, pkcs5, object);
break;
}
}
break;
}
/* we don't know whether it is encrypted or not, try both ways */
- key = parse_encrypted_private_key(blob);
+ key = parse_encrypted_private_key(type, blob);
if (!key)
{
key = parse_private_key(blob);