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