|
Jakub Jelen |
56fdfa |
commit 2fe812887139ce32eeca52f9a0c141bdc7c4c8af
|
|
Jakub Jelen |
56fdfa |
Author: Jakub Jelen <jjelen@redhat.com>
|
|
Jakub Jelen |
56fdfa |
Date: Wed May 22 17:25:22 2019 +0200
|
|
Jakub Jelen |
56fdfa |
|
|
Jakub Jelen |
56fdfa |
New PEM export format withou MD5
|
|
Jakub Jelen |
56fdfa |
|
|
Jakub Jelen |
56fdfa |
diff --git a/sshkey.c b/sshkey.c
|
|
Jakub Jelen |
56fdfa |
index b95ed0b1..1a271512 100644
|
|
Jakub Jelen |
56fdfa |
--- a/sshkey.c
|
|
Jakub Jelen |
56fdfa |
+++ b/sshkey.c
|
|
Jakub Jelen |
56fdfa |
@@ -3805,26 +3805,28 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *blob,
|
|
Jakub Jelen |
56fdfa |
const EVP_CIPHER *cipher = (len > 0) ? EVP_aes_128_cbc() : NULL;
|
|
Jakub Jelen |
56fdfa |
char *bptr;
|
|
Jakub Jelen |
56fdfa |
BIO *bio = NULL;
|
|
Jakub Jelen |
56fdfa |
+ EVP_PKEY *pkey = NULL;
|
|
Jakub Jelen |
56fdfa |
|
|
Jakub Jelen |
56fdfa |
if (len > 0 && len <= 4)
|
|
Jakub Jelen |
56fdfa |
return SSH_ERR_PASSPHRASE_TOO_SHORT;
|
|
Jakub Jelen |
56fdfa |
if ((bio = BIO_new(BIO_s_mem())) == NULL)
|
|
Jakub Jelen |
56fdfa |
return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
56fdfa |
+ if ((pkey = EVP_PKEY_new()) == NULL) {
|
|
Jakub Jelen |
56fdfa |
+ BIO_free(bio);
|
|
Jakub Jelen |
56fdfa |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
56fdfa |
+ }
|
|
Jakub Jelen |
56fdfa |
|
|
Jakub Jelen |
56fdfa |
switch (key->type) {
|
|
Jakub Jelen |
56fdfa |
case KEY_DSA:
|
|
Jakub Jelen |
56fdfa |
- success = PEM_write_bio_DSAPrivateKey(bio, key->dsa,
|
|
Jakub Jelen |
56fdfa |
- cipher, passphrase, len, NULL, NULL);
|
|
Jakub Jelen |
56fdfa |
+ success = EVP_PKEY_set1_DSA(pkey, key->dsa);
|
|
Jakub Jelen |
56fdfa |
break;
|
|
Jakub Jelen |
56fdfa |
#ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
56fdfa |
case KEY_ECDSA:
|
|
Jakub Jelen |
56fdfa |
- success = PEM_write_bio_ECPrivateKey(bio, key->ecdsa,
|
|
Jakub Jelen |
56fdfa |
- cipher, passphrase, len, NULL, NULL);
|
|
Jakub Jelen |
56fdfa |
+ success = EVP_PKEY_set1_EC_KEY(pkey, key->ecdsa);
|
|
Jakub Jelen |
56fdfa |
break;
|
|
Jakub Jelen |
56fdfa |
#endif
|
|
Jakub Jelen |
56fdfa |
case KEY_RSA:
|
|
Jakub Jelen |
56fdfa |
- success = PEM_write_bio_RSAPrivateKey(bio, key->rsa,
|
|
Jakub Jelen |
56fdfa |
- cipher, passphrase, len, NULL, NULL);
|
|
Jakub Jelen |
56fdfa |
+ success = EVP_PKEY_set1_RSA(pkey, key->rsa);
|
|
Jakub Jelen |
56fdfa |
break;
|
|
Jakub Jelen |
56fdfa |
default:
|
|
Jakub Jelen |
56fdfa |
success = 0;
|
|
Jakub Jelen |
56fdfa |
@@ -3834,6 +3836,12 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *blob,
|
|
Jakub Jelen |
56fdfa |
r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
56fdfa |
goto out;
|
|
Jakub Jelen |
56fdfa |
}
|
|
Jakub Jelen |
56fdfa |
+ success = PEM_write_bio_PrivateKey(bio, pkey,
|
|
Jakub Jelen |
56fdfa |
+ cipher, passphrase, len, NULL, NULL);
|
|
Jakub Jelen |
56fdfa |
+ if (success == 0) {
|
|
Jakub Jelen |
56fdfa |
+ r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
56fdfa |
+ goto out;
|
|
Jakub Jelen |
56fdfa |
+ }
|
|
Jakub Jelen |
56fdfa |
if ((blen = BIO_get_mem_data(bio, &bptr)) <= 0) {
|
|
Jakub Jelen |
56fdfa |
r = SSH_ERR_INTERNAL_ERROR;
|
|
Jakub Jelen |
56fdfa |
goto out;
|
|
Jakub Jelen |
56fdfa |
@@ -3842,6 +3850,7 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *blob,
|
|
Jakub Jelen |
56fdfa |
goto out;
|
|
Jakub Jelen |
56fdfa |
r = 0;
|
|
Jakub Jelen |
56fdfa |
out:
|
|
Jakub Jelen |
56fdfa |
+ EVP_PKEY_free(pkey);
|
|
Jakub Jelen |
56fdfa |
BIO_free(bio);
|
|
Jakub Jelen |
56fdfa |
return r;
|
|
Jakub Jelen |
56fdfa |
}
|
|
Jakub Jelen |
56fdfa |
|