]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/BIO_f_ssl.3
Regen manual pages.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / BIO_f_ssl.3
1 .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "BIO_F_SSL 3"
132 .TH BIO_F_SSL 3 "2018-09-11" "1.1.1" "OpenSSL"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 BIO_do_handshake, BIO_f_ssl, BIO_set_ssl, BIO_get_ssl, BIO_set_ssl_mode, BIO_set_ssl_renegotiate_bytes, BIO_get_num_renegotiates, BIO_set_ssl_renegotiate_timeout, BIO_new_ssl, BIO_new_ssl_connect, BIO_new_buffer_ssl_connect, BIO_ssl_copy_session_id, BIO_ssl_shutdown \- SSL BIO
139 .SH "SYNOPSIS"
140 .IX Header "SYNOPSIS"
141 .Vb 2
142 \& #include <openssl/bio.h>
143 \& #include <openssl/ssl.h>
144 \&
145 \& const BIO_METHOD *BIO_f_ssl(void);
146 \&
147 \& long BIO_set_ssl(BIO *b, SSL *ssl, long c);
148 \& long BIO_get_ssl(BIO *b, SSL **sslp);
149 \& long BIO_set_ssl_mode(BIO *b, long client);
150 \& long BIO_set_ssl_renegotiate_bytes(BIO *b, long num);
151 \& long BIO_set_ssl_renegotiate_timeout(BIO *b, long seconds);
152 \& long BIO_get_num_renegotiates(BIO *b);
153 \&
154 \& BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
155 \& BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
156 \& BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
157 \& int BIO_ssl_copy_session_id(BIO *to, BIO *from);
158 \& void BIO_ssl_shutdown(BIO *bio);
159 \&
160 \& long BIO_do_handshake(BIO *b);
161 .Ve
162 .SH "DESCRIPTION"
163 .IX Header "DESCRIPTION"
164 \&\fIBIO_f_ssl()\fR returns the \s-1SSL BIO\s0 method. This is a filter \s-1BIO\s0 which
165 is a wrapper round the OpenSSL \s-1SSL\s0 routines adding a \s-1BIO\s0 \*(L"flavour\*(R" to
166 \&\s-1SSL I/O.\s0
167 .PP
168 I/O performed on an \s-1SSL BIO\s0 communicates using the \s-1SSL\s0 protocol with
169 the SSLs read and write BIOs. If an \s-1SSL\s0 connection is not established
170 then an attempt is made to establish one on the first I/O call.
171 .PP
172 If a \s-1BIO\s0 is appended to an \s-1SSL BIO\s0 using \fIBIO_push()\fR it is automatically
173 used as the \s-1SSL\s0 BIOs read and write BIOs.
174 .PP
175 Calling \fIBIO_reset()\fR on an \s-1SSL BIO\s0 closes down any current \s-1SSL\s0 connection
176 by calling \fISSL_shutdown()\fR. \fIBIO_reset()\fR is then sent to the next \s-1BIO\s0 in
177 the chain: this will typically disconnect the underlying transport.
178 The \s-1SSL BIO\s0 is then reset to the initial accept or connect state.
179 .PP
180 If the close flag is set when an \s-1SSL BIO\s0 is freed then the internal
181 \&\s-1SSL\s0 structure is also freed using \fISSL_free()\fR.
182 .PP
183 \&\fIBIO_set_ssl()\fR sets the internal \s-1SSL\s0 pointer of \s-1BIO\s0 \fBb\fR to \fBssl\fR using
184 the close flag \fBc\fR.
185 .PP
186 \&\fIBIO_get_ssl()\fR retrieves the \s-1SSL\s0 pointer of \s-1BIO\s0 \fBb\fR, it can then be
187 manipulated using the standard \s-1SSL\s0 library functions.
188 .PP
189 \&\fIBIO_set_ssl_mode()\fR sets the \s-1SSL BIO\s0 mode to \fBclient\fR. If \fBclient\fR
190 is 1 client mode is set. If \fBclient\fR is 0 server mode is set.
191 .PP
192 \&\fIBIO_set_ssl_renegotiate_bytes()\fR sets the renegotiate byte count
193 to \fBnum\fR. When set after every \fBnum\fR bytes of I/O (read and write)
194 the \s-1SSL\s0 session is automatically renegotiated. \fBnum\fR must be at
195 least 512 bytes.
196 .PP
197 \&\fIBIO_set_ssl_renegotiate_timeout()\fR sets the renegotiate timeout to
198 \&\fBseconds\fR. When the renegotiate timeout elapses the session is
199 automatically renegotiated.
200 .PP
201 \&\fIBIO_get_num_renegotiates()\fR returns the total number of session
202 renegotiations due to I/O or timeout.
203 .PP
204 \&\fIBIO_new_ssl()\fR allocates an \s-1SSL BIO\s0 using \s-1SSL_CTX\s0 \fBctx\fR and using
205 client mode if \fBclient\fR is non zero.
206 .PP
207 \&\fIBIO_new_ssl_connect()\fR creates a new \s-1BIO\s0 chain consisting of an
208 \&\s-1SSL BIO\s0 (using \fBctx\fR) followed by a connect \s-1BIO.\s0
209 .PP
210 \&\fIBIO_new_buffer_ssl_connect()\fR creates a new \s-1BIO\s0 chain consisting
211 of a buffering \s-1BIO,\s0 an \s-1SSL BIO\s0 (using \fBctx\fR) and a connect
212 \&\s-1BIO.\s0
213 .PP
214 \&\fIBIO_ssl_copy_session_id()\fR copies an \s-1SSL\s0 session id between
215 \&\s-1BIO\s0 chains \fBfrom\fR and \fBto\fR. It does this by locating the
216 \&\s-1SSL\s0 BIOs in each chain and calling \fISSL_copy_session_id()\fR on
217 the internal \s-1SSL\s0 pointer.
218 .PP
219 \&\fIBIO_ssl_shutdown()\fR closes down an \s-1SSL\s0 connection on \s-1BIO\s0
220 chain \fBbio\fR. It does this by locating the \s-1SSL BIO\s0 in the
221 chain and calling \fISSL_shutdown()\fR on its internal \s-1SSL\s0
222 pointer.
223 .PP
224 \&\fIBIO_do_handshake()\fR attempts to complete an \s-1SSL\s0 handshake on the
225 supplied \s-1BIO\s0 and establish the \s-1SSL\s0 connection. It returns 1
226 if the connection was established successfully. A zero or negative
227 value is returned if the connection could not be established, the
228 call \fIBIO_should_retry()\fR should be used for non blocking connect BIOs
229 to determine if the call should be retried. If an \s-1SSL\s0 connection has
230 already been established this call has no effect.
231 .SH "NOTES"
232 .IX Header "NOTES"
233 \&\s-1SSL\s0 BIOs are exceptional in that if the underlying transport
234 is non blocking they can still request a retry in exceptional
235 circumstances. Specifically this will happen if a session
236 renegotiation takes place during a \fIBIO_read_ex()\fR operation, one
237 case where this happens is when step up occurs.
238 .PP
239 The \s-1SSL\s0 flag \s-1SSL_AUTO_RETRY\s0 can be
240 set to disable this behaviour. That is when this flag is set
241 an \s-1SSL BIO\s0 using a blocking transport will never request a
242 retry.
243 .PP
244 Since unknown \fIBIO_ctrl()\fR operations are sent through filter
245 BIOs the servers name and port can be set using \fIBIO_set_host()\fR
246 on the \s-1BIO\s0 returned by \fIBIO_new_ssl_connect()\fR without having
247 to locate the connect \s-1BIO\s0 first.
248 .PP
249 Applications do not have to call \fIBIO_do_handshake()\fR but may wish
250 to do so to separate the handshake process from other I/O
251 processing.
252 .PP
253 \&\fIBIO_set_ssl()\fR, \fIBIO_get_ssl()\fR, \fIBIO_set_ssl_mode()\fR,
254 \&\fIBIO_set_ssl_renegotiate_bytes()\fR, \fIBIO_set_ssl_renegotiate_timeout()\fR,
255 \&\fIBIO_get_num_renegotiates()\fR, and \fIBIO_do_handshake()\fR are implemented as macros.
256 .SH "EXAMPLE"
257 .IX Header "EXAMPLE"
258 This \s-1SSL/TLS\s0 client example, attempts to retrieve a page from an
259 \&\s-1SSL/TLS\s0 web server. The I/O routines are identical to those of the
260 unencrypted example in \fIBIO_s_connect\fR\|(3).
261 .PP
262 .Vb 5
263 \& BIO *sbio, *out;
264 \& int len;
265 \& char tmpbuf[1024];
266 \& SSL_CTX *ctx;
267 \& SSL *ssl;
268 \&
269 \& /* XXX Seed the PRNG if needed. */
270 \&
271 \& ctx = SSL_CTX_new(TLS_client_method());
272 \&
273 \& /* XXX Set verify paths and mode here. */
274 \&
275 \& sbio = BIO_new_ssl_connect(ctx);
276 \& BIO_get_ssl(sbio, &ssl);
277 \& if (ssl == NULL) {
278 \&     fprintf(stderr, "Can\*(Aqt locate SSL pointer\en");
279 \&     ERR_print_errors_fp(stderr);
280 \&     exit(1);
281 \& }
282 \&
283 \& /* Don\*(Aqt want any retries */
284 \& SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
285 \&
286 \& /* XXX We might want to do other things with ssl here */
287 \&
288 \& /* An empty host part means the loopback address */
289 \& BIO_set_conn_hostname(sbio, ":https");
290 \&
291 \& out = BIO_new_fp(stdout, BIO_NOCLOSE);
292 \& if (BIO_do_connect(sbio) <= 0) {
293 \&     fprintf(stderr, "Error connecting to server\en");
294 \&     ERR_print_errors_fp(stderr);
295 \&     exit(1);
296 \& }
297 \& if (BIO_do_handshake(sbio) <= 0) {
298 \&     fprintf(stderr, "Error establishing SSL connection\en");
299 \&     ERR_print_errors_fp(stderr);
300 \&     exit(1);
301 \& }
302 \&
303 \& /* XXX Could examine ssl here to get connection info */
304 \&
305 \& BIO_puts(sbio, "GET / HTTP/1.0\en\en");
306 \& for (;;) {
307 \&     len = BIO_read(sbio, tmpbuf, 1024);
308 \&     if (len <= 0)
309 \&         break;
310 \&     BIO_write(out, tmpbuf, len);
311 \& }
312 \& BIO_free_all(sbio);
313 \& BIO_free(out);
314 .Ve
315 .PP
316 Here is a simple server example. It makes use of a buffering
317 \&\s-1BIO\s0 to allow lines to be read from the \s-1SSL BIO\s0 using BIO_gets.
318 It creates a pseudo web page containing the actual request from
319 a client and also echoes the request to standard output.
320 .PP
321 .Vb 5
322 \& BIO *sbio, *bbio, *acpt, *out;
323 \& int len;
324 \& char tmpbuf[1024];
325 \& SSL_CTX *ctx;
326 \& SSL *ssl;
327 \&
328 \& /* XXX Seed the PRNG if needed. */
329 \&
330 \& ctx = SSL_CTX_new(TLS_server_method());
331 \& if (!SSL_CTX_use_certificate_file(ctx, "server.pem", SSL_FILETYPE_PEM)
332 \&         || !SSL_CTX_use_PrivateKey_file(ctx, "server.pem", SSL_FILETYPE_PEM)
333 \&         || !SSL_CTX_check_private_key(ctx)) {
334 \&     fprintf(stderr, "Error setting up SSL_CTX\en");
335 \&     ERR_print_errors_fp(stderr);
336 \&     exit(1);
337 \& }
338 \&
339 \& /* XXX Other things like set verify locations, EDH temp callbacks. */
340 \&
341 \& /* New SSL BIO setup as server */
342 \& sbio = BIO_new_ssl(ctx, 0);
343 \& BIO_get_ssl(sbio, &ssl);
344 \& if (ssl == NULL) {
345 \&     fprintf(stderr, "Can\*(Aqt locate SSL pointer\en");
346 \&     ERR_print_errors_fp(stderr);
347 \&     exit(1);
348 \& }
349 \&
350 \& SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
351 \& bbio = BIO_new(BIO_f_buffer());
352 \& sbio = BIO_push(bbio, sbio);
353 \& acpt = BIO_new_accept("4433");
354 \&
355 \& /*
356 \&  * By doing this when a new connection is established
357 \&  * we automatically have sbio inserted into it. The
358 \&  * BIO chain is now \*(Aqswallowed\*(Aq by the accept BIO and
359 \&  * will be freed when the accept BIO is freed.
360 \&  */
361 \& BIO_set_accept_bios(acpt, sbio);
362 \& out = BIO_new_fp(stdout, BIO_NOCLOSE);
363 \&
364 \& /* Setup accept BIO */
365 \& if (BIO_do_accept(acpt) <= 0) {
366 \&     fprintf(stderr, "Error setting up accept BIO\en");
367 \&     ERR_print_errors_fp(stderr);
368 \&     exit(1);
369 \& }
370 \&
371 \& /* We only want one connection so remove and free accept BIO */
372 \& sbio = BIO_pop(acpt);
373 \& BIO_free_all(acpt);
374 \&
375 \& if (BIO_do_handshake(sbio) <= 0) {
376 \&     fprintf(stderr, "Error in SSL handshake\en");
377 \&     ERR_print_errors_fp(stderr);
378 \&     exit(1);
379 \& }
380 \&
381 \& BIO_puts(sbio, "HTTP/1.0 200 OK\er\enContent\-type: text/plain\er\en\er\en");
382 \& BIO_puts(sbio, "\er\enConnection Established\er\enRequest headers:\er\en");
383 \& BIO_puts(sbio, "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\er\en");
384 \&
385 \& for (;;) {
386 \&     len = BIO_gets(sbio, tmpbuf, 1024);
387 \&     if (len <= 0)
388 \&         break;
389 \&     BIO_write(sbio, tmpbuf, len);
390 \&     BIO_write(out, tmpbuf, len);
391 \&     /* Look for blank line signifying end of headers*/
392 \&     if (tmpbuf[0] == \*(Aq\er\*(Aq || tmpbuf[0] == \*(Aq\en\*(Aq)
393 \&         break;
394 \& }
395 \&
396 \& BIO_puts(sbio, "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\er\en");
397 \& BIO_puts(sbio, "\er\en");
398 \& BIO_flush(sbio);
399 \& BIO_free_all(sbio);
400 .Ve
401 .SH "RETURN VALUES"
402 .IX Header "RETURN VALUES"
403 \&\fIBIO_f_ssl()\fR returns the \s-1SSL\s0 \fB\s-1BIO_METHOD\s0\fR structure.
404 .PP
405 \&\fIBIO_set_ssl()\fR, \fIBIO_get_ssl()\fR, \fIBIO_set_ssl_mode()\fR, \fIBIO_set_ssl_renegotiate_bytes()\fR,
406 \&\fIBIO_set_ssl_renegotiate_timeout()\fR and \fIBIO_get_num_renegotiates()\fR return 1 on
407 success or a value which is less than or equal to 0 if an error occurred.
408 .PP
409 \&\fIBIO_new_ssl()\fR, \fIBIO_new_ssl_connect()\fR and \fIBIO_new_buffer_ssl_connect()\fR return
410 a valid \fB\s-1BIO\s0\fR structure on success or \fB\s-1NULL\s0\fR if an error occurred.
411 .PP
412 \&\fIBIO_ssl_copy_session_id()\fR returns 1 on success or 0 on error.
413 .PP
414 \&\fIBIO_do_handshake()\fR returns 1 if the connection was established successfully.
415 A zero or negative value is returned if the connection could not be established.
416 .SH "HISTORY"
417 .IX Header "HISTORY"
418 In OpenSSL before 1.0.0 the \fIBIO_pop()\fR call was handled incorrectly,
419 the I/O \s-1BIO\s0 reference count was incorrectly incremented (instead of
420 decremented) and dissociated with the \s-1SSL BIO\s0 even if the \s-1SSL BIO\s0 was not
421 explicitly being popped (e.g. a pop higher up the chain). Applications which
422 included workarounds for this bug (e.g. freeing BIOs more than once) should
423 be modified to handle this fix or they may free up an already freed \s-1BIO.\s0
424 .SH "COPYRIGHT"
425 .IX Header "COPYRIGHT"
426 Copyright 2000\-2018 The OpenSSL Project Authors. All Rights Reserved.
427 .PP
428 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
429 this file except in compliance with the License.  You can obtain a copy
430 in the file \s-1LICENSE\s0 in the source distribution or at
431 <https://www.openssl.org/source/license.html>.