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