Some transport protocols (such as UDP) can be susceptible to amplification attacks. Unlike TCP there is
no initial connection setup in UDP that validates that the client can actually receive messages on its
advertised source address. An attacker could forge its source IP address and then send handshake
initiation messages to the server. The server would then send its response to the forged source IP. If
the response messages are larger than the original message then the amplification attack has succeeded.
If DTLS is used over UDP (or any datagram based protocol that does not validate the source IP) then it is
susceptible to this type of attack. TLSv1.3 is designed to operate over a stream-based transport protocol
(such as TCP). If TCP is being used then there is no need to use SSL_stateless(). However, some stream-
based transport protocols (e.g. QUIC) may not validate the source address. In this case a TLSv1.3
application would be susceptible to this attack.
As a countermeasure to this issue TLSv1.3 and DTLS include a stateless cookie mechanism. The idea is that
when a client attempts to connect to a server it sends a ClientHello message. The server responds with a
HelloRetryRequest (in TLSv1.3) or a HelloVerifyRequest (in DTLS) which contains a unique cookie. The
client then resends the ClientHello, but this time includes the cookie in the message thus proving that
the client is capable of receiving messages sent to that address. All of this can be done by the server
without allocating any state, and thus without consuming expensive resources.
OpenSSL implements this capability via the SSL_stateless() and DTLSv1_listen() functions. The ssl
parameter should be a newly allocated SSL object with its read and write BIOs set, in the same way as
might be done for a call to SSL_accept(). Typically, for DTLS, the read BIO will be in an "unconnected"
state and thus capable of receiving messages from any peer.
When a ClientHello is received that contains a cookie that has been verified, then these functions will
return with the ssl parameter updated into a state where the handshake can be continued by a call to (for
example) SSL_accept(). Additionally, for DTLSv1_listen(), the BIO_ADDR pointed to by peer will be filled
in with details of the peer that sent the ClientHello. If the underlying BIO is unable to obtain the
BIO_ADDR of the peer (for example because the BIO does not support this), then *peer will be cleared and
the family set to AF_UNSPEC. Typically user code is expected to "connect" the underlying socket to the
peer and continue the handshake in a connected state.
Warning: It is essential that the calling code connects the underlying socket to the peer after making
use of DTLSv1_listen(). In the typical case where BIO_s_datagram(3) is used, the peer address is updated
when receiving a datagram on an unconnected socket. If the socket is not connected, it can receive
datagrams from any host on the network, which will cause subsequent outgoing datagrams transmitted by
DTLS to be transmitted to that host. In other words, failing to call BIO_connect() or a similar OS-
specific function on a socket means that any host on the network can cause outgoing DTLS traffic to be
redirected to it by sending a datagram to the socket in question. This does not break the cryptographic
protections of DTLS but may facilitate a denial-of-service attack or allow unencrypted information in the
DTLS handshake to be learned by an attacker. This is due to the historical design of BIO_s_datagram(3);
see BIO_s_datagram(3) for details on this issue.
Once a socket has been connected, BIO_ctrl_set_connected(3) should be used to inform the BIO that the
socket is to be used in connected mode.
Prior to calling DTLSv1_listen() user code must ensure that cookie generation and verification callbacks
have been set up using SSL_CTX_set_cookie_generate_cb(3) and SSL_CTX_set_cookie_verify_cb(3)
respectively. For SSL_stateless(), SSL_CTX_set_stateless_cookie_generate_cb(3) and
SSL_CTX_set_stateless_cookie_verify_cb(3) must be used instead.
Since DTLSv1_listen() operates entirely statelessly whilst processing incoming ClientHellos it is unable
to process fragmented messages (since this would require the allocation of state). An implication of this
is that DTLSv1_listen()only supports ClientHellos that fit inside a single datagram.
For SSL_stateless() if an entire ClientHello message cannot be read without the "read" BIO becoming empty
then the SSL_stateless() call will fail. It is the application's responsibility to ensure that data read
from the "read" BIO during a single SSL_stateless() call is all from the same peer.
SSL_stateless() will fail (with a 0 return value) if some TLS version less than TLSv1.3 is used.
Both SSL_stateless() and DTLSv1_listen() will clear the error queue when they start.
SSL_stateless() cannot be used with QUIC SSL objects and returns an error if called on such an object.