]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/SSL_read_early_data.pod
Fix a typo in the SSL_get_max_early_data() declarations
[thirdparty/openssl.git] / doc / man3 / SSL_read_early_data.pod
CommitLineData
fd6c1025
MC
1=pod
2
3=head1 NAME
4
5SSL_set_max_early_data,
6SSL_CTX_set_max_early_data,
7SSL_get_max_early_data,
8SSL_CTX_get_max_early_data,
9SSL_SESSION_get_max_early_data,
0665b4ed 10SSL_write_early_data,
f533fbd4 11SSL_read_early_data,
fd6c1025
MC
12SSL_get_early_data_status
13- functions for sending and receiving early data
14
15=head1 SYNOPSIS
16
17 #include <openssl/ssl.h>
18
19 int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
20 uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
21 int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
a8e75d56 22 uint32_t SSL_get_max_early_data(const SSL *s);
fd6c1025
MC
23 uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s);
24
0665b4ed 25 int SSL_write_early_data(SSL *s, const void *buf, size_t num, size_t *written);
fd6c1025 26
f533fbd4 27 int SSL_read_early_data(SSL *s, void *buf, size_t num, size_t *readbytes);
fd6c1025
MC
28
29 int SSL_get_early_data_status(const SSL *s);
30
31=head1 DESCRIPTION
32
cd9f7f62
MC
33These functions are used to send and recieve early data where TLSv1.3 has been
34negotiated. Early data can be sent by the client immediately after its initial
35ClientHello without having to wait for the server to complete the handshake.
36Early data can only be sent if a session has previously been established with
37the server, and the server is known to support it. Additionally these functions
38can be used to send data from the server to the client when the client has not
39yet completed the authentication stage of the handshake.
fd6c1025
MC
40
41Early data has weaker security properties than other data sent over an SSL/TLS
cd9f7f62
MC
42connection. In particular the data does not have forward secrecy and there are
43no guarantees that the same early data was not replayed across multiple
fd6c1025 44connections. For this reason extreme care should be exercised when using early
83750d9b 45data. For specific details, consult the TLS 1.3 specification.
fd6c1025 46
ef466acc
MC
47When a server receives early data it may opt to immediately respond by sending
48application data back to the client. Data sent by the server at this stage is
49done before the full handshake has been completed. Specifically the client's
50authentication messages have not yet been received, i.e. the client is
cd9f7f62
MC
51unauthenticated at this point and care should be taken when using this
52capability.
ef466acc
MC
53
54A server or client can determine whether the full handshake has been completed
55or not by calling L<SSL_is_init_finished(3)>.
56
cd9f7f62
MC
57On the client side, the function SSL_SESSION_get_max_early_data() can be used to
58determine if a session established with a server can be used to send early data.
59If the session cannot be used then this function will return 0. Otherwise it
60will return the maximum number of early data bytes that can be sent.
fd6c1025 61
0665b4ed 62A client uses the function SSL_write_early_data() to send early data. This
cd9f7f62
MC
63function is similar to the L<SSL_write_ex(3)> function, but with the following
64differences. See L<SSL_write_ex(3)> for information on how to write bytes to
65the underlying connection, and how to handle any errors that may arise. This
66page describes the differences between SSL_write_early_data() and
67L<SSL_write_ex(3)>.
fd6c1025 68
09f28874
MC
69When called by a client, SSL_write_early_data() must be the first IO function
70called on a new connection, i.e. it must occur before any calls to
71L<SSL_write_ex(3)>, L<SSL_read_ex(3)>, L<SSL_connect(3)>, L<SSL_do_handshake(3)>
72or other similar functions. It may be called multiple times to stream data to
73the server, but the total number of bytes written must not exceed the value
74returned from SSL_SESSION_get_max_early_data(). Once the initial
75SSL_write_early_data() call has completed successfully the client may interleave
76calls to L<SSL_read_ex(3)> and L<SSL_read(3)> with calls to
77SSL_write_early_data() as required.
fd6c1025 78
0665b4ed
MC
79If SSL_write_early_data() fails you should call L<SSL_get_error(3)> to determine
80the correct course of action, as for L<SSL_write_ex(3)>.
fd6c1025 81
ef466acc
MC
82When the client no longer wishes to send any more early data then it should
83complete the handshake by calling a function such as L<SSL_connect(3)> or
84L<SSL_do_handshake(3)>. Alternatively you can call a standard write function
85such as L<SSL_write_ex(3)>, which will transparently complete the connection and
86write the requested data.
fd6c1025 87
fd6c1025
MC
88A server may choose to ignore early data that has been sent to it. Once the
89connection has been completed you can determine whether the server accepted or
90rejected the early data by calling SSL_get_early_data_status(). This will return
91SSL_EARLY_DATA_ACCEPTED if the data was accepted, SSL_EARLY_DATA_REJECTED if it
92was rejected or SSL_EARLY_DATA_NOT_SENT if no early data was sent. This function
93may be called by either the client or the server.
94
f533fbd4 95A server uses the SSL_read_early_data() function to receive early data on a
0665b4ed
MC
96connection. As for SSL_write_early_data() this must be the first IO function
97called on a connection, i.e. it must occur before any calls to
98L<SSL_write_ex(3)>, L<SSL_read_ex(3)>, L<SSL_accept(3)>, L<SSL_do_handshake(3)>,
99or other similar functions.
fd6c1025 100
cd9f7f62
MC
101SSL_read_early_data() is similar to L<SSL_read_ex(3)> with the following
102differences. Refer to L<SSL_read_ex(3)> for full details.
fd6c1025 103
f533fbd4 104SSL_read_early_data() may return 3 possible values:
fd6c1025
MC
105
106=over 4
107
f533fbd4 108=item SSL_READ_EARLY_DATA_ERROR
fd6c1025
MC
109
110This indicates an IO or some other error occured. This should be treated in the
111same way as a 0 return value from L<SSL_read_ex(3)>.
112
f533fbd4 113=item SSL_READ_EARLY_DATA_SUCCESS
fd6c1025
MC
114
115This indicates that early data was successfully read. This should be treated in
116the same way as a 1 return value from L<SSL_read_ex(3)>. You should continue to
f533fbd4 117call SSL_read_early_data() to read more data.
fd6c1025 118
f533fbd4 119=item SSL_READ_EARLY_DATA_FINISH
fd6c1025
MC
120
121This indicates that no more early data can be read. It may be returned on the
f533fbd4
MC
122first call to SSL_read_early_data() if the client has not sent any early data,
123or if the early data was rejected.
fd6c1025
MC
124
125=back
126
09f28874
MC
127Once the initial SSL_read_early_data() call has completed successfully (i.e. it
128has returned SSL_READ_EARLY_DATA_SUCCESS or SSL_READ_EARLY_DATA_FINISH) then the
129server may choose to write data immediately to the unauthenticated client using
130SSL_write_early_data(). If SSL_read_early_data() returned
131SSL_READ_EARLY_DATA_FINISH then in some situations (e.g. if the client only
cd9f7f62 132supports TLSv1.2) the handshake may have already been completed and calls
09f28874
MC
133to SSL_write_early_data() are not allowed. Call L<SSL_is_init_finished(3)> to
134determine whether the handshake has completed or not. If the handshake is still
135in progress then the server may interleave calls to SSL_write_early_data() with
136calls to SSL_read_early_data() as required.
137
138Servers must not call L<SSL_read_ex(3)>, L<SSL_read(3)>, L<SSL_write_ex(3)> or
139L<SSL_write(3)> until SSL_read_early_data() has returned with
140SSL_READ_EARLY_DATA_FINISH. Once it has done so the connection to the client
141still needs to be completed. Complete the connection by calling a function such
142as L<SSL_accept(3)> or L<SSL_do_handshake(3)>. Alternatively you can call a
143standard read function such as L<SSL_read_ex(3)>, which will transparently
144complete the connection and read the requested data. Note that it is an error to
145attempt to complete the connection before SSL_read_early_data() has returned
146SSL_READ_EARLY_DATA_FINISH.
f533fbd4
MC
147
148Only servers may call SSL_read_early_data().
149
150Calls to SSL_read_early_data() may, in certain circumstances, complete the
151connection immediately without further need to call a function such as
cd9f7f62
MC
152L<SSL_accept(3)>. This can happen if the client is using a protocol version less
153than TLSv1.3. Applications can test for this by calling
f533fbd4
MC
154L<SSL_is_init_finished(3)>. Alternatively, applications may choose to call
155L<SSL_accept(3)> anway. Such a call will successfully return immediately with no
156further action taken.
ef466acc 157
fd6c1025
MC
158When a session is created between a server and a client the server will specify
159the maximum amount of any early data that it will accept on any future
160connection attempt. By default this is approximately 16k. A server may override
161this default value by calling SSL_CTX_set_max_early_data() or
162SSL_set_max_early_data() to set it for the whole SSL_CTX or an individual SSL
163object respectively. Similarly the SSL_CTX_get_max_early_data() and
164SSL_get_max_early_data() functions can be used to obtain the current maximum
165early data settings for the SSL_CTX and SSL objects respectively.
166
167In the event that the current maximum early data setting for the server is
168different to that originally specified in a session that a client is resuming
169with then the lower of the two values will apply.
170
171=head1 RETURN VALUES
172
0665b4ed 173SSL_write_early_data() returns 1 for success or 0 for failure. In the event of a
ef466acc 174failure call L<SSL_get_error(3)> to determine the correct course of action.
fd6c1025 175
f533fbd4
MC
176SSL_read_early_data() returns SSL_READ_EARLY_DATA_ERROR for failure,
177SSL_READ_EARLY_DATA_SUCCESS for success with more data to read and
cd9f7f62
MC
178SSL_READ_EARLY_DATA_FINISH for success with no more to data be read. In the
179event of a failure call L<SSL_get_error(3)> to determine the correct course of
180action.
fd6c1025
MC
181
182SSL_get_max_early_data(), SSL_CTX_get_max_early_data() and
183SSL_SESSION_get_max_early_data() return the maximum number of early data bytes
184that may be sent.
185
186SSL_set_max_early_data() and SSL_CTX_set_max_early_data() return 1 for success
187or 0 for failure.
188
189SSL_get_early_data_status() returns SSL_EARLY_DATA_ACCEPTED if early data was
190accepted by the server, SSL_EARLY_DATA_REJECTED if early data was rejected by
191the server, or SSL_EARLY_DATA_NOT_SENT if no early data was sent.
192
193=head1 SEE ALSO
194
195L<SSL_get_error(3)>,
196L<SSL_write_ex(3)>,
197L<SSL_read_ex(3)>,
198L<SSL_connect(3)>,
199L<SSL_accept(3)>,
200L<SSL_do_handshake(3)>,
201L<ssl(7)>
202
203=head1 HISTORY
204
205All of the functions described above were added in OpenSSL 1.1.1.
206
207=head1 COPYRIGHT
208
209Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
210
211Licensed under the OpenSSL license (the "License"). You may not use
212this file except in compliance with the License. You can obtain a copy
213in the file LICENSE in the source distribution or at
214L<https://www.openssl.org/source/license.html>.
215
216=cut