Cleaning secret data after use
authorEasySec <easy.sec@free.fr>
Mon, 16 Oct 2017 19:05:10 +0000 (15:05 -0400)
committerRich Salz <rsalz@openssl.org>
Mon, 16 Oct 2017 19:06:29 +0000 (15:06 -0400)
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4509)

apps/enc.c

index 5117a4980e2da5fab23dbede335c6a8509127e1d..14b029b33f964f2b557efc343863df9d2d4579bb 100644 (file)
@@ -476,9 +476,13 @@ int enc_main(int argc, char **argv)
             BIO_printf(bio_err, "iv undefined\n");
             goto end;
         }
-        if ((hkey != NULL) && !set_hex(hkey, key, EVP_CIPHER_key_length(cipher))) {
-            BIO_printf(bio_err, "invalid hex key value\n");
-            goto end;
+        if (hkey != NULL) {
+            if (!set_hex(hkey, key, EVP_CIPHER_key_length(cipher))) {
+                BIO_printf(bio_err, "invalid hex key value\n");
+                goto end;
+            }
+            /* wiping secret data as we no longer need it */
+            OPENSSL_cleanse(hkey, strlen(hkey));
         }
 
         if ((benc = BIO_new(BIO_f_cipher())) == NULL)