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