Clean password buffer on stack for PEM_read_bio_PrivateKey
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Sat, 29 Jul 2017 10:19:29 +0000 (12:19 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Sat, 29 Jul 2017 13:00:47 +0000 (15:00 +0200)
and d2i_PKCS8PrivateKey_bio before it goes out of scope.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4047)

(cherry picked from commit 02fd47c8b0930dff9b188fd13bfb9da5e59444a8)

crypto/pem/pem_pk8.c
crypto/pem/pem_pkey.c

index 993c595a7b7b2020a6e11d647dab2c16b29d971d..5caad9faab8771a0ff3e152bd2610c04ffeeace5 100644 (file)
@@ -131,6 +131,7 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
     }
     p8inf = PKCS8_decrypt(p8, psbuf, klen);
     X509_SIG_free(p8);
+    OPENSSL_cleanse(psbuf, klen);
     if (!p8inf)
         return NULL;
     ret = EVP_PKCS82PKEY(p8inf);
index 63086227075ede42a8600b20552817c41ce484e1..671b374f365e160e1be7f60e60bf52b061f339c6 100644 (file)
@@ -66,6 +66,7 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
         }
         p8inf = PKCS8_decrypt(p8, psbuf, klen);
         X509_SIG_free(p8);
+        OPENSSL_cleanse(psbuf, klen);
         if (!p8inf)
             goto p8err;
         ret = EVP_PKCS82PKEY(p8inf);