Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL_CTX_use_PrivateKey_file how to give password

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.

like image 552
nintyfan Avatar asked Feb 10 '23 14:02

nintyfan


1 Answers

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.

like image 60
frasertweedale Avatar answered Feb 13 '23 04:02

frasertweedale