Debian Codegraph @

upstream/debian-unstable/man3/X509_STORE_CTX_set_verify_cb.3ssl

raw
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 "X509_STORE_CTX_SET_VERIFY_CB 3SSL"
58 .TH X509_STORE_CTX_SET_VERIFY_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 X509_STORE_CTX_get_cleanup,
65 X509_STORE_CTX_get_lookup_crls,
66 X509_STORE_CTX_get_lookup_certs,
67 X509_STORE_CTX_get_check_policy,
68 X509_STORE_CTX_get_cert_crl,
69 X509_STORE_CTX_get_check_crl,
70 X509_STORE_CTX_get_get_crl,
71 X509_STORE_CTX_set_get_crl,
72 X509_STORE_CTX_get_check_revocation,
73 X509_STORE_CTX_get_check_issued,
74 X509_STORE_CTX_get_get_issuer,
75 X509_STORE_CTX_get_verify_cb,
76 X509_STORE_CTX_set_verify_cb,
77 X509_STORE_CTX_verify_cb,
78 X509_STORE_CTX_print_verify_cb,
79 X509_STORE_CTX_set_current_reasons
80 \&\- get and set X509_STORE_CTX components such as verification callback
81 .SH SYNOPSIS
82 .IX Header "SYNOPSIS"
83 .Vb 1
84 \& #include <openssl/x509_vfy.h>
85 \&
86 \& typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *);
87 \& int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx);
88 \&
89 \& X509_STORE_CTX_verify_cb X509_STORE_CTX_get_verify_cb(X509_STORE_CTX *ctx);
90 \&
91 \& void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
92 \& X509_STORE_CTX_verify_cb verify_cb);
93 \&
94 \& X509_STORE_CTX_get_issuer_fn X509_STORE_CTX_get_get_issuer(X509_STORE_CTX *ctx);
95 \& X509_STORE_CTX_check_issued_fn X509_STORE_CTX_get_check_issued(X509_STORE_CTX *ctx);
96 \& X509_STORE_CTX_check_revocation_fn X509_STORE_CTX_get_check_revocation(X509_STORE_CTX *ctx);
97 \&
98 \& X509_STORE_CTX_get_crl_fn X509_STORE_CTX_get_get_crl(X509_STORE_CTX *ctx);
99 \&
100 \& void X509_STORE_CTX_set_get_crl(X509_STORE_CTX *ctx,
101 \& X509_STORE_CTX_get_crl_fn get_crl);
102 \&
103 \& X509_STORE_CTX_check_crl_fn X509_STORE_CTX_get_check_crl(X509_STORE_CTX *ctx);
104 \& X509_STORE_CTX_cert_crl_fn X509_STORE_CTX_get_cert_crl(X509_STORE_CTX *ctx);
105 \& X509_STORE_CTX_check_policy_fn X509_STORE_CTX_get_check_policy(X509_STORE_CTX *ctx);
106 \& X509_STORE_CTX_lookup_certs_fn X509_STORE_CTX_get_lookup_certs(X509_STORE_CTX *ctx);
107 \& X509_STORE_CTX_lookup_crls_fn X509_STORE_CTX_get_lookup_crls(X509_STORE_CTX *ctx);
108 \& X509_STORE_CTX_cleanup_fn X509_STORE_CTX_get_cleanup(X509_STORE_CTX *ctx);
109 \& void X509_STORE_CTX_set_current_reasons(X509_STORE_CTX *ctx,
110 \& unsigned int current_reasons);
111 .Ve
112 .SH DESCRIPTION
113 .IX Header "DESCRIPTION"
114 \&\fBX509_STORE_CTX_set_verify_cb()\fR sets the verification callback of \fBctx\fR to
115 \&\fBverify_cb\fR overwriting any existing callback.
116 .PP
117 The verification callback can be used to customise the operation of certificate
118 verification, for instance by overriding error conditions or logging errors for
119 debugging purposes.
120 .PP
121 However, a verification callback is \fBnot\fR essential and the default operation
122 is often sufficient.
123 .PP
124 The \fBok\fR parameter to the callback indicates the value the callback should
125 return to retain the default behaviour. If it is zero then an error condition
126 is indicated. If it is 1 then no error occurred. If the flag
127 \&\fBX509_V_FLAG_NOTIFY_POLICY\fR is set then \fBok\fR is set to 2 to indicate the
128 policy checking is complete.
129 .PP
130 The \fBctx\fR parameter to the callback is the \fBX509_STORE_CTX\fR structure that
131 is performing the verification operation. A callback can examine this
132 structure and receive additional information about the error, for example
133 by calling \fBX509_STORE_CTX_get_current_cert()\fR. Additional application data can
134 be passed to the callback via the \fBex_data\fR mechanism.
135 .PP
136 \&\fBX509_STORE_CTX_print_verify_cb()\fR is a verification callback function that,
137 when a certificate verification has failed, adds an entry to the error queue
138 with code \fBX509_R_CERTIFICATE_VERIFICATION_FAILED\fR and with diagnostic details,
139 including the most relevant fields of the target certificate that failed to
140 verify and, if appropriate, of the available untrusted and trusted certificates.
141 .PP
142 \&\fBX509_STORE_CTX_get_verify_cb()\fR returns the value of the current callback
143 for the specific \fBctx\fR.
144 .PP
145 \&\fBX509_STORE_CTX_get_get_issuer()\fR,
146 \&\fBX509_STORE_CTX_get_check_issued()\fR, \fBX509_STORE_CTX_get_check_revocation()\fR,
147 \&\fBX509_STORE_CTX_get_get_crl()\fR, \fBX509_STORE_CTX_get_check_crl()\fR,
148 \&\fBX509_STORE_CTX_get_cert_crl()\fR, \fBX509_STORE_CTX_get_check_policy()\fR,
149 \&\fBX509_STORE_CTX_get_lookup_certs()\fR, \fBX509_STORE_CTX_get_lookup_crls()\fR
150 and \fBX509_STORE_CTX_get_cleanup()\fR return the function pointers cached
151 from the corresponding \fBX509_STORE\fR, please see
152 \&\fBX509_STORE_set_verify\fR\|(3) for more information.
153 .PP
154 \&\fBX509_STORE_CTX_set_get_crl()\fR sets the function to get the crl for a given
155 certificate \fIx\fR.
156 When found, the crl must be assigned to \fI*crl\fR.
157 This function must return 0 on failure and 1 on success.
158 \&\fIIf no function to get the issuer is provided, the internal default
159 function will be used instead.\fR
160 .PP
161 \&\fBX509_STORE_CTX_set_current_reasons()\fR is used in conjunction with
162 X509_STORE_CTX_get_crl_fn. The X509_STORE_CTX_get_crl_fn callback must
163 use this method to set the reason why the certificate is invalid.
164 .SH WARNINGS
165 .IX Header "WARNINGS"
166 In general a verification callback should \fBNOT\fR unconditionally return 1 in
167 all circumstances because this will allow verification to succeed no matter
168 what the error. This effectively removes all security from the application
169 because \fBany\fR certificate (including untrusted generated ones) will be
170 accepted.
171 .SH NOTES
172 .IX Header "NOTES"
173 The verification callback can be set and inherited from the parent structure
174 performing the operation. In some cases (such as S/MIME verification) the
175 \&\fBX509_STORE_CTX\fR structure is created and destroyed internally and the
176 only way to set a custom verification callback is by inheriting it from the
177 associated \fBX509_STORE\fR.
178 .SH "RETURN VALUES"
179 .IX Header "RETURN VALUES"
180 \&\fBX509_STORE_CTX_set_verify_cb()\fR does not return a value.
181 .SH EXAMPLES
182 .IX Header "EXAMPLES"
183 Default callback operation:
184 .PP
185 .Vb 3
186 \& int verify_callback(int ok, X509_STORE_CTX *ctx) {
187 \& return ok;
188 \& }
189 .Ve
190 .PP
191 Simple example, suppose a certificate in the chain is expired and we wish
192 to continue after this error:
193 .PP
194 .Vb 7
195 \& int verify_callback(int ok, X509_STORE_CTX *ctx) {
196 \& /* Tolerate certificate expiration */
197 \& if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_HAS_EXPIRED)
198 \& return 1;
199 \& /* Otherwise don\*(Aqt override */
200 \& return ok;
201 \& }
202 .Ve
203 .PP
204 More complex example, we don't wish to continue after \fBany\fR certificate has
205 expired just one specific case:
206 .PP
207 .Vb 4
208 \& int verify_callback(int ok, X509_STORE_CTX *ctx)
209 \& {
210 \& int err = X509_STORE_CTX_get_error(ctx);
211 \& X509 *err_cert = X509_STORE_CTX_get_current_cert(ctx);
212 \&
213 \& if (err == X509_V_ERR_CERT_HAS_EXPIRED) {
214 \& if (check_is_acceptable_expired_cert(err_cert)
215 \& return 1;
216 \& }
217 \& return ok;
218 \& }
219 .Ve
220 .PP
221 Full featured logging callback. In this case the \fBbio_err\fR is assumed to be
222 a global logging \fBBIO\fR, an alternative would to store a BIO in \fBctx\fR using
223 \&\fBex_data\fR.
224 .PP
225 .Vb 4
226 \& int verify_callback(int ok, X509_STORE_CTX *ctx)
227 \& {
228 \& X509 *err_cert;
229 \& int err, depth;
230 \&
231 \& err_cert = X509_STORE_CTX_get_current_cert(ctx);
232 \& err = X509_STORE_CTX_get_error(ctx);
233 \& depth = X509_STORE_CTX_get_error_depth(ctx);
234 \&
235 \& BIO_printf(bio_err, "depth=%d ", depth);
236 \& if (err_cert) {
237 \& X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert),
238 \& 0, XN_FLAG_ONELINE);
239 \& BIO_puts(bio_err, "\en");
240 \& }
241 \& else
242 \& BIO_puts(bio_err, "<no cert>\en");
243 \& if (!ok)
244 \& BIO_printf(bio_err, "verify error:num=%d:%s\en", err,
245 \& X509_verify_cert_error_string(err));
246 \& switch (err) {
247 \& case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
248 \& BIO_puts(bio_err, "issuer= ");
249 \& X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert),
250 \& 0, XN_FLAG_ONELINE);
251 \& BIO_puts(bio_err, "\en");
252 \& break;
253 \& case X509_V_ERR_CERT_NOT_YET_VALID:
254 \& case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
255 \& BIO_printf(bio_err, "notBefore=");
256 \& ASN1_TIME_print(bio_err, X509_get_notBefore(err_cert));
257 \& BIO_printf(bio_err, "\en");
258 \& break;
259 \& case X509_V_ERR_CERT_HAS_EXPIRED:
260 \& case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
261 \& BIO_printf(bio_err, "notAfter=");
262 \& ASN1_TIME_print(bio_err, X509_get_notAfter(err_cert));
263 \& BIO_printf(bio_err, "\en");
264 \& break;
265 \& case X509_V_ERR_NO_EXPLICIT_POLICY:
266 \& policies_print(bio_err, ctx);
267 \& break;
268 \& }
269 \& if (err == X509_V_OK && ok == 2)
270 \& /* print out policies */
271 \&
272 \& BIO_printf(bio_err, "verify return:%d\en", ok);
273 \& return(ok);
274 \& }
275 .Ve
276 .SH "SEE ALSO"
277 .IX Header "SEE ALSO"
278 \&\fBX509_STORE_CTX_get_error\fR\|(3)
279 \&\fBX509_STORE_set_verify_cb_func\fR\|(3)
280 \&\fBX509_STORE_CTX_get_ex_new_index\fR\|(3)
281 .SH HISTORY
282 .IX Header "HISTORY"
283 The
284 \&\fBX509_STORE_CTX_get_get_issuer()\fR,
285 \&\fBX509_STORE_CTX_get_check_issued()\fR, \fBX509_STORE_CTX_get_check_revocation()\fR,
286 \&\fBX509_STORE_CTX_get_get_crl()\fR, \fBX509_STORE_CTX_get_check_crl()\fR,
287 \&\fBX509_STORE_CTX_get_cert_crl()\fR, \fBX509_STORE_CTX_get_check_policy()\fR,
288 \&\fBX509_STORE_CTX_get_lookup_certs()\fR, \fBX509_STORE_CTX_get_lookup_crls()\fR
289 and \fBX509_STORE_CTX_get_cleanup()\fR functions were added in OpenSSL 1.1.0.
290 .PP
291 \&\fBX509_STORE_CTX_print_verify_cb()\fR was added in OpenSSL 3.0.
292 .SH COPYRIGHT
293 .IX Header "COPYRIGHT"
294 Copyright 2009\-2023 The OpenSSL Project Authors. All Rights Reserved.
295 .PP
296 Licensed under the Apache License 2.0 (the "License"). You may not use
297 this file except in compliance with the License. You can obtain a copy
298 in the file LICENSE in the source distribution or at
299 <https://www.openssl.org/source/license.html>.