]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
PEM_def_callback(): use same parameter names as for pem_password_cb
authorRichard Levitte <levitte@openssl.org>
Wed, 25 Apr 2018 20:53:40 +0000 (22:53 +0200)
committerRichard Levitte <levitte@openssl.org>
Thu, 26 Apr 2018 08:52:15 +0000 (10:52 +0200)
Add a bit more commentary to explain what's going on.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6080)

(cherry picked from commit d6d94d339756332bbabe2a1032ac511ae31b3fdc)

crypto/pem/pem.h
crypto/pem/pem_lib.c

index aac72fb21eda3974fd40c4d5a583e72c2e02d7dd..9c1d939a919ed5a13d528a418ba91ef6b5c39a8b 100644 (file)
@@ -442,7 +442,8 @@ void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *d, unsigned int cnt);
 int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
                   unsigned int *siglen, EVP_PKEY *pkey);
 
-int PEM_def_callback(char *buf, int num, int w, void *key);
+/* The default pem_password_cb that's used internally */
+int PEM_def_callback(char *buf, int num, int rwflag, void *userdata);
 void PEM_proc_type(char *buf, int type);
 void PEM_dek_info(char *buf, const char *type, int len, char *str);
 
index c6cf63a24e8846112e266efc6c5d6763752d8585..119cb4a6fd159cb86850ba24f267c46720c45642 100644 (file)
@@ -82,15 +82,17 @@ static int load_iv(char **fromp, unsigned char *to, int num);
 static int check_pem(const char *nm, const char *name);
 int pem_check_suffix(const char *pem_str, const char *suffix);
 
-int PEM_def_callback(char *buf, int num, int w, void *key)
+int PEM_def_callback(char *buf, int num, int rwflag, void *userdata)
 {
     int i, min_len;
     const char *prompt;
-    if (key) {
-        i = strlen(key);
+
+    /* We assume that the user passes a default password as userdata */
+    if (userdata) {
+        i = strlen(userdata);
         i = (i > num) ? num : i;
-        memcpy(buf, key, i);
-        return (i);
+        memcpy(buf, userdata, i);
+        return i;
     }
 
     prompt = EVP_get_pw_prompt();
@@ -98,12 +100,15 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
         prompt = "Enter PEM pass phrase:";
 
     /*
-     * We assume that w == 0 means decryption,
-     * while w == 1 means encryption
+     * rwflag == 0 means decryption
+     * rwflag == 1 means encryption
+     *
+     * We assume that for encryption, we want a minimum length, while for
+     * decryption, we cannot know any minimum length, so we assume zero.
      */
-    min_len = w ? MIN_LENGTH : 0;
+    min_len = rwflag ? MIN_LENGTH : 0;
 
-    i = EVP_read_pw_string_min(buf, min_len, num, prompt, w);
+    i = EVP_read_pw_string_min(buf, min_len, num, prompt, rwflag);
     if (i != 0) {
         PEMerr(PEM_F_PEM_DEF_CALLBACK, PEM_R_PROBLEMS_GETTING_PASSWORD);
         memset(buf, 0, (unsigned int)num);