2 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include <openssl/opensslconf.h>
13 #include <openssl/err.h>
17 /* apps/apps.c depend on these */
18 char *default_config_file = NULL;
21 # include <openssl/ui.h>
23 /* Old style PEM password callback */
24 static int test_pem_password_cb(char *buf, int size, int rwflag, void *userdata)
26 OPENSSL_strlcpy(buf, (char *)userdata, (size_t)size);
31 * Test wrapping old style PEM password callback in a UI method through the
32 * use of UI utility functions
36 UI_METHOD *ui_method = NULL;
38 char defpass[] = "password";
42 if (!TEST_ptr(ui_method =
43 UI_UTIL_wrap_read_pem_callback( test_pem_password_cb, 0))
44 || !TEST_ptr(ui = UI_new_method(ui_method)))
47 /* The wrapper passes the UI userdata as the callback userdata param */
48 UI_add_user_data(ui, defpass);
50 if (!UI_add_input_string(ui, "prompt", UI_INPUT_FLAG_DEFAULT_PWD,
51 pass, 0, sizeof(pass) - 1))
54 switch (UI_process(ui)) {
56 TEST_info("test_old: UI process interrupted or cancelled");
64 if (TEST_str_eq(pass, defpass))
69 UI_destroy_method(ui_method);
74 /* Test of UI. This uses the UI method defined in apps/apps.c */
75 static int test_new_ui()
77 PW_CB_DATA cb_data = {
85 if (TEST_int_gt(password_callback(pass, sizeof(pass), 0, &cb_data), 0)
86 && TEST_str_eq(pass, cb_data.password))
94 void register_tests(void)
98 ADD_TEST(test_new_ui);