예제 #1
0
파일: uitest.c 프로젝트: Castaglia/openssl
/*
 * Test wrapping old style PEM password callback in a UI method through the
 * use of UI utility functions
 */
static int test_old()
{
    UI_METHOD *ui_method = NULL;
    UI *ui = NULL;
    char defpass[] = "password";
    char pass[16];
    int ok = 0;

    if ((ui_method =
         UI_UTIL_wrap_read_pem_callback(test_pem_password_cb, 0)) == NULL
        || (ui = UI_new_method(ui_method)) == NULL)
        goto err;

    /* The wrapper passes the UI userdata as the callback userdata param */
    UI_add_user_data(ui, defpass);

    if (!UI_add_input_string(ui, "prompt", UI_INPUT_FLAG_DEFAULT_PWD,
                             pass, 0, sizeof(pass) - 1))
        goto err;

    switch (UI_process(ui)) {
    case -2:
        BIO_printf(bio_err, "test_old: UI process interrupted or cancelled\n");
        /* fall through */
    case -1:
        goto err;
    default:
        break;
    }

    if (strcmp(pass, defpass) == 0)
        ok = 1;
    else
        BIO_printf(bio_err, "test_old: password failure\n");

 err:
    if (!ok)
        ERR_print_errors_fp(stderr);
    UI_free(ui);
    UI_destroy_method(ui_method);

    return ok;
}
예제 #2
0
파일: uitest.c 프로젝트: Ana06/openssl
/*
 * Test wrapping old style PEM password callback in a UI method through the
 * use of UI utility functions
 */
static int test_old(void)
{
    UI_METHOD *ui_method = NULL;
    UI *ui = NULL;
    char defpass[] = "password";
    char pass[16];
    int ok = 0;

    if (!TEST_ptr(ui_method =
                  UI_UTIL_wrap_read_pem_callback( test_pem_password_cb, 0))
            || !TEST_ptr(ui = UI_new_method(ui_method)))
        goto err;

    /* The wrapper passes the UI userdata as the callback userdata param */
    UI_add_user_data(ui, defpass);

    if (!UI_add_input_string(ui, "prompt", UI_INPUT_FLAG_DEFAULT_PWD,
                             pass, 0, sizeof(pass) - 1))
        goto err;

    switch (UI_process(ui)) {
    case -2:
        TEST_info("test_old: UI process interrupted or cancelled");
        /* fall through */
    case -1:
        goto err;
    default:
        break;
    }

    if (TEST_str_eq(pass, defpass))
        ok = 1;

 err:
    UI_free(ui);
    UI_destroy_method(ui_method);

    return ok;
}