diff options
Diffstat (limited to 'src/lib/libtls/man/tls_read.3')
-rw-r--r-- | src/lib/libtls/man/tls_read.3 | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/src/lib/libtls/man/tls_read.3 b/src/lib/libtls/man/tls_read.3 new file mode 100644 index 0000000000..74ce005758 --- /dev/null +++ b/src/lib/libtls/man/tls_read.3 | |||
@@ -0,0 +1,195 @@ | |||
1 | .\" $OpenBSD: tls_read.3,v 1.1 2017/01/25 23:53:18 schwarze Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | ||
4 | .\" | ||
5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
7 | .\" copyright notice and this permission notice appear in all copies. | ||
8 | .\" | ||
9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | .\" | ||
17 | .Dd $Mdocdate: January 25 2017 $ | ||
18 | .Dt TLS_READ 3 | ||
19 | .Os | ||
20 | .Sh NAME | ||
21 | .Nm tls_read , | ||
22 | .Nm tls_write , | ||
23 | .Nm tls_handshake , | ||
24 | .Nm tls_error , | ||
25 | .Nm tls_close , | ||
26 | .Nm tls_reset | ||
27 | .Nd use a TLS connection | ||
28 | .Sh SYNOPSIS | ||
29 | .In tls.h | ||
30 | .Ft ssize_t | ||
31 | .Fo tls_read | ||
32 | .Fa "struct tls *ctx" | ||
33 | .Fa "void *buf" | ||
34 | .Fa "size_t buflen" | ||
35 | .Fc | ||
36 | .Ft ssize_t | ||
37 | .Fo tls_write | ||
38 | .Fa "struct tls *ctx" | ||
39 | .Fa "const void *buf" | ||
40 | .Fa "size_t buflen" | ||
41 | .Fc | ||
42 | .Ft int | ||
43 | .Fn tls_handshake "struct tls *ctx" | ||
44 | .Ft const char * | ||
45 | .Fn tls_error "struct tls *ctx" | ||
46 | .Ft int | ||
47 | .Fn tls_close "struct tls *ctx" | ||
48 | .Ft void | ||
49 | .Fn tls_reset "struct tls *ctx" | ||
50 | .Sh DESCRIPTION | ||
51 | .Fn tls_read | ||
52 | reads | ||
53 | .Fa buflen | ||
54 | bytes of data from the socket into | ||
55 | .Fa buf . | ||
56 | It returns the amount of data read. | ||
57 | .Pp | ||
58 | .Fn tls_write | ||
59 | writes | ||
60 | .Fa buflen | ||
61 | bytes of data from | ||
62 | .Fa buf | ||
63 | to the socket. | ||
64 | It returns the amount of data written. | ||
65 | .Pp | ||
66 | .Fn tls_handshake | ||
67 | explicitly performs the TLS handshake. | ||
68 | It is only necessary to call this function if you need to guarantee that the | ||
69 | handshake has completed, as both | ||
70 | .Fn tls_read | ||
71 | and | ||
72 | .Fn tls_write | ||
73 | automatically perform the TLS handshake when necessary. | ||
74 | .Pp | ||
75 | The | ||
76 | .Fn tls_error | ||
77 | function may be used to retrieve a string containing more information | ||
78 | about the most recent error relating to a context. | ||
79 | .Pp | ||
80 | .Fn tls_close | ||
81 | closes a connection after use. | ||
82 | Only the TLS layer will be shut down and the caller is responsible for closing | ||
83 | the file descriptors, unless the connection was established using | ||
84 | .Xr tls_connect 3 | ||
85 | or | ||
86 | .Xr tls_connect_servername 3 . | ||
87 | After closing the connection, | ||
88 | .Fa ctx | ||
89 | can be passed to | ||
90 | .Xr tls_free 3 . | ||
91 | .\" XXX Fn tls_reset does what? | ||
92 | .Sh RETURN VALUES | ||
93 | .Fn tls_read | ||
94 | and | ||
95 | .Fn tls_write | ||
96 | return a size on success or -1 on error. | ||
97 | .Pp | ||
98 | .Fn tls_handshake | ||
99 | and | ||
100 | .Fn tls_close | ||
101 | return 0 on success or -1 on error. | ||
102 | .Pp | ||
103 | .Fn tls_error | ||
104 | returns | ||
105 | .Dv NULL | ||
106 | if no error occurred or the first place, or if memory allocation | ||
107 | failed while trying to assemble the string describing the error. | ||
108 | .Pp | ||
109 | The | ||
110 | .Fn tls_read , | ||
111 | .Fn tls_write , | ||
112 | .Fn tls_handshake , | ||
113 | and | ||
114 | .Fn tls_close | ||
115 | functions have two special return values: | ||
116 | .Pp | ||
117 | .Bl -tag -width "TLS_WANT_POLLOUT" -offset indent -compact | ||
118 | .It Dv TLS_WANT_POLLIN | ||
119 | The underlying read file descriptor needs to be readable in order to continue. | ||
120 | .It Dv TLS_WANT_POLLOUT | ||
121 | The underlying write file descriptor needs to be writeable in order to continue. | ||
122 | .El | ||
123 | .Pp | ||
124 | In the case of blocking file descriptors, the same function call should be | ||
125 | repeated immediately. | ||
126 | In the case of non-blocking file descriptors, the same function call should be | ||
127 | repeated when the required condition has been met. | ||
128 | .Pp | ||
129 | Callers of these functions cannot rely on the value of the global | ||
130 | .Ar errno . | ||
131 | To prevent mishandling of error conditions, | ||
132 | .Fn tls_read , | ||
133 | .Fn tls_write , | ||
134 | .Fn tls_handshake , | ||
135 | and | ||
136 | .Fn tls_close | ||
137 | all explicitly clear | ||
138 | .Ar errno . | ||
139 | .Sh EXAMPLES | ||
140 | The following example demonstrates how to handle TLS writes on a blocking | ||
141 | file descriptor: | ||
142 | .Bd -literal -offset indent | ||
143 | \&... | ||
144 | while (len > 0) { | ||
145 | ssize_t ret; | ||
146 | |||
147 | ret = tls_write(ctx, buf, len); | ||
148 | if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) | ||
149 | continue; | ||
150 | if (ret < 0) | ||
151 | err(1, "tls_write: %s", tls_error(ctx)); | ||
152 | buf += ret; | ||
153 | len -= ret; | ||
154 | } | ||
155 | \&... | ||
156 | .Ed | ||
157 | .Pp | ||
158 | The following example demonstrates how to handle TLS writes on a | ||
159 | non-blocking file descriptor using | ||
160 | .Xr poll 2 : | ||
161 | .Bd -literal -offset indent | ||
162 | \&... | ||
163 | pfd[0].fd = fd; | ||
164 | pfd[0].events = POLLIN|POLLOUT; | ||
165 | while (len > 0) { | ||
166 | nready = poll(pfd, 1, 0); | ||
167 | if (nready == -1) | ||
168 | err(1, "poll"); | ||
169 | if ((pfd[0].revents & (POLLERR|POLLNVAL))) | ||
170 | errx(1, "bad fd %d", pfd[0].fd); | ||
171 | if ((pfd[0].revents & (pfd[0].events|POLLHUP))) { | ||
172 | ssize_t ret; | ||
173 | |||
174 | ret = tls_write(ctx, buf, len); | ||
175 | if (ret == TLS_WANT_POLLIN) | ||
176 | pfd[0].events = POLLIN; | ||
177 | else if (ret == TLS_WANT_POLLOUT) | ||
178 | pfd[0].events = POLLOUT; | ||
179 | else if (ret < 0) | ||
180 | err(1, "tls_write: %s", tls_error(ctx)); | ||
181 | else { | ||
182 | buf += ret; | ||
183 | len -= ret; | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | \&... | ||
188 | .Ed | ||
189 | .Sh SEE ALSO | ||
190 | .Xr tls_accept_socket 3 , | ||
191 | .Xr tls_configure 3 , | ||
192 | .Xr tls_conn_version 3 , | ||
193 | .Xr tls_connect 3 , | ||
194 | .Xr tls_init 3 , | ||
195 | .Xr tls_ocsp_process_response 3 | ||