]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/man3/SSL_read_early_data.3
OpenSSL: Regen manual pages for OpenSSL 1.1.1j.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / man3 / SSL_read_early_data.3
1 .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "SSL_READ_EARLY_DATA 3"
136 .TH SSL_READ_EARLY_DATA 3 "2021-02-16" "1.1.1j" "OpenSSL"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 SSL_set_max_early_data, SSL_CTX_set_max_early_data, SSL_get_max_early_data, SSL_CTX_get_max_early_data, SSL_set_recv_max_early_data, SSL_CTX_set_recv_max_early_data, SSL_get_recv_max_early_data, SSL_CTX_get_recv_max_early_data, SSL_SESSION_get_max_early_data, SSL_SESSION_set_max_early_data, SSL_write_early_data, SSL_read_early_data, SSL_get_early_data_status, SSL_allow_early_data_cb_fn, SSL_CTX_set_allow_early_data_cb, SSL_set_allow_early_data_cb \&\- functions for sending and receiving early data
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 1
146 \& #include <openssl/ssl.h>
147 \&
148 \& int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
149 \& uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
150 \& int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
151 \& uint32_t SSL_get_max_early_data(const SSL *s);
152 \&
153 \& int SSL_CTX_set_recv_max_early_data(SSL_CTX *ctx, uint32_t recv_max_early_data);
154 \& uint32_t SSL_CTX_get_recv_max_early_data(const SSL_CTX *ctx);
155 \& int SSL_set_recv_max_early_data(SSL *s, uint32_t recv_max_early_data);
156 \& uint32_t SSL_get_recv_max_early_data(const SSL *s);
157 \&
158 \& uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s);
159 \& int SSL_SESSION_set_max_early_data(SSL_SESSION *s, uint32_t max_early_data);
160 \&
161 \& int SSL_write_early_data(SSL *s, const void *buf, size_t num, size_t *written);
162 \&
163 \& int SSL_read_early_data(SSL *s, void *buf, size_t num, size_t *readbytes);
164 \&
165 \& int SSL_get_early_data_status(const SSL *s);
166 \&
167 \&
168 \& typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg);
169 \&
170 \& void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx,
171 \&                                      SSL_allow_early_data_cb_fn cb,
172 \&                                      void *arg);
173 \& void SSL_set_allow_early_data_cb(SSL *s,
174 \&                                  SSL_allow_early_data_cb_fn cb,
175 \&                                  void *arg);
176 .Ve
177 .SH "DESCRIPTION"
178 .IX Header "DESCRIPTION"
179 These functions are used to send and receive early data where TLSv1.3 has been
180 negotiated. Early data can be sent by the client immediately after its initial
181 ClientHello without having to wait for the server to complete the handshake.
182 Early data can be sent if a session has previously been established with the
183 server or when establishing a new session using an out-of-band \s-1PSK,\s0 and only
184 when the server is known to support it. Additionally these functions can be used
185 to send data from the server to the client when the client has not yet completed
186 the authentication stage of the handshake.
187 .PP
188 Early data has weaker security properties than other data sent over an \s-1SSL/TLS\s0
189 connection. In particular the data does not have forward secrecy. There are also
190 additional considerations around replay attacks (see \*(L"\s-1REPLAY PROTECTION\*(R"\s0
191 below). For these reasons extreme care should be exercised when using early
192 data. For specific details, consult the \s-1TLS 1.3\s0 specification.
193 .PP
194 When a server receives early data it may opt to immediately respond by sending
195 application data back to the client. Data sent by the server at this stage is
196 done before the full handshake has been completed. Specifically the client's
197 authentication messages have not yet been received, i.e. the client is
198 unauthenticated at this point and care should be taken when using this
199 capability.
200 .PP
201 A server or client can determine whether the full handshake has been completed
202 or not by calling \fBSSL_is_init_finished\fR\|(3).
203 .PP
204 On the client side, the function \fBSSL_SESSION_get_max_early_data()\fR can be used to
205 determine if a session established with a server can be used to send early data.
206 If the session cannot be used then this function will return 0. Otherwise it
207 will return the maximum number of early data bytes that can be sent.
208 .PP
209 The function \fBSSL_SESSION_set_max_early_data()\fR sets the maximum number of early
210 data bytes that can be sent for a session. This would typically be used when
211 creating a \s-1PSK\s0 session file (see \fBSSL_CTX_set_psk_use_session_callback\fR\|(3)). If
212 using a ticket based \s-1PSK\s0 then this is set automatically to the value provided by
213 the server.
214 .PP
215 A client uses the function \fBSSL_write_early_data()\fR to send early data. This
216 function is similar to the \fBSSL_write_ex\fR\|(3) function, but with the following
217 differences. See \fBSSL_write_ex\fR\|(3) for information on how to write bytes to
218 the underlying connection, and how to handle any errors that may arise. This
219 page describes the differences between \fBSSL_write_early_data()\fR and
220 \&\fBSSL_write_ex\fR\|(3).
221 .PP
222 When called by a client, \fBSSL_write_early_data()\fR must be the first \s-1IO\s0 function
223 called on a new connection, i.e. it must occur before any calls to
224 \&\fBSSL_write_ex\fR\|(3), \fBSSL_read_ex\fR\|(3), \fBSSL_connect\fR\|(3), \fBSSL_do_handshake\fR\|(3)
225 or other similar functions. It may be called multiple times to stream data to
226 the server, but the total number of bytes written must not exceed the value
227 returned from \fBSSL_SESSION_get_max_early_data()\fR. Once the initial
228 \&\fBSSL_write_early_data()\fR call has completed successfully the client may interleave
229 calls to \fBSSL_read_ex\fR\|(3) and \fBSSL_read\fR\|(3) with calls to
230 \&\fBSSL_write_early_data()\fR as required.
231 .PP
232 If \fBSSL_write_early_data()\fR fails you should call \fBSSL_get_error\fR\|(3) to determine
233 the correct course of action, as for \fBSSL_write_ex\fR\|(3).
234 .PP
235 When the client no longer wishes to send any more early data then it should
236 complete the handshake by calling a function such as \fBSSL_connect\fR\|(3) or
237 \&\fBSSL_do_handshake\fR\|(3). Alternatively you can call a standard write function
238 such as \fBSSL_write_ex\fR\|(3), which will transparently complete the connection and
239 write the requested data.
240 .PP
241 A server may choose to ignore early data that has been sent to it. Once the
242 connection has been completed you can determine whether the server accepted or
243 rejected the early data by calling \fBSSL_get_early_data_status()\fR. This will return
244 \&\s-1SSL_EARLY_DATA_ACCEPTED\s0 if the data was accepted, \s-1SSL_EARLY_DATA_REJECTED\s0 if it
245 was rejected or \s-1SSL_EARLY_DATA_NOT_SENT\s0 if no early data was sent. This function
246 may be called by either the client or the server.
247 .PP
248 A server uses the \fBSSL_read_early_data()\fR function to receive early data on a
249 connection for which early data has been enabled using
250 \&\fBSSL_CTX_set_max_early_data()\fR or \fBSSL_set_max_early_data()\fR. As for
251 \&\fBSSL_write_early_data()\fR, this must be the first \s-1IO\s0 function
252 called on a connection, i.e. it must occur before any calls to
253 \&\fBSSL_write_ex\fR\|(3), \fBSSL_read_ex\fR\|(3), \fBSSL_accept\fR\|(3), \fBSSL_do_handshake\fR\|(3),
254 or other similar functions.
255 .PP
256 \&\fBSSL_read_early_data()\fR is similar to \fBSSL_read_ex\fR\|(3) with the following
257 differences. Refer to \fBSSL_read_ex\fR\|(3) for full details.
258 .PP
259 \&\fBSSL_read_early_data()\fR may return 3 possible values:
260 .IP "\s-1SSL_READ_EARLY_DATA_ERROR\s0" 4
261 .IX Item "SSL_READ_EARLY_DATA_ERROR"
262 This indicates an \s-1IO\s0 or some other error occurred. This should be treated in the
263 same way as a 0 return value from \fBSSL_read_ex\fR\|(3).
264 .IP "\s-1SSL_READ_EARLY_DATA_SUCCESS\s0" 4
265 .IX Item "SSL_READ_EARLY_DATA_SUCCESS"
266 This indicates that early data was successfully read. This should be treated in
267 the same way as a 1 return value from \fBSSL_read_ex\fR\|(3). You should continue to
268 call \fBSSL_read_early_data()\fR to read more data.
269 .IP "\s-1SSL_READ_EARLY_DATA_FINISH\s0" 4
270 .IX Item "SSL_READ_EARLY_DATA_FINISH"
271 This indicates that no more early data can be read. It may be returned on the
272 first call to \fBSSL_read_early_data()\fR if the client has not sent any early data,
273 or if the early data was rejected.
274 .PP
275 Once the initial \fBSSL_read_early_data()\fR call has completed successfully (i.e. it
276 has returned \s-1SSL_READ_EARLY_DATA_SUCCESS\s0 or \s-1SSL_READ_EARLY_DATA_FINISH\s0) then the
277 server may choose to write data immediately to the unauthenticated client using
278 \&\fBSSL_write_early_data()\fR. If \fBSSL_read_early_data()\fR returned
279 \&\s-1SSL_READ_EARLY_DATA_FINISH\s0 then in some situations (e.g. if the client only
280 supports TLSv1.2) the handshake may have already been completed and calls
281 to \fBSSL_write_early_data()\fR are not allowed. Call \fBSSL_is_init_finished\fR\|(3) to
282 determine whether the handshake has completed or not. If the handshake is still
283 in progress then the server may interleave calls to \fBSSL_write_early_data()\fR with
284 calls to \fBSSL_read_early_data()\fR as required.
285 .PP
286 Servers must not call \fBSSL_read_ex\fR\|(3), \fBSSL_read\fR\|(3), \fBSSL_write_ex\fR\|(3) or
287 \&\fBSSL_write\fR\|(3)  until \fBSSL_read_early_data()\fR has returned with
288 \&\s-1SSL_READ_EARLY_DATA_FINISH.\s0 Once it has done so the connection to the client
289 still needs to be completed. Complete the connection by calling a function such
290 as \fBSSL_accept\fR\|(3) or \fBSSL_do_handshake\fR\|(3). Alternatively you can call a
291 standard read function such as \fBSSL_read_ex\fR\|(3), which will transparently
292 complete the connection and read the requested data. Note that it is an error to
293 attempt to complete the connection before \fBSSL_read_early_data()\fR has returned
294 \&\s-1SSL_READ_EARLY_DATA_FINISH.\s0
295 .PP
296 Only servers may call \fBSSL_read_early_data()\fR.
297 .PP
298 Calls to \fBSSL_read_early_data()\fR may, in certain circumstances, complete the
299 connection immediately without further need to call a function such as
300 \&\fBSSL_accept\fR\|(3). This can happen if the client is using a protocol version less
301 than TLSv1.3. Applications can test for this by calling
302 \&\fBSSL_is_init_finished\fR\|(3). Alternatively, applications may choose to call
303 \&\fBSSL_accept\fR\|(3) anyway. Such a call will successfully return immediately with no
304 further action taken.
305 .PP
306 When a session is created between a server and a client the server will specify
307 the maximum amount of any early data that it will accept on any future
308 connection attempt. By default the server does not accept early data; a
309 server may indicate support for early data by calling
310 \&\fBSSL_CTX_set_max_early_data()\fR or
311 \&\fBSSL_set_max_early_data()\fR to set it for the whole \s-1SSL_CTX\s0 or an individual \s-1SSL\s0
312 object respectively. The \fBmax_early_data\fR parameter specifies the maximum
313 amount of early data in bytes that is permitted to be sent on a single
314 connection. Similarly the \fBSSL_CTX_get_max_early_data()\fR and
315 \&\fBSSL_get_max_early_data()\fR functions can be used to obtain the current maximum
316 early data settings for the \s-1SSL_CTX\s0 and \s-1SSL\s0 objects respectively. Generally a
317 server application will either use both of \fBSSL_read_early_data()\fR and
318 \&\fBSSL_CTX_set_max_early_data()\fR (or \fBSSL_set_max_early_data()\fR), or neither of them,
319 since there is no practical benefit from using only one of them. If the maximum
320 early data setting for a server is nonzero then replay protection is
321 automatically enabled (see \*(L"\s-1REPLAY PROTECTION\*(R"\s0 below).
322 .PP
323 If the server rejects the early data sent by a client then it will skip over
324 the data that is sent. The maximum amount of received early data that is skipped
325 is controlled by the recv_max_early_data setting. If a client sends more than
326 this then the connection will abort. This value can be set by calling
327 \&\fBSSL_CTX_set_recv_max_early_data()\fR or \fBSSL_set_recv_max_early_data()\fR. The current
328 value for this setting can be obtained by calling
329 \&\fBSSL_CTX_get_recv_max_early_data()\fR or \fBSSL_get_recv_max_early_data()\fR. The default
330 value for this setting is 16,384 bytes.
331 .PP
332 The recv_max_early_data value also has an impact on early data that is accepted.
333 The amount of data that is accepted will always be the lower of the
334 max_early_data for the session and the recv_max_early_data setting for the
335 server. If a client sends more data than this then the connection will abort.
336 .PP
337 The configured value for max_early_data on a server may change over time as
338 required. However, clients may have tickets containing the previously configured
339 max_early_data value. The recv_max_early_data should always be equal to or
340 higher than any recently configured max_early_data value in order to avoid
341 aborted connections. The recv_max_early_data should never be set to less than
342 the current configured max_early_data value.
343 .PP
344 Some server applications may wish to have more control over whether early data
345 is accepted or not, for example to mitigate replay risks (see \*(L"\s-1REPLAY PROTECTION\*(R"\s0
346 below) or to decline early_data when the server is heavily loaded. The functions
347 \&\fBSSL_CTX_set_allow_early_data_cb()\fR and \fBSSL_set_allow_early_data_cb()\fR set a
348 callback which is called at a point in the handshake immediately before a
349 decision is made to accept or reject early data. The callback is provided with a
350 pointer to the user data argument that was provided when the callback was first
351 set. Returning 1 from the callback will allow early data and returning 0 will
352 reject it. Note that the OpenSSL library may reject early data for other reasons
353 in which case this callback will not get called. Notably, the built-in replay
354 protection feature will still be used even if a callback is present unless it
355 has been explicitly disabled using the \s-1SSL_OP_NO_ANTI_REPLAY\s0 option. See
356 \&\*(L"\s-1REPLAY PROTECTION\*(R"\s0 below.
357 .SH "NOTES"
358 .IX Header "NOTES"
359 The whole purpose of early data is to enable a client to start sending data to
360 the server before a full round trip of network traffic has occurred. Application
361 developers should ensure they consider optimisation of the underlying \s-1TCP\s0 socket
362 to obtain a performant solution. For example Nagle's algorithm is commonly used
363 by operating systems in an attempt to avoid lots of small \s-1TCP\s0 packets. In many
364 scenarios this is beneficial for performance, but it does not work well with the
365 early data solution as implemented in OpenSSL. In Nagle's algorithm the \s-1OS\s0 will
366 buffer outgoing \s-1TCP\s0 data if a \s-1TCP\s0 packet has already been sent which we have not
367 yet received an \s-1ACK\s0 for from the peer. The buffered data will only be
368 transmitted if enough data to fill an entire \s-1TCP\s0 packet is accumulated, or if
369 the \s-1ACK\s0 is received from the peer. The initial ClientHello will be sent in the
370 first \s-1TCP\s0 packet along with any data from the first call to
371 \&\fBSSL_write_early_data()\fR. If the amount of data written will exceed the size of a
372 single \s-1TCP\s0 packet, or if there are more calls to \fBSSL_write_early_data()\fR then
373 that additional data will be sent in subsequent \s-1TCP\s0 packets which will be
374 buffered by the \s-1OS\s0 and not sent until an \s-1ACK\s0 is received for the first packet
375 containing the ClientHello. This means the early data is not actually
376 sent until a complete round trip with the server has occurred which defeats the
377 objective of early data.
378 .PP
379 In many operating systems the \s-1TCP_NODELAY\s0 socket option is available to disable
380 Nagle's algorithm. If an application opts to disable Nagle's algorithm
381 consideration should be given to turning it back on again after the handshake is
382 complete if appropriate.
383 .PP
384 In rare circumstances, it may be possible for a client to have a session that
385 reports a max early data value greater than 0, but where the server does not
386 support this. For example, this can occur if a server has had its configuration
387 changed to accept a lower max early data value such as by calling
388 \&\fBSSL_CTX_set_recv_max_early_data()\fR. Another example is if a server used to
389 support TLSv1.3 but was later downgraded to TLSv1.2. Sending early data to such
390 a server will cause the connection to abort. Clients that encounter an aborted
391 connection while sending early data may want to retry the connection without
392 sending early data as this does not happen automatically. A client will have to
393 establish a new transport layer connection to the server and attempt the \s-1SSL/TLS\s0
394 connection again but without sending early data. Note that it is inadvisable to
395 retry with a lower maximum protocol version.
396 .SH "REPLAY PROTECTION"
397 .IX Header "REPLAY PROTECTION"
398 When early data is in use the \s-1TLS\s0 protocol provides no security guarantees that
399 the same early data was not replayed across multiple connections. As a
400 mitigation for this issue OpenSSL automatically enables replay protection if the
401 server is configured with a nonzero max early data value. With replay
402 protection enabled sessions are forced to be single use only. If a client
403 attempts to reuse a session ticket more than once, then the second and
404 subsequent attempts will fall back to a full handshake (and any early data that
405 was submitted will be ignored). Note that single use tickets are enforced even
406 if a client does not send any early data.
407 .PP
408 The replay protection mechanism relies on the internal OpenSSL server session
409 cache (see \fBSSL_CTX_set_session_cache_mode\fR\|(3)). When replay protection is
410 being used the server will operate as if the \s-1SSL_OP_NO_TICKET\s0 option had been
411 selected (see \fBSSL_CTX_set_options\fR\|(3)). Sessions will be added to the cache
412 whenever a session ticket is issued. When a client attempts to resume the
413 session, OpenSSL will check for its presence in the internal cache. If it exists
414 then the resumption is allowed and the session is removed from the cache. If it
415 does not exist then the resumption is not allowed and a full handshake will
416 occur.
417 .PP
418 Note that some applications may maintain an external cache of sessions (see
419 \&\fBSSL_CTX_sess_set_new_cb\fR\|(3) and similar functions). It is the application's
420 responsibility to ensure that any sessions in the external cache are also
421 populated in the internal cache and that once removed from the internal cache
422 they are similarly removed from the external cache. Failing to do this could
423 result in an application becoming vulnerable to replay attacks. Note that
424 OpenSSL will lock the internal cache while a session is removed but that lock is
425 not held when the remove session callback (see \fBSSL_CTX_sess_set_remove_cb\fR\|(3))
426 is called. This could result in a small amount of time where the session has
427 been removed from the internal cache but is still available in the external
428 cache. Applications should be designed with this in mind in order to minimise
429 the possibility of replay attacks.
430 .PP
431 The OpenSSL replay protection does not apply to external Pre Shared Keys (PSKs)
432 (e.g. see \fBSSL_CTX_set_psk_find_session_callback\fR\|(3)). Therefore, extreme caution
433 should be applied when combining external PSKs with early data.
434 .PP
435 Some applications may mitigate the replay risks in other ways. For those
436 applications it is possible to turn off the built-in replay protection feature
437 using the \fB\s-1SSL_OP_NO_ANTI_REPLAY\s0\fR option. See \fBSSL_CTX_set_options\fR\|(3) for
438 details. Applications can also set a callback to make decisions about accepting
439 early data or not. See \fBSSL_CTX_set_allow_early_data_cb()\fR above for details.
440 .SH "RETURN VALUES"
441 .IX Header "RETURN VALUES"
442 \&\fBSSL_write_early_data()\fR returns 1 for success or 0 for failure. In the event of a
443 failure call \fBSSL_get_error\fR\|(3) to determine the correct course of action.
444 .PP
445 \&\fBSSL_read_early_data()\fR returns \s-1SSL_READ_EARLY_DATA_ERROR\s0 for failure,
446 \&\s-1SSL_READ_EARLY_DATA_SUCCESS\s0 for success with more data to read and
447 \&\s-1SSL_READ_EARLY_DATA_FINISH\s0 for success with no more to data be read. In the
448 event of a failure call \fBSSL_get_error\fR\|(3) to determine the correct course of
449 action.
450 .PP
451 \&\fBSSL_get_max_early_data()\fR, \fBSSL_CTX_get_max_early_data()\fR and
452 \&\fBSSL_SESSION_get_max_early_data()\fR return the maximum number of early data bytes
453 that may be sent.
454 .PP
455 \&\fBSSL_set_max_early_data()\fR, \fBSSL_CTX_set_max_early_data()\fR and
456 \&\fBSSL_SESSION_set_max_early_data()\fR return 1 for success or 0 for failure.
457 .PP
458 \&\fBSSL_get_early_data_status()\fR returns \s-1SSL_EARLY_DATA_ACCEPTED\s0 if early data was
459 accepted by the server, \s-1SSL_EARLY_DATA_REJECTED\s0 if early data was rejected by
460 the server, or \s-1SSL_EARLY_DATA_NOT_SENT\s0 if no early data was sent.
461 .SH "SEE ALSO"
462 .IX Header "SEE ALSO"
463 \&\fBSSL_get_error\fR\|(3),
464 \&\fBSSL_write_ex\fR\|(3),
465 \&\fBSSL_read_ex\fR\|(3),
466 \&\fBSSL_connect\fR\|(3),
467 \&\fBSSL_accept\fR\|(3),
468 \&\fBSSL_do_handshake\fR\|(3),
469 \&\fBSSL_CTX_set_psk_use_session_callback\fR\|(3),
470 \&\fBssl\fR\|(7)
471 .SH "HISTORY"
472 .IX Header "HISTORY"
473 All of the functions described above were added in OpenSSL 1.1.1.
474 .SH "COPYRIGHT"
475 .IX Header "COPYRIGHT"
476 Copyright 2017\-2020 The OpenSSL Project Authors. All Rights Reserved.
477 .PP
478 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
479 this file except in compliance with the License.  You can obtain a copy
480 in the file \s-1LICENSE\s0 in the source distribution or at
481 <https://www.openssl.org/source/license.html>.