Remove my local patch again, it was still not meant to be commited.
[dragonfly.git] / secure / lib / libssl / man / SSL_CTX_set_verify.3
CommitLineData
a7d27d5a
JR
1.rn '' }`
2''' $RCSfile$$Revision$$Date$
3'''
4''' $Log$
5'''
6.de Sh
984263bc
MD
7.br
8.if t .Sp
9.ne 5
10.PP
11\fB\\$1\fR
12.PP
13..
a7d27d5a 14.de Sp
984263bc
MD
15.if t .sp .5v
16.if n .sp
17..
a7d27d5a 18.de Ip
984263bc
MD
19.br
20.ie \\n(.$>=3 .ne \\$3
21.el .ne 3
22.IP "\\$1" \\$2
23..
a7d27d5a 24.de Vb
984263bc
MD
25.ft CW
26.nf
27.ne \\$1
28..
a7d27d5a 29.de Ve
984263bc
MD
30.ft R
31
32.fi
33..
a7d27d5a
JR
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'''
984263bc 40.tr \(*W-|\(bv\*(Tr
984263bc 41.ie n \{\
a7d27d5a
JR
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' '
984263bc
MD
62'br\}
63.el\{\
a7d27d5a
JR
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
984263bc 79'br\}
a7d27d5a
JR
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"
984263bc 92..
a7d27d5a
JR
93.nr % 0
94.rr F
984263bc 95.\}
a7d27d5a
JR
96.TH SSL_CTX_set_verify 3 "0.9.7d" "2/Sep/2004" "OpenSSL"
97.UC
98.if n .hy 0
984263bc 99.if n .na
a7d27d5a
JR
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
984263bc 112.bd B 3
a7d27d5a 113. \" fudge factors for nroff and troff
984263bc 114.if n \{\
a7d27d5a
JR
115. ds #H 0
116. ds #V .8m
117. ds #F .3m
118. ds #[ \f1
119. ds #] \fP
984263bc
MD
120.\}
121.if t \{\
a7d27d5a
JR
122. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
123. ds #V .6m
124. ds #F 0
125. ds #[ \&
126. ds #] \&
984263bc 127.\}
a7d27d5a 128. \" simple accents for nroff and troff
984263bc 129.if n \{\
a7d27d5a
JR
130. ds ' \&
131. ds ` \&
132. ds ^ \&
133. ds , \&
134. ds ~ ~
135. ds ? ?
136. ds ! !
137. ds /
138. ds q
984263bc
MD
139.\}
140.if t \{\
a7d27d5a
JR
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'
984263bc 150.\}
a7d27d5a 151. \" troff and (daisy-wheel) nroff accents
984263bc
MD
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'
a7d27d5a
JR
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'\*(#]
984263bc
MD
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
a7d27d5a
JR
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
984263bc
MD
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'
a7d27d5a 170. \" for low resolution devices (crt and lpr)
984263bc
MD
171.if \n(.H>23 .if \n(.V>19 \
172\{\
a7d27d5a
JR
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
984263bc
MD
188.\}
189.rm #[ #] #H #V #F C
984263bc
MD
190.SH "NAME"
191SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth \- set peer certificate verification parameters
192.SH "SYNOPSIS"
a7d27d5a 193.PP
984263bc
MD
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"
a7d27d5a 209\fISSL_CTX_set_verify()\fR sets the verification flags for \fBctx\fR to be \fBmode\fR and
984263bc 210specifies the \fBverify_callback\fR function to be used. If no callback function
a7d27d5a 211shall be specified, the NULL pointer can be used for \fBverify_callback\fR.
984263bc 212.PP
a7d27d5a 213\fISSL_set_verify()\fR sets the verification flags for \fBssl\fR to be \fBmode\fR and
984263bc 214specifies the \fBverify_callback\fR function to be used. If no callback function
a7d27d5a 215shall be specified, the NULL pointer can be used for \fBverify_callback\fR. In
984263bc
MD
216this case last \fBverify_callback\fR set specifically for this \fBssl\fR remains. If
217no special \fBcallback\fR was set before, the default callback for the underlying
a7d27d5a 218\fBctx\fR is used, that was valid at the the time \fBssl\fR was created with
984263bc
MD
219SSL_new(3).
220.PP
a7d27d5a
JR
221\fISSL_CTX_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
222verification that shall be allowed for \fBctx\fR. (See the BUGS section.)
984263bc 223.PP
a7d27d5a
JR
224\fISSL_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
225verification that shall be allowed for \fBssl\fR. (See the BUGS section.)
984263bc 226.SH "NOTES"
984263bc
MD
227The verification of certificates can be controlled by a set of logically
228or'ed \fBmode\fR flags:
229.Ip "\s-1SSL_VERIFY_NONE\s0" 4
a7d27d5a 230\fBServer mode:\fR the server will not send a client certificate request to the
984263bc
MD
231client, so the client will not send a certificate.
232.Sp
a7d27d5a 233\fBClient mode:\fR if not using an anonymous cipher (by default disabled), the
984263bc
MD
234server will send a certificate which will be checked. The result of the
235certificate verification process can be checked after the \s-1TLS/SSL\s0 handshake
236using the SSL_get_verify_result(3) function.
237The handshake will be continued regardless of the verification result.
238.Ip "\s-1SSL_VERIFY_PEER\s0" 4
a7d27d5a 239\fBServer mode:\fR the server sends a client certificate request to the client.
984263bc
MD
240The certificate returned (if any) is checked. If the verification process
241fails, the \s-1TLS/SSL\s0 handshake is
242immediately terminated with an alert message containing the reason for
243the verification failure.
244The behaviour can be controlled by the additional
a7d27d5a 245\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0 and \s-1SSL_VERIFY_CLIENT_ONCE\s0 flags.
984263bc 246.Sp
a7d27d5a 247\fBClient mode:\fR the server certificate is verified. If the verification process
984263bc
MD
248fails, the \s-1TLS/SSL\s0 handshake is
249immediately terminated with an alert message containing the reason for
250the verification failure. If no server certificate is sent, because an
251anonymous cipher is used, \s-1SSL_VERIFY_PEER\s0 is ignored.
252.Ip "\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0" 4
a7d27d5a 253\fBServer mode:\fR if the client did not return a certificate, the \s-1TLS/SSL\s0
984263bc
MD
254handshake is immediately terminated with a \*(L"handshake failure\*(R" alert.
255This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
256.Sp
a7d27d5a 257\fBClient mode:\fR ignored
984263bc 258.Ip "\s-1SSL_VERIFY_CLIENT_ONCE\s0" 4
a7d27d5a 259\fBServer mode:\fR only request a client certificate on the initial \s-1TLS/SSL\s0
984263bc
MD
260handshake. Do not ask for a client certificate again in case of a
261renegotiation. This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
262.Sp
a7d27d5a 263\fBClient mode:\fR ignored
984263bc
MD
264.PP
265Exactly one of the \fBmode\fR flags \s-1SSL_VERIFY_NONE\s0 and \s-1SSL_VERIFY_PEER\s0 must be
266set at any time.
267.PP
268The actual verification procedure is performed either using the built-in
269verification procedure or using another application provided verification
270function set with
271SSL_CTX_set_cert_verify_callback(3).
272The following descriptions apply in the case of the built-in procedure. An
273application provided procedure also has access to the verify depth information
274and the \fIverify_callback()\fR function, but the way this information is used
275may be different.
276.PP
a7d27d5a 277\fISSL_CTX_set_verify_depth()\fR and \fISSL_set_verify_depth()\fR set the limit up
984263bc
MD
278to which depth certificates in a chain are used during the verification
279procedure. If the certificate chain is longer than allowed, the certificates
280above the limit are ignored. Error messages are generated as if these
281certificates would not be present, most likely a
282X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY will be issued.
283The depth count is \*(L"level 0:peer certificate\*(R", \*(L"level 1: \s-1CA\s0 certificate\*(R",
a7d27d5a 284\*(L"level 2: higher level \s-1CA\s0 certificate\*(R", and so on. Setting the maximum
984263bc
MD
285depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9,
286allowing for the peer certificate and additional 9 \s-1CA\s0 certificates.
287.PP
288The \fBverify_callback\fR function is used to control the behaviour when the
a7d27d5a 289\s-1SSL_VERIFY_PEER\s0 flag is set. It must be supplied by the application and
984263bc
MD
290receives two arguments: \fBpreverify_ok\fR indicates, whether the verification of
291the 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
293for the certificate chain verification.
294.PP
295The 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.
297At each level signatures and issuer attributes are checked. Whenever
298a verification error is found, the error number is stored in \fBx509_ctx\fR
299and \fBverify_callback\fR is called with \fBpreverify_ok\fR=0. By applying
300X509_CTX_store_* functions \fBverify_callback\fR can locate the certificate
301in question and perform additional steps (see \s-1EXAMPLES\s0). If no error is
302found for a certificate, \fBverify_callback\fR is called with \fBpreverify_ok\fR=1
303before advancing to the next level.
304.PP
305The return value of \fBverify_callback\fR controls the strategy of the further
306verification process. If \fBverify_callback\fR returns 0, the verification
307process is immediately stopped with \*(L"verification failed\*(R" state. If
a7d27d5a 308\s-1SSL_VERIFY_PEER\s0 is set, a verification failure alert is sent to the peer and
984263bc
MD
309the \s-1TLS/SSL\s0 handshake is terminated. If \fBverify_callback\fR returns 1,
310the verification process is continued. If \fBverify_callback\fR always returns
a7d27d5a
JR
3111, the \s-1TLS/SSL\s0 handshake will not be terminated with respect to verification
312failures and the connection will be established. The calling process can
313however retrieve the error code of the last verification error using
984263bc
MD
314SSL_get_verify_result(3) or by maintaining its
315own error storage managed by \fBverify_callback\fR.
316.PP
317If no \fBverify_callback\fR is specified, the default callback will be used.
318Its return value is identical to \fBpreverify_ok\fR, so that any verification
319failure will lead to a termination of the \s-1TLS/SSL\s0 handshake with an
320alert message, if \s-1SSL_VERIFY_PEER\s0 is set.
321.SH "BUGS"
a7d27d5a
JR
322In client mode, it is not checked whether the SSL_VERIFY_PEER flag
323is set, but whether SSL_VERIFY_NONE is not set. This can lead to
324unexpected behaviour, if the SSL_VERIFY_PEER and SSL_VERIFY_NONE are not
984263bc
MD
325used as required (exactly one must be set at any time).
326.PP
327The certificate verification depth set with SSL[_CTX]\fI_verify_depth()\fR
328stops the verification at a certain depth. The error message produced
329will be that of an incomplete certificate chain and not
330X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected.
331.SH "RETURN VALUES"
984263bc
MD
332The SSL*_set_verify*() functions do not provide diagnostic information.
333.SH "EXAMPLES"
984263bc 334The following code sequence realizes an example \fBverify_callback\fR function
a7d27d5a 335that will always continue the TLS/SSL handshake regardless of verification
984263bc
MD
336failure, if wished. The callback realizes a verification depth limit with
337more informational output.
338.PP
339All verification errors are printed, informations about the certificate chain
340are printed on request.
341The example is realized for a server that does allow but not require client
342certificates.
343.PP
344The example makes use of the ex_data technique to store application data
a7d27d5a 345into/retrieve application data from the SSL structure
984263bc
MD
346(see SSL_get_ex_new_index(3),
347SSL_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
a7d27d5a 444.Vb 16
984263bc
MD
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);
a7d27d5a 451\&
984263bc
MD
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"
984263bc
MD
463ssl(3), SSL_new(3),
464SSL_CTX_get_verify_mode(3),
465SSL_get_verify_result(3),
466SSL_CTX_load_verify_locations(3),
467SSL_get_peer_certificate(3),
468SSL_CTX_set_cert_verify_callback(3),
469SSL_get_ex_data_X509_STORE_CTX_idx(3),
470SSL_get_ex_new_index(3)
a7d27d5a
JR
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