summaryrefslogtreecommitdiff
path: root/src/lib/libssl/doc/SSL_CTX_set_verify.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/doc/SSL_CTX_set_verify.3')
-rw-r--r--src/lib/libssl/doc/SSL_CTX_set_verify.3415
1 files changed, 0 insertions, 415 deletions
diff --git a/src/lib/libssl/doc/SSL_CTX_set_verify.3 b/src/lib/libssl/doc/SSL_CTX_set_verify.3
deleted file mode 100644
index 9292f2086b..0000000000
--- a/src/lib/libssl/doc/SSL_CTX_set_verify.3
+++ /dev/null
@@ -1,415 +0,0 @@
1.\"
2.\" $OpenBSD: SSL_CTX_set_verify.3,v 1.2 2014/12/02 14:11:01 jmc Exp $
3.\"
4.Dd $Mdocdate: December 2 2014 $
5.Dt SSL_CTX_SET_VERIFY 3
6.Os
7.Sh NAME
8.Nm SSL_CTX_set_verify ,
9.Nm SSL_set_verify ,
10.Nm SSL_CTX_set_verify_depth ,
11.Nm SSL_set_verify_depth
12.Nd set peer certificate verification parameters
13.Sh SYNOPSIS
14.In openssl/ssl.h
15.Ft void
16.Fo SSL_CTX_set_verify
17.Fa "SSL_CTX *ctx"
18.Fa "int mode"
19.Fa "int (*verify_callback)(int, X509_STORE_CTX *)"
20.Fc
21.Ft void
22.Fo SSL_set_verify
23.Fa "SSL *s"
24.Fa "int mode"
25.Fa "int (*verify_callback)(int, X509_STORE_CTX *)"
26.Fc
27.Ft void
28.Fn SSL_CTX_set_verify_depth "SSL_CTX *ctx" "int depth"
29.Ft void
30.Fn SSL_set_verify_depth "SSL *s" "int depth"
31.Ft int
32.Fn verify_callback "int preverify_ok" "X509_STORE_CTX *x509_ctx"
33.Sh DESCRIPTION
34.Fn SSL_CTX_set_verify
35sets the verification flags for
36.Fa ctx
37to be
38.Fa mode
39and
40specifies the
41.Fa verify_callback
42function to be used.
43If no callback function shall be specified, the
44.Dv NULL
45pointer can be used for
46.Fa verify_callback .
47.Pp
48.Fn SSL_set_verify
49sets the verification flags for
50.Fa ssl
51to be
52.Fa mode
53and specifies the
54.Fa verify_callback
55function to be used.
56If no callback function shall be specified, the
57.Dv NULL
58pointer can be used for
59.Fa verify_callback .
60In this case last
61.Fa verify_callback
62set specifically for this
63.Fa ssl
64remains.
65If no special callback was set before, the default callback for the underlying
66.Fa ctx
67is used, that was valid at the time
68.Fa ssl
69was created with
70.Xr SSL_new 3 .
71.Pp
72.Fn SSL_CTX_set_verify_depth
73sets the maximum
74.Fa depth
75for the certificate chain verification that shall be allowed for
76.Fa ctx .
77(See the
78.Sx BUGS
79section.)
80.Pp
81.Fn SSL_set_verify_depth
82sets the maximum
83.Fa depth
84for the certificate chain verification that shall be allowed for
85.Fa ssl .
86(See the
87.Sx BUGS
88section.)
89.Sh NOTES
90The verification of certificates can be controlled by a set of bitwise ORed
91.Fa mode
92flags:
93.Bl -tag -width Ds
94.It Dv SSL_VERIFY_NONE
95.Em Server mode:
96the server will not send a client certificate request to the client,
97so the client will not send a certificate.
98.Pp
99.Em Client mode:
100if not using an anonymous cipher (by default disabled),
101the server will send a certificate which will be checked.
102The result of the certificate verification process can be checked after the
103TLS/SSL handshake using the
104.Xr SSL_get_verify_result 3
105function.
106The handshake will be continued regardless of the verification result.
107.It Dv SSL_VERIFY_PEER
108.Em Server mode:
109the server sends a client certificate request to the client.
110The certificate returned (if any) is checked.
111If the verification process fails,
112the TLS/SSL handshake is immediately terminated with an alert message
113containing the reason for the verification failure.
114The behaviour can be controlled by the additional
115.Dv SSL_VERIFY_FAIL_IF_NO_PEER_CERT
116and
117.Dv SSL_VERIFY_CLIENT_ONCE
118flags.
119.Pp
120.Em Client mode:
121the server certificate is verified.
122If the verification process fails,
123the TLS/SSL handshake is immediately terminated with an alert message
124containing the reason for the verification failure.
125If no server certificate is sent, because an anonymous cipher is used,
126.Dv SSL_VERIFY_PEER
127is ignored.
128.It Dv SSL_VERIFY_FAIL_IF_NO_PEER_CERT
129.Em Server mode:
130if the client did not return a certificate, the TLS/SSL
131handshake is immediately terminated with a
132.Dq handshake failure
133alert.
134This flag must be used together with
135.Dv SSL_VERIFY_PEER.
136.Pp
137.Em Client mode:
138ignored
139.It Dv SSL_VERIFY_CLIENT_ONCE
140.Em Server mode:
141only request a client certificate on the initial TLS/SSL handshake.
142Do not ask for a client certificate again in case of a renegotiation.
143This flag must be used together with
144.Dv SSL_VERIFY_PEER .
145.Pp
146.Em Client mode:
147ignored
148.El
149.Pp
150Exactly one of the
151.Fa mode
152flags
153.Dv SSL_VERIFY_NONE
154and
155.Dv SSL_VERIFY_PEER
156must be set at any time.
157.Pp
158The actual verification procedure is performed either using the built-in
159verification procedure or using another application provided verification
160function set with
161.Xr SSL_CTX_set_cert_verify_callback 3 .
162The following descriptions apply in the case of the built-in procedure.
163An application provided procedure also has access to the verify depth
164information and the
165.Fa verify_callback Ns ()
166function, but the way this information is used may be different.
167.Pp
168.Fn SSL_CTX_set_verify_depth
169and
170.Fn SSL_set_verify_depth
171set the limit up to which depth certificates in a chain are used during the
172verification procedure.
173If the certificate chain is longer than allowed,
174the certificates above the limit are ignored.
175Error messages are generated as if these certificates would not be present,
176most likely a
177.Dv X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
178will be issued.
179The depth count is
180.Dq level 0: peer certificate ,
181.Dq level 1: CA certificate ,
182.Dq level 2: higher level CA certificate ,
183and so on.
184Setting the maximum depth to 2 allows the levels 0, 1, and 2.
185The default depth limit is 100,
186allowing for the peer certificate and an additional 100 CA certificates.
187.Pp
188The
189.Fa verify_callback
190function is used to control the behaviour when the
191.Dv SSL_VERIFY_PEER
192flag is set.
193It must be supplied by the application and receives two arguments:
194.Fa preverify_ok
195indicates whether the verification of the certificate in question was passed
196(preverify_ok=1) or not (preverify_ok=0).
197.Fa x509_ctx
198is a pointer to the complete context used
199for the certificate chain verification.
200.Pp
201The certificate chain is checked starting with the deepest nesting level
202(the root CA certificate) and worked upward to the peer's certificate.
203At each level signatures and issuer attributes are checked.
204Whenever a verification error is found, the error number is stored in
205.Fa x509_ctx
206and
207.Fa verify_callback
208is called with
209.Fa preverify_ok
210equal to 0.
211By applying
212.Fn X509_CTX_store_*
213functions
214.Fa verify_callback
215can locate the certificate in question and perform additional steps (see
216.Sx EXAMPLES ) .
217If no error is found for a certificate,
218.Fa verify_callback
219is called with
220.Fa preverify_ok
221equal to 1 before advancing to the next level.
222.Pp
223The return value of
224.Fa verify_callback
225controls the strategy of the further verification process.
226If
227.Fa verify_callback
228returns 0, the verification process is immediately stopped with
229.Dq verification failed
230state.
231If
232.Dv SSL_VERIFY_PEER
233is set, a verification failure alert is sent to the peer and the TLS/SSL
234handshake is terminated.
235If
236.Fa verify_callback
237returns 1, the verification process is continued.
238If
239.Fa verify_callback
240always returns 1,
241the TLS/SSL handshake will not be terminated with respect to verification
242failures and the connection will be established.
243The calling process can however retrieve the error code of the last
244verification error using
245.Xr SSL_get_verify_result 3
246or by maintaining its own error storage managed by
247.Fa verify_callback .
248.Pp
249If no
250.Fa verify_callback
251is specified, the default callback will be used.
252Its return value is identical to
253.Fa preverify_ok ,
254so that any verification
255failure will lead to a termination of the TLS/SSL handshake with an
256alert message, if
257.Dv SSL_VERIFY_PEER
258is set.
259.Sh RETURN VALUES
260The
261.Fn SSL*_set_verify*
262functions do not provide diagnostic information.
263.Sh EXAMPLES
264The following code sequence realizes an example
265.Fa verify_callback
266function that will always continue the TLS/SSL handshake regardless of
267verification failure, if wished.
268The callback realizes a verification depth limit with more informational output.
269.Pp
270All verification errors are printed;
271information about the certificate chain is printed on request.
272The example is realized for a server that does allow but not require client
273certificates.
274.Pp
275The example makes use of the ex_data technique to store application data
276into/retrieve application data from the
277.Vt SSL
278structure (see
279.Xr SSL_get_ex_new_index 3 ,
280.Xr SSL_get_ex_data_X509_STORE_CTX_idx 3 ) .
281.Bd -literal
282\&...
283
284typedef struct {
285 int verbose_mode;
286 int verify_depth;
287 int always_continue;
288} mydata_t;
289int mydata_index;
290\&...
291static int
292verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
293{
294 char buf[256];
295 X509 *err_cert;
296 int err, depth;
297 SSL *ssl;
298 mydata_t *mydata;
299
300 err_cert = X509_STORE_CTX_get_current_cert(ctx);
301 err = X509_STORE_CTX_get_error(ctx);
302 depth = X509_STORE_CTX_get_error_depth(ctx);
303
304 /*
305 * Retrieve the pointer to the SSL of the connection currently
306 * treated * and the application specific data stored into the
307 * SSL object.
308 */
309 ssl = X509_STORE_CTX_get_ex_data(ctx,
310 SSL_get_ex_data_X509_STORE_CTX_idx());
311 mydata = SSL_get_ex_data(ssl, mydata_index);
312
313 X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
314
315 /*
316 * Catch a too long certificate chain. The depth limit set using
317 * SSL_CTX_set_verify_depth() is by purpose set to "limit+1" so
318 * that whenever the "depth>verify_depth" condition is met, we
319 * have violated the limit and want to log this error condition.
320 * We must do it here, because the CHAIN_TOO_LONG error would not
321 * be found explicitly; only errors introduced by cutting off the
322 * additional certificates would be logged.
323 */
324 if (depth > mydata->verify_depth) {
325 preverify_ok = 0;
326 err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
327 X509_STORE_CTX_set_error(ctx, err);
328 }
329 if (!preverify_ok) {
330 printf("verify error:num=%d:%s:depth=%d:%s\en", err,
331 X509_verify_cert_error_string(err), depth, buf);
332 } else if (mydata->verbose_mode) {
333 printf("depth=%d:%s\en", depth, buf);
334 }
335
336 /*
337 * At this point, err contains the last verification error.
338 * We can use it for something special
339 */
340 if (!preverify_ok && (err ==
341 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)) {
342 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),
343 buf, 256);
344 printf("issuer= %s\en", buf);
345 }
346
347 if (mydata->always_continue)
348 return 1;
349 else
350 return preverify_ok;
351}
352\&...
353
354mydata_t mydata;
355
356\&...
357
358mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
359
360\&...
361
362SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
363 verify_callback);
364
365/*
366 * Let the verify_callback catch the verify_depth error so that we get
367 * an appropriate error in the logfile.
368 */
369SSL_CTX_set_verify_depth(verify_depth + 1);
370
371/*
372 * Set up the SSL specific data into "mydata" and store it into the SSL
373 * structure.
374 */
375mydata.verify_depth = verify_depth; ...
376SSL_set_ex_data(ssl, mydata_index, &mydata);
377
378\&...
379
380SSL_accept(ssl); /* check of success left out for clarity */
381if (peer = SSL_get_peer_certificate(ssl)) {
382 if (SSL_get_verify_result(ssl) == X509_V_OK) {
383 /* The client sent a certificate which verified OK */
384 }
385}
386.Ed
387.Sh SEE ALSO
388.Xr ssl 3 ,
389.Xr SSL_CTX_get_verify_mode 3 ,
390.Xr SSL_CTX_load_verify_locations 3 ,
391.Xr SSL_CTX_set_cert_verify_callback 3 ,
392.Xr SSL_get_ex_data_X509_STORE_CTX_idx 3 ,
393.Xr SSL_get_ex_new_index 3 ,
394.Xr SSL_get_peer_certificate 3 ,
395.Xr SSL_get_verify_result 3 ,
396.Xr SSL_new 3
397.Sh BUGS
398In client mode, it is not checked whether the
399.Dv SSL_VERIFY_PEER
400flag is set, but whether
401.Dv SSL_VERIFY_NONE
402is not set.
403This can lead to unexpected behaviour, if the
404.Dv SSL_VERIFY_PEER
405and
406.Dv SSL_VERIFY_NONE
407are not used as required (exactly one must be set at any time).
408.Pp
409The certificate verification depth set with
410.Fn SSL[_CTX]_verify_depth
411stops the verification at a certain depth.
412The error message produced will be that of an incomplete certificate chain and
413not
414.Dv X509_V_ERR_CERT_CHAIN_TOO_LONG
415as may be expected.