1 .\" $NetBSD: libcrypto.pl,v 1.3 2007/11/27 22:16:03 christos Exp $
3 .\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05)
6 .\" ========================================================================
7 .de Sh \" Subsection heading
15 .de Sp \" Vertical space (when we can't use .PP)
19 .de Vb \" Begin verbatim text
24 .de Ve \" End verbatim text
28 .\" Set up some character translations and predefined strings. \*(-- will
29 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
30 .\" double quote, and \*(R" will give a right double quote. \*(C+ will
31 .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
32 .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
33 .\" nothing in troff, for use with C<>.
35 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
39 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
40 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
53 .\" Escape single quotes in literal strings from groff's Unicode transform.
57 .\" If the F register is turned on, we'll generate index entries on stderr for
58 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
59 .\" entries marked with X<> in POD. Of course, you'll have to process the
60 .\" output yourself in some meaningful fashion.
63 . tm Index:\\$1\t\\n%\t"\\$2"
73 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
74 .\" Fear. Run. Save yourself. No user-serviceable parts.
75 . \" fudge factors for nroff and troff
84 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
90 . \" simple accents for nroff and troff
100 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
101 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
102 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
103 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
104 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
105 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
107 . \" troff and (daisy-wheel) nroff accents
108 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
109 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
110 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
111 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
112 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
113 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
114 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
115 .ds ae a\h'-(\w'a'u*4/10)'e
116 .ds Ae A\h'-(\w'A'u*4/10)'E
117 . \" corrections for vroff
118 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
119 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
120 . \" for low resolution devices (crt and lpr)
121 .if \n(.H>23 .if \n(.V>19 \
134 .\" ========================================================================
136 .IX Title "SSL_CTX_set_verify 3"
137 .TH SSL_CTX_set_verify 3 "2009-02-14" "1.1.0-dev" "OpenSSL"
138 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
139 .\" way too many mistakes in technical documents.
143 SSL_CTX_set_verify, SSL_set_verify, SSL_CTX_set_verify_depth, SSL_set_verify_depth \- set peer certificate verification parameters
147 .IX Header "SYNOPSIS"
149 \& #include <openssl/ssl.h>
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);
158 \& int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx);
161 .IX Header "DESCRIPTION"
162 \&\fISSL_CTX_set_verify()\fR sets the verification flags for \fBctx\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.
166 \&\fISSL_set_verify()\fR sets the verification flags for \fBssl\fR to be \fBmode\fR and
167 specifies the \fBverify_callback\fR function to be used. If no callback function
168 shall be specified, the \s-1NULL\s0 pointer can be used for \fBverify_callback\fR. In
169 this case last \fBverify_callback\fR set specifically for this \fBssl\fR remains. If
170 no special \fBcallback\fR was set before, the default callback for the underlying
171 \&\fBctx\fR is used, that was valid at the time \fBssl\fR was created with
172 \&\fISSL_new\fR\|(3).
174 \&\fISSL_CTX_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
175 verification that shall be allowed for \fBctx\fR. (See the \s-1BUGS\s0 section.)
177 \&\fISSL_set_verify_depth()\fR sets the maximum \fBdepth\fR for the certificate chain
178 verification that shall be allowed for \fBssl\fR. (See the \s-1BUGS\s0 section.)
181 The verification of certificates can be controlled by a set of logically
182 or'ed \fBmode\fR flags:
183 .IP "\s-1SSL_VERIFY_NONE\s0" 4
184 .IX Item "SSL_VERIFY_NONE"
185 \&\fBServer mode:\fR the server will not send a client certificate request to the
186 client, so the client will not send a certificate.
188 \&\fBClient mode:\fR if not using an anonymous cipher (by default disabled), the
189 server will send a certificate which will be checked. The result of the
190 certificate verification process can be checked after the \s-1TLS/SSL\s0 handshake
191 using the \fISSL_get_verify_result\fR\|(3) function.
192 The handshake will be continued regardless of the verification result.
193 .IP "\s-1SSL_VERIFY_PEER\s0" 4
194 .IX Item "SSL_VERIFY_PEER"
195 \&\fBServer mode:\fR the server sends a client certificate request to the client.
196 The certificate returned (if any) is checked. If the verification process
197 fails, the \s-1TLS/SSL\s0 handshake is
198 immediately terminated with an alert message containing the reason for
199 the verification failure.
200 The behaviour can be controlled by the additional
201 \&\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0 and \s-1SSL_VERIFY_CLIENT_ONCE\s0 flags.
203 \&\fBClient mode:\fR the server certificate is verified. If the verification process
204 fails, the \s-1TLS/SSL\s0 handshake is
205 immediately terminated with an alert message containing the reason for
206 the verification failure. If no server certificate is sent, because an
207 anonymous cipher is used, \s-1SSL_VERIFY_PEER\s0 is ignored.
208 .IP "\s-1SSL_VERIFY_FAIL_IF_NO_PEER_CERT\s0" 4
209 .IX Item "SSL_VERIFY_FAIL_IF_NO_PEER_CERT"
210 \&\fBServer mode:\fR if the client did not return a certificate, the \s-1TLS/SSL\s0
211 handshake is immediately terminated with a \*(L"handshake failure\*(R" alert.
212 This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
214 \&\fBClient mode:\fR ignored
215 .IP "\s-1SSL_VERIFY_CLIENT_ONCE\s0" 4
216 .IX Item "SSL_VERIFY_CLIENT_ONCE"
217 \&\fBServer mode:\fR only request a client certificate on the initial \s-1TLS/SSL\s0
218 handshake. Do not ask for a client certificate again in case of a
219 renegotiation. This flag must be used together with \s-1SSL_VERIFY_PEER\s0.
221 \&\fBClient mode:\fR ignored
223 Exactly one of the \fBmode\fR flags \s-1SSL_VERIFY_NONE\s0 and \s-1SSL_VERIFY_PEER\s0 must be
226 The actual verification procedure is performed either using the built-in
227 verification procedure or using another application provided verification
229 \&\fISSL_CTX_set_cert_verify_callback\fR\|(3).
230 The following descriptions apply in the case of the built-in procedure. An
231 application provided procedure also has access to the verify depth information
232 and the \fIverify_callback()\fR function, but the way this information is used
235 \&\fISSL_CTX_set_verify_depth()\fR and \fISSL_set_verify_depth()\fR set the limit up
236 to which depth certificates in a chain are used during the verification
237 procedure. If the certificate chain is longer than allowed, the certificates
238 above the limit are ignored. Error messages are generated as if these
239 certificates would not be present, most likely a
240 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY will be issued.
241 The depth count is \*(L"level 0:peer certificate\*(R", \*(L"level 1: \s-1CA\s0 certificate\*(R",
242 \&\*(L"level 2: higher level \s-1CA\s0 certificate\*(R", and so on. Setting the maximum
243 depth to 2 allows the levels 0, 1, and 2. The default depth limit is 9,
244 allowing for the peer certificate and additional 9 \s-1CA\s0 certificates.
246 The \fBverify_callback\fR function is used to control the behaviour when the
247 \&\s-1SSL_VERIFY_PEER\s0 flag is set. It must be supplied by the application and
248 receives two arguments: \fBpreverify_ok\fR indicates, whether the verification of
249 the certificate in question was passed (preverify_ok=1) or not
250 (preverify_ok=0). \fBx509_ctx\fR is a pointer to the complete context used
251 for the certificate chain verification.
253 The certificate chain is checked starting with the deepest nesting level
254 (the root \s-1CA\s0 certificate) and worked upward to the peer's certificate.
255 At each level signatures and issuer attributes are checked. Whenever
256 a verification error is found, the error number is stored in \fBx509_ctx\fR
257 and \fBverify_callback\fR is called with \fBpreverify_ok\fR=0. By applying
258 X509_CTX_store_* functions \fBverify_callback\fR can locate the certificate
259 in question and perform additional steps (see \s-1EXAMPLES\s0). If no error is
260 found for a certificate, \fBverify_callback\fR is called with \fBpreverify_ok\fR=1
261 before advancing to the next level.
263 The return value of \fBverify_callback\fR controls the strategy of the further
264 verification process. If \fBverify_callback\fR returns 0, the verification
265 process is immediately stopped with \*(L"verification failed\*(R" state. If
266 \&\s-1SSL_VERIFY_PEER\s0 is set, a verification failure alert is sent to the peer and
267 the \s-1TLS/SSL\s0 handshake is terminated. If \fBverify_callback\fR returns 1,
268 the verification process is continued. If \fBverify_callback\fR always returns
269 1, the \s-1TLS/SSL\s0 handshake will not be terminated with respect to verification
270 failures and the connection will be established. The calling process can
271 however retrieve the error code of the last verification error using
272 \&\fISSL_get_verify_result\fR\|(3) or by maintaining its
273 own error storage managed by \fBverify_callback\fR.
275 If no \fBverify_callback\fR is specified, the default callback will be used.
276 Its return value is identical to \fBpreverify_ok\fR, so that any verification
277 failure will lead to a termination of the \s-1TLS/SSL\s0 handshake with an
278 alert message, if \s-1SSL_VERIFY_PEER\s0 is set.
281 In client mode, it is not checked whether the \s-1SSL_VERIFY_PEER\s0 flag
282 is set, but whether \s-1SSL_VERIFY_NONE\s0 is not set. This can lead to
283 unexpected behaviour, if the \s-1SSL_VERIFY_PEER\s0 and \s-1SSL_VERIFY_NONE\s0 are not
284 used as required (exactly one must be set at any time).
286 The certificate verification depth set with SSL[_CTX]\fI_verify_depth()\fR
287 stops the verification at a certain depth. The error message produced
288 will be that of an incomplete certificate chain and not
289 X509_V_ERR_CERT_CHAIN_TOO_LONG as may be expected.
291 .IX Header "RETURN VALUES"
292 The SSL*_set_verify*() functions do not provide diagnostic information.
294 .IX Header "EXAMPLES"
295 The following code sequence realizes an example \fBverify_callback\fR function
296 that will always continue the \s-1TLS/SSL\s0 handshake regardless of verification
297 failure, if wished. The callback realizes a verification depth limit with
298 more informational output.
300 All verification errors are printed, informations about the certificate chain
301 are printed on request.
302 The example is realized for a server that does allow but not require client
305 The example makes use of the ex_data technique to store application data
306 into/retrieve application data from the \s-1SSL\s0 structure
307 (see \fISSL_get_ex_new_index\fR\|(3),
308 \&\fISSL_get_ex_data_X509_STORE_CTX_idx\fR\|(3)).
315 \& int always_continue;
319 \& static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
327 \& err_cert = X509_STORE_CTX_get_current_cert(ctx);
328 \& err = X509_STORE_CTX_get_error(ctx);
329 \& depth = X509_STORE_CTX_get_error_depth(ctx);
332 \& * Retrieve the pointer to the SSL of the connection currently treated
333 \& * and the application specific data stored into the SSL object.
335 \& ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
336 \& mydata = SSL_get_ex_data(ssl, mydata_index);
338 \& X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
341 \& * Catch a too long certificate chain. The depth limit set using
342 \& * SSL_CTX_set_verify_depth() is by purpose set to "limit+1" so
343 \& * that whenever the "depth>verify_depth" condition is met, we
344 \& * have violated the limit and want to log this error condition.
345 \& * We must do it here, because the CHAIN_TOO_LONG error would not
346 \& * be found explicitly; only errors introduced by cutting off the
347 \& * additional certificates would be logged.
349 \& if (depth > mydata\->verify_depth) {
351 \& err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
352 \& X509_STORE_CTX_set_error(ctx, err);
354 \& if (!preverify_ok) {
355 \& printf("verify error:num=%d:%s:depth=%d:%s\en", err,
356 \& X509_verify_cert_error_string(err), depth, buf);
358 \& else if (mydata\->verbose_mode)
360 \& printf("depth=%d:%s\en", depth, buf);
364 \& * At this point, err contains the last verification error. We can use
365 \& * it for something special
367 \& if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT))
369 \& X509_NAME_oneline(X509_get_issuer_name(ctx\->current_cert), buf, 256);
370 \& printf("issuer= %s\en", buf);
373 \& if (mydata\->always_continue)
376 \& return preverify_ok;
383 \& mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
386 \& SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
390 \& * Let the verify_callback catch the verify_depth error so that we get
391 \& * an appropriate error in the logfile.
393 \& SSL_CTX_set_verify_depth(verify_depth + 1);
396 \& * Set up the SSL specific data into "mydata" and store it into th SSL
399 \& mydata.verify_depth = verify_depth; ...
400 \& SSL_set_ex_data(ssl, mydata_index, &mydata);
403 \& SSL_accept(ssl); /* check of success left out for clarity */
404 \& if (peer = SSL_get_peer_certificate(ssl))
406 \& if (SSL_get_verify_result(ssl) == X509_V_OK)
408 \& /* The client sent a certificate which verified OK */
413 .IX Header "SEE ALSO"
414 \&\fIssl\fR\|(3), \fISSL_new\fR\|(3),
415 \&\fISSL_CTX_get_verify_mode\fR\|(3),
416 \&\fISSL_get_verify_result\fR\|(3),
417 \&\fISSL_CTX_load_verify_locations\fR\|(3),
418 \&\fISSL_get_peer_certificate\fR\|(3),
419 \&\fISSL_CTX_set_cert_verify_callback\fR\|(3),
420 \&\fISSL_get_ex_data_X509_STORE_CTX_idx\fR\|(3),
421 \&\fISSL_get_ex_new_index\fR\|(3)