]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/X509_STORE_CTX_set_verify_cb.3
MFC: r331627
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / X509_STORE_CTX_set_verify_cb.3
1 .\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "X509_STORE_CTX_set_verify_cb 3"
132 .TH X509_STORE_CTX_set_verify_cb 3 "2018-03-27" "1.0.2o" "OpenSSL"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 X509_STORE_CTX_set_verify_cb \- set verification callback
139 .SH "SYNOPSIS"
140 .IX Header "SYNOPSIS"
141 .Vb 1
142 \& #include <openssl/x509_vfy.h>
143 \&
144 \& void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
145 \&                                int (*verify_cb)(int ok, X509_STORE_CTX *ctx));
146 .Ve
147 .SH "DESCRIPTION"
148 .IX Header "DESCRIPTION"
149 \&\fIX509_STORE_CTX_set_verify_cb()\fR sets the verification callback of \fBctx\fR to
150 \&\fBverify_cb\fR overwriting any existing callback.
151 .PP
152 The verification callback can be used to customise the operation of certificate
153 verification, either by overriding error conditions or logging errors for
154 debugging purposes.
155 .PP
156 However a verification callback is \fBnot\fR essential and the default operation
157 is often sufficient.
158 .PP
159 The \fBok\fR parameter to the callback indicates the value the callback should
160 return to retain the default behaviour. If it is zero then and error condition
161 is indicated. If it is 1 then no error occurred. If the flag
162 \&\fBX509_V_FLAG_NOTIFY_POLICY\fR is set then \fBok\fR is set to 2 to indicate the
163 policy checking is complete.
164 .PP
165 The \fBctx\fR parameter to the callback is the \fBX509_STORE_CTX\fR structure that
166 is performing the verification operation. A callback can examine this
167 structure and receive additional information about the error, for example
168 by calling \fIX509_STORE_CTX_get_current_cert()\fR. Additional application data can
169 be passed to the callback via the \fBex_data\fR mechanism.
170 .SH "WARNING"
171 .IX Header "WARNING"
172 In general a verification callback should \fB\s-1NOT\s0\fR unconditionally return 1 in
173 all circumstances because this will allow verification to succeed no matter
174 what the error. This effectively removes all security from the application
175 because \fBany\fR certificate (including untrusted generated ones) will be
176 accepted.
177 .SH "NOTES"
178 .IX Header "NOTES"
179 The verification callback can be set and inherited from the parent structure
180 performing the operation. In some cases (such as S/MIME verification) the
181 \&\fBX509_STORE_CTX\fR structure is created and destroyed internally and the
182 only way to set a custom verification callback is by inheriting it from the
183 associated \fBX509_STORE\fR.
184 .SH "RETURN VALUES"
185 .IX Header "RETURN VALUES"
186 \&\fIX509_STORE_CTX_set_verify_cb()\fR does not return a value.
187 .SH "EXAMPLES"
188 .IX Header "EXAMPLES"
189 Default callback operation:
190 .PP
191 .Vb 4
192 \& int verify_callback(int ok, X509_STORE_CTX *ctx)
193 \&        {
194 \&        return ok;
195 \&        }
196 .Ve
197 .PP
198 Simple example, suppose a certificate in the chain is expired and we wish
199 to continue after this error:
200 .PP
201 .Vb 8
202 \& int verify_callback(int ok, X509_STORE_CTX *ctx)
203 \&        {
204 \&        /* Tolerate certificate expiration */
205 \&        if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_HAS_EXPIRED)
206 \&                        return 1;
207 \&        /* Otherwise don\*(Aqt override */
208 \&        return ok;
209 \&        }
210 .Ve
211 .PP
212 More complex example, we don't wish to continue after \fBany\fR certificate has
213 expired just one specific case:
214 .PP
215 .Vb 11
216 \& int verify_callback(int ok, X509_STORE_CTX *ctx)
217 \&        {
218 \&        int err = X509_STORE_CTX_get_error(ctx);
219 \&        X509 *err_cert = X509_STORE_CTX_get_current_cert(ctx);
220 \&        if (err == X509_V_ERR_CERT_HAS_EXPIRED)
221 \&                {
222 \&                if (check_is_acceptable_expired_cert(err_cert)
223 \&                        return 1;
224 \&                }
225 \&        return ok;
226 \&        }
227 .Ve
228 .PP
229 Full featured logging callback. In this case the \fBbio_err\fR is assumed to be
230 a global logging \fB\s-1BIO\s0\fR, an alternative would to store a \s-1BIO\s0 in \fBctx\fR using
231 \&\fBex_data\fR.
232 .PP
233 .Vb 4
234 \& int verify_callback(int ok, X509_STORE_CTX *ctx)
235 \&        {
236 \&        X509 *err_cert;
237 \&        int err,depth;
238 \&
239 \&        err_cert = X509_STORE_CTX_get_current_cert(ctx);
240 \&        err =   X509_STORE_CTX_get_error(ctx);
241 \&        depth = X509_STORE_CTX_get_error_depth(ctx);
242 \&
243 \&        BIO_printf(bio_err,"depth=%d ",depth);
244 \&        if (err_cert)
245 \&                {
246 \&                X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert),
247 \&                                        0, XN_FLAG_ONELINE);
248 \&                BIO_puts(bio_err, "\en");
249 \&                }
250 \&        else
251 \&                BIO_puts(bio_err, "<no cert>\en");
252 \&        if (!ok)
253 \&                BIO_printf(bio_err,"verify error:num=%d:%s\en",err,
254 \&                        X509_verify_cert_error_string(err));
255 \&        switch (err)
256 \&                {
257 \&        case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
258 \&                BIO_puts(bio_err,"issuer= ");
259 \&                X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert),
260 \&                                        0, XN_FLAG_ONELINE);
261 \&                BIO_puts(bio_err, "\en");
262 \&                break;
263 \&        case X509_V_ERR_CERT_NOT_YET_VALID:
264 \&        case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
265 \&                BIO_printf(bio_err,"notBefore=");
266 \&                ASN1_TIME_print(bio_err,X509_get_notBefore(err_cert));
267 \&                BIO_printf(bio_err,"\en");
268 \&                break;
269 \&        case X509_V_ERR_CERT_HAS_EXPIRED:
270 \&        case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
271 \&                BIO_printf(bio_err,"notAfter=");
272 \&                ASN1_TIME_print(bio_err,X509_get_notAfter(err_cert));
273 \&                BIO_printf(bio_err,"\en");
274 \&                break;
275 \&        case X509_V_ERR_NO_EXPLICIT_POLICY:
276 \&                policies_print(bio_err, ctx);
277 \&                break;
278 \&                }
279 \&        if (err == X509_V_OK && ok == 2)
280 \&                /* print out policies */
281 \&
282 \&        BIO_printf(bio_err,"verify return:%d\en",ok);
283 \&        return(ok);
284 \&        }
285 .Ve
286 .SH "SEE ALSO"
287 .IX Header "SEE ALSO"
288 \&\fIX509_STORE_CTX_get_error\fR\|(3)
289 \&\fIX509_STORE_set_verify_cb_func\fR\|(3)
290 \&\fIX509_STORE_CTX_get_ex_new_index\fR\|(3)
291 .SH "HISTORY"
292 .IX Header "HISTORY"
293 \&\fIX509_STORE_CTX_set_verify_cb()\fR is available in all versions of SSLeay and
294 OpenSSL.