|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2002-2017 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <stdio.h>
|
|
Packit Service |
084de1 |
#include <string.h>
|
|
Packit Service |
084de1 |
#include <openssl/opensslconf.h>
|
|
Packit Service |
084de1 |
#include <openssl/err.h>
|
|
Packit Service |
084de1 |
#include "apps.h"
|
|
Packit Service |
084de1 |
#include "testutil.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* apps/apps.c depend on these */
|
|
Packit Service |
084de1 |
char *default_config_file = NULL;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <openssl/ui.h>
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Old style PEM password callback */
|
|
Packit Service |
084de1 |
static int test_pem_password_cb(char *buf, int size, int rwflag, void *userdata)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
OPENSSL_strlcpy(buf, (char *)userdata, (size_t)size);
|
|
Packit Service |
084de1 |
return strlen(buf);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Test wrapping old style PEM password callback in a UI method through the
|
|
Packit Service |
084de1 |
* use of UI utility functions
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
static int test_old(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
UI_METHOD *ui_method = NULL;
|
|
Packit Service |
084de1 |
UI *ui = NULL;
|
|
Packit Service |
084de1 |
char defpass[] = "password";
|
|
Packit Service |
084de1 |
char pass[16];
|
|
Packit Service |
084de1 |
int ok = 0;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (!TEST_ptr(ui_method =
|
|
Packit Service |
084de1 |
UI_UTIL_wrap_read_pem_callback( test_pem_password_cb, 0))
|
|
Packit Service |
084de1 |
|| !TEST_ptr(ui = UI_new_method(ui_method)))
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* The wrapper passes the UI userdata as the callback userdata param */
|
|
Packit Service |
084de1 |
UI_add_user_data(ui, defpass);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (!UI_add_input_string(ui, "prompt", UI_INPUT_FLAG_DEFAULT_PWD,
|
|
Packit Service |
084de1 |
pass, 0, sizeof(pass) - 1))
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
switch (UI_process(ui)) {
|
|
Packit Service |
084de1 |
case -2:
|
|
Packit Service |
084de1 |
TEST_info("test_old: UI process interrupted or cancelled");
|
|
Packit Service |
084de1 |
/* fall through */
|
|
Packit Service |
084de1 |
case -1:
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
default:
|
|
Packit Service |
084de1 |
break;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (TEST_str_eq(pass, defpass))
|
|
Packit Service |
084de1 |
ok = 1;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
err:
|
|
Packit Service |
084de1 |
UI_free(ui);
|
|
Packit Service |
084de1 |
UI_destroy_method(ui_method);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return ok;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Test of UI. This uses the UI method defined in apps/apps.c */
|
|
Packit Service |
084de1 |
static int test_new_ui(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
PW_CB_DATA cb_data = {
|
|
Packit Service |
084de1 |
"password",
|
|
Packit Service |
084de1 |
"prompt"
|
|
Packit Service |
084de1 |
};
|
|
Packit Service |
084de1 |
char pass[16];
|
|
Packit Service |
084de1 |
int ok = 0;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
setup_ui_method();
|
|
Packit Service |
084de1 |
if (TEST_int_gt(password_callback(pass, sizeof(pass), 0, &cb_data), 0)
|
|
Packit Service |
084de1 |
&& TEST_str_eq(pass, cb_data.password))
|
|
Packit Service |
084de1 |
ok = 1;
|
|
Packit Service |
084de1 |
destroy_ui_method();
|
|
Packit Service |
084de1 |
return ok;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int setup_tests(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ADD_TEST(test_old);
|
|
Packit Service |
084de1 |
ADD_TEST(test_new_ui);
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|