summaryrefslogtreecommitdiff
path: root/src/lib/libssl/doc/BIO_f_ssl.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/doc/BIO_f_ssl.3')
-rw-r--r--src/lib/libssl/doc/BIO_f_ssl.3475
1 files changed, 475 insertions, 0 deletions
diff --git a/src/lib/libssl/doc/BIO_f_ssl.3 b/src/lib/libssl/doc/BIO_f_ssl.3
new file mode 100644
index 0000000000..31c9963edb
--- /dev/null
+++ b/src/lib/libssl/doc/BIO_f_ssl.3
@@ -0,0 +1,475 @@
1.Dd $Mdocdate: October 12 2014 $
2.Dt BIO_F_SSL 3
3.Os
4.Sh NAME
5.Nm BIO_f_ssl ,
6.Nm BIO_set_ssl ,
7.Nm BIO_get_ssl ,
8.Nm BIO_set_ssl_mode ,
9.Nm BIO_set_ssl_renegotiate_bytes ,
10.Nm BIO_get_num_renegotiates ,
11.Nm BIO_set_ssl_renegotiate_timeout ,
12.Nm BIO_new_ssl ,
13.Nm BIO_new_ssl_connect ,
14.Nm BIO_new_buffer_ssl_connect ,
15.Nm BIO_ssl_copy_session_id ,
16.Nm BIO_ssl_shutdown
17.Nd SSL BIO
18.Sh SYNOPSIS
19.In openssl/bio.h
20.In openssl/ssl.h
21.Ft BIO_METHOD *
22.Fn BIO_f_ssl void
23.Fd #define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
24.Fd #define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
25.Fd #define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
26.Fd #define BIO_set_ssl_renegotiate_bytes(b,num) \
27BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL)
28.Fd #define BIO_set_ssl_renegotiate_timeout(b,seconds) \
29BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL)
30.Fd #define BIO_get_num_renegotiates(b) \
31BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL)
32.Ft BIO *
33.Fn BIO_new_ssl "SSL_CTX *ctx" "int client"
34.Ft BIO *
35.Fn BIO_new_ssl_connect "SSL_CTX *ctx"
36.Ft BIO *
37.Fn BIO_new_buffer_ssl_connect "SSL_CTX *ctx"
38.Ft int
39.Fn BIO_ssl_copy_session_id "BIO *to" "BIO *from"
40.Ft void
41.Fn BIO_ssl_shutdown "BIO *bio"
42.Fd #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
43.Sh DESCRIPTION
44.Fn BIO_f_ssl
45returns the
46.Vt SSL
47.Vt BIO
48method.
49This is a filter
50.Vt BIO
51which is a wrapper around the OpenSSL
52.Vt SSL
53routines adding a
54.Vt BIO
55.Dq flavor
56to SSL I/O.
57.Pp
58I/O performed on an
59.Vt SSL
60.Vt BIO
61communicates using the SSL protocol with
62the
63.Vt SSL Ns 's
64read and write
65.Vt BIO Ns s.
66If an SSL connection is not established then an attempt is made to establish
67one on the first I/O call.
68.Pp
69If a
70.Vt BIO
71is appended to an
72.Vt SSL
73.Vt BIO
74using
75.Xr BIO_push 3
76it is automatically used as the
77.Vt SSL
78.Vt BIO Ns 's read and write
79.Vt BIO Ns s.
80.Pp
81Calling
82.Xr BIO_reset 3
83on an
84.Vt SSL
85.Vt BIO
86closes down any current SSL connection by calling
87.Xr SSL_shutdown 3 .
88.Xr BIO_reset
89is then sent to the next
90.Vt BIO
91in the chain; this will typically disconnect the underlying transport.
92The
93.Vt SSL
94.Vt BIO
95is then reset to the initial accept or connect state.
96.Pp
97If the close flag is set when an
98.Vt SSL
99.Vt BIO
100is freed then the internal
101.Vt SSL
102structure is also freed using
103.Xr SSL_free 3 .
104.Pp
105.Fn BIO_set_ssl
106sets the internal
107.Vt SSL
108pointer of
109.Vt BIO
110.Fa b
111to
112.Fa ssl
113using
114the close flag
115.Fa c .
116.Pp
117.Fn BIO_get_ssl
118retrieves the
119.Vt SSL
120pointer of
121.Vt BIO
122.Fa b ;
123it can then be manipulated using the standard SSL library functions.
124.Pp
125.Fn BIO_set_ssl_mode
126sets the
127.Vt SSL
128.Vt BIO
129mode to
130.Fa client .
131If
132.Fa client
133is 1, client mode is set.
134If
135.Fa client
136is 0, server mode is set.
137.Pp
138.Fn BIO_set_ssl_renegotiate_bytes
139sets the renegotiate byte count to
140.Fa num .
141When set after every
142.Fa num
143bytes of I/O (read and write) the SSL session is automatically renegotiated.
144.Fa num
145must be at least 512 bytes.
146.Pp
147.Fn BIO_set_ssl_renegotiate_timeout
148sets the renegotiate timeout to
149.Fa seconds .
150When the renegotiate timeout elapses the session is automatically renegotiated.
151.Pp
152.Fn BIO_get_num_renegotiates
153returns the total number of session renegotiations due to I/O or timeout.
154.Pp
155.Fn BIO_new_ssl
156allocates an
157.Vt SSL
158.Vt BIO
159using
160.Vt SSL_CTX
161.Va ctx
162and using client mode if
163.Fa client
164is nonzero.
165.Pp
166.Fn BIO_new_ssl_connect
167creates a new
168.Vt BIO
169chain consisting of an
170.Vt SSL
171.Vt BIO
172(using
173.Fa ctx )
174followed by a connect BIO.
175.Pp
176.Fn BIO_new_buffer_ssl_connect
177creates a new
178.Vt BIO
179chain consisting of a buffering
180.Vt BIO ,
181an
182.Vt SSL
183.Vt BIO
184(using
185.Fa ctx )
186and a connect
187.Vt BIO .
188.Pp
189.Fn BIO_ssl_copy_session_id
190copies an SSL session id between
191.Vt BIO
192chains
193.Fa from
194and
195.Fa to .
196It does this by locating the
197.Vt SSL
198.Vt BIO Ns s
199in each chain and calling
200.Xr SSL_copy_session_id 3
201on the internal
202.Vt SSL
203pointer.
204.Pp
205.Fn BIO_ssl_shutdown
206closes down an SSL connection on
207.Vt BIO
208chain
209.Fa bio .
210It does this by locating the
211.Vt SSL
212.Vt BIO
213in the
214chain and calling
215.Xr SSL_shutdown 3
216on its internal
217.Vt SSL
218pointer.
219.Pp
220.Fn BIO_do_handshake
221attempts to complete an SSL handshake on the supplied
222.Vt BIO
223and establish the SSL connection.
224It returns 1 if the connection was established successfully.
225A zero or negative value is returned if the connection could not be
226established; the call
227.Xr BIO_should_retry 3
228should be used for non blocking connect
229.Vt BIO Ns s
230to determine if the call should be retried.
231If an SSL connection has already been established this call has no effect.
232.Sh NOTES
233.Vt SSL
234.Vt BIO Ns s
235are exceptional in that if the underlying transport is non-blocking they can
236still request a retry in exceptional circumstances.
237Specifically this will happen if a session renegotiation takes place during a
238.Xr BIO_read 3
239operation.
240One case where this happens is when SGC or step up occurs.
241.Pp
242In OpenSSL 0.9.6 and later the SSL flag
243.Dv SSL_AUTO_RETRY
244can be set to disable this behaviour.
245In other words, when this flag is set an
246.Vt SSL
247.Vt BIO
248using a blocking transport will never request a retry.
249.Pp
250Since unknown
251.Xr BIO_ctrl 3
252operations are sent through filter
253.Vt BIO Ns s
254the server name and port can be set using
255.Xr BIO_set_host 3
256on the
257.Vt BIO
258returned by
259.Fn BIO_new_ssl_connect
260without having to locate the connect
261.Vt BIO
262first.
263.Pp
264Applications do not have to call
265.Fn BIO_do_handshake
266but may wish to do so to separate the handshake process from other I/O
267processing.
268.Sh RETURN VALUES
269.\" XXX
270This section is incomplete.
271.Sh EXAMPLE
272This SSL/TLS client example attempts to retrieve a page from an SSL/TLS web
273server.
274The I/O routines are identical to those of the unencrypted example in
275.Xr BIO_s_connect 3 .
276.Bd -literal
277BIO *sbio, *out;
278int len;
279char tmpbuf[1024];
280SSL_CTX *ctx;
281SSL *ssl;
282
283ERR_load_crypto_strings();
284ERR_load_SSL_strings();
285OpenSSL_add_all_algorithms();
286
287/*
288 * We would seed the PRNG here if the platform didn't do it automatically
289 */
290
291ctx = SSL_CTX_new(SSLv23_client_method());
292
293/*
294 * We'd normally set some stuff like the verify paths and mode here because
295 * as things stand this will connect to any server whose certificate is
296 * signed by any CA.
297 */
298
299sbio = BIO_new_ssl_connect(ctx);
300
301BIO_get_ssl(sbio, &ssl);
302
303if (!ssl) {
304 fprintf(stderr, "Can't locate SSL pointer\en");
305 /* whatever ... */
306}
307
308/* Don't want any retries */
309SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
310
311/* We might want to do other things with ssl here */
312
313BIO_set_conn_hostname(sbio, "localhost:https");
314
315out = BIO_new_fp(stdout, BIO_NOCLOSE);
316if (BIO_do_connect(sbio) <= 0) {
317 fprintf(stderr, "Error connecting to server\en");
318 ERR_print_errors_fp(stderr);
319 /* whatever ... */
320}
321
322if (BIO_do_handshake(sbio) <= 0) {
323 fprintf(stderr, "Error establishing SSL connection\en");
324 ERR_print_errors_fp(stderr);
325 /* whatever ... */
326}
327
328/* Could examine ssl here to get connection info */
329
330BIO_puts(sbio, "GET / HTTP/1.0\en\en");
331for (;;) {
332 len = BIO_read(sbio, tmpbuf, 1024);
333 if(len <= 0) break;
334 BIO_write(out, tmpbuf, len);
335}
336BIO_free_all(sbio);
337BIO_free(out);
338.Ed
339.Pp
340Here is a simple server example.
341It makes use of a buffering
342.Vt BIO
343to allow lines to be read from the
344.Vt SSL
345.Vt BIO
346using
347.Xr BIO_gets 3 .
348It creates a pseudo web page containing the actual request from a client and
349also echoes the request to standard output.
350.Bd -literal
351BIO *sbio, *bbio, *acpt, *out;
352int len;
353char tmpbuf[1024];
354SSL_CTX *ctx;
355SSL *ssl;
356
357ERR_load_crypto_strings();
358ERR_load_SSL_strings();
359OpenSSL_add_all_algorithms();
360
361/* Might seed PRNG here */
362
363ctx = SSL_CTX_new(SSLv23_server_method());
364
365if (!SSL_CTX_use_certificate_file(ctx,"server.pem",SSL_FILETYPE_PEM)
366 || !SSL_CTX_use_PrivateKey_file(ctx,"server.pem",SSL_FILETYPE_PEM)
367 || !SSL_CTX_check_private_key(ctx)) {
368 fprintf(stderr, "Error setting up SSL_CTX\en");
369 ERR_print_errors_fp(stderr);
370 return 0;
371}
372
373/*
374 * Might do other things here like setting verify locations and DH and/or
375 * RSA temporary key callbacks
376 */
377
378/* New SSL BIO setup as server */
379sbio = BIO_new_ssl(ctx,0);
380
381BIO_get_ssl(sbio, &ssl);
382
383if (!ssl) {
384 fprintf(stderr, "Can't locate SSL pointer\en");
385 /* whatever ... */
386}
387
388/* Don't want any retries */
389SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
390
391/* Create the buffering BIO */
392
393bbio = BIO_new(BIO_f_buffer());
394
395/* Add to chain */
396sbio = BIO_push(bbio, sbio);
397
398acpt = BIO_new_accept("4433");
399
400/*
401 * By doing this when a new connection is established we automatically
402 * have sbio inserted into it. The BIO chain is now 'swallowed' by the
403 * accept BIO and will be freed when the accept BIO is freed.
404 */
405
406BIO_set_accept_bios(acpt,sbio);
407
408out = BIO_new_fp(stdout, BIO_NOCLOSE);
409
410/* Setup accept BIO */
411if (BIO_do_accept(acpt) <= 0) {
412 fprintf(stderr, "Error setting up accept BIO\en");
413 ERR_print_errors_fp(stderr);
414 return 0;
415}
416
417/* Now wait for incoming connection */
418if (BIO_do_accept(acpt) <= 0) {
419 fprintf(stderr, "Error in connection\en");
420 ERR_print_errors_fp(stderr);
421 return 0;
422}
423
424/* We only want one connection so remove and free accept BIO */
425
426sbio = BIO_pop(acpt);
427
428BIO_free_all(acpt);
429
430if (BIO_do_handshake(sbio) <= 0) {
431 fprintf(stderr, "Error in SSL handshake\en");
432 ERR_print_errors_fp(stderr);
433 return 0;
434}
435
436BIO_puts(sbio, "HTTP/1.0 200 OK\er\enContent-type: text/plain\er\en\er\en");
437BIO_puts(sbio, "\er\enConnection Established\er\enRequest headers:\er\en");
438BIO_puts(sbio, "--------------------------------------------------\er\en");
439
440for (;;) {
441 len = BIO_gets(sbio, tmpbuf, 1024);
442 if (len <= 0)
443 break;
444 BIO_write(sbio, tmpbuf, len);
445 BIO_write(out, tmpbuf, len);
446 /* Look for blank line signifying end of headers */
447 if ((tmpbuf[0] == '\er') || (tmpbuf[0] == '\en'))
448 break;
449}
450
451BIO_puts(sbio, "--------------------------------------------------\er\en");
452BIO_puts(sbio, "\er\en");
453
454/* Since there is a buffering BIO present we had better flush it */
455BIO_flush(sbio);
456
457BIO_free_all(sbio);
458.Ed
459.Sh BUGS
460In OpenSSL versions before 1.0.0 the
461.Xr BIO_pop 3
462call was handled incorrectly:
463the I/O BIO reference count was incorrectly incremented (instead of
464decremented) and dissociated with the
465.Vt SSL
466.Vt BIO
467even if the
468.Vt SSL
469.Vt BIO
470was not
471explicitly being popped (e.g., a pop higher up the chain).
472Applications which included workarounds for this bug (e.g., freeing BIOs more
473than once) should be modified to handle this fix or they may free up an already
474freed
475.Vt BIO .