In cases where we ask PEM_def_callback for minimum 0 length, accept 0 length
authorRichard Levitte <levitte@openssl.org>
Fri, 4 May 2018 12:19:44 +0000 (14:19 +0200)
committerRichard Levitte <levitte@openssl.org>
Sat, 12 May 2018 08:22:22 +0000 (10:22 +0200)
Fixes #4716

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

(cherry picked from commit c82c3462267afdbbaa53e11da0508ce4e03c02b3)

CHANGES
crypto/pem/pem_lib.c
crypto/pem/pem_pk8.c
crypto/pem/pem_pkey.c
crypto/pem/pvkfmt.c

diff --git a/CHANGES b/CHANGES
index e8cd3617bb7f9f21f496211ca220967ee8ebecfb..bfd0bcd4024be6ade1c63a0c260c6780629c76d8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,10 @@
 
  Changes between 1.1.0h and 1.1.0i [xx XXX xxxx]
 
+  *) When unlocking a pass phrase protected PEM file or PKCS#8 container, we
+     now allow empty (zero character) pass phrases.
+     [Richard Levitte]
+
   *) Certificate time validation (X509_cmp_time) enforces stricter
      compliance with RFC 5280. Fractional seconds and timezone offsets
      are no longer allowed.
index fdf2b006dca8808d36b40139efe5ab2e61ca7e2c..33c03eec00f4d8ed587b1caa3b88939912b76c83 100644 (file)
@@ -408,7 +408,7 @@ int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
         keylen = PEM_def_callback(buf, PEM_BUFSIZE, 0, u);
     else
         keylen = callback(buf, PEM_BUFSIZE, 0, u);
-    if (keylen <= 0) {
+    if (keylen < 0) {
         PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_PASSWORD_READ);
         return 0;
     }
index 5caad9faab8771a0ff3e152bd2610c04ffeeace5..5e57dc33c75b723f70e118373083683c0951c7f7 100644 (file)
@@ -124,7 +124,7 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
         klen = cb(psbuf, PEM_BUFSIZE, 0, u);
     else
         klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
-    if (klen <= 0) {
+    if (klen < 0) {
         PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
         X509_SIG_free(p8);
         return NULL;
index 671b374f365e160e1be7f60e60bf52b061f339c6..2cce5bebd866baa1480d59a99138a2a79e632f78 100644 (file)
@@ -59,7 +59,7 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
             klen = cb(psbuf, PEM_BUFSIZE, 0, u);
         else
             klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
-        if (klen <= 0) {
+        if (klen < 0) {
             PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, PEM_R_BAD_PASSWORD_READ);
             X509_SIG_free(p8);
             goto err;
index d0a423957cb308ceb4663c1872c534ca793dd0f7..63ce9259638ab030a9c109c9eca1ba98eb653c70 100644 (file)
@@ -685,7 +685,7 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
             inlen = cb(psbuf, PEM_BUFSIZE, 0, u);
         else
             inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
-        if (inlen <= 0) {
+        if (inlen < 0) {
             PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_PASSWORD_READ);
             goto err;
         }