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