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