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>
16 * The VMS build does stdio via a socketpair.
19 # include "../apps/vms_term_sock.h"
22 #include "../apps/apps.h"
25 #include "test_main_custom.h"
27 /* apps/apps.c depend on these */
28 char *default_config_file = NULL;
32 # include <openssl/ui.h>
34 /* Old style PEM password callback */
35 static int test_pem_password_cb(char *buf, int size, int rwflag, void *userdata)
37 OPENSSL_strlcpy(buf, (char *)userdata, (size_t)size);
42 * Test wrapping old style PEM password callback in a UI method through the
43 * use of UI utility functions
47 UI_METHOD *ui_method = NULL;
49 char defpass[] = "password";
53 if (!TEST_ptr(ui_method =
54 UI_UTIL_wrap_read_pem_callback( test_pem_password_cb, 0))
55 || !TEST_ptr(ui = UI_new_method(ui_method)))
58 /* The wrapper passes the UI userdata as the callback userdata param */
59 UI_add_user_data(ui, defpass);
61 if (!UI_add_input_string(ui, "prompt", UI_INPUT_FLAG_DEFAULT_PWD,
62 pass, 0, sizeof(pass) - 1))
65 switch (UI_process(ui)) {
67 TEST_info("test_old: UI process interrupted or cancelled");
75 if (TEST_str_eq(pass, defpass))
80 UI_destroy_method(ui_method);
85 /* Test of UI. This uses the UI method defined in apps/apps.c */
86 static int test_new_ui()
88 PW_CB_DATA cb_data = {
96 if (TEST_int_gt(password_callback(pass, sizeof(pass), 0, &cb_data), 0)
97 && TEST_str_eq(pass, cb_data.password))
105 int test_main(int argc, char *argv[])
109 bio_err = dup_bio_err(FORMAT_TEXT);
111 #ifndef OPENSSL_NO_UI
113 ADD_TEST(test_new_ui);
116 ret = run_tests(argv[0]);
118 (void)BIO_flush(bio_err);