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 * We know that on VMS, the [.apps] object files are compiled with uppercased
17 * symbols. We must therefore follow suit, or there will be linking errors.
18 * Additionally, the VMS build does stdio via a socketpair.
22 # pragma names uppercase, truncated
24 # include "../apps/vms_term_sock.h"
27 #include "../apps/apps.h"
30 # pragma names restore
34 #include "test_main_custom.h"
36 /* apps/apps.c depend on these */
37 char *default_config_file
= NULL
;
41 # include <openssl/ui.h>
43 /* Old style PEM password callback */
44 static int test_pem_password_cb(char *buf
, int size
, int rwflag
, void *userdata
)
46 OPENSSL_strlcpy(buf
, (char *)userdata
, (size_t)size
);
51 * Test wrapping old style PEM password callback in a UI method through the
52 * use of UI utility functions
56 UI_METHOD
*ui_method
= NULL
;
58 char defpass
[] = "password";
63 UI_UTIL_wrap_read_pem_callback(test_pem_password_cb
, 0)) == NULL
64 || (ui
= UI_new_method(ui_method
)) == NULL
)
67 /* The wrapper passes the UI userdata as the callback userdata param */
68 UI_add_user_data(ui
, defpass
);
70 if (!UI_add_input_string(ui
, "prompt", UI_INPUT_FLAG_DEFAULT_PWD
,
71 pass
, 0, sizeof(pass
) - 1))
74 switch (UI_process(ui
)) {
76 BIO_printf(bio_err
, "test_old: UI process interrupted or cancelled\n");
84 if (strcmp(pass
, defpass
) == 0)
87 BIO_printf(bio_err
, "test_old: password failure\n");
91 ERR_print_errors_fp(stderr
);
93 UI_destroy_method(ui_method
);
98 /* Test of UI. This uses the UI method defined in apps/apps.c */
99 static int test_new_ui()
101 PW_CB_DATA cb_data
= {
109 if (password_callback(pass
, sizeof(pass
), 0, &cb_data
) > 0
110 && strcmp(pass
, cb_data
.password
) == 0)
113 BIO_printf(bio_err
, "test_new: password failure\n");
116 ERR_print_errors_fp(stderr
);
124 int test_main(int argc
, char *argv
[])
128 bio_err
= dup_bio_err(FORMAT_TEXT
);
130 #ifndef OPENSSL_NO_UI
132 ADD_TEST(test_new_ui
);
135 ret
= run_tests(argv
[0]);
137 (void)BIO_flush(bio_err
);