5

SSL_CTX_use_PrivateKey_file function or SSL_CTX_check_private_key function asks for password in terminal for my private key. I would like to pass this password in some OpenSSL function, so one of these functions don't asks about it in terminal. My application will get password from command line or from dialog window.

1 Answer 1

10

The function you are looking for is:

void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);

The callback function argument pem_password_cb has the signature:

int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);

buf is the destination buffer for the passphrase. size gives the size of the buffer. rwflag indicates whether the passphrase is for a decryption (read) or encryption (write) operation.

*userdata is arbitrary data the application can specify to be passed to the callback. You can set the userdata via the function:

void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);

See the SSL_CTX_set_default_passwd_cb(3) man page for more information.

2
  • 2
    Sorry, but I don't have enough reputation to vote up your post. Your solution was good, but I don't have manual pages for this function.
    – nintyfan
    Commented Mar 27, 2015 at 10:21
  • 1
    @nintyfan no worries; I updated my answer with a link to the official web version of the man page. Feel free to come back and upvote the answer when you have enough rep :) Commented Mar 27, 2015 at 12:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.