diff --git a/changelog b/changelog index 7c64fa31..9221c0e3 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,5 @@ + * support loading DER formatted PKCS#8 keys * ease commandline use * add DH param generation menu entry * improve token handling and PIN changing dialogs diff --git a/lib/pki_evp.cpp b/lib/pki_evp.cpp index 0c073a58..1c575ee1 100644 --- a/lib/pki_evp.cpp +++ b/lib/pki_evp.cpp @@ -278,6 +278,21 @@ void pki_evp::fload(const QString fname) rewind(fp); pkey = d2i_PrivateKey_fp(fp, NULL); } + if (!pkey) { + ign_openssl_error(); + rewind(fp); + pkey = d2i_PKCS8PrivateKey_fp(fp, NULL, cb, &p); + } + if (!pkey) { + PKCS8_PRIV_KEY_INFO *p8inf; + ign_openssl_error(); + rewind(fp); + p8inf = d2i_PKCS8_PRIV_KEY_INFO_fp(fp, NULL); + if (p8inf) { + pkey = EVP_PKCS82PKEY(p8inf); + PKCS8_PRIV_KEY_INFO_free(p8inf); + } + } if (!pkey) { ign_openssl_error(); rewind(fp); @@ -292,7 +307,7 @@ void pki_evp::fload(const QString fname) if (ign_openssl_error()) { if (pkey) EVP_PKEY_free(pkey); - throw errorEx(tr("Unable to load the private key in file %1. Tried PEM and DER private and public key types.").arg(fname)); + throw errorEx(tr("Unable to load the private key in file %1. Tried PEM and DER private, public and PKCS#8 key types.").arg(fname)); } if (pkey){ if (pkey->type == EVP_PKEY_EC)