static int passwd_cb(char *buf, int size, int rwflag, void *filename) { #if OPENSSL_VERSION_NUMBER >= 0x00907000L UI *ui; const char *prompt; ui = UI_new(); if (ui == NULL) goto err; prompt = UI_construct_prompt(ui, "passphrase", filename); UI_add_input_string(ui, prompt, 0, buf, 0, size - 1); UI_process(ui); UI_free(ui); return strlen(buf); err: LM_ERR("passwd_cb failed\n"); if (ui) UI_free(ui); return 0; #else if( des_read_pw_string(buf, size-1, "Enter Private Key password:"******"passwd_cb failed\n"); return 0; } return strlen( buf ); #endif }
static char *file_get_pass(const UI_METHOD *ui_method, char *pass, size_t maxsize, const char *prompt_info, void *data) { UI *ui = UI_new(); char *prompt = NULL; if (ui == NULL) { OSSL_STOREerr(OSSL_STORE_F_FILE_GET_PASS, ERR_R_MALLOC_FAILURE); return NULL; } if (ui_method != NULL) UI_set_method(ui, ui_method); UI_add_user_data(ui, data); if ((prompt = UI_construct_prompt(ui, "pass phrase", prompt_info)) == NULL) { OSSL_STOREerr(OSSL_STORE_F_FILE_GET_PASS, ERR_R_MALLOC_FAILURE); pass = NULL; } else if (!UI_add_input_string(ui, prompt, UI_INPUT_FLAG_DEFAULT_PWD, pass, 0, maxsize - 1)) { OSSL_STOREerr(OSSL_STORE_F_FILE_GET_PASS, ERR_R_UI_LIB); pass = NULL; } else { switch (UI_process(ui)) { case -2: OSSL_STOREerr(OSSL_STORE_F_FILE_GET_PASS, OSSL_STORE_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED); pass = NULL; break; case -1: OSSL_STOREerr(OSSL_STORE_F_FILE_GET_PASS, ERR_R_UI_LIB); pass = NULL; break; default: break; } } OPENSSL_free(prompt); UI_free(ui); return pass; }
static int passwd_cb(char *buf, int size, int rwflag, void *filename) { UI *ui; const char *prompt; ui = UI_new(); if (ui == NULL) goto err; prompt = UI_construct_prompt(ui, "passphrase", filename); UI_add_input_string(ui, prompt, 0, buf, 0, size - 1); UI_process(ui); UI_free(ui); return strlen(buf); err: LM_ERR("passwd_cb failed\n"); if (ui) UI_free(ui); return 0; }
static int hwcrhk_get_pass(const char *prompt_info, int *len_io, char *buf, HWCryptoHook_PassphraseContext *ppctx, HWCryptoHook_CallerContext *cactx) { pem_password_cb *callback = NULL; void *callback_data = NULL; UI_METHOD *ui_method = NULL; /* Despite what the documentation says prompt_info can be * an empty string. */ if (prompt_info && !*prompt_info) prompt_info = NULL; if (cactx) { if (cactx->ui_method) ui_method = cactx->ui_method; if (cactx->password_callback) callback = cactx->password_callback; if (cactx->callback_data) callback_data = cactx->callback_data; } if (ppctx) { if (ppctx->ui_method) { ui_method = ppctx->ui_method; callback = NULL; } if (ppctx->callback_data) callback_data = ppctx->callback_data; } if (callback == NULL && ui_method == NULL) { HWCRHKerr(HWCRHK_F_HWCRHK_GET_PASS,HWCRHK_R_NO_CALLBACK); return -1; } if (ui_method) { UI *ui = UI_new_method(ui_method); if (ui) { int ok; char *prompt = UI_construct_prompt(ui, "pass phrase", prompt_info); ok = UI_add_input_string(ui,prompt, UI_INPUT_FLAG_DEFAULT_PWD, buf,0,(*len_io) - 1); UI_add_user_data(ui, callback_data); UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0); if (ok >= 0) do { ok=UI_process(ui); } while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0)); if (ok >= 0) *len_io = strlen(buf); UI_free(ui); OPENSSL_free(prompt); } } else { *len_io = callback(buf, *len_io, 0, callback_data); } if(!*len_io) return -1; return 0; }
int password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_tmp) { UI *ui = NULL; int res = 0; const char *prompt_info = NULL; const char *password = NULL; PW_CB_DATA *cb_data = (PW_CB_DATA *)cb_tmp; if (cb_data) { if (cb_data->password) password = (const char*)cb_data->password; if (cb_data->prompt_info) prompt_info = cb_data->prompt_info; } if (password) { res = strlen(password); if (res > bufsiz) res = bufsiz; memcpy(buf, password, res); return res; } ui = UI_new_method(ui_method); if (ui) { int ok = 0; char *buff = NULL; int ui_flags = 0; char *prompt = NULL; prompt = UI_construct_prompt(ui, "pass phrase", prompt_info); ui_flags |= UI_INPUT_FLAG_DEFAULT_PWD; UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0); if (ok >= 0) ok = UI_add_input_string(ui,prompt,ui_flags,buf, PW_MIN_LENGTH,BUFSIZ-1); if (ok >= 0 && verify) { buff = (char *)OPENSSL_malloc(bufsiz); ok = UI_add_verify_string(ui,prompt,ui_flags,buff, PW_MIN_LENGTH,BUFSIZ-1, buf); } if (ok >= 0) do { ok = UI_process(ui); } while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0)); if (buff) { OPENSSL_cleanse(buff,(unsigned int)bufsiz); OPENSSL_free(buff); } if (ok >= 0) res = strlen(buf); if (ok == -1) { BIO_printf(bio_err, "User interface error\n"); ERR_print_errors(bio_err); OPENSSL_cleanse(buf,(unsigned int)bufsiz); res = 0; } if (ok == -2) { BIO_printf(bio_err,"aborted!\n"); OPENSSL_cleanse(buf,(unsigned int)bufsiz); res = 0; } UI_free(ui); OPENSSL_free(prompt); } return res; }