| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "SSL_CTX_SET_DEFAULT_PASSWD_CB 3SSL" |
| 58 |
.TH SSL_CTX_SET_DEFAULT_PASSWD_CB 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
SSL_CTX_set_default_passwd_cb, SSL_CTX_set_default_passwd_cb_userdata, |
| 65 |
SSL_CTX_get_default_passwd_cb, SSL_CTX_get_default_passwd_cb_userdata, |
| 66 |
SSL_set_default_passwd_cb, SSL_set_default_passwd_cb_userdata, |
| 67 |
SSL_get_default_passwd_cb, SSL_get_default_passwd_cb_userdata \- set or |
| 68 |
get passwd callback for encrypted PEM file handling |
| 69 |
.SH SYNOPSIS |
| 70 |
.IX Header "SYNOPSIS" |
| 71 |
.Vb 1 |
| 72 |
\& #include <openssl/ssl.h> |
| 73 |
\& |
| 74 |
\& void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); |
| 75 |
\& void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); |
| 76 |
\& pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx); |
| 77 |
\& void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx); |
| 78 |
\& |
| 79 |
\& void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb); |
| 80 |
\& void SSL_set_default_passwd_cb_userdata(SSL *s, void *u); |
| 81 |
\& pem_password_cb *SSL_get_default_passwd_cb(SSL *s); |
| 82 |
\& void *SSL_get_default_passwd_cb_userdata(SSL *s); |
| 83 |
.Ve |
| 84 |
.SH DESCRIPTION |
| 85 |
.IX Header "DESCRIPTION" |
| 86 |
\&\fBSSL_CTX_set_default_passwd_cb()\fR sets the default password callback called |
| 87 |
when loading/storing a PEM certificate with encryption. |
| 88 |
.PP |
| 89 |
\&\fBSSL_CTX_set_default_passwd_cb_userdata()\fR sets a pointer to userdata, \fBu\fR, |
| 90 |
which will be provided to the password callback on invocation. |
| 91 |
.PP |
| 92 |
\&\fBSSL_CTX_get_default_passwd_cb()\fR returns a function pointer to the password |
| 93 |
callback currently set in \fBctx\fR. If no callback was explicitly set, the |
| 94 |
NULL pointer is returned. |
| 95 |
.PP |
| 96 |
\&\fBSSL_CTX_get_default_passwd_cb_userdata()\fR returns a pointer to the userdata |
| 97 |
currently set in \fBctx\fR. If no userdata was explicitly set, the NULL pointer |
| 98 |
is returned. |
| 99 |
.PP |
| 100 |
\&\fBSSL_set_default_passwd_cb()\fR, \fBSSL_set_default_passwd_cb_userdata()\fR, |
| 101 |
\&\fBSSL_get_default_passwd_cb()\fR and \fBSSL_get_default_passwd_cb_userdata()\fR perform |
| 102 |
the same function as their SSL_CTX counterparts, but using an SSL object. |
| 103 |
.PP |
| 104 |
The password callback, which must be provided by the application, hands back the |
| 105 |
password to be used during decryption. |
| 106 |
On invocation a pointer to userdata |
| 107 |
is provided. The function must store the password into the provided buffer |
| 108 |
\&\fBbuf\fR which is of size \fBsize\fR. The actual length of the password must |
| 109 |
be returned to the calling function. \fBrwflag\fR indicates whether the |
| 110 |
callback is used for reading/decryption (rwflag=0) or writing/encryption |
| 111 |
(rwflag=1). |
| 112 |
For more details, see \fBpem_password_cb\fR\|(3). |
| 113 |
.SH NOTES |
| 114 |
.IX Header "NOTES" |
| 115 |
When loading or storing private keys, a password might be supplied to |
| 116 |
protect the private key. The way this password can be supplied may depend |
| 117 |
on the application. If only one private key is handled, it can be practical |
| 118 |
to have the callback handle the password dialog interactively. If several |
| 119 |
keys have to be handled, it can be practical to ask for the password once, |
| 120 |
then keep it in memory and use it several times. In the last case, the |
| 121 |
password could be stored into the userdata storage and the |
| 122 |
callback only returns the password already stored. |
| 123 |
.PP |
| 124 |
When asking for the password interactively, the callback can use |
| 125 |
\&\fBrwflag\fR to check, whether an item shall be encrypted (rwflag=1). |
| 126 |
In this case the password dialog may ask for the same password twice |
| 127 |
for comparison in order to catch typos, that would make decryption |
| 128 |
impossible. |
| 129 |
.PP |
| 130 |
Other items in PEM formatting (certificates) can also be encrypted, it is |
| 131 |
however not usual, as certificate information is considered public. |
| 132 |
.SH "RETURN VALUES" |
| 133 |
.IX Header "RETURN VALUES" |
| 134 |
These functions do not provide diagnostic information. |
| 135 |
.SH EXAMPLES |
| 136 |
.IX Header "EXAMPLES" |
| 137 |
The following example returns the password provided as userdata to the |
| 138 |
calling function. The password is considered to be a '\e0' terminated |
| 139 |
string. If the password does not fit into the buffer, the password is |
| 140 |
truncated. |
| 141 |
.PP |
| 142 |
.Vb 6 |
| 143 |
\& int my_cb(char *buf, int size, int rwflag, void *u) |
| 144 |
\& { |
| 145 |
\& strncpy(buf, (char *)u, size); |
| 146 |
\& buf[size \- 1] = \*(Aq\e0\*(Aq; |
| 147 |
\& return strlen(buf); |
| 148 |
\& } |
| 149 |
.Ve |
| 150 |
.SH "SEE ALSO" |
| 151 |
.IX Header "SEE ALSO" |
| 152 |
\&\fBssl\fR\|(7), |
| 153 |
\&\fBSSL_CTX_use_certificate\fR\|(3) |
| 154 |
.SH HISTORY |
| 155 |
.IX Header "HISTORY" |
| 156 |
\&\fBSSL_CTX_get_default_passwd_cb()\fR, \fBSSL_CTX_get_default_passwd_cb_userdata()\fR, |
| 157 |
\&\fBSSL_set_default_passwd_cb()\fR and \fBSSL_set_default_passwd_cb_userdata()\fR were |
| 158 |
added in OpenSSL 1.1.0. |
| 159 |
.SH COPYRIGHT |
| 160 |
.IX Header "COPYRIGHT" |
| 161 |
Copyright 2000\-2019 The OpenSSL Project Authors. All Rights Reserved. |
| 162 |
.PP |
| 163 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 164 |
this file except in compliance with the License. You can obtain a copy |
| 165 |
in the file LICENSE in the source distribution or at |
| 166 |
<https://www.openssl.org/source/license.html>. |