1SSL_CTX_SET_CLIENT_CERT_CB(3ossl) OpenSSL SSL_CTX_SET_CLIENT_CERT_CB(3ossl)
2
3
4
6 SSL_CTX_set_client_cert_cb, SSL_CTX_get_client_cert_cb - handle client
7 certificate callback function
8
10 #include <openssl/ssl.h>
11
12 void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
13 int (*client_cert_cb)(SSL *ssl, X509 **x509,
14 EVP_PKEY **pkey));
15 int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509,
16 EVP_PKEY **pkey);
17
19 SSL_CTX_set_client_cert_cb() sets the client_cert_cb callback, that is
20 called when a client certificate is requested by a server and no
21 certificate was yet set for the SSL object.
22
23 When client_cert_cb is NULL, no callback function is used.
24
25 SSL_CTX_get_client_cert_cb() returns a pointer to the currently set
26 callback function.
27
28 client_cert_cb is the application defined callback. If it wants to set
29 a certificate, a certificate/private key combination must be set using
30 the x509 and pkey arguments and "1" must be returned. The certificate
31 will be installed into ssl, see the NOTES and BUGS sections. If no
32 certificate should be set, "0" has to be returned and no certificate
33 will be sent. A negative return value will suspend the handshake and
34 the handshake function will return immediately. SSL_get_error(3) will
35 return SSL_ERROR_WANT_X509_LOOKUP to indicate, that the handshake was
36 suspended. The next call to the handshake function will again lead to
37 the call of client_cert_cb. It is the job of the client_cert_cb to
38 store information about the state of the last call, if required to
39 continue.
40
42 During a handshake (or renegotiation) a server may request a
43 certificate from the client. A client certificate must only be sent,
44 when the server did send the request.
45
46 When a certificate was set using the SSL_CTX_use_certificate(3) family
47 of functions, it will be sent to the server. The TLS standard requires
48 that only a certificate is sent, if it matches the list of acceptable
49 CAs sent by the server. This constraint is violated by the default
50 behavior of the OpenSSL library. Using the callback function it is
51 possible to implement a proper selection routine or to allow a user
52 interaction to choose the certificate to be sent.
53
54 If a callback function is defined and no certificate was yet defined
55 for the SSL object, the callback function will be called. If the
56 callback function returns a certificate, the OpenSSL library will try
57 to load the private key and certificate data into the SSL object using
58 the SSL_use_certificate() and SSL_use_private_key() functions. Thus it
59 will permanently install the certificate and key for this SSL object.
60 It will not be reset by calling SSL_clear(3). If the callback returns
61 no certificate, the OpenSSL library will not send a certificate.
62
64 SSL_CTX_get_client_cert_cb() returns function pointer of client_cert_cb
65 or NULL if the callback is not set.
66
68 The client_cert_cb cannot return a complete certificate chain, it can
69 only return one client certificate. If the chain only has a length of
70 2, the root CA certificate may be omitted according to the TLS standard
71 and thus a standard conforming answer can be sent to the server. For a
72 longer chain, the client must send the complete chain (with the option
73 to leave out the root CA certificate). This can only be accomplished by
74 either adding the intermediate CA certificates into the trusted
75 certificate store for the SSL_CTX object (resulting in having to add CA
76 certificates that otherwise maybe would not be trusted), or by adding
77 the chain certificates using the SSL_CTX_add_extra_chain_cert(3)
78 function, which is only available for the SSL_CTX object as a whole and
79 that therefore probably can only apply for one client certificate,
80 making the concept of the callback function (to allow the choice from
81 several certificates) questionable.
82
83 Once the SSL object has been used in conjunction with the callback
84 function, the certificate will be set for the SSL object and will not
85 be cleared even when SSL_clear(3) is being called. It is therefore
86 mandatory to destroy the SSL object using SSL_free(3) and create a new
87 one to return to the previous state.
88
90 ssl(7), SSL_CTX_use_certificate(3), SSL_CTX_add_extra_chain_cert(3),
91 SSL_get_client_CA_list(3), SSL_clear(3), SSL_free(3)
92
94 Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
95
96 Licensed under the Apache License 2.0 (the "License"). You may not use
97 this file except in compliance with the License. You can obtain a copy
98 in the file LICENSE in the source distribution or at
99 <https://www.openssl.org/source/license.html>.
100
101
102
1033.0.9 2023-07-27 SSL_CTX_SET_CLIENT_CERT_CB(3ossl)