diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libtls/tls_init.3 | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/src/lib/libtls/tls_init.3 b/src/lib/libtls/tls_init.3 index d321768755..70493fae03 100644 --- a/src/lib/libtls/tls_init.3 +++ b/src/lib/libtls/tls_init.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: tls_init.3,v 1.28 2015/09/10 11:00:54 beck Exp $ | 1 | .\" $OpenBSD: tls_init.3,v 1.29 2015/09/10 11:21:08 jsing Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
| 4 | .\" | 4 | .\" |
| @@ -46,7 +46,6 @@ | |||
| 46 | .Nm tls_server , | 46 | .Nm tls_server , |
| 47 | .Nm tls_configure , | 47 | .Nm tls_configure , |
| 48 | .Nm tls_reset , | 48 | .Nm tls_reset , |
| 49 | .Nm tls_close , | ||
| 50 | .Nm tls_free , | 49 | .Nm tls_free , |
| 51 | .Nm tls_connect , | 50 | .Nm tls_connect , |
| 52 | .Nm tls_connect_fds , | 51 | .Nm tls_connect_fds , |
| @@ -54,8 +53,10 @@ | |||
| 54 | .Nm tls_connect_socket , | 53 | .Nm tls_connect_socket , |
| 55 | .Nm tls_accept_fds , | 54 | .Nm tls_accept_fds , |
| 56 | .Nm tls_accept_socket , | 55 | .Nm tls_accept_socket , |
| 56 | .Nm tls_handshake , | ||
| 57 | .Nm tls_read , | 57 | .Nm tls_read , |
| 58 | .Nm tls_write | 58 | .Nm tls_write , |
| 59 | .Nm tls_close | ||
| 59 | .Nd TLS client and server API | 60 | .Nd TLS client and server API |
| 60 | .Sh SYNOPSIS | 61 | .Sh SYNOPSIS |
| 61 | .In tls.h | 62 | .In tls.h |
| @@ -115,8 +116,6 @@ | |||
| 115 | .Fn tls_configure "struct tls *ctx" "struct tls_config *config" | 116 | .Fn tls_configure "struct tls *ctx" "struct tls_config *config" |
| 116 | .Ft "void" | 117 | .Ft "void" |
| 117 | .Fn tls_reset "struct tls *ctx" | 118 | .Fn tls_reset "struct tls *ctx" |
| 118 | .Ft "int" | ||
| 119 | .Fn tls_close "struct tls *ctx" | ||
| 120 | .Ft "void" | 119 | .Ft "void" |
| 121 | .Fn tls_free "struct tls *ctx" | 120 | .Fn tls_free "struct tls *ctx" |
| 122 | .Ft "int" | 121 | .Ft "int" |
| @@ -131,9 +130,13 @@ | |||
| 131 | .Ft "int" | 130 | .Ft "int" |
| 132 | .Fn tls_accept_socket "struct tls *tls" "struct tls **cctx" "int socket" | 131 | .Fn tls_accept_socket "struct tls *tls" "struct tls **cctx" "int socket" |
| 133 | .Ft "int" | 132 | .Ft "int" |
| 133 | .Fn tls_handshake "struct tls *ctx" | ||
| 134 | .Ft "int" | ||
| 134 | .Fn tls_read "struct tls *ctx" "void *buf" "size_t buflen" "size_t *outlen" | 135 | .Fn tls_read "struct tls *ctx" "void *buf" "size_t buflen" "size_t *outlen" |
| 135 | .Ft "int" | 136 | .Ft "int" |
| 136 | .Fn tls_write "struct tls *ctx" "const void *buf" "size_t buflen" "size_t *outlen" | 137 | .Fn tls_write "struct tls *ctx" "const void *buf" "size_t buflen" "size_t *outlen" |
| 138 | .Ft "int" | ||
| 139 | .Fn tls_close "struct tls *ctx" | ||
| 137 | .Sh DESCRIPTION | 140 | .Sh DESCRIPTION |
| 138 | The | 141 | The |
| 139 | .Nm tls | 142 | .Nm tls |
| @@ -193,10 +196,14 @@ Alternatively, a new client connection can be accepted over a pair of existing | |||
| 193 | file descriptors by calling | 196 | file descriptors by calling |
| 194 | .Fn tls_accept_fds . | 197 | .Fn tls_accept_fds . |
| 195 | .Pp | 198 | .Pp |
| 199 | The TLS handshake can be completed by calling | ||
| 200 | .Fn tls_handshake . | ||
| 196 | Two functions are provided for input and output, | 201 | Two functions are provided for input and output, |
| 197 | .Fn tls_read | 202 | .Fn tls_read |
| 198 | and | 203 | and |
| 199 | .Fn tls_write . | 204 | .Fn tls_write . |
| 205 | Both of these functions will result in the TLS handshake being performed if it | ||
| 206 | has not already completed. | ||
| 200 | .Pp | 207 | .Pp |
| 201 | After use, a tls | 208 | After use, a tls |
| 202 | .Em context | 209 | .Em context |
| @@ -351,13 +358,6 @@ creates a new tls context for server connections. | |||
| 351 | readies a tls context for use by applying the configuration | 358 | readies a tls context for use by applying the configuration |
| 352 | options. | 359 | options. |
| 353 | .It | 360 | .It |
| 354 | .Fn tls_close | ||
| 355 | closes a connection after use. | ||
| 356 | If the connection was established using | ||
| 357 | .Fn tls_connect_fds , | ||
| 358 | only the TLS layer will be closed and it is the caller's responsibility to close | ||
| 359 | the file descriptors. | ||
| 360 | .It | ||
| 361 | .Fn tls_free | 361 | .Fn tls_free |
| 362 | frees a tls context after use. | 362 | frees a tls context after use. |
| 363 | .El | 363 | .El |
| @@ -385,20 +385,23 @@ creates a new context suitable for reading and writing on an existing pair of | |||
| 385 | file descriptors and returns it in | 385 | file descriptors and returns it in |
| 386 | .Fa *cctx . | 386 | .Fa *cctx . |
| 387 | A configured server context should be passed in | 387 | A configured server context should be passed in |
| 388 | .Fa ctx | 388 | .Fa ctx . |
| 389 | and | ||
| 390 | .Fa *cctx | ||
| 391 | should be initialized to NULL. | ||
| 392 | .It | 389 | .It |
| 393 | .Fn tls_accept_socket | 390 | .Fn tls_accept_socket |
| 394 | creates a new context suitable for reading and writing on an already | 391 | creates a new context suitable for reading and writing on an already |
| 395 | established socket connection and returns it in | 392 | established socket connection and returns it in |
| 396 | .Fa *cctx . | 393 | .Fa *cctx . |
| 397 | A configured server context should be passed in | 394 | A configured server context should be passed in |
| 398 | .Fa ctx | 395 | .Fa ctx . |
| 396 | .It | ||
| 397 | .Fn tls_handshake | ||
| 398 | performs the TLS handshake. | ||
| 399 | It is only neccessary to call this function if you need to guarantee that the | ||
| 400 | handshake has completed, as both | ||
| 401 | .Fn tls_read | ||
| 399 | and | 402 | and |
| 400 | .Fa *cctx | 403 | .Fn tls_write |
| 401 | should be initialized to NULL. | 404 | will perform the TLS handshake if necessary. |
| 402 | .It | 405 | .It |
| 403 | .Fn tls_read | 406 | .Fn tls_read |
| 404 | reads | 407 | reads |
| @@ -416,23 +419,28 @@ bytes of data from | |||
| 416 | to the socket. | 419 | to the socket. |
| 417 | The amount of data written is returned in | 420 | The amount of data written is returned in |
| 418 | .Fa outlen . | 421 | .Fa outlen . |
| 422 | .It | ||
| 423 | .Fn tls_close | ||
| 424 | closes a connection after use. | ||
| 425 | If the connection was established using | ||
| 426 | .Fn tls_connect_fds , | ||
| 427 | only the TLS layer will be closed and it is the caller's responsibility to close | ||
| 428 | the file descriptors. | ||
| 419 | .El | 429 | .El |
| 420 | .Sh RETURN VALUES | 430 | .Sh RETURN VALUES |
| 421 | Functions that return | 431 | Functions that return |
| 422 | .Vt int | 432 | .Vt int |
| 423 | will return 0 on success and -1 on error. | 433 | will return 0 on success and -1 on error. |
| 424 | Functions that return a pointer will return NULL on error. | 434 | Functions that return a pointer will return NULL on error, which indicates an |
| 435 | out of memory condition. | ||
| 425 | .Pp | 436 | .Pp |
| 426 | The | 437 | The |
| 427 | .Fn tls_close , | 438 | .Fn tls_handshake , |
| 428 | .Fn tls_read | 439 | .Fn tls_read , |
| 429 | and | 440 | .Fn tls_write , |
| 430 | .Fn tls_write | ||
| 431 | functions, along with the | ||
| 432 | .Fn tls_accept | ||
| 433 | and | 441 | and |
| 434 | .Fn tls_connect | 442 | .Fn tls_close |
| 435 | function families, have two special return values: | 443 | functions have two special return values: |
| 436 | .Pp | 444 | .Pp |
| 437 | .Bl -tag -width "TLS_WRITE_AGAIN" -offset indent -compact | 445 | .Bl -tag -width "TLS_WRITE_AGAIN" -offset indent -compact |
| 438 | .It Dv TLS_READ_AGAIN | 446 | .It Dv TLS_READ_AGAIN |
| @@ -450,13 +458,7 @@ even when calling | |||
| 450 | .Pp | 458 | .Pp |
| 451 | While there are cases where these functions will return one or the | 459 | While there are cases where these functions will return one or the |
| 452 | other or both, the best practice is to always check for both. | 460 | other or both, the best practice is to always check for both. |
| 453 | The caller should call the appropriate function or, in the case of the | 461 | In all cases the same function call should be repeated. |
| 454 | .Fn tls_close | ||
| 455 | and the | ||
| 456 | .Fn tls_accept | ||
| 457 | and | ||
| 458 | .Fn tls_connect | ||
| 459 | function families, repeat the call. | ||
| 460 | .Sh EXAMPLES | 462 | .Sh EXAMPLES |
| 461 | Example showing how to handle partial TLS writes. | 463 | Example showing how to handle partial TLS writes. |
| 462 | .Bd -literal -offset indent | 464 | .Bd -literal -offset indent |
