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