Update build for OpenSSL-0.9.8j upgrade.
[dragonfly.git] / secure / lib / libssl / man / SSL_CTX_set_verify.3
CommitLineData
e257b235 1.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05)
e056f0e0
JR
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
984263bc
MD
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
e056f0e0 13.de Sp \" Vertical space (when we can't use .PP)
984263bc
MD
14.if t .sp .5v
15.if n .sp
16..
e056f0e0 17.de Vb \" Begin verbatim text
984263bc
MD
18.ft CW
19.nf
20.ne \\$1
21..
e056f0e0 22.de Ve \" End verbatim text
984263bc 23.ft R
984263bc
MD
24.fi
25..
e056f0e0
JR
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
e257b235
PA
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-
e056f0e0 33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
984263bc 34.ie n \{\
e056f0e0
JR
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' ""
984263bc
MD
43'br\}
44.el\{\
e056f0e0
JR
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
984263bc 49'br\}
e056f0e0 50.\"
e257b235
PA
51.\" Escape single quotes in literal strings from groff's Unicode transform.
52.ie \n(.g .ds Aq \(aq
53.el .ds Aq '
54.\"
e056f0e0
JR
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.
e257b235 59.ie \nF \{\
e056f0e0
JR
60. de IX
61. tm Index:\\$1\t\\n%\t"\\$2"
984263bc 62..
e056f0e0
JR
63. nr % 0
64. rr F
984263bc 65.\}
e257b235
PA
66.el \{\
67. de IX
68..
69.\}
aac4ff6f 70.\"
e056f0e0
JR
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
984263bc 74.if n \{\
e056f0e0
JR
75. ds #H 0
76. ds #V .8m
77. ds #F .3m
78. ds #[ \f1
79. ds #] \fP
984263bc
MD
80.\}
81.if t \{\
e056f0e0
JR
82. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
83. ds #V .6m
84. ds #F 0
85. ds #[ \&
86. ds #] \&
984263bc 87.\}
e056f0e0 88. \" simple accents for nroff and troff
984263bc 89.if n \{\
e056f0e0
JR
90. ds ' \&
91. ds ` \&
92. ds ^ \&
93. ds , \&
94. ds ~ ~
95. ds /
984263bc
MD
96.\}
97.if t \{\
e056f0e0
JR
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'
984263bc 104.\}
e056f0e0 105. \" troff and (daisy-wheel) nroff accents
984263bc
MD
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
e056f0e0 115. \" corrections for vroff
984263bc
MD
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'
e056f0e0 118. \" for low resolution devices (crt and lpr)
984263bc
MD
119.if \n(.H>23 .if \n(.V>19 \
120\{\
e056f0e0
JR
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
984263bc
MD
130.\}
131.rm #[ #] #H #V #F C
e056f0e0
JR
132.\" ========================================================================
133.\"
134.IX Title "SSL_CTX_set_verify 3"
e257b235
PA
135.TH SSL_CTX_set_verify 3 "2009-01-11" "0.9.8j" "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
984263bc
MD
140.SH "NAME"
141SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth \- set peer certificate verification parameters
142.SH "SYNOPSIS"
e056f0e0 143.IX Header "SYNOPSIS"
984263bc
MD
144.Vb 1
145\& #include <openssl/ssl.h>
e257b235 146\&
984263bc
MD
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);
e257b235 153\&
984263bc
MD
154\& int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
155.Ve
156.SH "DESCRIPTION"
e056f0e0
JR
157.IX Header "DESCRIPTION"
158\&\fISSL_CTX_set_verify()\fR sets the verification flags for \fBctx\fR to be \fBmode\fR and
984263bc 159specifies the \fBverify_callback\fR function to be used. If no callback function
e056f0e0 160shall be specified, the \s-1NULL\s0 pointer can be used for \fBverify_callback\fR.
984263bc 161.PP
e056f0e0 162\&\fISSL_set_verify()\fR sets the verification flags for \fBssl\fR to be \fBmode\fR and
984263bc 163specifies the \fBverify_callback\fR function to be used. If no callback function
e056f0e0 164shall be specified, the \s-1NULL\s0 pointer can be used for \fBverify_callback\fR. In
984263bc
MD
165this case last \fBverify_callback\fR set specifically for this \fBssl\fR remains. If
166no special \fBcallback\fR was set before, the default callback for the underlying
e056f0e0
JR
167\&\fBctx\fR is used, that was valid at the the time \fBssl\fR was created with
168\&\fISSL_new\fR\|(3).
984263bc 169.PP
e056f0e0
JR
170\&\fISSL_CTX_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
171verification that shall be allowed for \fBctx\fR. (See the \s-1BUGS\s0 section.)
984263bc 172.PP
e056f0e0
JR
173\&\fISSL_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
174verification that shall be allowed for \fBssl\fR. (See the \s-1BUGS\s0 section.)
984263bc 175.SH "NOTES"
e056f0e0 176.IX Header "NOTES"
984263bc
MD
177The verification of certificates can be controlled by a set of logically
178or'ed \fBmode\fR flags:
e056f0e0
JR
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
984263bc
MD
182client, so the client will not send a certificate.
183.Sp
e056f0e0 184\&\fBClient mode:\fR if not using an anonymous cipher (by default disabled), the
984263bc
MD
185server will send a certificate which will be checked. The result of the
186certificate verification process can be checked after the \s-1TLS/SSL\s0 handshake
e056f0e0 187using the \fISSL_get_verify_result\fR\|(3) function.
984263bc 188The handshake will be continued regardless of the verification result.
e056f0e0
JR
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.
984263bc
MD
192The certificate returned (if any) is checked. If the verification process
193fails, the \s-1TLS/SSL\s0 handshake is
194immediately terminated with an alert message containing the reason for
195the verification failure.
196The behaviour can be controlled by the additional
e056f0e0 197\&\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0 and \s-1SSL_VERIFY_CLIENT_ONCE\s0 flags.
984263bc 198.Sp
e056f0e0 199\&\fBClient mode:\fR the server certificate is verified. If the verification process
984263bc
MD
200fails, the \s-1TLS/SSL\s0 handshake is
201immediately terminated with an alert message containing the reason for
202the verification failure. If no server certificate is sent, because an
203anonymous cipher is used, \s-1SSL_VERIFY_PEER\s0 is ignored.
e056f0e0
JR
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
984263bc
MD
207handshake is immediately terminated with a \*(L"handshake failure\*(R" alert.
208This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
209.Sp
e056f0e0
JR
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
984263bc
MD
214handshake. Do not ask for a client certificate again in case of a
215renegotiation. This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
216.Sp
e056f0e0 217\&\fBClient mode:\fR ignored
984263bc
MD
218.PP
219Exactly one of the \fBmode\fR flags \s-1SSL_VERIFY_NONE\s0 and \s-1SSL_VERIFY_PEER\s0 must be
220set at any time.
221.PP
222The actual verification procedure is performed either using the built-in
223verification procedure or using another application provided verification
224function set with
e056f0e0 225\&\fISSL_CTX_set_cert_verify_callback\fR\|(3).
984263bc
MD
226The following descriptions apply in the case of the built-in procedure. An
227application provided procedure also has access to the verify depth information
228and the \fIverify_callback()\fR function, but the way this information is used
229may be different.
230.PP
e056f0e0 231\&\fISSL_CTX_set_verify_depth()\fR and \fISSL_set_verify_depth()\fR set the limit up
984263bc
MD
232to which depth certificates in a chain are used during the verification
233procedure. If the certificate chain is longer than allowed, the certificates
234above the limit are ignored. Error messages are generated as if these
235certificates would not be present, most likely a
236X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY will be issued.
237The depth count is \*(L"level 0:peer certificate\*(R", \*(L"level 1: \s-1CA\s0 certificate\*(R",
e056f0e0 238\&\*(L"level 2: higher level \s-1CA\s0 certificate\*(R", and so on. Setting the maximum
984263bc
MD
239depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9,
240allowing for the peer certificate and additional 9 \s-1CA\s0 certificates.
241.PP
242The \fBverify_callback\fR function is used to control the behaviour when the
e056f0e0 243\&\s-1SSL_VERIFY_PEER\s0 flag is set. It must be supplied by the application and
984263bc
MD
244receives two arguments: \fBpreverify_ok\fR indicates, whether the verification of
245the 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
247for the certificate chain verification.
248.PP
249The 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.
251At each level signatures and issuer attributes are checked. Whenever
252a verification error is found, the error number is stored in \fBx509_ctx\fR
253and \fBverify_callback\fR is called with \fBpreverify_ok\fR=0. By applying
254X509_CTX_store_* functions \fBverify_callback\fR can locate the certificate
255in question and perform additional steps (see \s-1EXAMPLES\s0). If no error is
256found for a certificate, \fBverify_callback\fR is called with \fBpreverify_ok\fR=1
257before advancing to the next level.
258.PP
259The return value of \fBverify_callback\fR controls the strategy of the further
260verification process. If \fBverify_callback\fR returns 0, the verification
261process is immediately stopped with \*(L"verification failed\*(R" state. If
e056f0e0 262\&\s-1SSL_VERIFY_PEER\s0 is set, a verification failure alert is sent to the peer and
984263bc
MD
263the \s-1TLS/SSL\s0 handshake is terminated. If \fBverify_callback\fR returns 1,
264the verification process is continued. If \fBverify_callback\fR always returns
a7d27d5a
JR
2651, the \s-1TLS/SSL\s0 handshake will not be terminated with respect to verification
266failures and the connection will be established. The calling process can
267however retrieve the error code of the last verification error using
e056f0e0 268\&\fISSL_get_verify_result\fR\|(3) or by maintaining its
984263bc
MD
269own error storage managed by \fBverify_callback\fR.
270.PP
271If no \fBverify_callback\fR is specified, the default callback will be used.
272Its return value is identical to \fBpreverify_ok\fR, so that any verification
273failure will lead to a termination of the \s-1TLS/SSL\s0 handshake with an
274alert message, if \s-1SSL_VERIFY_PEER\s0 is set.
275.SH "BUGS"
e056f0e0
JR
276.IX Header "BUGS"
277In client mode, it is not checked whether the \s-1SSL_VERIFY_PEER\s0 flag
278is set, but whether \s-1SSL_VERIFY_NONE\s0 is not set. This can lead to
279unexpected behaviour, if the \s-1SSL_VERIFY_PEER\s0 and \s-1SSL_VERIFY_NONE\s0 are not
984263bc
MD
280used as required (exactly one must be set at any time).
281.PP
282The certificate verification depth set with SSL[_CTX]\fI_verify_depth()\fR
283stops the verification at a certain depth. The error message produced
284will be that of an incomplete certificate chain and not
285X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected.
286.SH "RETURN VALUES"
e056f0e0 287.IX Header "RETURN VALUES"
984263bc
MD
288The SSL*_set_verify*() functions do not provide diagnostic information.
289.SH "EXAMPLES"
e056f0e0 290.IX Header "EXAMPLES"
984263bc 291The following code sequence realizes an example \fBverify_callback\fR function
e056f0e0 292that will always continue the \s-1TLS/SSL\s0 handshake regardless of verification
984263bc
MD
293failure, if wished. The callback realizes a verification depth limit with
294more informational output.
295.PP
296All verification errors are printed, informations about the certificate chain
297are printed on request.
298The example is realized for a server that does allow but not require client
299certificates.
300.PP
301The example makes use of the ex_data technique to store application data
e056f0e0
JR
302into/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)).
984263bc 305.PP
e257b235 306.Vb 10
984263bc
MD
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;
e257b235 322\&
984263bc
MD
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);
e257b235 326\&
984263bc
MD
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);
e257b235 333\&
984263bc 334\& X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
e257b235 335\&
984263bc
MD
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\& */
e257b235 345\& if (depth > mydata\->verify_depth) {
984263bc
MD
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\& }
e257b235 354\& else if (mydata\->verbose_mode)
984263bc
MD
355\& {
356\& printf("depth=%d:%s\en", depth, buf);
357\& }
e257b235 358\&
984263bc
MD
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\& {
e257b235 365\& X509_NAME_oneline(X509_get_issuer_name(ctx\->current_cert), buf, 256);
984263bc
MD
366\& printf("issuer= %s\en", buf);
367\& }
e257b235
PA
368\&
369\& if (mydata\->always_continue)
984263bc
MD
370\& return 1;
371\& else
372\& return preverify_ok;
373\& }
374\& ...
e257b235 375\&
984263bc 376\& mydata_t mydata;
e257b235 377\&
984263bc
MD
378\& ...
379\& mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
e257b235 380\&
984263bc
MD
381\& ...
382\& SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
383\& verify_callback);
e257b235 384\&
984263bc
MD
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);
e257b235 390\&
984263bc
MD
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);
e257b235 397\&
984263bc
MD
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"
a7d27d5a 409.IX Header "SEE ALSO"
e056f0e0
JR
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)