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