Example #1
0
UI *UI_new(void)
{
    return (UI_new_method(NULL));
}
Example #2
0
static int hwcrhk_get_pass(const char *prompt_info,
                           int *len_io, char *buf,
                           HWCryptoHook_PassphraseContext * ppctx,
                           HWCryptoHook_CallerContext * cactx)
{
    pem_password_cb *callback = NULL;
    void *callback_data = NULL;
    UI_METHOD *ui_method = NULL;
    /*
     * Despite what the documentation says prompt_info can be an empty
     * string.
     */
    if (prompt_info && !*prompt_info)
        prompt_info = NULL;

    if (cactx) {
        if (cactx->ui_method)
            ui_method = cactx->ui_method;
        if (cactx->password_callback)
            callback = cactx->password_callback;
        if (cactx->callback_data)
            callback_data = cactx->callback_data;
    }
    if (ppctx) {
        if (ppctx->ui_method) {
            ui_method = ppctx->ui_method;
            callback = NULL;
        }
        if (ppctx->callback_data)
            callback_data = ppctx->callback_data;
    }
    if (callback == NULL && ui_method == NULL) {
        HWCRHKerr(HWCRHK_F_HWCRHK_GET_PASS, HWCRHK_R_NO_CALLBACK);
        return -1;
    }

    if (ui_method) {
        UI *ui = UI_new_method(ui_method);
        if (ui) {
            int ok;
            char *prompt = UI_construct_prompt(ui,
                                               "pass phrase", prompt_info);

            ok = UI_add_input_string(ui, prompt,
                                     UI_INPUT_FLAG_DEFAULT_PWD,
                                     buf, 0, (*len_io) - 1);
            UI_add_user_data(ui, callback_data);
            UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0);

            if (ok >= 0)
                do {
                    ok = UI_process(ui);
                }
                while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0));

            if (ok >= 0)
                *len_io = strlen(buf);

            UI_free(ui);
            OPENSSL_free(prompt);
        }
    } else {
        *len_io = callback(buf, *len_io, 0, callback_data);
    }
    if (!*len_io)
        return -1;
    return 0;
}
Example #3
0
static int hwcrhk_insert_card(const char *prompt_info,
                              const char *wrong_info,
                              HWCryptoHook_PassphraseContext * ppctx,
                              HWCryptoHook_CallerContext * cactx)
{
    int ok = -1;
    UI *ui;
    void *callback_data = NULL;
    UI_METHOD *ui_method = NULL;

    if (cactx) {
        if (cactx->ui_method)
            ui_method = cactx->ui_method;
        if (cactx->callback_data)
            callback_data = cactx->callback_data;
    }
    if (ppctx) {
        if (ppctx->ui_method)
            ui_method = ppctx->ui_method;
        if (ppctx->callback_data)
            callback_data = ppctx->callback_data;
    }
    if (ui_method == NULL) {
        HWCRHKerr(HWCRHK_F_HWCRHK_INSERT_CARD, HWCRHK_R_NO_CALLBACK);
        return -1;
    }

    ui = UI_new_method(ui_method);

    if (ui) {
        char answer;
        char buf[BUFSIZ];
        /*
         * Despite what the documentation says wrong_info can be an empty
         * string.
         */
        if (wrong_info && *wrong_info)
            BIO_snprintf(buf, sizeof(buf) - 1,
                         "Current card: \"%s\"\n", wrong_info);
        else
            buf[0] = 0;
        ok = UI_dup_info_string(ui, buf);
        if (ok >= 0 && prompt_info) {
            BIO_snprintf(buf, sizeof(buf) - 1,
                         "Insert card \"%s\"", prompt_info);
            ok = UI_dup_input_boolean(ui, buf,
                                      "\n then hit <enter> or C<enter> to cancel\n",
                                      "\r\n", "Cc", UI_INPUT_FLAG_ECHO,
                                      &answer);
        }
        UI_add_user_data(ui, callback_data);

        if (ok >= 0)
            ok = UI_process(ui);
        UI_free(ui);

        if (ok == -2 || (ok >= 0 && answer == 'C'))
            ok = 1;
        else if (ok < 0)
            ok = -1;
        else
            ok = 0;
    }
    return ok;
}