1SSL_CTX_set_client_cert_cb(3) OpenSSL SSL_CTX_set_client_cert_cb(3)
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, int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
13 int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
14 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
15
17 SSL_CTX_set_client_cert_cb() sets the client_cert_cb() callback, that
18 is called when a client certificate is requested by a server and no
19 certificate was yet set for the SSL object.
20
21 When client_cert_cb() is NULL, no callback function is used.
22
23 SSL_CTX_get_client_cert_cb() returns a pointer to the currently set
24 callback function.
25
26 client_cert_cb() is the application defined callback. If it wants to
27 set a certificate, a certificate/private key combination must be set
28 using the x509 and pkey arguments and "1" must be returned. The
29 certificate will be installed into ssl, see the NOTES and BUGS
30 sections. If no certificate should be set, "0" has to be returned and
31 no certificate will be sent. A negative return value will suspend the
32 handshake and the handshake function will return immediately.
33 SSL_get_error(3) will return SSL_ERROR_WANT_X509_LOOKUP to indicate,
34 that the handshake was suspended. The next call to the handshake
35 function will again lead to the call of client_cert_cb(). It is the job
36 of the client_cert_cb() to store information about the state of the
37 last call, if required to continue.
38
40 During a handshake (or renegotiation) a server may request a
41 certificate from the client. A client certificate must only be sent,
42 when the server did send the request.
43
44 When a certificate was set using the SSL_CTX_use_certificate(3) family
45 of functions, it will be sent to the server. The TLS standard requires
46 that only a certificate is sent, if it matches the list of acceptable
47 CAs sent by the server. This constraint is violated by the default
48 behavior of the OpenSSL library. Using the callback function it is
49 possible to implement a proper selection routine or to allow a user
50 interaction to choose the certificate to be sent.
51
52 If a callback function is defined and no certificate was yet defined
53 for the SSL object, the callback function will be called. If the
54 callback function returns a certificate, the OpenSSL library will try
55 to load the private key and certificate data into the SSL object using
56 the SSL_use_certificate() and SSL_use_private_key() functions. Thus it
57 will permanently install the certificate and key for this SSL object.
58 It will not be reset by calling SSL_clear(3). If the callback returns
59 no certificate, the OpenSSL library will not send a certificate.
60
62 The client_cert_cb() cannot return a complete certificate chain, it can
63 only return one client certificate. If the chain only has a length of
64 2, the root CA certificate may be omitted according to the TLS standard
65 and thus a standard conforming answer can be sent to the server. For a
66 longer chain, the client must send the complete chain (with the option
67 to leave out the root CA certificate). This can only be accomplished by
68 either adding the intermediate CA certificates into the trusted
69 certificate store for the SSL_CTX object (resulting in having to add CA
70 certificates that otherwise maybe would not be trusted), or by adding
71 the chain certificates using the SSL_CTX_add_extra_chain_cert(3)
72 function, which is only available for the SSL_CTX object as a whole and
73 that therefore probably can only apply for one client certificate,
74 making the concept of the callback function (to allow the choice from
75 several certificates) questionable.
76
77 Once the SSL object has been used in conjunction with the callback
78 function, the certificate will be set for the SSL object and will not
79 be cleared even when SSL_clear(3) is being called. It is therefore
80 mandatory to destroy the SSL object using SSL_free(3) and create a new
81 one to return to the previous state.
82
84 ssl(3), SSL_CTX_use_certificate(3), SSL_CTX_add_extra_chain_cert(3),
85 SSL_get_client_CA_list(3), SSL_clear(3), SSL_free(3)
86
87
88
891.0.2k 2017-01-26 SSL_CTX_set_client_cert_cb(3)