SF Bug #110 Exported private key from 4096 bit SSH key is wrong

Actually, it just differs. It is PKCS#8 instead of PKCS#1
This commit is contained in:
Christian Hohnstaedt 2018-01-06 21:18:31 +01:00
parent 0ba41583fb
commit eaabb2a28d
2 changed files with 29 additions and 1 deletions

View File

@ -219,7 +219,9 @@ exportType::etype db_key::clipboardFormat(QModelIndexList indexes)
"pub", tr("SSH2 public"));
if (allPriv)
types << exportType(exportType::PEM_private, "pem",
tr("PEM private"));
tr("PEM private"))
<< exportType(exportType::PKCS8, "pk8",
"PKCS#8");
ExportDialog *dlg = new ExportDialog(mainwin,
tr("Export keys to Clipboard"), QString(), NULL,

View File

@ -81,6 +81,8 @@ BIO *pki_key::pem(BIO *b, int format)
{
EVP_PKEY *pkey;
QByteArray ba;
int keytype;
if (!b)
b = BIO_new(BIO_s_mem());
@ -90,6 +92,30 @@ BIO *pki_key::pem(BIO *b, int format)
BIO_write(b, ba.data(), ba.size());
break;
case exportType::PEM_private:
pkey = decryptKey();
keytype = EVP_PKEY_id(pkey);
switch (keytype) {
case EVP_PKEY_RSA:
PEM_write_bio_RSAPrivateKey(b,
EVP_PKEY_get0_RSA(pkey),
NULL, NULL, 0, NULL, NULL);
break;
case EVP_PKEY_DSA:
PEM_write_bio_DSAPrivateKey(b,
EVP_PKEY_get0_DSA(pkey),
NULL, NULL, 0, NULL, NULL);
break;
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC:
PEM_write_bio_ECPrivateKey(b,
EVP_PKEY_get0_EC_KEY(pkey),
NULL, NULL, 0, NULL, NULL);
break;
#endif
}
EVP_PKEY_free(pkey);
break;
case exportType::PKCS8:
pkey = decryptKey();
PEM_write_bio_PrivateKey(b, pkey, NULL, NULL, 0, NULL, NULL);
EVP_PKEY_free(pkey);