| 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_CLIENT_CERT_CB 3SSL" |
| 58 |
.TH SSL_CTX_SET_CLIENT_CERT_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_client_cert_cb, SSL_CTX_get_client_cert_cb \- handle client certificate callback function |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& #include <openssl/ssl.h> |
| 69 |
\& |
| 70 |
\& void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, |
| 71 |
\& int (*client_cert_cb)(SSL *ssl, X509 **x509, |
| 72 |
\& EVP_PKEY **pkey)); |
| 73 |
\& int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, |
| 74 |
\& EVP_PKEY **pkey); |
| 75 |
.Ve |
| 76 |
.SH DESCRIPTION |
| 77 |
.IX Header "DESCRIPTION" |
| 78 |
\&\fBSSL_CTX_set_client_cert_cb()\fR sets the \fIclient_cert_cb\fR callback, that is |
| 79 |
called when a client certificate is requested by a server and no certificate |
| 80 |
was yet set for the SSL object. |
| 81 |
.PP |
| 82 |
When \fIclient_cert_cb\fR is NULL, no callback function is used. |
| 83 |
.PP |
| 84 |
\&\fBSSL_CTX_get_client_cert_cb()\fR returns a pointer to the currently set callback |
| 85 |
function. |
| 86 |
.PP |
| 87 |
\&\fIclient_cert_cb\fR is the application defined callback. If it wants to |
| 88 |
set a certificate, a certificate/private key combination must be set |
| 89 |
using the \fIx509\fR and \fIpkey\fR arguments and "1" must be returned. The |
| 90 |
certificate will be installed into \fIssl\fR, see the NOTES and BUGS sections. |
| 91 |
If no certificate should be set, "0" has to be returned and no certificate |
| 92 |
will be sent. A negative return value will suspend the handshake and the |
| 93 |
handshake function will return immediately. \fBSSL_get_error\fR\|(3) |
| 94 |
will return SSL_ERROR_WANT_X509_LOOKUP to indicate, that the handshake was |
| 95 |
suspended. The next call to the handshake function will again lead to the call |
| 96 |
of \fIclient_cert_cb\fR. It is the job of the \fIclient_cert_cb\fR to store information |
| 97 |
about the state of the last call, if required to continue. |
| 98 |
.SH NOTES |
| 99 |
.IX Header "NOTES" |
| 100 |
During a handshake (or renegotiation) a server may request a certificate |
| 101 |
from the client. A client certificate must only be sent, when the server |
| 102 |
did send the request. |
| 103 |
.PP |
| 104 |
When a certificate was set using the |
| 105 |
\&\fBSSL_CTX_use_certificate\fR\|(3) family of functions, |
| 106 |
it will be sent to the server. The TLS standard requires that only a |
| 107 |
certificate is sent, if it matches the list of acceptable CAs sent by the |
| 108 |
server. This constraint is violated by the default behavior of the OpenSSL |
| 109 |
library. Using the callback function it is possible to implement a proper |
| 110 |
selection routine or to allow a user interaction to choose the certificate to |
| 111 |
be sent. |
| 112 |
.PP |
| 113 |
If a callback function is defined and no certificate was yet defined for the |
| 114 |
SSL object, the callback function will be called. |
| 115 |
If the callback function returns a certificate, the OpenSSL library |
| 116 |
will try to load the private key and certificate data into the SSL |
| 117 |
object using the \fBSSL_use_certificate()\fR and \fBSSL_use_private_key()\fR functions. |
| 118 |
Thus it will permanently install the certificate and key for this SSL |
| 119 |
object. It will not be reset by calling \fBSSL_clear\fR\|(3). |
| 120 |
If the callback returns no certificate, the OpenSSL library will not send |
| 121 |
a certificate. |
| 122 |
.SH "RETURN VALUES" |
| 123 |
.IX Header "RETURN VALUES" |
| 124 |
\&\fBSSL_CTX_get_client_cert_cb()\fR returns function pointer of \fIclient_cert_cb\fR or |
| 125 |
NULL if the callback is not set. |
| 126 |
.SH BUGS |
| 127 |
.IX Header "BUGS" |
| 128 |
The \fIclient_cert_cb\fR cannot return a complete certificate chain, it can |
| 129 |
only return one client certificate. If the chain only has a length of 2, |
| 130 |
the root CA certificate may be omitted according to the TLS standard and |
| 131 |
thus a standard conforming answer can be sent to the server. For a |
| 132 |
longer chain, the client must send the complete chain (with the option |
| 133 |
to leave out the root CA certificate). This can only be accomplished by |
| 134 |
either adding the intermediate CA certificates into the trusted |
| 135 |
certificate store for the SSL_CTX object (resulting in having to add |
| 136 |
CA certificates that otherwise maybe would not be trusted), or by adding |
| 137 |
the chain certificates using the |
| 138 |
\&\fBSSL_CTX_add_extra_chain_cert\fR\|(3) |
| 139 |
function, which is only available for the SSL_CTX object as a whole and that |
| 140 |
therefore probably can only apply for one client certificate, making |
| 141 |
the concept of the callback function (to allow the choice from several |
| 142 |
certificates) questionable. |
| 143 |
.PP |
| 144 |
Once the SSL object has been used in conjunction with the callback function, |
| 145 |
the certificate will be set for the SSL object and will not be cleared |
| 146 |
even when \fBSSL_clear\fR\|(3) is being called. It is therefore |
| 147 |
mandatory to destroy the SSL object using \fBSSL_free\fR\|(3) |
| 148 |
and create a new one to return to the previous state. |
| 149 |
.SH "SEE ALSO" |
| 150 |
.IX Header "SEE ALSO" |
| 151 |
\&\fBssl\fR\|(7), \fBSSL_CTX_use_certificate\fR\|(3), |
| 152 |
\&\fBSSL_CTX_add_extra_chain_cert\fR\|(3), |
| 153 |
\&\fBSSL_get_client_CA_list\fR\|(3), |
| 154 |
\&\fBSSL_clear\fR\|(3), \fBSSL_free\fR\|(3) |
| 155 |
.SH COPYRIGHT |
| 156 |
.IX Header "COPYRIGHT" |
| 157 |
Copyright 2002\-2020 The OpenSSL Project Authors. All Rights Reserved. |
| 158 |
.PP |
| 159 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 160 |
this file except in compliance with the License. You can obtain a copy |
| 161 |
in the file LICENSE in the source distribution or at |
| 162 |
<https://www.openssl.org/source/license.html>. |