1SSL_CTX_set_default_passwd_cb(3) OpenSSL SSL_CTX_set_default_passwd_cb(3)
2
3
4
6 SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata -
7 set passwd callback for encrypted PEM file handling
8
10 #include <openssl/ssl.h>
11
12 void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
13 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
14
15 int pem_passwd_cb(char *buf, int size, int rwflag, void *userdata);
16
18 SSL_CTX_set_default_passwd_cb() sets the default password callback
19 called when loading/storing a PEM certificate with encryption.
20
21 SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to userdata
22 which will be provided to the password callback on invocation.
23
24 The pem_passwd_cb(), which must be provided by the application, hands
25 back the password to be used during decryption. On invocation a pointer
26 to userdata is provided. The pem_passwd_cb must write the password into
27 the provided buffer buf which is of size size. The actual length of the
28 password must be returned to the calling function. rwflag indicates
29 whether the callback is used for reading/decryption (rwflag=0) or
30 writing/encryption (rwflag=1).
31
33 When loading or storing private keys, a password might be supplied to
34 protect the private key. The way this password can be supplied may
35 depend on the application. If only one private key is handled, it can
36 be practical to have pem_passwd_cb() handle the password dialog
37 interactively. If several keys have to be handled, it can be practical
38 to ask for the password once, then keep it in memory and use it several
39 times. In the last case, the password could be stored into the userdata
40 storage and the pem_passwd_cb() only returns the password already
41 stored.
42
43 When asking for the password interactively, pem_passwd_cb() can use
44 rwflag to check, whether an item shall be encrypted (rwflag=1). In
45 this case the password dialog may ask for the same password twice for
46 comparison in order to catch typos, that would make decryption
47 impossible.
48
49 Other items in PEM formatting (certificates) can also be encrypted, it
50 is however not usual, as certificate information is considered public.
51
53 SSL_CTX_set_default_passwd_cb() and
54 SSL_CTX_set_default_passwd_cb_userdata() do not provide diagnostic
55 information.
56
58 The following example returns the password provided as userdata to the
59 calling function. The password is considered to be a '\0' terminated
60 string. If the password does not fit into the buffer, the password is
61 truncated.
62
63 int pem_passwd_cb(char *buf, int size, int rwflag, void *password)
64 {
65 strncpy(buf, (char *)(password), size);
66 buf[size - 1] = '\0';
67 return(strlen(buf));
68 }
69
71 ssl(3), SSL_CTX_use_certificate(3)
72
73
74
751.0.2o 2018-03-27 SSL_CTX_set_default_passwd_cb(3)