Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
mtrojnar committed Jan 27, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3c7b2cc commit 3b80c73
Showing 1 changed file with 0 additions and 104 deletions.
104 changes: 0 additions & 104 deletions src/eng_back.c
Original file line number Diff line number Diff line change
@@ -88,110 +88,6 @@ static void ctx_destroy_pin(ENGINE_CTX *ctx)
}
}

/* Get the PIN via asking user interface. The supplied call-back data are
* 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, 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);
if (!ui) {
ctx_log(ctx, LOG_ERR, "UI_new failed\n");
return 0;
}
if (callback_data)
UI_add_user_data(ui, callback_data);

ctx_destroy_pin(ctx);
ctx->pin = OPENSSL_malloc(MAX_PIN_LENGTH+1);
if (!ctx->pin)
return 0;
memset(ctx->pin, 0, MAX_PIN_LENGTH+1);
ctx->pin_length = MAX_PIN_LENGTH;
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) <= 0) {
ctx_log(ctx, LOG_ERR, "UI_dup_input_string failed\n");
UI_free(ui);
OPENSSL_free(prompt);
return 0;
}
OPENSSL_free(prompt);

if (UI_process(ui)) {
ctx_log(ctx, LOG_ERR, "UI_process failed\n");
UI_free(ui);
return 0;
}
UI_free(ui);
return 1;
}

/* Return 1 if the user has already logged in */
static int slot_logged_in(ENGINE_CTX *ctx, PKCS11_SLOT *slot) {
int logged_in = 0;

/* Check if already logged in to avoid resetting state */
if (PKCS11_is_logged_in(slot, 0, &logged_in) != 0) {
ctx_log(ctx, LOG_WARNING, "Unable to check if already logged in\n");
return 0;
}
return logged_in;
}

/*
* Log-into the token if necessary.
*
* @slot is PKCS11 slot to log in
* @tok is PKCS11 token to log in (??? could be derived as @slot->token)
* @ui_method is OpenSSL user interface which is used to ask for a password
* @callback_data are application data to the user interface
* @return 1 on success, 0 on error.
*/
static int ctx_login(ENGINE_CTX *ctx, PKCS11_SLOT *slot, PKCS11_TOKEN *tok,
UI_METHOD *ui_method, void *callback_data)
{
if (!(ctx->force_login || tok->loginRequired) || slot_logged_in(ctx, slot))
return 1;

/* If the token has a secure login (i.e., an external keypad),
* then use a NULL PIN. Otherwise, obtain a new PIN if needed. */
if (tok->secureLogin && !ctx->forced_pin) {
/* Free the PIN if it has already been
* assigned (i.e, cached by ctx_get_pin) */
ctx_destroy_pin(ctx);
} else if (!ctx->pin) {
ctx->pin = OPENSSL_malloc(MAX_PIN_LENGTH+1);
ctx->pin_length = MAX_PIN_LENGTH;
if (ctx->pin == NULL) {
ctx_log(ctx, LOG_ERR, "Could not allocate memory for PIN\n");
return 0;
}
memset(ctx->pin, 0, MAX_PIN_LENGTH+1);
if (!ctx_get_pin(ctx, tok->label, ui_method, callback_data)) {
ctx_destroy_pin(ctx);
ctx_log(ctx, LOG_ERR, "No PIN code was entered\n");
return 0;
}
}

/* Now login in with the (possibly NULL) PIN */
if (PKCS11_login(slot, 0, ctx->pin)) {
/* Login failed, so free the PIN if present */
ctx_destroy_pin(ctx);
ctx_log(ctx, LOG_ERR, "Login failed\n");
return 0;
}
return 1;
}

/******************************************************************************/
/* Initialization and cleanup */
/******************************************************************************/

0 comments on commit 3b80c73

Please sign in to comment.