1SSL_CTX_SET_DEFAULT_PASSWD_CB(3)    OpenSSL   SSL_CTX_SET_DEFAULT_PASSWD_CB(3)
2
3
4

NAME

6       SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata,
7       SSL_CTX_get_default_passwd_cb, SSL_CTX_get_default_passwd_cb_userdata,
8       SSL_set_default_passwd_cb, SSL_set_default_passwd_cb_userdata,
9       SSL_get_default_passwd_cb, SSL_get_default_passwd_cb_userdata - set or
10       get passwd callback for encrypted PEM file handling
11

SYNOPSIS

13        #include <openssl/ssl.h>
14
15        void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
16        void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
17        pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
18        void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
19
20        void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
21        void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
22        pem_password_cb *SSL_get_default_passwd_cb(SSL *s);
23        void *SSL_get_default_passwd_cb_userdata(SSL *s);
24

DESCRIPTION

26       SSL_CTX_set_default_passwd_cb() sets the default password callback
27       called when loading/storing a PEM certificate with encryption.
28
29       SSL_CTX_set_default_passwd_cb_userdata() sets a pointer to userdata, u,
30       which will be provided to the password callback on invocation.
31
32       SSL_CTX_get_default_passwd_cb() returns a function pointer to the
33       password callback currently set in ctx. If no callback was explicitly
34       set, the NULL pointer is returned.
35
36       SSL_CTX_get_default_passwd_cb_userdata() returns a pointer to the
37       userdata currently set in ctx. If no userdata was explicitly set, the
38       NULL pointer is returned.
39
40       SSL_set_default_passwd_cb(), SSL_set_default_passwd_cb_userdata(),
41       SSL_get_default_passwd_cb() and SSL_get_default_passwd_cb_userdata()
42       perform the same function as their SSL_CTX counterparts, but using an
43       SSL object.
44
45       The password callback, which must be provided by the application, hands
46       back the password to be used during decryption.  On invocation a
47       pointer to userdata is provided. The function must store the password
48       into the provided buffer buf which is of size size. The actual length
49       of the password must be returned to the calling function. rwflag
50       indicates whether the callback is used for reading/decryption
51       (rwflag=0) or writing/encryption (rwflag=1).  For more details, see
52       pem_password_cb(3).
53

NOTES

55       When loading or storing private keys, a password might be supplied to
56       protect the private key. The way this password can be supplied may
57       depend on the application. If only one private key is handled, it can
58       be practical to have the callback handle the password dialog
59       interactively. If several keys have to be handled, it can be practical
60       to ask for the password once, then keep it in memory and use it several
61       times. In the last case, the password could be stored into the userdata
62       storage and the callback only returns the password already stored.
63
64       When asking for the password interactively, the callback can use rwflag
65       to check, whether an item shall be encrypted (rwflag=1).  In this case
66       the password dialog may ask for the same password twice for comparison
67       in order to catch typos, that would make decryption impossible.
68
69       Other items in PEM formatting (certificates) can also be encrypted, it
70       is however not usual, as certificate information is considered public.
71

RETURN VALUES

73       These functions do not provide diagnostic information.
74

EXAMPLES

76       The following example returns the password provided as userdata to the
77       calling function. The password is considered to be a '\0' terminated
78       string. If the password does not fit into the buffer, the password is
79       truncated.
80
81        int my_cb(char *buf, int size, int rwflag, void *u)
82        {
83            strncpy(buf, (char *)u, size);
84            buf[size - 1] = '\0';
85            return strlen(buf);
86        }
87

SEE ALSO

89       ssl(7), SSL_CTX_use_certificate(3)
90

HISTORY

92       SSL_CTX_get_default_passwd_cb(),
93       SSL_CTX_get_default_passwd_cb_userdata(), SSL_set_default_passwd_cb()
94       and SSL_set_default_passwd_cb_userdata() were added in OpenSSL 1.1.0.
95
97       Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
98
99       Licensed under the OpenSSL license (the "License").  You may not use
100       this file except in compliance with the License.  You can obtain a copy
101       in the file LICENSE in the source distribution or at
102       <https://www.openssl.org/source/license.html>.
103
104
105
1061.1.1i                            2021-07-22  SSL_CTX_SET_DEFAULT_PASSWD_CB(3)
Impressum