Merge from vendor branch NTPD:
[dragonfly.git] / secure / lib / libssl / man / SSL_CTX_set_verify.3
1 .rn '' }`
2 ''' $RCSfile$$Revision$$Date$
3 '''
4 ''' $Log$
5 '''
6 .de Sh
7 .br
8 .if t .Sp
9 .ne 5
10 .PP
11 \fB\\$1\fR
12 .PP
13 ..
14 .de Sp
15 .if t .sp .5v
16 .if n .sp
17 ..
18 .de Ip
19 .br
20 .ie \\n(.$>=3 .ne \\$3
21 .el .ne 3
22 .IP "\\$1" \\$2
23 ..
24 .de Vb
25 .ft CW
26 .nf
27 .ne \\$1
28 ..
29 .de Ve
30 .ft R
31
32 .fi
33 ..
34 '''
35 '''
36 '''     Set up \*(-- to give an unbreakable dash;
37 '''     string Tr holds user defined translation string.
38 '''     Bell System Logo is used as a dummy character.
39 '''
40 .tr \(*W-|\(bv\*(Tr
41 .ie n \{\
42 .ds -- \(*W-
43 .ds PI pi
44 .if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
45 .if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
46 .ds L" ""
47 .ds R" ""
48 '''   \*(M", \*(S", \*(N" and \*(T" are the equivalent of
49 '''   \*(L" and \*(R", except that they are used on ".xx" lines,
50 '''   such as .IP and .SH, which do another additional levels of
51 '''   double-quote interpretation
52 .ds M" """
53 .ds S" """
54 .ds N" """""
55 .ds T" """""
56 .ds L' '
57 .ds R' '
58 .ds M' '
59 .ds S' '
60 .ds N' '
61 .ds T' '
62 'br\}
63 .el\{\
64 .ds -- \(em\|
65 .tr \*(Tr
66 .ds L" ``
67 .ds R" ''
68 .ds M" ``
69 .ds S" ''
70 .ds N" ``
71 .ds T" ''
72 .ds L' `
73 .ds R' '
74 .ds M' `
75 .ds S' '
76 .ds N' `
77 .ds T' '
78 .ds PI \(*p
79 'br\}
80 .\"     If the F register is turned on, we'll generate
81 .\"     index entries out stderr for the following things:
82 .\"             TH      Title 
83 .\"             SH      Header
84 .\"             Sh      Subsection 
85 .\"             Ip      Item
86 .\"             X<>     Xref  (embedded
87 .\"     Of course, you have to process the output yourself
88 .\"     in some meaninful fashion.
89 .if \nF \{
90 .de IX
91 .tm Index:\\$1\t\\n%\t"\\$2"
92 ..
93 .nr % 0
94 .rr F
95 .\}
96 .TH SSL_CTX_set_verify 3 "0.9.7d" "2/Sep/2004" "OpenSSL"
97 .UC
98 .if n .hy 0
99 .if n .na
100 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
101 .de CQ          \" put $1 in typewriter font
102 .ft CW
103 'if n "\c
104 'if t \\&\\$1\c
105 'if n \\&\\$1\c
106 'if n \&"
107 \\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
108 '.ft R
109 ..
110 .\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
111 .       \" AM - accent mark definitions
112 .bd B 3
113 .       \" fudge factors for nroff and troff
114 .if n \{\
115 .       ds #H 0
116 .       ds #V .8m
117 .       ds #F .3m
118 .       ds #[ \f1
119 .       ds #] \fP
120 .\}
121 .if t \{\
122 .       ds #H ((1u-(\\\\n(.fu%2u))*.13m)
123 .       ds #V .6m
124 .       ds #F 0
125 .       ds #[ \&
126 .       ds #] \&
127 .\}
128 .       \" simple accents for nroff and troff
129 .if n \{\
130 .       ds ' \&
131 .       ds ` \&
132 .       ds ^ \&
133 .       ds , \&
134 .       ds ~ ~
135 .       ds ? ?
136 .       ds ! !
137 .       ds /
138 .       ds q
139 .\}
140 .if t \{\
141 .       ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
142 .       ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
143 .       ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
144 .       ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
145 .       ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
146 .       ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
147 .       ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
148 .       ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
149 .       ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
150 .\}
151 .       \" troff and (daisy-wheel) nroff accents
152 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
153 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
154 .ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
155 .ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
156 .ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
157 .ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
158 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
159 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
160 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
161 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
162 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
163 .ds ae a\h'-(\w'a'u*4/10)'e
164 .ds Ae A\h'-(\w'A'u*4/10)'E
165 .ds oe o\h'-(\w'o'u*4/10)'e
166 .ds Oe O\h'-(\w'O'u*4/10)'E
167 .       \" corrections for vroff
168 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
169 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
170 .       \" for low resolution devices (crt and lpr)
171 .if \n(.H>23 .if \n(.V>19 \
172 \{\
173 .       ds : e
174 .       ds 8 ss
175 .       ds v \h'-1'\o'\(aa\(ga'
176 .       ds _ \h'-1'^
177 .       ds . \h'-1'.
178 .       ds 3 3
179 .       ds o a
180 .       ds d- d\h'-1'\(ga
181 .       ds D- D\h'-1'\(hy
182 .       ds th \o'bp'
183 .       ds Th \o'LP'
184 .       ds ae ae
185 .       ds Ae AE
186 .       ds oe oe
187 .       ds Oe OE
188 .\}
189 .rm #[ #] #H #V #F C
190 .SH "NAME"
191 SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth \- set peer certificate verification parameters
192 .SH "SYNOPSIS"
193 .PP
194 .Vb 1
195 \& #include <openssl/ssl.h>
196 .Ve
197 .Vb 6
198 \& void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
199 \&                         int (*verify_callback)(int, X509_STORE_CTX *));
200 \& void SSL_set_verify(SSL *s, int mode,
201 \&                     int (*verify_callback)(int, X509_STORE_CTX *));
202 \& void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
203 \& void SSL_set_verify_depth(SSL *s, int depth);
204 .Ve
205 .Vb 1
206 \& int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
207 .Ve
208 .SH "DESCRIPTION"
209 \fISSL_CTX_set_verify()\fR sets the verification flags for \fBctx\fR to be \fBmode\fR and
210 specifies the \fBverify_callback\fR function to be used. If no callback function
211 shall be specified, the NULL pointer can be used for \fBverify_callback\fR.
212 .PP
213 \fISSL_set_verify()\fR sets the verification flags for \fBssl\fR to be \fBmode\fR and
214 specifies the \fBverify_callback\fR function to be used. If no callback function
215 shall be specified, the NULL pointer can be used for \fBverify_callback\fR. In
216 this case last \fBverify_callback\fR set specifically for this \fBssl\fR remains. If
217 no special \fBcallback\fR was set before, the default callback for the underlying
218 \fBctx\fR is used, that was valid at the the time \fBssl\fR was created with
219 SSL_new(3).
220 .PP
221 \fISSL_CTX_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
222 verification that shall be allowed for \fBctx\fR. (See the BUGS section.)
223 .PP
224 \fISSL_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
225 verification that shall be allowed for \fBssl\fR. (See the BUGS section.)
226 .SH "NOTES"
227 The verification of certificates can be controlled by a set of logically
228 or'ed \fBmode\fR flags:
229 .Ip "\s-1SSL_VERIFY_NONE\s0" 4
230 \fBServer mode:\fR the server will not send a client certificate request to the
231 client, so the client will not send a certificate.
232 .Sp
233 \fBClient mode:\fR if not using an anonymous cipher (by default disabled), the
234 server will send a certificate which will be checked. The result of the
235 certificate verification process can be checked after the \s-1TLS/SSL\s0 handshake
236 using the SSL_get_verify_result(3) function.
237 The handshake will be continued regardless of the verification result.
238 .Ip "\s-1SSL_VERIFY_PEER\s0" 4
239 \fBServer mode:\fR the server sends a client certificate request to the client.
240 The certificate returned (if any) is checked. If the verification process
241 fails, the \s-1TLS/SSL\s0 handshake is
242 immediately terminated with an alert message containing the reason for
243 the verification failure.
244 The behaviour can be controlled by the additional
245 \s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0 and \s-1SSL_VERIFY_CLIENT_ONCE\s0 flags.
246 .Sp
247 \fBClient mode:\fR the server certificate is verified. If the verification process
248 fails, the \s-1TLS/SSL\s0 handshake is
249 immediately terminated with an alert message containing the reason for
250 the verification failure. If no server certificate is sent, because an
251 anonymous cipher is used, \s-1SSL_VERIFY_PEER\s0 is ignored.
252 .Ip "\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0" 4
253 \fBServer mode:\fR if the client did not return a certificate, the \s-1TLS/SSL\s0
254 handshake is immediately terminated with a \*(L"handshake failure\*(R" alert.
255 This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
256 .Sp
257 \fBClient mode:\fR ignored
258 .Ip "\s-1SSL_VERIFY_CLIENT_ONCE\s0" 4
259 \fBServer mode:\fR only request a client certificate on the initial \s-1TLS/SSL\s0
260 handshake. Do not ask for a client certificate again in case of a
261 renegotiation. This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
262 .Sp
263 \fBClient mode:\fR ignored
264 .PP
265 Exactly one of the \fBmode\fR flags \s-1SSL_VERIFY_NONE\s0 and \s-1SSL_VERIFY_PEER\s0 must be
266 set at any time.
267 .PP
268 The actual verification procedure is performed either using the built-in
269 verification procedure or using another application provided verification
270 function set with
271 SSL_CTX_set_cert_verify_callback(3).
272 The following descriptions apply in the case of the built-in procedure. An
273 application provided procedure also has access to the verify depth information
274 and the \fIverify_callback()\fR function, but the way this information is used
275 may be different.
276 .PP
277 \fISSL_CTX_set_verify_depth()\fR and \fISSL_set_verify_depth()\fR set the limit up
278 to which depth certificates in a chain are used during the verification
279 procedure. If the certificate chain is longer than allowed, the certificates
280 above the limit are ignored. Error messages are generated as if these
281 certificates would not be present, most likely a
282 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY will be issued.
283 The depth count is \*(L"level 0:peer certificate\*(R", \*(L"level 1: \s-1CA\s0 certificate\*(R",
284 \*(L"level 2: higher level \s-1CA\s0 certificate\*(R", and so on. Setting the maximum
285 depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9,
286 allowing for the peer certificate and additional 9 \s-1CA\s0 certificates.
287 .PP
288 The \fBverify_callback\fR function is used to control the behaviour when the
289 \s-1SSL_VERIFY_PEER\s0 flag is set. It must be supplied by the application and
290 receives two arguments: \fBpreverify_ok\fR indicates, whether the verification of
291 the certificate in question was passed (preverify_ok=1) or not
292 (preverify_ok=0). \fBx509_ctx\fR is a pointer to the complete context used
293 for the certificate chain verification.
294 .PP
295 The certificate chain is checked starting with the deepest nesting level
296 (the root \s-1CA\s0 certificate) and worked upward to the peer's certificate.
297 At each level signatures and issuer attributes are checked. Whenever
298 a verification error is found, the error number is stored in \fBx509_ctx\fR
299 and \fBverify_callback\fR is called with \fBpreverify_ok\fR=0. By applying
300 X509_CTX_store_* functions \fBverify_callback\fR can locate the certificate
301 in question and perform additional steps (see \s-1EXAMPLES\s0). If no error is
302 found for a certificate, \fBverify_callback\fR is called with \fBpreverify_ok\fR=1
303 before advancing to the next level.
304 .PP
305 The return value of \fBverify_callback\fR controls the strategy of the further
306 verification process. If \fBverify_callback\fR returns 0, the verification
307 process is immediately stopped with \*(L"verification failed\*(R" state. If
308 \s-1SSL_VERIFY_PEER\s0 is set, a verification failure alert is sent to the peer and
309 the \s-1TLS/SSL\s0 handshake is terminated. If \fBverify_callback\fR returns 1,
310 the verification process is continued. If \fBverify_callback\fR always returns
311 1, the \s-1TLS/SSL\s0 handshake will not be terminated with respect to verification
312 failures and the connection will be established. The calling process can
313 however retrieve the error code of the last verification error using
314 SSL_get_verify_result(3) or by maintaining its
315 own error storage managed by \fBverify_callback\fR.
316 .PP
317 If no \fBverify_callback\fR is specified, the default callback will be used.
318 Its return value is identical to \fBpreverify_ok\fR, so that any verification
319 failure will lead to a termination of the \s-1TLS/SSL\s0 handshake with an
320 alert message, if \s-1SSL_VERIFY_PEER\s0 is set.
321 .SH "BUGS"
322 In client mode, it is not checked whether the SSL_VERIFY_PEER flag
323 is set, but whether SSL_VERIFY_NONE is not set. This can lead to
324 unexpected behaviour, if the SSL_VERIFY_PEER and SSL_VERIFY_NONE are not
325 used as required (exactly one must be set at any time).
326 .PP
327 The certificate verification depth set with SSL[_CTX]\fI_verify_depth()\fR
328 stops the verification at a certain depth. The error message produced
329 will be that of an incomplete certificate chain and not
330 X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected.
331 .SH "RETURN VALUES"
332 The SSL*_set_verify*() functions do not provide diagnostic information.
333 .SH "EXAMPLES"
334 The following code sequence realizes an example \fBverify_callback\fR function
335 that will always continue the TLS/SSL handshake regardless of verification
336 failure, if wished. The callback realizes a verification depth limit with
337 more informational output.
338 .PP
339 All verification errors are printed, informations about the certificate chain
340 are printed on request.
341 The example is realized for a server that does allow but not require client
342 certificates.
343 .PP
344 The example makes use of the ex_data technique to store application data
345 into/retrieve application data from the SSL structure
346 (see SSL_get_ex_new_index(3),
347 SSL_get_ex_data_X509_STORE_CTX_idx(3)).
348 .PP
349 .Vb 15
350 \& ...
351 \& typedef struct {
352 \&   int verbose_mode;
353 \&   int verify_depth;
354 \&   int always_continue;
355 \& } mydata_t;
356 \& int mydata_index;
357 \& ...
358 \& static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
359 \& {
360 \&    char    buf[256];
361 \&    X509   *err_cert;
362 \&    int     err, depth;
363 \&    SSL    *ssl;
364 \&    mydata_t *mydata;
365 .Ve
366 .Vb 3
367 \&    err_cert = X509_STORE_CTX_get_current_cert(ctx);
368 \&    err = X509_STORE_CTX_get_error(ctx);
369 \&    depth = X509_STORE_CTX_get_error_depth(ctx);
370 .Ve
371 .Vb 6
372 \&    /*
373 \&     * Retrieve the pointer to the SSL of the connection currently treated
374 \&     * and the application specific data stored into the SSL object.
375 \&     */
376 \&    ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
377 \&    mydata = SSL_get_ex_data(ssl, mydata_index);
378 .Ve
379 .Vb 1
380 \&    X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
381 .Ve
382 .Vb 22
383 \&    /*
384 \&     * Catch a too long certificate chain. The depth limit set using
385 \&     * SSL_CTX_set_verify_depth() is by purpose set to "limit+1" so
386 \&     * that whenever the "depth>verify_depth" condition is met, we
387 \&     * have violated the limit and want to log this error condition.
388 \&     * We must do it here, because the CHAIN_TOO_LONG error would not
389 \&     * be found explicitly; only errors introduced by cutting off the
390 \&     * additional certificates would be logged.
391 \&     */
392 \&    if (depth > mydata->verify_depth) {
393 \&        preverify_ok = 0;
394 \&        err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
395 \&        X509_STORE_CTX_set_error(ctx, err);
396 \&    } 
397 \&    if (!preverify_ok) {
398 \&        printf("verify error:num=%d:%s:depth=%d:%s\en", err,
399 \&                 X509_verify_cert_error_string(err), depth, buf);
400 \&    }
401 \&    else if (mydata->verbose_mode)
402 \&    {
403 \&        printf("depth=%d:%s\en", depth, buf);
404 \&    }
405 .Ve
406 .Vb 9
407 \&    /*
408 \&     * At this point, err contains the last verification error. We can use
409 \&     * it for something special
410 \&     */
411 \&    if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT))
412 \&    {
413 \&      X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256);
414 \&      printf("issuer= %s\en", buf);
415 \&    }
416 .Ve
417 .Vb 6
418 \&    if (mydata->always_continue)
419 \&      return 1;
420 \&    else
421 \&      return preverify_ok;
422 \& }
423 \& ...
424 .Ve
425 .Vb 1
426 \& mydata_t mydata;
427 .Ve
428 .Vb 2
429 \& ...
430 \& mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
431 .Ve
432 .Vb 3
433 \& ...
434 \& SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
435 \&                    verify_callback);
436 .Ve
437 .Vb 5
438 \& /*
439 \&  * Let the verify_callback catch the verify_depth error so that we get
440 \&  * an appropriate error in the logfile.
441 \&  */
442 \& SSL_CTX_set_verify_depth(verify_depth + 1);
443 .Ve
444 .Vb 16
445 \& /*
446 \&  * Set up the SSL specific data into "mydata" and store it into th SSL
447 \&  * structure.
448 \&  */
449 \& mydata.verify_depth = verify_depth; ...
450 \& SSL_set_ex_data(ssl, mydata_index, &mydata);
451 \&                                             
452 \& ...
453 \& SSL_accept(ssl);       /* check of success left out for clarity */
454 \& if (peer = SSL_get_peer_certificate(ssl))
455 \& {
456 \&   if (SSL_get_verify_result(ssl) == X509_V_OK)
457 \&   {
458 \&     /* The client sent a certificate which verified OK */
459 \&   }
460 \& }
461 .Ve
462 .SH "SEE ALSO"
463 ssl(3), SSL_new(3),
464 SSL_CTX_get_verify_mode(3),
465 SSL_get_verify_result(3),
466 SSL_CTX_load_verify_locations(3),
467 SSL_get_peer_certificate(3),
468 SSL_CTX_set_cert_verify_callback(3),
469 SSL_get_ex_data_X509_STORE_CTX_idx(3),
470 SSL_get_ex_new_index(3)
471
472 .rn }` ''
473 .IX Title "SSL_CTX_set_verify 3"
474 .IX Name "SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth - set peer certificate verification parameters"
475
476 .IX Header "NAME"
477
478 .IX Header "SYNOPSIS"
479
480 .IX Header "DESCRIPTION"
481
482 .IX Header "NOTES"
483
484 .IX Item "\s-1SSL_VERIFY_NONE\s0"
485
486 .IX Item "\s-1SSL_VERIFY_PEER\s0"
487
488 .IX Item "\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0"
489
490 .IX Item "\s-1SSL_VERIFY_CLIENT_ONCE\s0"
491
492 .IX Header "BUGS"
493
494 .IX Header "RETURN VALUES"
495
496 .IX Header "EXAMPLES"
497
498 .IX Header "SEE ALSO"
499