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>
14 #include "../apps/apps.h"
17 #include "test_main_custom.h"
19 /* apps/apps.c depend on these */
20 char *default_config_file = NULL;
24 # include <openssl/ui.h>
26 /* Old style PEM password callback */
27 static int test_pem_password_cb(char *buf, int size, int rwflag, void *userdata)
29 OPENSSL_strlcpy(buf, (char *)userdata, (size_t)size);
34 * Test wrapping old style PEM password callback in a UI method through the
35 * use of UI utility functions
39 UI_METHOD *ui_method = NULL;
41 char defpass[] = "password";
46 UI_UTIL_wrap_read_pem_callback(test_pem_password_cb, 0)) == NULL
47 || (ui = UI_new_method(ui_method)) == NULL)
50 /* The wrapper passes the UI userdata as the callback userdata param */
51 UI_add_user_data(ui, defpass);
53 if (!UI_add_input_string(ui, "prompt", UI_INPUT_FLAG_DEFAULT_PWD,
54 pass, 0, sizeof(pass) - 1))
57 switch (UI_process(ui)) {
59 BIO_printf(bio_err, "test_old: UI process interrupted or cancelled\n");
67 if (strcmp(pass, defpass) == 0)
70 BIO_printf(bio_err, "test_old: password failure\n");
74 ERR_print_errors_fp(stderr);
76 UI_destroy_method(ui_method);
81 /* Test of UI. This uses the UI method defined in apps/apps.c */
82 static int test_new_ui()
84 PW_CB_DATA cb_data = {
92 if (password_callback(pass, sizeof(pass), 0, &cb_data) > 0
93 && strcmp(pass, cb_data.password) == 0)
96 BIO_printf(bio_err, "test_new: password failure\n");
99 ERR_print_errors_fp(stderr);
107 int test_main(int argc, char *argv[])
111 bio_err = dup_bio_err(FORMAT_TEXT);
113 #ifndef OPENSSL_NO_UI
115 ADD_TEST(test_new_ui);
118 ret = run_tests(argv[0]);
120 (void)BIO_flush(bio_err);