diff options
| author | schwarze <> | 2015-02-16 16:42:14 +0000 |
|---|---|---|
| committer | schwarze <> | 2015-02-16 16:42:14 +0000 |
| commit | 9a3026fb0a89a15ea2def3629cc13a69f1fc678c (patch) | |
| tree | 28ac935f3dd22b133413a78861848f9501389a34 /src/lib/libcrypto | |
| parent | 4ab59c54f9da1075f740a1004c326b0784ed4de0 (diff) | |
| download | openbsd-9a3026fb0a89a15ea2def3629cc13a69f1fc678c.tar.gz openbsd-9a3026fb0a89a15ea2def3629cc13a69f1fc678c.tar.bz2 openbsd-9a3026fb0a89a15ea2def3629cc13a69f1fc678c.zip | |
third batch of perlpod(1) to mdoc(7) conversion
Diffstat (limited to 'src/lib/libcrypto')
| -rw-r--r-- | src/lib/libcrypto/man/BIO_push.3 | 117 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_read.3 | 115 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_accept.3 | 279 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_bio.3 | 295 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_connect.3 | 332 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_fd.3 | 137 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_file.3 | 248 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_mem.3 | 190 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_null.3 | 32 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_s_socket.3 | 99 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_set_callback.3 | 129 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/BIO_should_retry.3 | 145 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/Makefile | 6 |
13 files changed, 2121 insertions, 3 deletions
diff --git a/src/lib/libcrypto/man/BIO_push.3 b/src/lib/libcrypto/man/BIO_push.3 new file mode 100644 index 0000000000..848a09ba53 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_push.3 | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_PUSH 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_push , | ||
| 6 | .Nm BIO_pop | ||
| 7 | .Nd add and remove BIOs from a chain | ||
| 8 | .Sh SYNOPSIS | ||
| 9 | .In openssl/bio.h | ||
| 10 | .Ft BIO * | ||
| 11 | .Fo BIO_push | ||
| 12 | .Fa "BIO *b" | ||
| 13 | .Fa "BIO *append" | ||
| 14 | .Fc | ||
| 15 | .Ft BIO * | ||
| 16 | .Fo BIO_pop | ||
| 17 | .Fa "BIO *b" | ||
| 18 | .Fc | ||
| 19 | .Sh DESCRIPTION | ||
| 20 | The | ||
| 21 | .Fn BIO_push | ||
| 22 | function appends the BIO | ||
| 23 | .Fa append | ||
| 24 | to | ||
| 25 | .Fa b | ||
| 26 | and returns | ||
| 27 | .Fa b . | ||
| 28 | .Pp | ||
| 29 | .Fn BIO_pop | ||
| 30 | removes the BIO | ||
| 31 | .Fa b | ||
| 32 | from a chain and returns the next BIO in the chain, or | ||
| 33 | .Dv NULL | ||
| 34 | if there is no next BIO. | ||
| 35 | The removed BIO then becomes a single BIO with no association with the | ||
| 36 | original chain, it can thus be freed or attached to a different chain. | ||
| 37 | .Sh RETURN VALUES | ||
| 38 | .Fn BIO_push | ||
| 39 | returns the beginning of the chain, | ||
| 40 | .Fa b . | ||
| 41 | .Pp | ||
| 42 | .Fn BIO_pop | ||
| 43 | returns the next BIO in the chain, or | ||
| 44 | .Dv NULL | ||
| 45 | if there is no next BIO. | ||
| 46 | .Sh NOTES | ||
| 47 | The names of these functions are perhaps a little misleading. | ||
| 48 | .Fn BIO_push | ||
| 49 | joins two BIO chains whereas | ||
| 50 | .Fn BIO_pop | ||
| 51 | deletes a single BIO from a chain, | ||
| 52 | the deleted BIO does not need to be at the end of a chain. | ||
| 53 | .Pp | ||
| 54 | The process of calling | ||
| 55 | .Fn BIO_push | ||
| 56 | and | ||
| 57 | .Fn BIO_pop | ||
| 58 | on a BIO may have additional consequences: | ||
| 59 | a control call is made to the affected BIOs. | ||
| 60 | Any effects will be noted in the descriptions of individual BIOs. | ||
| 61 | .Sh EXAMPLES | ||
| 62 | For these examples suppose | ||
| 63 | .Sy md1 | ||
| 64 | and | ||
| 65 | .Sy md2 | ||
| 66 | are digest BIOs, | ||
| 67 | .Sy b64 | ||
| 68 | is a base64 BIO and | ||
| 69 | .Sy f | ||
| 70 | is a file BIO. | ||
| 71 | .Pp | ||
| 72 | If the call | ||
| 73 | .Pp | ||
| 74 | .Dl BIO_push(b64, f); | ||
| 75 | .Pp | ||
| 76 | is made then the new chain will be | ||
| 77 | .Sy b64-f . | ||
| 78 | After making the calls | ||
| 79 | .Bd -literal -offset indent | ||
| 80 | BIO_push(md2, b64); | ||
| 81 | BIO_push(md1, md2); | ||
| 82 | .Ed | ||
| 83 | .Pp | ||
| 84 | the new chain is | ||
| 85 | .Sy md1-md2-b64-f . | ||
| 86 | Data written to | ||
| 87 | .Sy md1 | ||
| 88 | will be digested | ||
| 89 | by | ||
| 90 | .Sy md1 | ||
| 91 | and | ||
| 92 | .Sy md2 , | ||
| 93 | .Sy base64 | ||
| 94 | encoded and written to | ||
| 95 | .Sy f . | ||
| 96 | .Pp | ||
| 97 | It should be noted that reading causes data to pass | ||
| 98 | in the reverse direction, that is data is read from | ||
| 99 | .Sy f , | ||
| 100 | base64 | ||
| 101 | .Sy decoded | ||
| 102 | and digested | ||
| 103 | by | ||
| 104 | .Sy md1 | ||
| 105 | and | ||
| 106 | .Sy md2 . | ||
| 107 | If this call is made: | ||
| 108 | .Pp | ||
| 109 | .Dl BIO_pop(md2); | ||
| 110 | .Pp | ||
| 111 | The call will return | ||
| 112 | .Sy b64 | ||
| 113 | and the new chain will be | ||
| 114 | .Sy md1-b64-f Ns ; | ||
| 115 | data can be written to | ||
| 116 | .Sy md1 | ||
| 117 | as before. | ||
diff --git a/src/lib/libcrypto/man/BIO_read.3 b/src/lib/libcrypto/man/BIO_read.3 new file mode 100644 index 0000000000..3114ab3da4 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_read.3 | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_READ 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_read , | ||
| 6 | .Nm BIO_write , | ||
| 7 | .Nm BIO_gets , | ||
| 8 | .Nm BIO_puts | ||
| 9 | .Nd BIO I/O functions | ||
| 10 | .Sh SYNOPSIS | ||
| 11 | .In openssl/bio.h | ||
| 12 | .Ft int | ||
| 13 | .Fo BIO_read | ||
| 14 | .Fa "BIO *b" | ||
| 15 | .Fa "void *buf" | ||
| 16 | .Fa "int len" | ||
| 17 | .Fc | ||
| 18 | .Ft int | ||
| 19 | .Fo BIO_gets | ||
| 20 | .Fa "BIO *b" | ||
| 21 | .Fa "char *buf" | ||
| 22 | .Fa "int size" | ||
| 23 | .Fc | ||
| 24 | .Ft int | ||
| 25 | .Fo BIO_write | ||
| 26 | .Fa "BIO *b" | ||
| 27 | .Fa "const void *buf" | ||
| 28 | .Fa "int len" | ||
| 29 | .Fc | ||
| 30 | .Ft int | ||
| 31 | .Fo BIO_puts | ||
| 32 | .Fa "BIO *b" | ||
| 33 | .Fa "const char *buf" | ||
| 34 | .Fc | ||
| 35 | .Sh DESCRIPTION | ||
| 36 | .Fn BIO_read | ||
| 37 | attempts to read | ||
| 38 | .Fa len | ||
| 39 | bytes from BIO | ||
| 40 | .Fa b | ||
| 41 | and places the data in | ||
| 42 | .Fa buf . | ||
| 43 | .Pp | ||
| 44 | .Fn BIO_gets | ||
| 45 | performs the BIOs "gets" operation and places the data in | ||
| 46 | .Fa buf . | ||
| 47 | Usually this operation will attempt to read a line of data | ||
| 48 | from the BIO of maximum length | ||
| 49 | .Fa len . | ||
| 50 | There are exceptions to this however, for example | ||
| 51 | .Fn BIO_gets | ||
| 52 | on a digest BIO will calculate and return the digest | ||
| 53 | and other BIOs may not support | ||
| 54 | .Fn BIO_gets | ||
| 55 | at all. | ||
| 56 | .Pp | ||
| 57 | .Fn BIO_write | ||
| 58 | attempts to write | ||
| 59 | .Fa len | ||
| 60 | bytes from | ||
| 61 | .Fa buf | ||
| 62 | to BIO | ||
| 63 | .Fa b . | ||
| 64 | .Pp | ||
| 65 | .Fn BIO_puts | ||
| 66 | attempts to write a null terminated string | ||
| 67 | .Fa buf | ||
| 68 | to BIO | ||
| 69 | .Fa b . | ||
| 70 | .Sh RETURN VALUES | ||
| 71 | All these functions return either the amount of data successfully | ||
| 72 | read or written (if the return value is positive) or that no data | ||
| 73 | was successfully read or written if the result is 0 or -1. | ||
| 74 | If the return value is -2, then the operation is not implemented | ||
| 75 | in the specific BIO type. | ||
| 76 | .Sh NOTES | ||
| 77 | A 0 or -1 return is not necessarily an indication of an error. | ||
| 78 | In particular when the source/sink is non-blocking or of a certain type | ||
| 79 | it may merely be an indication that no data is currently available and that | ||
| 80 | the application should retry the operation later. | ||
| 81 | .Pp | ||
| 82 | One technique sometimes used with blocking sockets | ||
| 83 | is to use a system call (such as | ||
| 84 | .Xr select 2 , | ||
| 85 | .Xr poll 2 | ||
| 86 | or equivalent) to determine when data is available and then call | ||
| 87 | .Xr read 3 | ||
| 88 | to read the data. | ||
| 89 | The equivalent with BIOs (that is call | ||
| 90 | .Xr select 2 | ||
| 91 | on the underlying I/O structure and then call | ||
| 92 | .Fn BIO_read | ||
| 93 | to read the data) should | ||
| 94 | .Em not | ||
| 95 | be used because a single call to | ||
| 96 | .Fn BIO_read | ||
| 97 | can cause several reads (and writes in the case of SSL BIOs) | ||
| 98 | on the underlying I/O structure and may block as a result. | ||
| 99 | Instead | ||
| 100 | .Xr select 2 | ||
| 101 | (or equivalent) should be combined with non blocking I/O | ||
| 102 | so successive reads will request a retry instead of blocking. | ||
| 103 | .Pp | ||
| 104 | See | ||
| 105 | .Xr BIO_should_retry 3 | ||
| 106 | for details of how to determine the cause of a retry and other I/O issues. | ||
| 107 | .Pp | ||
| 108 | If the | ||
| 109 | .Fn BIO_gets | ||
| 110 | function is not supported by a BIO then it is possible to | ||
| 111 | work around this by adding a buffering BIO | ||
| 112 | .Xr BIO_f_buffer 3 | ||
| 113 | to the chain. | ||
| 114 | .Sh SEE ALSO | ||
| 115 | .Xr BIO_should_retry 3 | ||
diff --git a/src/lib/libcrypto/man/BIO_s_accept.3 b/src/lib/libcrypto/man/BIO_s_accept.3 new file mode 100644 index 0000000000..f5adfcc07c --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_accept.3 | |||
| @@ -0,0 +1,279 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_ACCEPT 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_accept , | ||
| 6 | .Nm BIO_set_accept_port , | ||
| 7 | .Nm BIO_get_accept_port , | ||
| 8 | .Nm BIO_new_accept , | ||
| 9 | .Nm BIO_set_nbio_accept , | ||
| 10 | .Nm BIO_set_accept_bios , | ||
| 11 | .Nm BIO_set_bind_mode , | ||
| 12 | .Nm BIO_get_bind_mode , | ||
| 13 | .Nm BIO_do_accept | ||
| 14 | .Nd accept BIO | ||
| 15 | .Sh SYNOPSIS | ||
| 16 | .In openssl/bio.h | ||
| 17 | .Ft BIO_METHOD * | ||
| 18 | .Fo BIO_s_accept | ||
| 19 | .Fa void | ||
| 20 | .Fc | ||
| 21 | .Ft long | ||
| 22 | .Fo BIO_set_accept_port | ||
| 23 | .Fa "BIO *b" | ||
| 24 | .Fa "char *name" | ||
| 25 | .Fc | ||
| 26 | .Ft char * | ||
| 27 | .Fo BIO_get_accept_port | ||
| 28 | .Fa "BIO *b" | ||
| 29 | .Fc | ||
| 30 | .Ft BIO * | ||
| 31 | .Fo BIO_new_accept | ||
| 32 | .Fa "char *host_port" | ||
| 33 | .Fc | ||
| 34 | .Ft long | ||
| 35 | .Fo BIO_set_nbio_accept | ||
| 36 | .Fa "BIO *b" | ||
| 37 | .Fa "int n" | ||
| 38 | .Fc | ||
| 39 | .Ft long | ||
| 40 | .Fo BIO_set_accept_bios | ||
| 41 | .Fa "BIO *b" | ||
| 42 | .Fa "char *bio" | ||
| 43 | .Fc | ||
| 44 | .Ft long | ||
| 45 | .Fo BIO_set_bind_mode | ||
| 46 | .Fa "BIO *b" | ||
| 47 | .Fa "long mode" | ||
| 48 | .Fc | ||
| 49 | .Ft long | ||
| 50 | .Fo BIO_get_bind_mode | ||
| 51 | .Fa "BIO *b" | ||
| 52 | .Fa "long dummy" | ||
| 53 | .Fc | ||
| 54 | .Fd #define BIO_BIND_NORMAL 0 | ||
| 55 | .Fd #define BIO_BIND_REUSEADDR_IF_UNUSED 1 | ||
| 56 | .Fd #define BIO_BIND_REUSEADDR 2 | ||
| 57 | .Ft int | ||
| 58 | .Fo BIO_do_accept | ||
| 59 | .Fa "BIO *b" | ||
| 60 | .Fc | ||
| 61 | .Sh DESCRIPTION | ||
| 62 | .Fn BIO_s_accept | ||
| 63 | returns the accept BIO method. | ||
| 64 | This is a wrapper round the platform's TCP/IP socket accept routines. | ||
| 65 | .Pp | ||
| 66 | Using accept BIOs, TCP/IP connections can be accepted | ||
| 67 | and data transferred using only BIO routines. | ||
| 68 | In this way any platform specific operations | ||
| 69 | are hidden by the BIO abstraction. | ||
| 70 | .Pp | ||
| 71 | Read and write operations on an accept BIO | ||
| 72 | will perform I/O on the underlying connection. | ||
| 73 | If no connection is established and the port (see below) is set up | ||
| 74 | properly then the BIO waits for an incoming connection. | ||
| 75 | .Pp | ||
| 76 | Accept BIOs support | ||
| 77 | .Xr BIO_puts 3 | ||
| 78 | but not | ||
| 79 | .Xr BIO_gets 3 . | ||
| 80 | .Pp | ||
| 81 | If the close flag is set on an accept BIO, then any active | ||
| 82 | connection on that chain is shutdown and the socket closed when | ||
| 83 | the BIO is freed. | ||
| 84 | .Pp | ||
| 85 | Calling | ||
| 86 | .Xr BIO_reset 3 | ||
| 87 | on a accept BIO will close any active connection and reset the BIO | ||
| 88 | into a state where it awaits another incoming connection. | ||
| 89 | .Pp | ||
| 90 | .Xr BIO_get_fd 3 | ||
| 91 | and | ||
| 92 | .Xr BIO_set_fd 3 | ||
| 93 | can be called to retrieve or set the accept socket. | ||
| 94 | See | ||
| 95 | .Xr BIO_s_fd 3 . | ||
| 96 | .Pp | ||
| 97 | .Fn BIO_set_accept_port | ||
| 98 | uses the string | ||
| 99 | .Fa name | ||
| 100 | to set the accept port. | ||
| 101 | The port is represented as a string of the form | ||
| 102 | .Ar host : Ns Ar port , | ||
| 103 | where | ||
| 104 | .Ar host | ||
| 105 | is the interface to use and | ||
| 106 | .Ar port | ||
| 107 | is the port. | ||
| 108 | Either or both values can be | ||
| 109 | .Qq * | ||
| 110 | which is interpreted as meaning any interface or port respectively. | ||
| 111 | .Ar port | ||
| 112 | has the same syntax as the port specified in | ||
| 113 | .Xr BIO_set_conn_port 3 | ||
| 114 | for connect BIOs. | ||
| 115 | It can be a numerical port string or a string to lookup using | ||
| 116 | .Xr getservbyname 3 | ||
| 117 | and a string table. | ||
| 118 | .Pp | ||
| 119 | .Fn BIO_new_accept | ||
| 120 | combines | ||
| 121 | .Xr BIO_new 3 | ||
| 122 | and | ||
| 123 | .Fn BIO_set_accept_port | ||
| 124 | into a single call. | ||
| 125 | It creates a new accept BIO with port | ||
| 126 | .Fa host_port . | ||
| 127 | .Pp | ||
| 128 | .Fn BIO_set_nbio_accept | ||
| 129 | sets the accept socket to blocking mode (the default) if | ||
| 130 | .Fa n | ||
| 131 | is 0 or non blocking mode if | ||
| 132 | .Fa n | ||
| 133 | is 1. | ||
| 134 | .Pp | ||
| 135 | .Fn BIO_set_accept_bios | ||
| 136 | can be used to set a chain of BIOs which will be duplicated | ||
| 137 | and prepended to the chain when an incoming connection is received. | ||
| 138 | This is useful if, for example, a buffering or SSL BIO | ||
| 139 | is required for each connection. | ||
| 140 | The chain of BIOs must not be freed after this call, | ||
| 141 | they will be automatically freed when the accept BIO is freed. | ||
| 142 | .Pp | ||
| 143 | .Fn BIO_set_bind_mode | ||
| 144 | and | ||
| 145 | .Fn BIO_get_bind_mode | ||
| 146 | set and retrieve the current bind mode. | ||
| 147 | If | ||
| 148 | .Dv BIO_BIND_NORMAL Pq the default | ||
| 149 | is set, then another socket cannot be bound to the same port. | ||
| 150 | If | ||
| 151 | .Dv BIO_BIND_REUSEADDR | ||
| 152 | is set, then other sockets can bind to the same port. | ||
| 153 | If | ||
| 154 | .Dv BIO_BIND_REUSEADDR_IF_UNUSED | ||
| 155 | is set, then an attempt is first made to use | ||
| 156 | .Dv BIO_BIN_NORMAL ; | ||
| 157 | if this fails and the port is not in use, | ||
| 158 | then a second attempt is made using | ||
| 159 | .Dv BIO_BIND_REUSEADDR . | ||
| 160 | .Pp | ||
| 161 | .Fn BIO_do_accept | ||
| 162 | serves two purposes. | ||
| 163 | When it is first called, after the accept BIO has been setup, | ||
| 164 | it will attempt to create the accept socket and bind an address to it. | ||
| 165 | Second and subsequent calls to | ||
| 166 | .Fn BIO_do_accept | ||
| 167 | will await an incoming connection, or request a retry in non blocking mode. | ||
| 168 | .Sh NOTES | ||
| 169 | When an accept BIO is at the end of a chain, it will await an | ||
| 170 | incoming connection before processing I/O calls. | ||
| 171 | When an accept BIO is not at then end of a chain, | ||
| 172 | it passes I/O calls to the next BIO in the chain. | ||
| 173 | .Pp | ||
| 174 | When a connection is established a new socket BIO is created | ||
| 175 | for the connection and appended to the chain. | ||
| 176 | That is the chain is now accept->socket. | ||
| 177 | This effectively means that attempting I/O on an initial accept | ||
| 178 | socket will await an incoming connection then perform I/O on it. | ||
| 179 | .Pp | ||
| 180 | If any additional BIOs have been set using | ||
| 181 | .Fn BIO_set_accept_bios , | ||
| 182 | then they are placed between the socket and the accept BIO, | ||
| 183 | that is the chain will be accept->otherbios->socket. | ||
| 184 | .Pp | ||
| 185 | If a server wishes to process multiple connections (as is normally | ||
| 186 | the case), then the accept BIO must be made available for further | ||
| 187 | incoming connections. | ||
| 188 | This can be done by waiting for a connection and then calling: | ||
| 189 | .Pp | ||
| 190 | .Dl connection = BIO_pop(accept); | ||
| 191 | .Pp | ||
| 192 | After this call, | ||
| 193 | .Sy connection | ||
| 194 | will contain a BIO for the recently established connection and | ||
| 195 | .Sy accept | ||
| 196 | will now be a single BIO again which can be used | ||
| 197 | to await further incoming connections. | ||
| 198 | If no further connections will be accepted, the | ||
| 199 | .Sy accept | ||
| 200 | can be freed using | ||
| 201 | .Xr BIO_free 3 . | ||
| 202 | .Pp | ||
| 203 | If only a single connection will be processed, | ||
| 204 | it is possible to perform I/O using the accept BIO itself. | ||
| 205 | This is often undesirable however because the accept BIO | ||
| 206 | will still accept additional incoming connections. | ||
| 207 | This can be resolved by using | ||
| 208 | .Xr BIO_pop 3 | ||
| 209 | (see above) and freeing up the accept BIO after the initial connection. | ||
| 210 | .Pp | ||
| 211 | If the underlying accept socket is non-blocking and | ||
| 212 | .Fn BIO_do_accept | ||
| 213 | is called to await an incoming connection, it is possible for | ||
| 214 | .Xr BIO_should_io_special 3 | ||
| 215 | with the reason | ||
| 216 | .Dv BIO_RR_ACCEPT . | ||
| 217 | If this happens, then it is an indication that an accept attempt | ||
| 218 | would block: the application should take appropriate action | ||
| 219 | to wait until the underlying socket has accepted a connection | ||
| 220 | and retry the call. | ||
| 221 | .Pp | ||
| 222 | .Fn BIO_set_accept_port , | ||
| 223 | .Fn BIO_get_accept_port , | ||
| 224 | .Fn BIO_set_nbio_accept , | ||
| 225 | .Fn BIO_set_accept_bios , | ||
| 226 | .Fn BIO_set_bind_mode , | ||
| 227 | .Fn BIO_get_bind_mode , | ||
| 228 | and | ||
| 229 | .Fn BIO_do_accept | ||
| 230 | are macros. | ||
| 231 | .Sh EXAMPLES | ||
| 232 | This example accepts two connections on port 4444, | ||
| 233 | sends messages down each and finally closes both down. | ||
| 234 | .Bd -literal -offset 2n | ||
| 235 | BIO *abio, *cbio, *cbio2; | ||
| 236 | ERR_load_crypto_strings(); | ||
| 237 | abio = BIO_new_accept("4444"); | ||
| 238 | |||
| 239 | /* First call to BIO_accept() sets up accept BIO */ | ||
| 240 | if (BIO_do_accept(abio) <= 0) { | ||
| 241 | fprintf(stderr, "Error setting up accept\en"); | ||
| 242 | ERR_print_errors_fp(stderr); | ||
| 243 | exit(0); | ||
| 244 | } | ||
| 245 | |||
| 246 | /* Wait for incoming connection */ | ||
| 247 | if (BIO_do_accept(abio) <= 0) { | ||
| 248 | fprintf(stderr, "Error accepting connection\en"); | ||
| 249 | ERR_print_errors_fp(stderr); | ||
| 250 | exit(0); | ||
| 251 | } | ||
| 252 | fprintf(stderr, "Connection 1 established\en"); | ||
| 253 | |||
| 254 | /* Retrieve BIO for connection */ | ||
| 255 | cbio = BIO_pop(abio); | ||
| 256 | |||
| 257 | BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\en"); | ||
| 258 | fprintf(stderr, "Sent out data on connection 1\en"); | ||
| 259 | |||
| 260 | /* Wait for another connection */ | ||
| 261 | if (BIO_do_accept(abio) <= 0) { | ||
| 262 | fprintf(stderr, "Error accepting connection\en"); | ||
| 263 | ERR_print_errors_fp(stderr); | ||
| 264 | exit(0); | ||
| 265 | } | ||
| 266 | fprintf(stderr, "Connection 2 established\en"); | ||
| 267 | |||
| 268 | /* Close accept BIO to refuse further connections */ | ||
| 269 | cbio2 = BIO_pop(abio); | ||
| 270 | BIO_free(abio); | ||
| 271 | |||
| 272 | BIO_puts(cbio2, "Connection 2: Sending out Data on second\en"); | ||
| 273 | fprintf(stderr, "Sent out data on connection 2\en"); | ||
| 274 | BIO_puts(cbio, "Connection 1: Second connection established\en"); | ||
| 275 | |||
| 276 | /* Close the two established connections */ | ||
| 277 | BIO_free(cbio); | ||
| 278 | BIO_free(cbio2); | ||
| 279 | .Ed | ||
diff --git a/src/lib/libcrypto/man/BIO_s_bio.3 b/src/lib/libcrypto/man/BIO_s_bio.3 new file mode 100644 index 0000000000..af7bdabd33 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_bio.3 | |||
| @@ -0,0 +1,295 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_BIO 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_bio , | ||
| 6 | .Nm BIO_make_bio_pair , | ||
| 7 | .Nm BIO_destroy_bio_pair , | ||
| 8 | .Nm BIO_shutdown_wr , | ||
| 9 | .Nm BIO_set_write_buf_size , | ||
| 10 | .Nm BIO_get_write_buf_size , | ||
| 11 | .Nm BIO_new_bio_pair , | ||
| 12 | .Nm BIO_get_write_guarantee , | ||
| 13 | .Nm BIO_ctrl_get_write_guarantee , | ||
| 14 | .Nm BIO_get_read_request , | ||
| 15 | .Nm BIO_ctrl_get_read_request , | ||
| 16 | .Nm BIO_ctrl_reset_read_request | ||
| 17 | .Nd BIO pair BIO | ||
| 18 | .Sh SYNOPSIS | ||
| 19 | .In openssl/bio.h | ||
| 20 | .Ft BIO_METHOD * | ||
| 21 | .Fo BIO_s_bio | ||
| 22 | .Fa void | ||
| 23 | .Fc | ||
| 24 | .Bd -unfilled | ||
| 25 | #define BIO_make_bio_pair(b1, b2) \e | ||
| 26 | (int)BIO_ctrl(b1, BIO_C_MAKE_BIO_PAIR, 0, b2) | ||
| 27 | #define BIO_destroy_bio_pair(b) \e | ||
| 28 | (int)BIO_ctrl(b, BIO_C_DESTROY_BIO_PAIR, 0, NULL) | ||
| 29 | #define BIO_shutdown_wr(b) \e | ||
| 30 | (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) | ||
| 31 | #define BIO_set_write_buf_size(b, size) \e | ||
| 32 | (int)BIO_ctrl(b, BIO_C_SET_WRITE_BUF_SIZE, size, NULL) | ||
| 33 | #define BIO_get_write_buf_size(b, size) \e | ||
| 34 | (size_t)BIO_ctrl(b, BIO_C_GET_WRITE_BUF_SIZE, size, NULL) | ||
| 35 | .Ed | ||
| 36 | .Pp | ||
| 37 | .Ft int | ||
| 38 | .Fo BIO_new_bio_pair | ||
| 39 | .Fa "BIO **bio1" | ||
| 40 | .Fa "size_t writebuf1" | ||
| 41 | .Fa "BIO **bio2" | ||
| 42 | .Fa "size_t writebuf2" | ||
| 43 | .Fc | ||
| 44 | .Bd -unfilled | ||
| 45 | #define BIO_get_write_guarantee(b) \e | ||
| 46 | (int)BIO_ctrl(b, BIO_C_GET_WRITE_GUARANTEE, 0, NULL) | ||
| 47 | .Ed | ||
| 48 | .Pp | ||
| 49 | .Ft size_t | ||
| 50 | .Fo BIO_ctrl_get_write_guarantee | ||
| 51 | .Fa "BIO *b" | ||
| 52 | .Fc | ||
| 53 | .Bd -unfilled | ||
| 54 | #define BIO_get_read_request(b) \e | ||
| 55 | (int)BIO_ctrl(b, BIO_C_GET_READ_REQUEST, 0, NULL) | ||
| 56 | .Ed | ||
| 57 | .Pp | ||
| 58 | .Ft size_t | ||
| 59 | .Fo BIO_ctrl_get_read_request | ||
| 60 | .Fa "BIO *b" | ||
| 61 | .Fc | ||
| 62 | .Ft int | ||
| 63 | .Fo BIO_ctrl_reset_read_request | ||
| 64 | .Fa "BIO *b" | ||
| 65 | .Fc | ||
| 66 | .Sh DESCRIPTION | ||
| 67 | .Fn BIO_s_bio | ||
| 68 | returns the method for a BIO pair. | ||
| 69 | A BIO pair is a pair of source/sink BIOs where data written to either | ||
| 70 | half of the pair is buffered and can be read from the other half. | ||
| 71 | Both halves must usually be handled by the same application thread | ||
| 72 | since no locking is done on the internal data structures. | ||
| 73 | .Pp | ||
| 74 | Since BIO chains typically end in a source/sink BIO, | ||
| 75 | it is possible to make this one half of a BIO pair and | ||
| 76 | have all the data processed by the chain under application control. | ||
| 77 | .Pp | ||
| 78 | One typical use of BIO pairs is | ||
| 79 | to place TLS/SSL I/O under application control. | ||
| 80 | This can be used when the application wishes to use a non standard | ||
| 81 | transport for TLS/SSL or the normal socket routines are inappropriate. | ||
| 82 | .Pp | ||
| 83 | Calls to | ||
| 84 | .Xr BIO_read 3 | ||
| 85 | will read data from the buffer or request a retry if no data is available. | ||
| 86 | .Pp | ||
| 87 | Calls to | ||
| 88 | .Xr BIO_write 3 | ||
| 89 | will place data in the buffer or request a retry if the buffer is full. | ||
| 90 | .Pp | ||
| 91 | The standard calls | ||
| 92 | .Xr BIO_ctrl_pending 3 | ||
| 93 | and | ||
| 94 | .Xr BIO_ctrl_wpending 3 | ||
| 95 | can be used to determine the amount of pending data | ||
| 96 | in the read or write buffer. | ||
| 97 | .Pp | ||
| 98 | .Xr BIO_reset 3 | ||
| 99 | clears any data in the write buffer. | ||
| 100 | .Pp | ||
| 101 | .Fn BIO_make_bio_pair | ||
| 102 | joins two separate BIOs into a connected pair. | ||
| 103 | .Pp | ||
| 104 | .Fn BIO_destroy_pair | ||
| 105 | destroys the association between two connected BIOs. | ||
| 106 | Freeing up any half of the pair will automatically destroy the association. | ||
| 107 | .Pp | ||
| 108 | .Fn BIO_shutdown_wr | ||
| 109 | is used to close down a BIO | ||
| 110 | .Fa b . | ||
| 111 | After this call no further writes on BIO | ||
| 112 | .Fa b | ||
| 113 | are allowed; they will return an error. | ||
| 114 | Reads on the other half of the pair will return any pending data | ||
| 115 | or EOF when all pending data has been read. | ||
| 116 | .Pp | ||
| 117 | .Fn BIO_set_write_buf_size | ||
| 118 | sets the write buffer size of BIO | ||
| 119 | .Fa b | ||
| 120 | to | ||
| 121 | .Fa size . | ||
| 122 | If the size is not initialized a default value is used. | ||
| 123 | This is currently 17K, sufficient for a maximum size TLS record. | ||
| 124 | .Pp | ||
| 125 | .Fn BIO_get_write_buf_size | ||
| 126 | returns the size of the write buffer. | ||
| 127 | .Pp | ||
| 128 | .Fn BIO_new_bio_pair | ||
| 129 | combines the calls to | ||
| 130 | .Xr BIO_new 3 , | ||
| 131 | .Fn BIO_make_bio_pair | ||
| 132 | and | ||
| 133 | .Fn BIO_set_write_buf_size | ||
| 134 | to create a connected pair of BIOs | ||
| 135 | .Fa bio1 | ||
| 136 | and | ||
| 137 | .Fa bio2 | ||
| 138 | with write buffer sizes | ||
| 139 | .Fa writebuf1 | ||
| 140 | and | ||
| 141 | .Fa writebuf2 . | ||
| 142 | If either size is zero, then the default size is used. | ||
| 143 | .Fn BIO_new_bio_pair | ||
| 144 | does not check whether | ||
| 145 | .Fa bio1 | ||
| 146 | or | ||
| 147 | .Fa bio2 | ||
| 148 | do point to some other BIO, the values are overwritten, | ||
| 149 | .Xr BIO_free 3 | ||
| 150 | is not called. | ||
| 151 | .Pp | ||
| 152 | .Fn BIO_get_write_guarantee | ||
| 153 | and | ||
| 154 | .Fn BIO_ctrl_get_write_guarantee | ||
| 155 | return the maximum length of data | ||
| 156 | that can be currently written to the BIO. | ||
| 157 | Writes larger than this value will return a value from | ||
| 158 | .Xr BIO_write 3 | ||
| 159 | less than the amount requested or if the buffer is full request a retry. | ||
| 160 | .Fn BIO_ctrl_get_write_guarantee | ||
| 161 | is a function whereas | ||
| 162 | .Fn BIO_get_write_guarantee | ||
| 163 | is a macro. | ||
| 164 | .Pp | ||
| 165 | .Fn BIO_get_read_request | ||
| 166 | and | ||
| 167 | .Fn BIO_ctrl_get_read_request | ||
| 168 | return the amount of data requested, or the buffer size if it is less, | ||
| 169 | if the last read attempt at the other half of the BIO pair failed | ||
| 170 | due to an empty buffer. | ||
| 171 | This can be used to determine how much data should be | ||
| 172 | written to the BIO so the next read will succeed: | ||
| 173 | this is most useful in TLS/SSL applications where the amount of | ||
| 174 | data read is usually meaningful rather than just a buffer size. | ||
| 175 | After a successful read this call will return zero. | ||
| 176 | It also will return zero once new data has been written | ||
| 177 | satisfying the read request or part of it. | ||
| 178 | Note that | ||
| 179 | .Fn BIO_get_read_request | ||
| 180 | never returns an amount larger than that returned by | ||
| 181 | .Fn BIO_get_write_guarantee . | ||
| 182 | .Pp | ||
| 183 | .Fn BIO_ctrl_reset_read_request | ||
| 184 | can also be used to reset the value returned by | ||
| 185 | .Fn BIO_get_read_request | ||
| 186 | to zero. | ||
| 187 | .Sh RETURN VALUES | ||
| 188 | .Fn BIO_new_bio_pair | ||
| 189 | returns 1 on success, with the new BIOs available in | ||
| 190 | .Fa bio1 | ||
| 191 | and | ||
| 192 | .Fa bio2 , | ||
| 193 | or 0 on failure, with NULL pointers stored into the locations for | ||
| 194 | .Fa bio1 | ||
| 195 | and | ||
| 196 | .Fa bio2 . | ||
| 197 | Check the error stack for more information. | ||
| 198 | .\" XXX More return values need to be added here. | ||
| 199 | .Sh NOTES | ||
| 200 | Both halves of a BIO pair should be freed. | ||
| 201 | Even if one half is implicitly freed due to a | ||
| 202 | .Xr BIO_free_all 3 | ||
| 203 | or | ||
| 204 | .Xr SSL_free 3 | ||
| 205 | call, the other half still needs to be freed. | ||
| 206 | .Pp | ||
| 207 | When used in bidirectional applications (such as TLS/SSL) | ||
| 208 | care should be taken to flush any data in the write buffer. | ||
| 209 | This can be done by calling | ||
| 210 | .Xr BIO_pending 3 | ||
| 211 | on the other half of the pair and, if any data is pending, | ||
| 212 | reading it and sending it to the underlying transport. | ||
| 213 | This must be done before any normal processing (such as calling | ||
| 214 | .Xr select 2 ) | ||
| 215 | due to a request and | ||
| 216 | .Xr BIO_should_read 3 | ||
| 217 | being true. | ||
| 218 | .Pp | ||
| 219 | To see why this is important, | ||
| 220 | consider a case where a request is sent using | ||
| 221 | .Xr BIO_write 3 | ||
| 222 | and a response read with | ||
| 223 | .Xr BIO_read 3 , | ||
| 224 | this can occur during an TLS/SSL handshake for example. | ||
| 225 | .Xr BIO_write 3 | ||
| 226 | will succeed and place data in the write buffer. | ||
| 227 | .Xr BIO_read 3 | ||
| 228 | will initially fail and | ||
| 229 | .Xr BIO_should_read 3 | ||
| 230 | will be true. | ||
| 231 | If the application then waits for data to become available | ||
| 232 | on the underlying transport before flushing the write buffer, | ||
| 233 | it will never succeed because the request was never sent. | ||
| 234 | .Sh EXAMPLE | ||
| 235 | The BIO pair can be used to have full control | ||
| 236 | over the network access of an application. | ||
| 237 | The application can call | ||
| 238 | .Xr select 2 | ||
| 239 | on the socket as required without having to go through the SSL-interface. | ||
| 240 | .Bd -literal -offset 2n | ||
| 241 | BIO *internal_bio, *network_bio; | ||
| 242 | \&... | ||
| 243 | BIO_new_bio_pair(internal_bio, 0, network_bio, 0); | ||
| 244 | SSL_set_bio(ssl, internal_bio, internal_bio); | ||
| 245 | SSL_operations(); | ||
| 246 | \&... | ||
| 247 | |||
| 248 | application | TLS-engine | ||
| 249 | | | | ||
| 250 | +----------> SSL_operations() | ||
| 251 | | /\e || | ||
| 252 | | || \e/ | ||
| 253 | | BIO-pair (internal_bio) | ||
| 254 | +----------< BIO-pair (network_bio) | ||
| 255 | | | | ||
| 256 | socket | | ||
| 257 | |||
| 258 | \&... | ||
| 259 | SSL_free(ssl); /* implicitly frees internal_bio */ | ||
| 260 | BIO_free(network_bio); | ||
| 261 | \&... | ||
| 262 | .Ed | ||
| 263 | .Pp | ||
| 264 | As the BIO pair will only buffer the data and never directly access | ||
| 265 | the connection, it behaves non-blocking and will return as soon as | ||
| 266 | the write buffer is full or the read buffer is drained. | ||
| 267 | Then the application has to flush the write buffer | ||
| 268 | and/or fill the read buffer. | ||
| 269 | .Pp | ||
| 270 | Use | ||
| 271 | .Xr BIO_ctrl_pending 3 | ||
| 272 | to find out whether data is buffered in the BIO | ||
| 273 | and must be transfered to the network. | ||
| 274 | Use | ||
| 275 | .Fn BIO_ctrl_get_read_request | ||
| 276 | to find out how many bytes must be written into the buffer before the | ||
| 277 | .Xr SSL_operation 3 | ||
| 278 | can successfully be continued. | ||
| 279 | .Sh SEE ALSO | ||
| 280 | .Xr bio 3 , | ||
| 281 | .Xr BIO_read 3 , | ||
| 282 | .Xr BIO_should_retry 3 , | ||
| 283 | .Xr ssl 3 , | ||
| 284 | .Xr SSL_set_bio 3 | ||
| 285 | .Sh CAVEATS | ||
| 286 | As the data is buffered, | ||
| 287 | .Xr SSL_operation 3 | ||
| 288 | may return with an | ||
| 289 | .Dv ERROR_SSL_WANT_READ | ||
| 290 | condition, but there is still data in the write buffer. | ||
| 291 | An application must not rely on the error value of | ||
| 292 | .Xr SSL_operation 3 | ||
| 293 | but must assure that the write buffer is always flushed first. | ||
| 294 | Otherwise a deadlock may occur as the peer might be waiting | ||
| 295 | for the data before being able to continue. | ||
diff --git a/src/lib/libcrypto/man/BIO_s_connect.3 b/src/lib/libcrypto/man/BIO_s_connect.3 new file mode 100644 index 0000000000..960400e853 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_connect.3 | |||
| @@ -0,0 +1,332 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_CONNECT 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_connect , | ||
| 6 | .Nm BIO_new_connect , | ||
| 7 | .Nm BIO_set_conn_hostname , | ||
| 8 | .Nm BIO_set_conn_port , | ||
| 9 | .Nm BIO_set_conn_ip , | ||
| 10 | .Nm BIO_set_conn_int_port , | ||
| 11 | .Nm BIO_get_conn_hostname , | ||
| 12 | .Nm BIO_get_conn_port , | ||
| 13 | .Nm BIO_get_conn_ip , | ||
| 14 | .Nm BIO_get_conn_int_port , | ||
| 15 | .Nm BIO_set_nbio , | ||
| 16 | .Nm BIO_do_connect | ||
| 17 | .Nd connect BIO | ||
| 18 | .Sh SYNOPSIS | ||
| 19 | .In openssl/bio.h | ||
| 20 | .Ft BIO_METHOD * | ||
| 21 | .Fo BIO_s_connect | ||
| 22 | .Fa void | ||
| 23 | .Fc | ||
| 24 | .Ft BIO * | ||
| 25 | .Fo BIO_new_connect | ||
| 26 | .Fa "char *name" | ||
| 27 | .Fc | ||
| 28 | .Ft long | ||
| 29 | .Fo BIO_set_conn_hostname | ||
| 30 | .Fa "BIO *b" | ||
| 31 | .Fa "char *name" | ||
| 32 | .Fc | ||
| 33 | .Ft long | ||
| 34 | .Fo BIO_set_conn_port | ||
| 35 | .Fa "BIO *b" | ||
| 36 | .Fa "char *port" | ||
| 37 | .Fc | ||
| 38 | .Ft long | ||
| 39 | .Fo BIO_set_conn_ip | ||
| 40 | .Fa "BIO *b" | ||
| 41 | .Fa "char *ip" | ||
| 42 | .Fc | ||
| 43 | .Ft long | ||
| 44 | .Fo BIO_set_conn_int_port | ||
| 45 | .Fa "BIO *b" | ||
| 46 | .Fa "char *port" | ||
| 47 | .Fc | ||
| 48 | .Ft char * | ||
| 49 | .Fo BIO_get_conn_hostname | ||
| 50 | .Fa "BIO *b" | ||
| 51 | .Fc | ||
| 52 | .Ft char * | ||
| 53 | .Fo BIO_get_conn_port | ||
| 54 | .Fa "BIO *b" | ||
| 55 | .Fc | ||
| 56 | .Ft char * | ||
| 57 | .Fo BIO_get_conn_ip | ||
| 58 | .Fa "BIO *b" | ||
| 59 | .Fa "dummy" | ||
| 60 | .Fc | ||
| 61 | .Ft long | ||
| 62 | .Fo BIO_get_conn_int_port | ||
| 63 | .Fa "BIO *b" | ||
| 64 | .Fa "int port" | ||
| 65 | .Fc | ||
| 66 | .Ft long | ||
| 67 | .Fo BIO_set_nbio | ||
| 68 | .Fa "BIO *b" | ||
| 69 | .Fa "long n" | ||
| 70 | .Fc | ||
| 71 | .Ft int | ||
| 72 | .Fo BIO_do_connect | ||
| 73 | .Fa "BIO *b" | ||
| 74 | .Fc | ||
| 75 | .Sh DESCRIPTION | ||
| 76 | .Fn BIO_s_connect | ||
| 77 | returns the connect BIO method. | ||
| 78 | This is a wrapper around the platform's TCP/IP socket connection routines. | ||
| 79 | .Pp | ||
| 80 | Using connect BIOs, TCP/IP connections can be made and data | ||
| 81 | transferred using only BIO routines. | ||
| 82 | In this way any platform specific operations | ||
| 83 | are hidden by the BIO abstraction. | ||
| 84 | .Pp | ||
| 85 | Read and write operations on a connect BIO will perform I/O | ||
| 86 | on the underlying connection. | ||
| 87 | If no connection is established and the port and hostname (see below) | ||
| 88 | is set up properly, then a connection is established first. | ||
| 89 | .Pp | ||
| 90 | Connect BIOs support | ||
| 91 | .Xr BIO_puts 3 | ||
| 92 | but not | ||
| 93 | .Xr BIO_gets 3 . | ||
| 94 | .Pp | ||
| 95 | If the close flag is set on a connect BIO, then any active connection | ||
| 96 | is shutdown and the socket closed when the BIO is freed. | ||
| 97 | .Pp | ||
| 98 | Calling | ||
| 99 | .Xr BIO_reset 3 | ||
| 100 | on a connect BIO will close any active connection and reset the BIO | ||
| 101 | into a state where it can connect to the same host again. | ||
| 102 | .Pp | ||
| 103 | .Xr BIO_get_fd 3 | ||
| 104 | places the underlying socket in | ||
| 105 | .Fa c | ||
| 106 | if it is not | ||
| 107 | .Dv NULL , | ||
| 108 | it also returns the socket. | ||
| 109 | If | ||
| 110 | .Fa c | ||
| 111 | is not | ||
| 112 | .Dv NULL | ||
| 113 | it should be of type | ||
| 114 | .Vt "int *" . | ||
| 115 | .Pp | ||
| 116 | .Fn BIO_set_conn_hostname | ||
| 117 | uses the string | ||
| 118 | .Fa name | ||
| 119 | to set the hostname. | ||
| 120 | The hostname can be an IP address. | ||
| 121 | The hostname can also include the port in the form | ||
| 122 | .Ar hostname : Ns Ar port . | ||
| 123 | It is also acceptable to use the forms | ||
| 124 | .Ar hostname Ns / Ns Pa any/other/path | ||
| 125 | or | ||
| 126 | .Ar hostname : Ns Ar port Ns / Ns Pa any/other/path . | ||
| 127 | .Pp | ||
| 128 | .Fn BIO_set_conn_port | ||
| 129 | sets the port to | ||
| 130 | .Fa port . | ||
| 131 | .Fa port | ||
| 132 | can be the numerical form or a string such as | ||
| 133 | .Cm http . | ||
| 134 | A string will be looked up first using | ||
| 135 | .Xr getservbyname 3 | ||
| 136 | on the host platform, but if that fails | ||
| 137 | a built-in table of port names will be used. | ||
| 138 | Currently the list is | ||
| 139 | .Cm http , | ||
| 140 | .Cm telnet , | ||
| 141 | .Cm socks , | ||
| 142 | .Cm https , | ||
| 143 | .Cm ssl , | ||
| 144 | .Cm ftp , | ||
| 145 | .Cm gopher , | ||
| 146 | and | ||
| 147 | .Cm wais . | ||
| 148 | .Pp | ||
| 149 | .Fn BIO_set_conn_ip | ||
| 150 | sets the IP address to | ||
| 151 | .Fa ip | ||
| 152 | using binary form, that is four bytes specifying the IP address | ||
| 153 | in big-endian form. | ||
| 154 | .Pp | ||
| 155 | .Fn BIO_set_conn_int_port | ||
| 156 | sets the port using | ||
| 157 | .Fa port . | ||
| 158 | .Fa port | ||
| 159 | should | ||
| 160 | be of type | ||
| 161 | .Vt "int *" . | ||
| 162 | .Pp | ||
| 163 | .Fn BIO_get_conn_hostname | ||
| 164 | returns the hostname of the connect BIO or | ||
| 165 | .Dv NULL | ||
| 166 | if the BIO is initialized but no hostname is set. | ||
| 167 | This return value is an internal pointer which should not be modified. | ||
| 168 | .Pp | ||
| 169 | .Fn BIO_get_conn_port | ||
| 170 | returns the port as a string. | ||
| 171 | .Pp | ||
| 172 | .Fn BIO_get_conn_ip | ||
| 173 | returns the IP address in binary form. | ||
| 174 | .Pp | ||
| 175 | .Fn BIO_get_conn_int_port | ||
| 176 | returns the port as an | ||
| 177 | .Vt int . | ||
| 178 | .Pp | ||
| 179 | .Fn BIO_set_nbio | ||
| 180 | sets the non blocking I/O flag to | ||
| 181 | .Fa n . | ||
| 182 | If | ||
| 183 | .Fa n | ||
| 184 | is zero then blocking I/O is set. | ||
| 185 | If | ||
| 186 | .Fa n | ||
| 187 | is 1 then non blocking I/O is set. | ||
| 188 | Blocking I/O is the default. | ||
| 189 | The call to | ||
| 190 | .Fn BIO_set_nbio | ||
| 191 | should be made before the connection is established | ||
| 192 | because non blocking I/O is set during the connect process. | ||
| 193 | .Pp | ||
| 194 | .Fn BIO_new_connect | ||
| 195 | combines | ||
| 196 | .Xr BIO_new 3 | ||
| 197 | and | ||
| 198 | .Fn BIO_set_conn_hostname | ||
| 199 | into a single call. | ||
| 200 | It creates a new connect BIO with | ||
| 201 | .Fa name . | ||
| 202 | .Pp | ||
| 203 | .Fn BIO_do_connect | ||
| 204 | attempts to connect the supplied BIO. | ||
| 205 | It returns 1 if the connection was established successfully. | ||
| 206 | A zero or negative value is returned if the connection | ||
| 207 | could not be established. | ||
| 208 | The call | ||
| 209 | .Xr BIO_should_retry 3 | ||
| 210 | should be used for non blocking connect BIOs | ||
| 211 | to determine if the call should be retried. | ||
| 212 | .Sh NOTES | ||
| 213 | If blocking I/O is set then a non positive return value from any | ||
| 214 | I/O call is caused by an error condition, although a zero return | ||
| 215 | will normally mean that the connection was closed. | ||
| 216 | .Pp | ||
| 217 | If the port name is supplied as part of the host name then this will | ||
| 218 | override any value set with | ||
| 219 | .Fn BIO_set_conn_port . | ||
| 220 | This may be undesirable if the application does not wish to allow | ||
| 221 | connection to arbitrary ports. | ||
| 222 | This can be avoided by checking for the presence of the | ||
| 223 | .Sq \&: | ||
| 224 | character in the passed hostname and either indicating an error | ||
| 225 | or truncating the string at that point. | ||
| 226 | .Pp | ||
| 227 | The values returned by | ||
| 228 | .Fn BIO_get_conn_hostname , | ||
| 229 | .Fn BIO_get_conn_port , | ||
| 230 | .Fn BIO_get_conn_ip , | ||
| 231 | and | ||
| 232 | .Fn BIO_get_conn_int_port | ||
| 233 | are updated when a connection attempt is made. | ||
| 234 | Before any connection attempt the values returned | ||
| 235 | are those set by the application itself. | ||
| 236 | .Pp | ||
| 237 | Applications do not have to call | ||
| 238 | .Fn BIO_do_connect | ||
| 239 | but may wish to do so to separate the connection process | ||
| 240 | from other I/O processing. | ||
| 241 | .Pp | ||
| 242 | If non-blocking I/O is set, | ||
| 243 | then retries will be requested as appropriate. | ||
| 244 | .Pp | ||
| 245 | It addition to | ||
| 246 | .Xr BIO_should_read 3 | ||
| 247 | and | ||
| 248 | .Xr BIO_should_write 3 | ||
| 249 | it is also possible for | ||
| 250 | .Xr BIO_should_io_special 3 | ||
| 251 | to be true during the initial connection process with the reason | ||
| 252 | .Dv BIO_RR_CONNECT . | ||
| 253 | If this is returned, it is an indication | ||
| 254 | that a connection attempt would block. | ||
| 255 | The application should then take appropriate action to wait | ||
| 256 | until the underlying socket has connected and retry the call. | ||
| 257 | .Pp | ||
| 258 | .Fn BIO_set_conn_hostname , | ||
| 259 | .Fn BIO_set_conn_port , | ||
| 260 | .Fn BIO_set_conn_ip , | ||
| 261 | .Fn BIO_set_conn_int_port , | ||
| 262 | .Fn BIO_get_conn_hostname , | ||
| 263 | .Fn BIO_get_conn_port , | ||
| 264 | .Fn BIO_get_conn_ip , | ||
| 265 | .Fn BIO_get_conn_int_port , | ||
| 266 | .Fn BIO_set_nbio , | ||
| 267 | and | ||
| 268 | .Fn BIO_do_connect | ||
| 269 | are macros. | ||
| 270 | .Sh RETURN VALUES | ||
| 271 | .Fn BIO_s_connect | ||
| 272 | returns the connect BIO method. | ||
| 273 | .Pp | ||
| 274 | .Xr BIO_get_fd 3 | ||
| 275 | returns the socket or -1 if the BIO has not been initialized. | ||
| 276 | .Pp | ||
| 277 | .Fn BIO_set_conn_hostname , | ||
| 278 | .Fn BIO_set_conn_port , | ||
| 279 | .Fn BIO_set_conn_ip , | ||
| 280 | and | ||
| 281 | .Fn BIO_set_conn_int_port | ||
| 282 | always return 1. | ||
| 283 | .Pp | ||
| 284 | .Fn BIO_get_conn_hostname | ||
| 285 | returns the connected hostname or | ||
| 286 | .Dv NULL | ||
| 287 | if none is set. | ||
| 288 | .Pp | ||
| 289 | .Fn BIO_get_conn_port | ||
| 290 | returns a string representing the connected port or | ||
| 291 | .Dv NULL | ||
| 292 | if not set. | ||
| 293 | .Pp | ||
| 294 | .Fn BIO_get_conn_ip | ||
| 295 | returns a pointer to the connected IP address in binary form | ||
| 296 | or all zeros if not set. | ||
| 297 | .Pp | ||
| 298 | .Fn BIO_get_conn_int_port | ||
| 299 | returns the connected port or 0 if none was set. | ||
| 300 | .Pp | ||
| 301 | .Fn BIO_set_nbio | ||
| 302 | always returns 1. | ||
| 303 | .Pp | ||
| 304 | .Fn BIO_do_connect | ||
| 305 | returns 1 if the connection was successfully | ||
| 306 | established and 0 or -1 if the connection failed. | ||
| 307 | .Sh EXAMPLES | ||
| 308 | This example connects to a webserver on the local host and attempts | ||
| 309 | to retrieve a page and copy the result to standard output. | ||
| 310 | .Bd -literal -offset 2n | ||
| 311 | BIO *cbio, *out; | ||
| 312 | int len; | ||
| 313 | char tmpbuf[1024]; | ||
| 314 | |||
| 315 | ERR_load_crypto_strings(); | ||
| 316 | cbio = BIO_new_connect("localhost:http"); | ||
| 317 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | ||
| 318 | if (BIO_do_connect(cbio) <= 0) { | ||
| 319 | fprintf(stderr, "Error connecting to server\en"); | ||
| 320 | ERR_print_errors_fp(stderr); | ||
| 321 | /* whatever ... */ | ||
| 322 | } | ||
| 323 | BIO_puts(cbio, "GET / HTTP/1.0\en\en"); | ||
| 324 | for(;;) { | ||
| 325 | len = BIO_read(cbio, tmpbuf, 1024); | ||
| 326 | if (len <= 0) | ||
| 327 | break; | ||
| 328 | BIO_write(out, tmpbuf, len); | ||
| 329 | } | ||
| 330 | BIO_free(cbio); | ||
| 331 | BIO_free(out); | ||
| 332 | .Ed | ||
diff --git a/src/lib/libcrypto/man/BIO_s_fd.3 b/src/lib/libcrypto/man/BIO_s_fd.3 new file mode 100644 index 0000000000..3d6a2a3ca9 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_fd.3 | |||
| @@ -0,0 +1,137 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_FD 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_fd , | ||
| 6 | .Nm BIO_set_fd , | ||
| 7 | .Nm BIO_get_fd , | ||
| 8 | .Nm BIO_new_fd | ||
| 9 | .Nd file descriptor BIO | ||
| 10 | .Sh SYNOPSIS | ||
| 11 | .In openssl/bio.h | ||
| 12 | .Ft BIO_METHOD * | ||
| 13 | .Fo BIO_s_fd | ||
| 14 | .Fa "void" | ||
| 15 | .Fc | ||
| 16 | .Fd #define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) | ||
| 17 | .Fd #define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) | ||
| 18 | .Ft BIO * | ||
| 19 | .Fo BIO_new_fd | ||
| 20 | .Fa "int fd" | ||
| 21 | .Fa "int close_flag" | ||
| 22 | .Fc | ||
| 23 | .Sh DESCRIPTION | ||
| 24 | .Fn BIO_s_fd | ||
| 25 | returns the file descriptor BIO method. | ||
| 26 | This is a wrapper around the platform's file descriptor routines such as | ||
| 27 | .Xr read 2 | ||
| 28 | and | ||
| 29 | .Xr write 2 . | ||
| 30 | .Pp | ||
| 31 | .Xr BIO_read 3 | ||
| 32 | and | ||
| 33 | .Xr BIO_write 3 | ||
| 34 | read or write the underlying descriptor. | ||
| 35 | .Xr BIO_puts 3 | ||
| 36 | is supported but | ||
| 37 | .Xr BIO_gets 3 | ||
| 38 | is not. | ||
| 39 | .Pp | ||
| 40 | If the close flag is set, | ||
| 41 | .Xr close 2 | ||
| 42 | is called on the underlying file descriptor when the BIO is freed. | ||
| 43 | .Pp | ||
| 44 | .Xr BIO_reset 3 | ||
| 45 | attempts to set the file pointer to the start of the file using | ||
| 46 | .Fn lseek fd 0 0 . | ||
| 47 | .Pp | ||
| 48 | .Xr BIO_seek 3 | ||
| 49 | sets the file pointer to position | ||
| 50 | .Fa ofs | ||
| 51 | from start of file using | ||
| 52 | .Fn lseek fd ofs 0 . | ||
| 53 | .Pp | ||
| 54 | .Xr BIO_tell 3 | ||
| 55 | returns the current file position by calling | ||
| 56 | .Fn lseek fd 0 1 . | ||
| 57 | .Pp | ||
| 58 | .Fn BIO_set_fd | ||
| 59 | sets the file descriptor of BIO | ||
| 60 | .Fa b | ||
| 61 | to | ||
| 62 | .Fa fd | ||
| 63 | and the close flag to | ||
| 64 | .Fa c . | ||
| 65 | .Pp | ||
| 66 | .Fn BIO_get_fd | ||
| 67 | places the file descriptor in | ||
| 68 | .Fa c | ||
| 69 | if it is not | ||
| 70 | .Dv NULL , | ||
| 71 | it also returns the file descriptor. | ||
| 72 | If | ||
| 73 | .Fa c | ||
| 74 | is not | ||
| 75 | .Dv NULL , | ||
| 76 | it should be of type | ||
| 77 | .Vt "int *" . | ||
| 78 | .Pp | ||
| 79 | .Fn BIO_new_fd | ||
| 80 | returns a file descriptor BIO using | ||
| 81 | .Fa fd | ||
| 82 | and | ||
| 83 | .Fa close_flag . | ||
| 84 | .Sh NOTES | ||
| 85 | The behaviour of | ||
| 86 | .Xr BIO_read 3 | ||
| 87 | and | ||
| 88 | .Xr BIO_write 3 | ||
| 89 | depends on the behavior of the platform's | ||
| 90 | .Xr read 2 | ||
| 91 | and | ||
| 92 | .Xr write 2 | ||
| 93 | calls on the descriptor. | ||
| 94 | If the underlying file descriptor is in a non blocking mode, | ||
| 95 | then the BIO will behave in the manner described in the | ||
| 96 | .Xr BIO_read 3 | ||
| 97 | and | ||
| 98 | .Xr BIO_should_retry 3 | ||
| 99 | manual pages. | ||
| 100 | .Pp | ||
| 101 | File descriptor BIOs should not be used for socket I/O. | ||
| 102 | Use socket BIOs instead. | ||
| 103 | .Sh RETURN VALUES | ||
| 104 | .Fn BIO_s_fd | ||
| 105 | returns the file descriptor BIO method. | ||
| 106 | .Pp | ||
| 107 | .Xr BIO_reset 3 | ||
| 108 | returns zero for success and -1 if an error occurred. | ||
| 109 | .Xr BIO_seek 3 | ||
| 110 | and | ||
| 111 | .Xr BIO_tell 3 | ||
| 112 | return the current file position or -1 if an error occurred. | ||
| 113 | These values reflect the underlying | ||
| 114 | .Xr lseek 2 | ||
| 115 | behaviour. | ||
| 116 | .Pp | ||
| 117 | .Fn BIO_set_fd | ||
| 118 | always returns 1. | ||
| 119 | .Pp | ||
| 120 | .Fn BIO_get_fd | ||
| 121 | returns the file descriptor or -1 if the BIO has not been initialized. | ||
| 122 | .Pp | ||
| 123 | .Fn BIO_new_fd | ||
| 124 | returns the newly allocated BIO or | ||
| 125 | .Dv NULL | ||
| 126 | if an error occurred. | ||
| 127 | .Sh EXAMPLE | ||
| 128 | This is a file descriptor BIO version of "Hello World": | ||
| 129 | .Bd -literal -offset indent | ||
| 130 | BIO *out; | ||
| 131 | out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE); | ||
| 132 | BIO_printf(out, "Hello World\en"); | ||
| 133 | BIO_free(out); | ||
| 134 | .Ed | ||
| 135 | .Sh SEE ALSO | ||
| 136 | .Xr BIO_read 3 , | ||
| 137 | .Xr BIO_seek 3 | ||
diff --git a/src/lib/libcrypto/man/BIO_s_file.3 b/src/lib/libcrypto/man/BIO_s_file.3 new file mode 100644 index 0000000000..c7075a3fb7 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_file.3 | |||
| @@ -0,0 +1,248 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_FILE 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_file , | ||
| 6 | .Nm BIO_new_file , | ||
| 7 | .Nm BIO_new_fp , | ||
| 8 | .Nm BIO_set_fp , | ||
| 9 | .Nm BIO_get_fp , | ||
| 10 | .Nm BIO_read_filename , | ||
| 11 | .Nm BIO_write_filename , | ||
| 12 | .Nm BIO_append_filename , | ||
| 13 | .Nm BIO_rw_filename | ||
| 14 | .Nd FILE bio | ||
| 15 | .Sh SYNOPSIS | ||
| 16 | .In openssl/bio.h | ||
| 17 | .Ft BIO_METHOD * | ||
| 18 | .Fo BIO_s_file | ||
| 19 | .Fa void | ||
| 20 | .Fc | ||
| 21 | .Ft BIO * | ||
| 22 | .Fo BIO_new_file | ||
| 23 | .Fa "const char *filename" | ||
| 24 | .Fa "const char *mode" | ||
| 25 | .Fc | ||
| 26 | .Ft BIO * | ||
| 27 | .Fo BIO_new_fp | ||
| 28 | .Fa "FILE *stream" | ||
| 29 | .Fa "int flags" | ||
| 30 | .Fc | ||
| 31 | .Ft long | ||
| 32 | .Fo BIO_set_fp | ||
| 33 | .Fa "BIO *b" | ||
| 34 | .Fa "FILE *fp" | ||
| 35 | .Fa "int flags" | ||
| 36 | .Fc | ||
| 37 | .Ft long | ||
| 38 | .Fo BIO_get_fp | ||
| 39 | .Fa "BIO *b" | ||
| 40 | .Fa "FILE **fpp" | ||
| 41 | .Fc | ||
| 42 | .Ft int | ||
| 43 | .Fo BIO_read_filename | ||
| 44 | .Fa "BIO *b" | ||
| 45 | .Fa "char *name" | ||
| 46 | .Fc | ||
| 47 | .Ft int | ||
| 48 | .Fo BIO_write_filename | ||
| 49 | .Fa "BIO *b" | ||
| 50 | .Fa "char *name" | ||
| 51 | .Fc | ||
| 52 | .Ft int | ||
| 53 | .Fo BIO_append_filename | ||
| 54 | .Fa "BIO *b" | ||
| 55 | .Fa "char *name" | ||
| 56 | .Fc | ||
| 57 | .Ft int | ||
| 58 | .Fo BIO_rw_filename | ||
| 59 | .Fa "BIO *b" | ||
| 60 | .Fa "char *name" | ||
| 61 | .Fc | ||
| 62 | .Sh DESCRIPTION | ||
| 63 | .Fn BIO_s_file | ||
| 64 | returns the BIO file method. | ||
| 65 | As its name implies, it is a wrapper around the stdio | ||
| 66 | .Vt FILE | ||
| 67 | structure and it is a source/sink BIO. | ||
| 68 | .Pp | ||
| 69 | Calls to | ||
| 70 | .Xr BIO_read 3 | ||
| 71 | and | ||
| 72 | .Xr BIO_write 3 | ||
| 73 | read and write data to the underlying stream. | ||
| 74 | .Xr BIO_gets 3 | ||
| 75 | and | ||
| 76 | .Xr BIO_puts 3 | ||
| 77 | are supported on file BIOs. | ||
| 78 | .Pp | ||
| 79 | .Xr BIO_flush 3 | ||
| 80 | on a file BIO calls the | ||
| 81 | .Xr fflush 3 | ||
| 82 | function on the wrapped stream. | ||
| 83 | .Pp | ||
| 84 | .Xr BIO_reset 3 | ||
| 85 | attempts to change the file pointer to the start of file using | ||
| 86 | .Fn fseek stream 0 0 . | ||
| 87 | .Pp | ||
| 88 | .Xr BIO_seek 3 | ||
| 89 | sets the file pointer to position | ||
| 90 | .Fa ofs | ||
| 91 | from the start of the file using | ||
| 92 | .Fn fseek stream ofs 0 . | ||
| 93 | .Pp | ||
| 94 | .Xr BIO_eof 3 | ||
| 95 | calls | ||
| 96 | .Xr feof 3 . | ||
| 97 | .Pp | ||
| 98 | Setting the | ||
| 99 | .Dv BIO_CLOSE | ||
| 100 | flag calls | ||
| 101 | .Xr fclose 3 | ||
| 102 | on the stream when the BIO is freed. | ||
| 103 | .Pp | ||
| 104 | .Fn BIO_new_file | ||
| 105 | creates a new file BIO with mode | ||
| 106 | .Fa mode . | ||
| 107 | The meaning of | ||
| 108 | .Fa mode | ||
| 109 | is the same as for the stdio function | ||
| 110 | .Xr fopen 3 . | ||
| 111 | The | ||
| 112 | .Dv BIO_CLOSE | ||
| 113 | flag is set on the returned BIO. | ||
| 114 | .Pp | ||
| 115 | .Fn BIO_new_fp | ||
| 116 | creates a file BIO wrapping | ||
| 117 | .Fa stream . | ||
| 118 | Flags can be: | ||
| 119 | .Dv BIO_CLOSE , BIO_NOCLOSE Pq the close flag , | ||
| 120 | .Dv BIO_FP_TEXT | ||
| 121 | (sets the underlying stream to text mode, default is binary: | ||
| 122 | this only has any effect under Win32). | ||
| 123 | .Pp | ||
| 124 | .Fn BIO_set_fp | ||
| 125 | set the file pointer of a file BIO to | ||
| 126 | .Fa fp . | ||
| 127 | .Fa flags | ||
| 128 | has the same meaning as in | ||
| 129 | .Fn BIO_new_fp . | ||
| 130 | .Fn BIO_set_fp | ||
| 131 | is a macro. | ||
| 132 | .Pp | ||
| 133 | .Fn BIO_get_fp | ||
| 134 | retrieves the file pointer of a file BIO, it is a macro. | ||
| 135 | .Pp | ||
| 136 | .Xr BIO_seek 3 | ||
| 137 | is a macro that sets the position pointer to | ||
| 138 | .Fa offset | ||
| 139 | bytes from the start of file. | ||
| 140 | .Pp | ||
| 141 | .Xr BIO_tell 3 | ||
| 142 | returns the value of the position pointer. | ||
| 143 | .Pp | ||
| 144 | .Fn BIO_read_filename , | ||
| 145 | .Fn BIO_write_filename , | ||
| 146 | .Fn BIO_append_filename , | ||
| 147 | and | ||
| 148 | .Fn BIO_rw_filename | ||
| 149 | set the file BIO | ||
| 150 | .Fa b | ||
| 151 | to use file | ||
| 152 | .Fa name | ||
| 153 | for reading, writing, append or read write respectively. | ||
| 154 | .Sh NOTES | ||
| 155 | When wrapping stdout, stdin, or stderr, the underlying stream | ||
| 156 | should not normally be closed, so the | ||
| 157 | .Dv BIO_NOCLOSE | ||
| 158 | flag should be set. | ||
| 159 | .Pp | ||
| 160 | Because the file BIO calls the underlying stdio functions, any quirks | ||
| 161 | in stdio behaviour will be mirrored by the corresponding BIO. | ||
| 162 | .Pp | ||
| 163 | On Windows, | ||
| 164 | .Fn BIO_new_files | ||
| 165 | reserves for the filename argument to be UTF-8 encoded. | ||
| 166 | In other words, if you have to make it work in a multi-lingual | ||
| 167 | environment, encode file names in UTF-8. | ||
| 168 | .Sh RETURN VALUES | ||
| 169 | .Fn BIO_s_file | ||
| 170 | returns the file BIO method. | ||
| 171 | .Pp | ||
| 172 | .Fn BIO_new_file | ||
| 173 | and | ||
| 174 | .Fn BIO_new_fp | ||
| 175 | return a file BIO or | ||
| 176 | .Dv NULL | ||
| 177 | if an error occurred. | ||
| 178 | .Pp | ||
| 179 | .Fn BIO_set_fp | ||
| 180 | and | ||
| 181 | .Fn BIO_get_fp | ||
| 182 | return 1 for success or 0 for failure (although the current | ||
| 183 | implementation never returns 0). | ||
| 184 | .Pp | ||
| 185 | .Xr BIO_seek 3 | ||
| 186 | returns the same value as the underlying | ||
| 187 | .Xr fseek 3 | ||
| 188 | function: 0 for success or -1 for failure. | ||
| 189 | .Pp | ||
| 190 | .Xr BIO_tell 3 | ||
| 191 | returns the current file position. | ||
| 192 | .Pp | ||
| 193 | .Fn BIO_read_filename , | ||
| 194 | .Fn BIO_write_filename , | ||
| 195 | .Fn BIO_append_filename , | ||
| 196 | and | ||
| 197 | .Fn BIO_rw_filename | ||
| 198 | return 1 for success or 0 for failure. | ||
| 199 | .Sh EXAMPLES | ||
| 200 | File BIO "hello world": | ||
| 201 | .Bd -literal -offset indent | ||
| 202 | BIO *bio_out; | ||
| 203 | bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); | ||
| 204 | BIO_printf(bio_out, "Hello World\en"); | ||
| 205 | .Ed | ||
| 206 | .Pp | ||
| 207 | Alternative technique: | ||
| 208 | .Bd -literal -offset indent | ||
| 209 | BIO *bio_out; | ||
| 210 | bio_out = BIO_new(BIO_s_file()); | ||
| 211 | if(bio_out == NULL) /* Error ... */ | ||
| 212 | if(!BIO_set_fp(bio_out, stdout, BIO_NOCLOSE)) /* Error ... */ | ||
| 213 | BIO_printf(bio_out, "Hello World\en"); | ||
| 214 | .Ed | ||
| 215 | .Pp | ||
| 216 | Write to a file: | ||
| 217 | .Bd -literal -offset indent | ||
| 218 | BIO *out; | ||
| 219 | out = BIO_new_file("filename.txt", "w"); | ||
| 220 | if(!out) /* Error occurred */ | ||
| 221 | BIO_printf(out, "Hello World\en"); | ||
| 222 | BIO_free(out); | ||
| 223 | .Ed | ||
| 224 | .Pp | ||
| 225 | Alternative technique: | ||
| 226 | .Bd -literal -offset indent | ||
| 227 | BIO *out; | ||
| 228 | out = BIO_new(BIO_s_file()); | ||
| 229 | if(out == NULL) /* Error ... */ | ||
| 230 | if(!BIO_write_filename(out, "filename.txt")) /* Error ... */ | ||
| 231 | BIO_printf(out, "Hello World\en"); | ||
| 232 | BIO_free(out); | ||
| 233 | .Ed | ||
| 234 | .Sh SEE ALSO | ||
| 235 | .Xr BIO_read 3 , | ||
| 236 | .Xr BIO_seek 3 | ||
| 237 | .Sh BUGS | ||
| 238 | .Xr BIO_reset 3 | ||
| 239 | and | ||
| 240 | .Xr BIO_seek 3 | ||
| 241 | are implemented using | ||
| 242 | .Xr fseek 3 | ||
| 243 | on the underlying stream. | ||
| 244 | The return value for | ||
| 245 | .Xr fseek 3 | ||
| 246 | is 0 for success or -1 if an error occurred. | ||
| 247 | This differs from other types of BIO which will typically return | ||
| 248 | 1 for success and a non positive value if an error occurred. | ||
diff --git a/src/lib/libcrypto/man/BIO_s_mem.3 b/src/lib/libcrypto/man/BIO_s_mem.3 new file mode 100644 index 0000000000..a37b4bff98 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_mem.3 | |||
| @@ -0,0 +1,190 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_MEM 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_mem , | ||
| 6 | .Nm BIO_set_mem_eof_return , | ||
| 7 | .Nm BIO_get_mem_data , | ||
| 8 | .Nm BIO_set_mem_buf , | ||
| 9 | .Nm BIO_get_mem_ptr , | ||
| 10 | .Nm BIO_new_mem_buf | ||
| 11 | .Nd memory BIO | ||
| 12 | .Sh SYNOPSIS | ||
| 13 | .In openssl/bio.h | ||
| 14 | .Ft BIO_METHOD * | ||
| 15 | .Fo BIO_s_mem | ||
| 16 | .Fa "void" | ||
| 17 | .Fc | ||
| 18 | .Ft long | ||
| 19 | .Fo BIO_set_mem_eof_return | ||
| 20 | .Fa "BIO *b" | ||
| 21 | .Fa "int v" | ||
| 22 | .Fc | ||
| 23 | .Ft long | ||
| 24 | .Fo BIO_get_mem_data | ||
| 25 | .Fa "BIO *b" | ||
| 26 | .Fa "char **pp" | ||
| 27 | .Fc | ||
| 28 | .Ft long | ||
| 29 | .Fo BIO_set_mem_buf | ||
| 30 | .Fa "BIO *b" | ||
| 31 | .Fa "BUF_MEM *bm" | ||
| 32 | .Fa "int c" | ||
| 33 | .Fc | ||
| 34 | .Ft long | ||
| 35 | .Fo BIO_get_mem_ptr | ||
| 36 | .Fa "BIO *b" | ||
| 37 | .Fa "BUF_MEM **pp" | ||
| 38 | .Fc | ||
| 39 | .Ft BIO * | ||
| 40 | .Fo BIO_new_mem_buf | ||
| 41 | .Fa "void *buf" | ||
| 42 | .Fa "int len" | ||
| 43 | .Fc | ||
| 44 | .Sh DESCRIPTION | ||
| 45 | .Fn BIO_s_mem | ||
| 46 | returns the memory BIO method function. | ||
| 47 | .Pp | ||
| 48 | A memory BIO is a source/sink BIO which uses memory for its I/O. | ||
| 49 | Data written to a memory BIO is stored in a | ||
| 50 | .Vt BUF_MEM | ||
| 51 | structure which is extended as appropriate to accommodate the stored data. | ||
| 52 | .Pp | ||
| 53 | Any data written to a memory BIO can be recalled by reading from it. | ||
| 54 | Unless the memory BIO is read only, | ||
| 55 | any data read from it is deleted from the BIO. | ||
| 56 | .Pp | ||
| 57 | Memory BIOs support | ||
| 58 | .Xr BIO_gets 3 | ||
| 59 | and | ||
| 60 | .Xr BIO_puts 3 . | ||
| 61 | .Pp | ||
| 62 | If the | ||
| 63 | .Dv BIO_CLOSE | ||
| 64 | flag is set when a memory BIO is freed, the underlying | ||
| 65 | .Dv BUF_MEM | ||
| 66 | structure is also freed. | ||
| 67 | .Pp | ||
| 68 | Calling | ||
| 69 | .Xr BIO_reset 3 | ||
| 70 | on a read/write memory BIO clears any data in it. | ||
| 71 | On a read only BIO it restores the BIO to its original state | ||
| 72 | and the read only data can be read again. | ||
| 73 | .Pp | ||
| 74 | .Xr BIO_eof 3 | ||
| 75 | is true if no data is in the BIO. | ||
| 76 | .Pp | ||
| 77 | .Xr BIO_ctrl_pending 3 | ||
| 78 | returns the number of bytes currently stored. | ||
| 79 | .Pp | ||
| 80 | .Xr BIO_set_mem_eof_return 3 | ||
| 81 | sets the behaviour of memory BIO | ||
| 82 | .Fa b | ||
| 83 | when it is empty. | ||
| 84 | If | ||
| 85 | .Fa v | ||
| 86 | is zero, then an empty memory BIO will return EOF: | ||
| 87 | It will return zero and | ||
| 88 | .Fn BIO_should_retry | ||
| 89 | will be false. | ||
| 90 | If | ||
| 91 | .Fa v | ||
| 92 | is non-zero then it will return | ||
| 93 | .Fa v | ||
| 94 | when it is empty and it will set the read retry flag: | ||
| 95 | .Fn BIO_read_retry | ||
| 96 | is true. | ||
| 97 | To avoid ambiguity with a normal positive return value | ||
| 98 | .Fa v | ||
| 99 | should be set to a negative value, typically -1. | ||
| 100 | .Pp | ||
| 101 | .Fn BIO_get_mem_data | ||
| 102 | sets | ||
| 103 | .Fa pp | ||
| 104 | to a pointer to the start of the memory BIO's data | ||
| 105 | and returns the total amount of data available. | ||
| 106 | It is implemented as a macro. | ||
| 107 | .Pp | ||
| 108 | .Fn BIO_set_mem_buf | ||
| 109 | sets the internal BUF_MEM structure to | ||
| 110 | .Fa bm | ||
| 111 | and sets the close flag to | ||
| 112 | .Fa c , | ||
| 113 | that is | ||
| 114 | .Fa c | ||
| 115 | should be either | ||
| 116 | .Dv BIO_CLOSE | ||
| 117 | or | ||
| 118 | .Dv BIO_NOCLOSE . | ||
| 119 | .Fn BIO_set_mem_buf | ||
| 120 | is a macro. | ||
| 121 | .Pp | ||
| 122 | .Fn BIO_get_mem_ptr | ||
| 123 | places the underlying | ||
| 124 | .Vt BUF_MEM | ||
| 125 | structure in | ||
| 126 | .Fa pp . | ||
| 127 | It is a macro. | ||
| 128 | .Pp | ||
| 129 | .Fn BIO_new_mem_buf | ||
| 130 | creates a memory BIO using | ||
| 131 | .Fa len | ||
| 132 | bytes of data at | ||
| 133 | .Fa buf . | ||
| 134 | If | ||
| 135 | .Fa len | ||
| 136 | is -1, then | ||
| 137 | .Fa buf | ||
| 138 | is assumed to be NUL terminated and its length is determined by | ||
| 139 | .Xr strlen 3 . | ||
| 140 | The BIO is set to a read only state and as a result cannot be written to. | ||
| 141 | This is useful when some data needs to be made available | ||
| 142 | from a static area of memory in the form of a BIO. | ||
| 143 | The supplied data is read directly from the supplied buffer: | ||
| 144 | it is | ||
| 145 | .Em not | ||
| 146 | copied first, so the supplied area of memory must be unchanged | ||
| 147 | until the BIO is freed. | ||
| 148 | .Sh NOTES | ||
| 149 | Writes to memory BIOs will always succeed if memory is available: | ||
| 150 | their size can grow indefinitely. | ||
| 151 | .Pp | ||
| 152 | Every read from a read/write memory BIO will remove the data just read | ||
| 153 | with an internal copy operation. | ||
| 154 | If a BIO contains a lot of data and it is read in small chunks, | ||
| 155 | the operation can be very slow. | ||
| 156 | The use of a read only memory BIO avoids this problem. | ||
| 157 | If the BIO must be read/write then adding a buffering BIO | ||
| 158 | to the chain will speed up the process. | ||
| 159 | .Sh EXAMPLES | ||
| 160 | Create a memory BIO and write some data to it: | ||
| 161 | .Bd -literal -offset indent | ||
| 162 | BIO *mem = BIO_new(BIO_s_mem()); | ||
| 163 | BIO_puts(mem, "Hello World\en"); | ||
| 164 | .Ed | ||
| 165 | .Pp | ||
| 166 | Create a read only memory BIO: | ||
| 167 | .Bd -literal -offset indent | ||
| 168 | char data[] = "Hello World"; | ||
| 169 | BIO *mem; | ||
| 170 | mem = BIO_new_mem_buf(data, -1); | ||
| 171 | .Ed | ||
| 172 | .Pp | ||
| 173 | Extract the | ||
| 174 | .Vt BUF_MEM | ||
| 175 | structure from a memory BIO and then free up the BIO: | ||
| 176 | .Bd -literal -offset indent | ||
| 177 | BUF_MEM *bptr; | ||
| 178 | BIO_get_mem_ptr(mem, &bptr); | ||
| 179 | /* Make sure BIO_free() leaves BUF_MEM alone. */ | ||
| 180 | BIO_set_close(mem, BIO_NOCLOSE); | ||
| 181 | BIO_free(mem); | ||
| 182 | .Ed | ||
| 183 | .Sh BUGS | ||
| 184 | There should be an option to set the maximum size of a memory BIO. | ||
| 185 | .Pp | ||
| 186 | There should be a way to "rewind" a read/write BIO without destroying | ||
| 187 | its contents. | ||
| 188 | .Pp | ||
| 189 | The copying operation should not occur after every small read | ||
| 190 | of a large BIO to improve efficiency. | ||
diff --git a/src/lib/libcrypto/man/BIO_s_null.3 b/src/lib/libcrypto/man/BIO_s_null.3 new file mode 100644 index 0000000000..05008aabfc --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_null.3 | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_NULL 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_null | ||
| 6 | .Nd null data sink | ||
| 7 | .Sh SYNOPSIS | ||
| 8 | .In openssl/bio.h | ||
| 9 | .Ft BIO_METHOD * | ||
| 10 | .Fo BIO_s_null | ||
| 11 | .Fa void | ||
| 12 | .Fc | ||
| 13 | .Sh DESCRIPTION | ||
| 14 | .Fn BIO_s_null | ||
| 15 | returns the null sink BIO method. | ||
| 16 | Data written to the null sink is discarded, reads return EOF. | ||
| 17 | .Sh NOTES | ||
| 18 | A null sink BIO behaves in a similar manner to the | ||
| 19 | .Xr null 4 | ||
| 20 | device. | ||
| 21 | .Pp | ||
| 22 | A null bio can be placed on the end of a chain to discard any data | ||
| 23 | passed through it. | ||
| 24 | .Pp | ||
| 25 | A null sink is useful if, for example, an application wishes | ||
| 26 | to digest some data by writing through a digest bio | ||
| 27 | but not send the digested data anywhere. | ||
| 28 | Since a BIO chain must normally include a source/sink BIO, | ||
| 29 | this can be achieved by adding a null sink BIO to the end of the chain. | ||
| 30 | .Sh RETURN VALUES | ||
| 31 | .Fn BIO_s_null | ||
| 32 | returns the null sink BIO method. | ||
diff --git a/src/lib/libcrypto/man/BIO_s_socket.3 b/src/lib/libcrypto/man/BIO_s_socket.3 new file mode 100644 index 0000000000..f7aff6a4c8 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_s_socket.3 | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_S_SOCKET 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_s_socket , | ||
| 6 | .Nm BIO_new_socket | ||
| 7 | .Nd socket BIO | ||
| 8 | .Sh SYNOPSIS | ||
| 9 | .In openssl/bio.h | ||
| 10 | .Ft BIO_METHOD * | ||
| 11 | .Fo BIO_s_socket | ||
| 12 | .Fa void | ||
| 13 | .Fc | ||
| 14 | .Ft long | ||
| 15 | .Fo BIO_set_fd | ||
| 16 | .Fa "BIO *b" | ||
| 17 | .Fa "int fd" | ||
| 18 | .Fa "long close_flag" | ||
| 19 | .Fc | ||
| 20 | .Ft long | ||
| 21 | .Fo BIO_get_fd | ||
| 22 | .Fa "BIO *b" | ||
| 23 | .Fa "int *c" | ||
| 24 | .Fc | ||
| 25 | .Ft BIO * | ||
| 26 | .Fo BIO_new_socket | ||
| 27 | .Fa "int sock" | ||
| 28 | .Fa "int close_flag" | ||
| 29 | .Fc | ||
| 30 | .Sh DESCRIPTION | ||
| 31 | .Fn BIO_s_socket | ||
| 32 | returns the socket BIO method. | ||
| 33 | This is a wrapper around the platform's socket routines. | ||
| 34 | .Pp | ||
| 35 | .Xr BIO_read 3 | ||
| 36 | and | ||
| 37 | .Xr BIO_write 3 | ||
| 38 | read or write the underlying socket. | ||
| 39 | .Xr BIO_puts 3 | ||
| 40 | is supported but | ||
| 41 | .Xr BIO_gets 3 | ||
| 42 | is not. | ||
| 43 | .Pp | ||
| 44 | If the close flag is set, then the socket is shut down and closed | ||
| 45 | when the BIO is freed. | ||
| 46 | .Pp | ||
| 47 | .Fn BIO_set_fd | ||
| 48 | sets the socket of BIO | ||
| 49 | .Fa b | ||
| 50 | to | ||
| 51 | .Fa fd | ||
| 52 | and the close flag to | ||
| 53 | .Fa close_flag . | ||
| 54 | .Pp | ||
| 55 | .Fn BIO_get_fd | ||
| 56 | places the socket in | ||
| 57 | .Fa c | ||
| 58 | if it is not | ||
| 59 | .Dv NULL , | ||
| 60 | it also returns the socket. | ||
| 61 | If | ||
| 62 | .Fa c | ||
| 63 | is not | ||
| 64 | .Dv NULL | ||
| 65 | it should be of type | ||
| 66 | .Vt "int *" . | ||
| 67 | .Pp | ||
| 68 | .Fn BIO_new_socket | ||
| 69 | returns a socket BIO using | ||
| 70 | .Fa sock | ||
| 71 | and | ||
| 72 | .Fa close_flag . | ||
| 73 | .Sh NOTES | ||
| 74 | Socket BIOs also support any relevant functionality of file descriptor BIOs. | ||
| 75 | .Pp | ||
| 76 | The reason for having separate file descriptor and socket BIOs | ||
| 77 | is that on some platforms, sockets are not file descriptors | ||
| 78 | and use distinct I/O routines. | ||
| 79 | Windows is one such platform. | ||
| 80 | Any code mixing the two will not work on all platforms. | ||
| 81 | .Pp | ||
| 82 | .Fn BIO_set_fd | ||
| 83 | and | ||
| 84 | .Fn BIO_get_fd | ||
| 85 | are macros. | ||
| 86 | .Sh RETURN VALUES | ||
| 87 | .Fn BIO_s_socket | ||
| 88 | returns the socket BIO method. | ||
| 89 | .Pp | ||
| 90 | .Fn BIO_set_fd | ||
| 91 | always returns 1. | ||
| 92 | .Pp | ||
| 93 | .Fn BIO_get_fd | ||
| 94 | returns the socket or -1 if the BIO has not been initialized. | ||
| 95 | .Pp | ||
| 96 | .Fn BIO_new_socket | ||
| 97 | returns the newly allocated BIO or | ||
| 98 | .Dv NULL | ||
| 99 | if an error occurred. | ||
diff --git a/src/lib/libcrypto/man/BIO_set_callback.3 b/src/lib/libcrypto/man/BIO_set_callback.3 new file mode 100644 index 0000000000..39d284890e --- /dev/null +++ b/src/lib/libcrypto/man/BIO_set_callback.3 | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_SET_CALLBACK 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_set_callback , | ||
| 6 | .Nm BIO_get_callback , | ||
| 7 | .Nm BIO_set_callback_arg , | ||
| 8 | .Nm BIO_get_callback_arg , | ||
| 9 | .Nm BIO_debug_callback | ||
| 10 | .Nd BIO callback functions | ||
| 11 | .Sh SYNOPSIS | ||
| 12 | .In openssl/bio.h | ||
| 13 | .Fd #define BIO_set_callback(b,cb) ((b)->callback=(cb)) | ||
| 14 | .Fd #define BIO_get_callback(b) ((b)->callback) | ||
| 15 | .Fd #define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg)) | ||
| 16 | .Fd #define BIO_get_callback_arg(b) ((b)->cb_arg) | ||
| 17 | .Ft long | ||
| 18 | .Fo BIO_debug_callback | ||
| 19 | .Fa "BIO *bio" | ||
| 20 | .Fa "int cmd" | ||
| 21 | .Fa "const char *argp" | ||
| 22 | .Fa "int argi" | ||
| 23 | .Fa "long argl" | ||
| 24 | .Fa "long ret" | ||
| 25 | .Fc | ||
| 26 | .Ft typedef long * | ||
| 27 | .Fo callback | ||
| 28 | .Fa "BIO *b" | ||
| 29 | .Fa "int oper" | ||
| 30 | .Fa "const char *argp" | ||
| 31 | .Fa "int argi" | ||
| 32 | .Fa "long argl" | ||
| 33 | .Fa "long retvalue" | ||
| 34 | .Fc | ||
| 35 | .Sh DESCRIPTION | ||
| 36 | .Fn BIO_set_callback | ||
| 37 | and | ||
| 38 | .Fn BIO_get_callback | ||
| 39 | set and retrieve the BIO callback, they are both macros. | ||
| 40 | The callback is called during most high level BIO operations. | ||
| 41 | It can be used for debugging purposes to trace operations on a BIO | ||
| 42 | or to modify its operation. | ||
| 43 | .Pp | ||
| 44 | .Fn BIO_set_callback_arg | ||
| 45 | and | ||
| 46 | .Fn BIO_get_callback_arg | ||
| 47 | are macros which can be used to set and retrieve an argument | ||
| 48 | for use in the callback. | ||
| 49 | .Pp | ||
| 50 | .Fn BIO_debug_callback | ||
| 51 | is a standard debugging callback which prints | ||
| 52 | out information relating to each BIO operation. | ||
| 53 | If the callback argument is set, it is interpreted as a BIO | ||
| 54 | to send the information to, otherwise stderr is used. | ||
| 55 | .Pp | ||
| 56 | .Fn callback | ||
| 57 | is the callback function itself. | ||
| 58 | The meaning of each argument is described below. | ||
| 59 | .Pp | ||
| 60 | The BIO the callback is attached to is passed in | ||
| 61 | .Fa b . | ||
| 62 | .Pp | ||
| 63 | .Fa oper | ||
| 64 | is set to the operation being performed. | ||
| 65 | For some operations the callback is called twice, | ||
| 66 | once before and once after the actual operation. | ||
| 67 | The latter case has | ||
| 68 | .Fa oper | ||
| 69 | or'ed with | ||
| 70 | .Dv BIO_CB_RETURN . | ||
| 71 | .Pp | ||
| 72 | The meaning of the arguments | ||
| 73 | .Fa argp , | ||
| 74 | .Fa argi | ||
| 75 | and | ||
| 76 | .Fa argl | ||
| 77 | depends on the value of | ||
| 78 | .Fa oper , | ||
| 79 | that is the operation being performed. | ||
| 80 | .Pp | ||
| 81 | .Fa retvalue | ||
| 82 | is the return value that would be returned to the application | ||
| 83 | if no callback were present. | ||
| 84 | The actual value returned is the return value of the callback itself. | ||
| 85 | In the case of callbacks called before the actual BIO operation, | ||
| 86 | 1 is placed in retvalue. | ||
| 87 | If the return value is not positive, it will be immediately returned to | ||
| 88 | the application and the BIO operation will not be performed. | ||
| 89 | .Pp | ||
| 90 | The callback should normally simply return | ||
| 91 | .Fa retvalue | ||
| 92 | when it has finished processing, unless it specifically wishes | ||
| 93 | to modify the value returned to the application. | ||
| 94 | .Ss Callback operations | ||
| 95 | .Bl -tag -width Ds | ||
| 96 | .It Fn BIO_free b | ||
| 97 | .Fn callback b BIO_CB_FREE NULL 0L 0L 1L | ||
| 98 | is called before the free operation. | ||
| 99 | .It Fn BIO_read b out outl | ||
| 100 | .Fn callback b BIO_CB_READ out outl 0L 1L | ||
| 101 | is called before the read and | ||
| 102 | .Fn callback b BIO_CB_READ|BIO_CB_RETURN out outl 0L retvalue | ||
| 103 | after. | ||
| 104 | .It Fn BIO_write b in inl | ||
| 105 | .Fn callback b BIO_CB_WRITE in inl 0L 1L | ||
| 106 | is called before the write and | ||
| 107 | .Fn callback b BIO_CB_WRITE|BIO_CB_RETURN in inl 0L retvalue | ||
| 108 | after. | ||
| 109 | .It Fn BIO_gets b out outl | ||
| 110 | .Fn callback b BIO_CB_GETS out outl 0L 1L | ||
| 111 | is called before the operation and | ||
| 112 | .Fn callback b BIO_CB_GETS|BIO_CB_RETURN out outl 0L retvalue | ||
| 113 | after. | ||
| 114 | .It Fn BIO_puts b in | ||
| 115 | .Fn callback b BIO_CB_WRITE in 0 0L 1L | ||
| 116 | is called before the operation and | ||
| 117 | .Fn callback b BIO_CB_WRITE|BIO_CB_RETURN in 0 0L retvalue | ||
| 118 | after. | ||
| 119 | .It Fn BIO_ctrl b cmd larg parg | ||
| 120 | .Fn callback b BIO_CB_CTRL parg cmd larg 1L | ||
| 121 | is called before the call and | ||
| 122 | .Fn callback b BIO_CB_CTRL|BIO_CB_RETURN parg cmd larg ret | ||
| 123 | after. | ||
| 124 | .El | ||
| 125 | .Sh EXAMPLES | ||
| 126 | The | ||
| 127 | .Fn BIO_debug_callback | ||
| 128 | function is a good example, its source is in the file | ||
| 129 | .Pa crypto/bio/bio_cb.c . | ||
diff --git a/src/lib/libcrypto/man/BIO_should_retry.3 b/src/lib/libcrypto/man/BIO_should_retry.3 new file mode 100644 index 0000000000..cb5eda3121 --- /dev/null +++ b/src/lib/libcrypto/man/BIO_should_retry.3 | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | .Dd $Mdocdate: February 16 2015 $ | ||
| 2 | .Dt BIO_SHOULD_RETRY 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm BIO_should_retry , | ||
| 6 | .Nm BIO_should_read , | ||
| 7 | .Nm BIO_should_write , | ||
| 8 | .Nm BIO_should_io_special , | ||
| 9 | .Nm BIO_retry_type , | ||
| 10 | .Nm BIO_get_retry_BIO , | ||
| 11 | .Nm BIO_get_retry_reason | ||
| 12 | .Nd BIO retry functions | ||
| 13 | .Sh SYNOPSIS | ||
| 14 | .In openssl/bio.h | ||
| 15 | .Pp | ||
| 16 | .Fd #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) | ||
| 17 | .Fd #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) | ||
| 18 | .Fd #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) | ||
| 19 | .Fd #define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS) | ||
| 20 | .Fd #define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY) | ||
| 21 | .Fd #define BIO_FLAGS_READ 0x01 | ||
| 22 | .Fd #define BIO_FLAGS_WRITE 0x02 | ||
| 23 | .Fd #define BIO_FLAGS_IO_SPECIAL 0x04 | ||
| 24 | .Fd #define BIO_FLAGS_RWS \e | ||
| 25 | .Fd \& (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) | ||
| 26 | .Fd #define BIO_FLAGS_SHOULD_RETRY 0x08 | ||
| 27 | .Ft BIO * | ||
| 28 | .Fo BIO_get_retry_BIO | ||
| 29 | .Fa "BIO *bio" | ||
| 30 | .Fa "int *reason" | ||
| 31 | .Fc | ||
| 32 | .Ft int | ||
| 33 | .Fo BIO_get_retry_reason | ||
| 34 | .Fa "BIO *bio" | ||
| 35 | .Fc | ||
| 36 | .Sh DESCRIPTION | ||
| 37 | These functions determine why a BIO is not able to read or write data. | ||
| 38 | They will typically be called after a failed | ||
| 39 | .Xr BIO_read 3 | ||
| 40 | or | ||
| 41 | .Xr BIO_write 3 | ||
| 42 | call. | ||
| 43 | .Pp | ||
| 44 | .Fn BIO_should_retry | ||
| 45 | is true if the call that produced this condition | ||
| 46 | should be retried at a later time. | ||
| 47 | .Pp | ||
| 48 | If | ||
| 49 | .Fn BIO_should_retry | ||
| 50 | is false, the cause is an error condition. | ||
| 51 | .Pp | ||
| 52 | .Fn BIO_should_read | ||
| 53 | is true if the cause of the condition is that a BIO needs to read data. | ||
| 54 | .Pp | ||
| 55 | .Fn BIO_should_write | ||
| 56 | is true if the cause of the condition is that a BIO needs to write data. | ||
| 57 | .Pp | ||
| 58 | .Fn BIO_should_io_special | ||
| 59 | is true if some "special" condition, that is a reason other than | ||
| 60 | reading or writing, is the cause of the condition. | ||
| 61 | .Pp | ||
| 62 | .Fn BIO_retry_type | ||
| 63 | returns a mask of the cause of a retry condition consisting of the values | ||
| 64 | .Dv BIO_FLAGS_READ , | ||
| 65 | .Dv BIO_FLAGS_WRITE , | ||
| 66 | .Dv BIO_FLAGS_IO_SPECIAL | ||
| 67 | though current BIO types will only set one of these. | ||
| 68 | .Pp | ||
| 69 | .Fn BIO_get_retry_BIO | ||
| 70 | determines the precise reason for the special condition. | ||
| 71 | It returns the BIO that caused this condition and if | ||
| 72 | .Fa reason | ||
| 73 | is not | ||
| 74 | .Dv NULL | ||
| 75 | it contains the reason code. | ||
| 76 | The meaning of the reason code and the action that should be taken | ||
| 77 | depends on the type of BIO that resulted in this condition. | ||
| 78 | .Pp | ||
| 79 | .Fn BIO_get_retry_reason | ||
| 80 | returns the reason for a special condition | ||
| 81 | if passed the relevant BIO, for example as returned by | ||
| 82 | .Fn BIO_get_retry_BIO . | ||
| 83 | .Sh NOTES | ||
| 84 | If | ||
| 85 | .Fn BIO_should_retry | ||
| 86 | returns false, then the precise "error condition" depends on | ||
| 87 | the BIO type that caused it and the return code of the BIO operation. | ||
| 88 | For example if a call to | ||
| 89 | .Xr BIO_read 3 | ||
| 90 | on a socket BIO returns 0 and | ||
| 91 | .Fn BIO_should_retry | ||
| 92 | is false, then the cause will be that the connection closed. | ||
| 93 | A similar condition on a file BIO will mean that it has reached EOF. | ||
| 94 | Some BIO types may place additional information on the error queue. | ||
| 95 | For more details see the individual BIO type manual pages. | ||
| 96 | .Pp | ||
| 97 | If the underlying I/O structure is in a blocking mode, | ||
| 98 | almost all current BIO types will not request a retry, | ||
| 99 | because the underlying I/O calls will not. | ||
| 100 | If the application knows that the BIO type will never | ||
| 101 | signal a retry then it need not call | ||
| 102 | .Fn BIO_should_retry | ||
| 103 | after a failed BIO I/O call. | ||
| 104 | This is typically done with file BIOs. | ||
| 105 | .Pp | ||
| 106 | SSL BIOs are the only current exception to this rule: | ||
| 107 | they can request a retry even if the underlying I/O structure | ||
| 108 | is blocking, if a handshake occurs during a call to | ||
| 109 | .Xr BIO_read 3 . | ||
| 110 | An application can retry the failed call immediately | ||
| 111 | or avoid this situation by setting | ||
| 112 | .Dv SSL_MODE_AUTO_RETRY | ||
| 113 | on the underlying SSL structure. | ||
| 114 | .Pp | ||
| 115 | While an application may retry a failed non blocking call immediately, | ||
| 116 | this is likely to be very inefficient because the call will fail | ||
| 117 | repeatedly until data can be processed or is available. | ||
| 118 | An application will normally wait until the necessary condition | ||
| 119 | is satisfied. | ||
| 120 | How this is done depends on the underlying I/O structure. | ||
| 121 | .Pp | ||
| 122 | For example if the cause is ultimately a socket and | ||
| 123 | .Fn BIO_should_read | ||
| 124 | is true then a call to | ||
| 125 | .Xr select 2 | ||
| 126 | may be made to wait until data is available | ||
| 127 | and then retry the BIO operation. | ||
| 128 | By combining the retry conditions of several non blocking BIOs in a single | ||
| 129 | .Xr select 2 | ||
| 130 | call it is possible to service several BIOs in a single thread, | ||
| 131 | though the performance may be poor if SSL BIOs are present because | ||
| 132 | long delays can occur during the initial handshake process. | ||
| 133 | .Pp | ||
| 134 | It is possible for a BIO to block indefinitely if the underlying I/O | ||
| 135 | structure cannot process or return any data. | ||
| 136 | This depends on the behaviour of the platforms I/O functions. | ||
| 137 | This is often not desirable: one solution is to use non blocking I/O | ||
| 138 | and use a timeout on the | ||
| 139 | .Xr select 2 | ||
| 140 | (or equivalent) call. | ||
| 141 | .Sh BUGS | ||
| 142 | The OpenSSL ASN1 functions cannot gracefully deal with non blocking I/O: | ||
| 143 | they cannot retry after a partial read or write. | ||
| 144 | This is usually worked around by only passing the relevant data to ASN1 | ||
| 145 | functions when the entire structure can be read or written. | ||
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile index fcf9416248..2ac6e5b6f6 100644 --- a/src/lib/libcrypto/man/Makefile +++ b/src/lib/libcrypto/man/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.17 2015/02/14 14:09:01 schwarze Exp $ | 1 | # $OpenBSD: Makefile,v 1.18 2015/02/16 16:42:14 schwarze Exp $ |
| 2 | 2 | ||
| 3 | .include <bsd.own.mk> # for NOMAN | 3 | .include <bsd.own.mk> # for NOMAN |
| 4 | 4 | ||
| @@ -21,8 +21,6 @@ MAN= \ | |||
| 21 | BIO_f_null.3 \ | 21 | BIO_f_null.3 \ |
| 22 | BIO_find_type.3 \ | 22 | BIO_find_type.3 \ |
| 23 | BIO_new.3 \ | 23 | BIO_new.3 \ |
| 24 | |||
| 25 | GENMAN= \ | ||
| 26 | BIO_push.3 \ | 24 | BIO_push.3 \ |
| 27 | BIO_read.3 \ | 25 | BIO_read.3 \ |
| 28 | BIO_s_accept.3 \ | 26 | BIO_s_accept.3 \ |
| @@ -35,6 +33,8 @@ GENMAN= \ | |||
| 35 | BIO_s_socket.3 \ | 33 | BIO_s_socket.3 \ |
| 36 | BIO_set_callback.3 \ | 34 | BIO_set_callback.3 \ |
| 37 | BIO_should_retry.3 \ | 35 | BIO_should_retry.3 \ |
| 36 | |||
| 37 | GENMAN= \ | ||
| 38 | BN_BLINDING_new.3 \ | 38 | BN_BLINDING_new.3 \ |
| 39 | BN_CTX_new.3 \ | 39 | BN_CTX_new.3 \ |
| 40 | BN_CTX_start.3 \ | 40 | BN_CTX_start.3 \ |
