[pkg-opensc-commit] [libp11] 04/06: Add more information to UI prompt (#152)

Eric Dorland eric at moszumanska.debian.org
Mon May 22 03:43:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to annotated tag libp11-0.4.6
in repository libp11.

commit 1a80f37475dbaffb7903dae20520ed470495e2de
Author: Matt Hauck <matthauck at gmail.com>
Date:   Thu Apr 6 10:34:09 2017 -0700

    Add more information to UI prompt (#152)
    
    This alerts the user for which token/key a PIN is being requsted.
    This addresses some remaining concerns discussed in issue #146.
---
 src/eng_back.c | 16 ++++++++++++----
 src/p11_key.c  | 10 +++++++++-
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/eng_back.c b/src/eng_back.c
index 2db6054..9dc50c4 100644
--- a/src/eng_back.c
+++ b/src/eng_back.c
@@ -93,9 +93,10 @@ static void ctx_destroy_pin(ENGINE_CTX *ctx)
  * passed to the user interface implemented by an application. Only the
  * application knows how to interpret the call-back data.
  * A (strdup'ed) copy of the PIN code will be stored in the pin variable. */
-static int ctx_get_pin(ENGINE_CTX *ctx, UI_METHOD *ui_method, void *callback_data)
+static int ctx_get_pin(ENGINE_CTX *ctx, const char* token_label, UI_METHOD *ui_method, void *callback_data)
 {
 	UI *ui;
+	char* prompt;
 
 	/* call ui to ask for a pin */
 	ui = UI_new_method(ui_method);
@@ -112,12 +113,19 @@ static int ctx_get_pin(ENGINE_CTX *ctx, UI_METHOD *ui_method, void *callback_dat
 		return 0;
 	memset(ctx->pin, 0, MAX_PIN_LENGTH+1);
 	ctx->pin_length = MAX_PIN_LENGTH;
-	if (!UI_add_input_string(ui, "PKCS#11 token PIN: ",
+	prompt = UI_construct_prompt(ui, "PKCS#11 token PIN", token_label);
+	if (!prompt) {
+		return 0;
+	}
+	if (!UI_dup_input_string(ui, prompt,
 			UI_INPUT_FLAG_DEFAULT_PWD, ctx->pin, 4, MAX_PIN_LENGTH)) {
-		fprintf(stderr, "UI_add_input_string failed\n");
+		fprintf(stderr, "UI_dup_input_string failed\n");
 		UI_free(ui);
+		OPENSSL_free(prompt);
 		return 0;
 	}
+	OPENSSL_free(prompt);
+
 	if (UI_process(ui)) {
 		fprintf(stderr, "UI_process failed\n");
 		UI_free(ui);
@@ -166,7 +174,7 @@ static int ctx_login(ENGINE_CTX *ctx, PKCS11_SLOT *slot, PKCS11_TOKEN *tok,
 			return 0;
 		}
 		memset(ctx->pin, 0, MAX_PIN_LENGTH+1);
-		if (!ctx_get_pin(ctx, ui_method, callback_data)) {
+		if (!ctx_get_pin(ctx, tok->label, ui_method, callback_data)) {
 			ctx_destroy_pin(ctx);
 			fprintf(stderr, "No PIN code was entered\n");
 			return 0;
diff --git a/src/p11_key.c b/src/p11_key.c
index 0702f4b..17eee79 100644
--- a/src/p11_key.c
+++ b/src/p11_key.c
@@ -344,6 +344,7 @@ int pkcs11_authenticate(PKCS11_KEY *key)
 	PKCS11_CTX *ctx = SLOT2CTX(slot);
 	PKCS11_CTX_private *cpriv = PRIVCTX(ctx);
 	char pin[MAX_PIN_LENGTH+1];
+	char* prompt;
 	UI *ui;
 	int rv;
 
@@ -361,11 +362,18 @@ int pkcs11_authenticate(PKCS11_KEY *key)
 	if (cpriv->ui_user_data != NULL)
 		UI_add_user_data(ui, cpriv->ui_user_data);
 	memset(pin, 0, MAX_PIN_LENGTH+1);
-	if (!UI_add_input_string(ui, "PKCS#11 key PIN: ",
+	prompt = UI_construct_prompt(ui, "PKCS#11 key PIN", key->label);
+	if (!prompt) {
+		return PKCS11_UI_FAILED;
+	}
+	if (!UI_dup_input_string(ui, prompt,
 			UI_INPUT_FLAG_DEFAULT_PWD, pin, 4, MAX_PIN_LENGTH)) {
 		UI_free(ui);
+		OPENSSL_free(prompt);
 		return PKCS11_UI_FAILED;
 	}
+	OPENSSL_free(prompt);
+
 	if (UI_process(ui)) {
 		UI_free(ui);
 		return PKCS11_UI_FAILED;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git



More information about the pkg-opensc-commit mailing list