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