DTLSV1_LISTEN(3SSL)
π DTLSv1_listen β the 3SSL manual, bestie edition π
okay so if you're deep in openssl/ssl.h territory and you need to listen for incoming connections without keeping state around, this is the page for you. this is DTLSv1_listen(3SSL) and also SSL_stateless, they're besties.
β¨ NAME β¨
SSL_stateless, DTLSv1_listen β statelessly listen for incoming connections π¦ no state, no problem, no cap.
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
int SSL_stateless(SSL *s);
int DTLSv1_listen(SSL *ssl, BIO_ADDR *peer);
β¨ DESCRIPTION β¨
so, the tea: SSL_stateless() statelessly listens for new incoming TLSv1.3 connections. DTLSv1_listen() statelessly listens for new incoming DTLS connections. π
and the way this works is: if a ClientHello shows up that does not contain a cookie, then they respond with a request for a new ClientHello that does contain a cookie. Then if a ClientHello arrives with a cookie that checks out and gets verified, the function returns so the handshake can actually be completed (for example, by calling SSL_accept()). iconic behavior honestly. β¨
β¨ NOTES β¨
okay bestie this part is important, sit with me. π«Ά
some transport protocols (like UDP) can be susceptible to amplification attacks. Unlike TCP, there's no initial connection setup in UDP that validates the client can actually receive messages on its advertised source address. So 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 that forged source IP. And if the response messages are bigger than the original message, then boom β the amplification attack has succeeded. π
so if DTLS is used over UDP (or any datagram-based protocol that doesn't validate the source IP), then it's susceptible to this type of attack. TLSv1.3 is designed to operate over a stream-based transport protocol (like 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 that case a TLSv1.3 application would be susceptible to this attack too. π
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. And the whole thing can be done by the server without allocating any state, so without consuming expensive resources. slay. π
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 ofDTLSv1_listen(). In the typical case whereBIO_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 callBIO_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 ofBIO_s_datagram(3); seeBIO_s_datagram(3)for details on this issue. π fr fr, don't skip this one.
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 that 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.
β¨ RETURN VALUES β¨
for SSL_stateless():
- a return value of
1indicates success and thesslobject will be set up ready to continue the handshake β¨ - a return value of
0or-1indicates failure. If the value is0then aHelloRetryRequestwas sent. A value of-1indicates any other error. User code may retry theSSL_stateless()call. π
for DTLSv1_listen():
- a return value of
>= 1indicates success. Thesslobject will be set up ready to continue the handshake. thepeervalue will also be filled in. π - a return value of
0indicates a non-fatal error. This could (for example) be because of nonblocking IO, or some invalid message having been received from a peer. Errors may be placed on the OpenSSL error queue with further information if appropriate. Typically user code is expected to retry the call toDTLSv1_listen()in the event of a non-fatal error. - a return value of
<0indicates a fatal error. This could (for example) be because of a failure to allocate sufficient memory for the operation. π
for DTLSv1_listen(), prior to OpenSSL 1.1.0, fatal and non-fatal errors both produce return codes <= 0 (in typical implementations user code treats all errors as non-fatal), whilst return codes >0 indicate success. (iykyk, old versions were built different.)
β¨ SEE ALSO β¨
SSL_CTX_set_cookie_generate_cb(3), SSL_CTX_set_cookie_verify_cb(3), SSL_CTX_set_stateless_cookie_generate_cb(3), SSL_CTX_set_stateless_cookie_verify_cb(3), SSL_get_error(3), SSL_accept(3), ssl(7), bio(7) β go read those next bestie, they're the lore π
β¨ HISTORY β¨
- The
SSL_stateless()function was added in OpenSSL 1.1.1. π¦ - The
DTLSv1_listen()return codes were clarified in OpenSSL 1.1.0. The type of"peer"also changed in OpenSSL 1.1.0.
β¨ COPYRIGHT β¨
Copyright 2015-2023 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
that's the whole page babes, go forth and stateless-listen responsibly ππ
β§ο½₯οΎ OpenSSL 4.0.3, dated 2026-09-29 β this page was served fresh, keep it in your heart forever β§ο½₯οΎ π β¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms