Blame SOURCES/krb5-1.11.3-prompter1.patch

5af5b2
commit a8eec52a13ba108b8855aef8cf9dafeb37811d2e
5af5b2
Author: Nalin Dahyabhai <nalin@redhat.com>
5af5b2
Date:   Fri Mar 15 12:05:56 2013 -0400
5af5b2
5af5b2
    Add PEM password prompter callback in PKINIT
5af5b2
    
5af5b2
    Supply a callack to PEM_read_bio_PrivateKey() using the prompter to
5af5b2
    request a password for encrypted PEM data.  Otherwise OpenSSL will use
5af5b2
    the controlling terminal.
5af5b2
    
5af5b2
    [ghudson@mit.edu: minor style cleanup, commit message]
5af5b2
    
5af5b2
    ticket: 7590
5af5b2
5af5b2
diff --git a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
5af5b2
index 6dbda9b..7186ce8 100644
5af5b2
--- a/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
5af5b2
+++ b/src/plugins/preauth/pkinit/pkinit_crypto_openssl.c
5af5b2
@@ -656,11 +656,50 @@ cleanup:
5af5b2
     return retval;
5af5b2
 }
5af5b2
 
5af5b2
+struct get_key_cb_data {
5af5b2
+    krb5_context context;
5af5b2
+    pkinit_identity_crypto_context id_cryptoctx;
5af5b2
+    char *filename;
5af5b2
+};
5af5b2
+
5af5b2
+static int
5af5b2
+get_key_cb(char *buf, int size, int rwflag, void *userdata)
5af5b2
+{
5af5b2
+    struct get_key_cb_data *data = userdata;
5af5b2
+    pkinit_identity_crypto_context id_cryptoctx;
5af5b2
+    krb5_data rdat;
5af5b2
+    krb5_prompt kprompt;
5af5b2
+    krb5_prompt_type prompt_type;
5af5b2
+    krb5_error_code retval;
5af5b2
+    char *prompt;
5af5b2
+
5af5b2
+    if (asprintf(&prompt, "%s %s", _("Pass phrase for"), data->filename) < 0)
5af5b2
+        return -1;
5af5b2
+    rdat.data = buf;
5af5b2
+    rdat.length = size;
5af5b2
+    kprompt.prompt = prompt;
5af5b2
+    kprompt.hidden = 1;
5af5b2
+    kprompt.reply = &rda;;
5af5b2
+    prompt_type = KRB5_PROMPT_TYPE_PREAUTH;
5af5b2
+
5af5b2
+    /* PROMPTER_INVOCATION */
5af5b2
+    k5int_set_prompt_types(data->context, &prompt_type);
5af5b2
+    id_cryptoctx = data->id_cryptoctx;
5af5b2
+    retval = data->id_cryptoctx->prompter(data->context,
5af5b2
+                                          id_cryptoctx->prompter_data, NULL,
5af5b2
+                                          NULL, 1, &kprompt);
5af5b2
+    k5int_set_prompt_types(data->context, 0);
5af5b2
+    free(prompt);
5af5b2
+    return retval ? -1 : (int)rdat.length;
5af5b2
+}
5af5b2
+
5af5b2
 static krb5_error_code
5af5b2
-get_key(char *filename, EVP_PKEY **retkey)
5af5b2
+get_key(krb5_context context, pkinit_identity_crypto_context id_cryptoctx,
5af5b2
+        char *filename, EVP_PKEY **retkey)
5af5b2
 {
5af5b2
     EVP_PKEY *pkey = NULL;
5af5b2
     BIO *tmp = NULL;
5af5b2
+    struct get_key_cb_data cb_data;
5af5b2
     int code;
5af5b2
     krb5_error_code retval;
5af5b2
 
5af5b2
@@ -676,7 +715,10 @@ get_key(char *filename, EVP_PKEY **retkey)
5af5b2
         retval = errno;
5af5b2
         goto cleanup;
5af5b2
     }
5af5b2
-    pkey = (EVP_PKEY *) PEM_read_bio_PrivateKey(tmp, NULL, NULL, NULL);
5af5b2
+    cb_data.context = context;
5af5b2
+    cb_data.id_cryptoctx = id_cryptoctx;
5af5b2
+    cb_data.filename = filename;
5af5b2
+    pkey = PEM_read_bio_PrivateKey(tmp, NULL, get_key_cb, &cb_data);
5af5b2
     if (pkey == NULL) {
5af5b2
         retval = EIO;
5af5b2
         pkiDebug("failed to read private key from %s\n", filename);
5af5b2
@@ -4333,7 +4375,7 @@ pkinit_load_fs_cert_and_key(krb5_context context,
5af5b2
         pkiDebug("failed to load user's certificate from '%s'\n", certname);
5af5b2
         goto cleanup;
5af5b2
     }
5af5b2
-    retval = get_key(keyname, &y);
5af5b2
+    retval = get_key(context, id_cryptoctx, keyname, &y);
5af5b2
     if (retval != 0 || y == NULL) {
5af5b2
         pkiDebug("failed to load user's private key from '%s'\n", keyname);
5af5b2
         goto cleanup;