Raise an error on syscall failure in tls_retry_write_records
[openssl.git] / doc / man3 / SSL_CTX_set_cert_verify_callback.pod
1 =pod
2
3 =head1 NAME
4
5 SSL_CTX_set_cert_verify_callback - set peer certificate verification procedure
6
7 =head1 SYNOPSIS
8
9  #include <openssl/ssl.h>
10
11  void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
12                                        int (*callback)(X509_STORE_CTX *, void *),
13                                        void *arg);
14
15 =head1 DESCRIPTION
16
17 SSL_CTX_set_cert_verify_callback() sets the verification callback function for
18 I<ctx>. SSL objects that are created from I<ctx> inherit the setting valid at
19 the time when L<SSL_new(3)> is called.
20
21 =head1 NOTES
22
23 When a peer certificate has been received during a SSL/TLS handshake,
24 a verification function is called regardless of the verification mode.
25 If the application does not explicitly specify a verification callback function,
26 the built-in verification function is used.
27 If a verification callback I<callback> is specified via
28 SSL_CTX_set_cert_verify_callback(), the supplied callback function is called
29 instead with the arguments callback(X509_STORE_CTX *x509_store_ctx, void *arg).
30 The argument I<arg> is specified by the application when setting I<callback>.
31 By setting I<callback> to NULL, the default behaviour is restored.
32
33 I<callback> should return 1 to indicate verification success
34 and 0 to indicate verification failure.
35 In server mode, a return value of 0 leads to handshake failure.
36 In client mode, the behaviour is as follows.
37 All values, including 0, are ignored
38 if the verification mode is B<SSL_VERIFY_NONE>.
39 Otherwise, when the return value is less than or equal to 0, the handshake will
40 fail.
41
42 In client mode I<callback> may also call the L<SSL_set_retry_verify(3)>
43 function on the B<SSL> object set in the I<x509_store_ctx> ex data (see
44 L<SSL_get_ex_data_X509_STORE_CTX_idx(3)>) and return 1. This would be
45 typically done in case the certificate verification was not yet able
46 to succeed. This makes the handshake suspend and return control to the
47 calling application with B<SSL_ERROR_WANT_RETRY_VERIFY>. The app can for
48 instance fetch further certificates or cert status information needed for
49 the verification. Calling L<SSL_connect(3)> again resumes the connection
50 attempt by retrying the server certificate verification step.
51 This process may even be repeated if need be.
52
53 In any case a viable verification result value must be reflected
54 in the B<error> member of I<x509_store_ctx>,
55 which can be done using L<X509_STORE_CTX_set_error(3)>.
56 This is particularly important in case
57 the I<callback> allows the connection to continue (by returning 1).
58 Note that the verification status in the store context is a possibly durable
59 indication of the chain's validity!
60 This gets recorded in the SSL session (and thus also in session tickets)
61 and the validity of the originally presented chain is then visible
62 on resumption, even though no chain is presented int that case.
63 Moreover, the calling application will be informed about the detailed result of
64 the verification procedure and may elect to base further decisions on it.
65
66 Within I<x509_store_ctx>, I<callback> has access to the I<verify_callback>
67 function set using L<SSL_CTX_set_verify(3)>.
68
69 =head1 RETURN VALUES
70
71 SSL_CTX_set_cert_verify_callback() does not return a value.
72
73 =head1 WARNINGS
74
75 Do not mix the verification callback described in this function with the
76 B<verify_callback> function called during the verification process. The
77 latter is set using the L<SSL_CTX_set_verify(3)>
78 family of functions.
79
80 Providing a complete verification procedure including certificate purpose
81 settings etc is a complex task. The built-in procedure is quite powerful
82 and in most cases it should be sufficient to modify its behaviour using
83 the B<verify_callback> function.
84
85 =head1 BUGS
86
87 SSL_CTX_set_cert_verify_callback() does not provide diagnostic information.
88
89 =head1 SEE ALSO
90
91 L<ssl(7)>, L<SSL_CTX_set_verify(3)>,
92 L<X509_STORE_CTX_set_error(3)>,
93 L<SSL_get_verify_result(3)>,
94 L<SSL_set_retry_verify(3)>,
95 L<SSL_CTX_load_verify_locations(3)>
96
97 =head1 COPYRIGHT
98
99 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
100
101 Licensed under the Apache License 2.0 (the "License").  You may not use
102 this file except in compliance with the License.  You can obtain a copy
103 in the file LICENSE in the source distribution or at
104 L<https://www.openssl.org/source/license.html>.
105
106 =cut