-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DTLS: Add server side stateless and CID QoL API #8224
Open
julek-wolfssl
wants to merge
2
commits into
wolfSSL:master
Choose a base branch
from
julek-wolfssl:dtls-server-demux
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+911
−64
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1997,8 +1997,8 @@ const char* wolfSSL_get_cipher_name(WOLFSSL* ssl); | |
/*! | ||
\ingroup IO | ||
|
||
\brief This function returns the file descriptor (fd) used as the | ||
input/output facility for the SSL connection. Typically this | ||
\brief This function returns the read file descriptor (fd) used as the | ||
input facility for the SSL connection. Typically this | ||
will be a socket file descriptor. | ||
|
||
\return fd If successful the call will return the SSL session file | ||
|
@@ -2016,9 +2016,38 @@ const char* wolfSSL_get_cipher_name(WOLFSSL* ssl); | |
\endcode | ||
|
||
\sa wolfSSL_set_fd | ||
\sa wolfSSL_set_read_fd | ||
\sa wolfSSL_set_write_fd | ||
*/ | ||
int wolfSSL_get_fd(const WOLFSSL*); | ||
|
||
/*! | ||
\ingroup IO | ||
|
||
\brief This function returns the write file descriptor (fd) used as the | ||
output facility for the SSL connection. Typically this | ||
will be a socket file descriptor. | ||
|
||
\return fd If successful the call will return the SSL session file | ||
descriptor. | ||
|
||
\param ssl pointer to the SSL session, created with wolfSSL_new(). | ||
|
||
_Example_ | ||
\code | ||
int sockfd; | ||
WOLFSSL* ssl = 0; | ||
... | ||
sockfd = wolfSSL_get_wfd(ssl); | ||
... | ||
\endcode | ||
|
||
\sa wolfSSL_set_fd | ||
\sa wolfSSL_set_read_fd | ||
\sa wolfSSL_set_write_fd | ||
*/ | ||
int wolfSSL_get_wfd(const WOLFSSL*); | ||
|
||
/*! | ||
\ingroup Setup | ||
|
||
|
@@ -2289,6 +2318,48 @@ int wolfSSL_peek(WOLFSSL* ssl, void* data, int sz); | |
*/ | ||
int wolfSSL_accept(WOLFSSL*); | ||
|
||
/*! | ||
\ingroup IO | ||
|
||
\brief This function is called on the server side and statelessly listens | ||
for an SSL client to initiate the DTLS handshake. | ||
|
||
\return WOLFSSL_SUCCESS ClientHello containing a valid cookie was received. | ||
The connection can be continued with wolfSSL_accept(). | ||
\return WOLFSSL_FAILURE The I/O layer returned WANT_READ. This is either | ||
because there is no data to read and we are using non-blocking sockets or | ||
we sent a cookie request and we are waiting for a reply. The user should | ||
call wolfDTLS_accept_stateless again after data becomes available in | ||
the I/O layer. | ||
\return WOLFSSL_FATAL_ERROR A fatal error occurred. The ssl object should be | ||
free'd and allocated again to continue. | ||
|
||
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new(). | ||
|
||
_Example_ | ||
\code | ||
int ret = 0; | ||
int err = 0; | ||
WOLFSSL* ssl; | ||
... | ||
do { | ||
ret = wolfDTLS_accept_stateless(ssl); | ||
if (ret == WOLFSSL_FATAL_ERROR) | ||
// re-allocate the ssl object with wolfSSL_free() and wolfSSL_new() | ||
} while (ret != WOLFSSL_SUCCESS); | ||
ret = wolfSSL_accept(ssl); | ||
if (ret != SSL_SUCCESS) { | ||
err = wolfSSL_get_error(ssl, ret); | ||
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer)); | ||
} | ||
\endcode | ||
|
||
\sa wolfSSL_accept | ||
\sa wolfSSL_get_error | ||
\sa wolfSSL_connect | ||
*/ | ||
int wolfDTLS_accept_stateless(WOLFSSL* ssl); | ||
|
||
/*! | ||
\ingroup Setup | ||
|
||
|
@@ -3856,12 +3927,52 @@ int wolfSSL_dtls(WOLFSSL* ssl); | |
\endcode | ||
|
||
\sa wolfSSL_dtls_get_current_timeout | ||
\sa wolfSSL_dtls_set_pending_peer | ||
\sa wolfSSL_dtls_get_peer | ||
\sa wolfSSL_dtls_got_timeout | ||
\sa wolfSSL_dtls | ||
*/ | ||
int wolfSSL_dtls_set_peer(WOLFSSL* ssl, void* peer, unsigned int peerSz); | ||
|
||
/*! | ||
\brief This function sets the pending DTLS peer, peer (sockaddr_in) with | ||
size of peerSz. This sets the pending peer that will be upgraded to a | ||
regular peer when we successfully de-protect the next record. This is useful | ||
in scenarios where the peer's address can change to avoid off-path attackers | ||
from changing the peer address. This should be used with Connection ID's to | ||
allow seamless and safe transition to a new peer address. | ||
|
||
\return SSL_SUCCESS will be returned upon success. | ||
\return SSL_FAILURE will be returned upon failure. | ||
\return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled | ||
with DTLS support. | ||
|
||
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new(). | ||
\param peer pointer to peer’s sockaddr_in structure. If NULL then the peer | ||
information in ssl is cleared. | ||
\param peerSz size of the sockaddr_in structure pointed to by peer. If 0 | ||
then the peer information in ssl is cleared. | ||
|
||
_Example_ | ||
\code | ||
int ret = 0; | ||
WOLFSSL* ssl; | ||
sockaddr_in addr; | ||
... | ||
ret = wolfSSL_dtls_set_pending_peer(ssl, &addr, sizeof(addr)); | ||
if (ret != SSL_SUCCESS) { | ||
// failed to set DTLS peer | ||
} | ||
\endcode | ||
|
||
\sa wolfSSL_dtls_get_current_timeout | ||
\sa wolfSSL_dtls_set_peer | ||
\sa wolfSSL_dtls_get_peer | ||
\sa wolfSSL_dtls_got_timeout | ||
\sa wolfSSL_dtls | ||
*/ | ||
int wolfSSL_dtls_set_pending_peer(WOLFSSL* ssl, void* peer, unsigned int peerSz); | ||
|
||
/*! | ||
\brief This function gets the sockaddr_in (of size peerSz) of the current | ||
DTLS peer. The function will compare peerSz to the actual DTLS peer size | ||
|
@@ -3899,6 +4010,40 @@ int wolfSSL_dtls_set_peer(WOLFSSL* ssl, void* peer, unsigned int peerSz); | |
*/ | ||
int wolfSSL_dtls_get_peer(WOLFSSL* ssl, void* peer, unsigned int* peerSz); | ||
|
||
/*! | ||
\brief This function gets the sockaddr_in (of size peerSz) of the current | ||
DTLS peer. This is a zero-copy alternative to wolfSSL_dtls_get_peer(). | ||
|
||
\return SSL_SUCCESS will be returned upon success. | ||
\return SSL_FAILURE will be returned upon failure. | ||
\return SSL_NOT_IMPLEMENTED will be returned if wolfSSL was not compiled | ||
with DTLS support. | ||
|
||
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new(). | ||
\param peer pointer to return the internal buffer holding the peer address | ||
\param peerSz output the size of the actual sockaddr_in structure | ||
pointed to by peer. | ||
|
||
_Example_ | ||
\code | ||
int ret = 0; | ||
WOLFSSL* ssl; | ||
sockaddr_in* addr; | ||
unsigned int addrSz; | ||
... | ||
ret = wolfSSL_dtls_get_peer(ssl, &addr, &addrSz); | ||
if (ret != SSL_SUCCESS) { | ||
// failed to get DTLS peer | ||
} | ||
\endcode | ||
|
||
\sa wolfSSL_dtls_get_current_timeout | ||
\sa wolfSSL_dtls_got_timeout | ||
\sa wolfSSL_dtls_set_peer | ||
\sa wolfSSL_dtls | ||
*/ | ||
int wolfSSL_dtls_get0_peer(WOLFSSL* ssl, const void** peer, unsigned int* peerSz); | ||
|
||
/*! | ||
\ingroup Debug | ||
|
||
|
@@ -14138,6 +14283,35 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data, | |
int wolfSSL_read_early_data(WOLFSSL* ssl, void* data, int sz, | ||
int* outSz); | ||
|
||
/*! | ||
\ingroup IO | ||
|
||
\brief | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing doc |
||
|
||
\param [in] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new(). | ||
\param [in] data data to inject into the ssl object. | ||
\param [in] sz number of bytes of data to inject. | ||
|
||
\return BAD_FUNC_ARG if any pointer parameter is NULL or sz <= 0 | ||
\return APP_DATA_READY if there is application data left to read | ||
\return MEMORY_E if allocation fails | ||
\return WOLFSSL_SUCCESS on success | ||
|
||
_Example_ | ||
\code | ||
byte buf[2000] | ||
sz = recv(fd, buf, sizeof(buf), 0); | ||
if (sz <= 0) | ||
// error | ||
if (wolfSSL_inject(ssl, buf, sz) != WOLFSSL_SUCCESS) | ||
// error | ||
sz = wolfSSL_read(ssl, buf, sizeof(buf); | ||
\endcode | ||
|
||
\sa wolfSSL_read | ||
*/ | ||
int wolfSSL_inject(WOLFSSL* ssl, const void* data, int sz); | ||
|
||
/*! | ||
\ingroup Setup | ||
|
||
|
@@ -14955,6 +15129,7 @@ connection into the buffer pointed by the parameter buffer. See RFC 9146 and RFC | |
\param buffer A buffer where the ConnectionID will be copied | ||
\param bufferSz available space in buffer | ||
|
||
\sa wolfSSL_dtls_cid_get0_rx | ||
\sa wolfSSL_dtls_cid_use | ||
\sa wolfSSL_dtls_cid_is_enabled | ||
\sa wolfSSL_dtls_cid_set | ||
|
@@ -14967,6 +15142,27 @@ int wolfSSL_dtls_cid_get_rx(WOLFSSL* ssl, unsigned char* buffer, | |
|
||
/*! | ||
|
||
\brief Get the ConnectionID used by the other peer. See RFC 9146 and RFC | ||
9147. | ||
|
||
\return WOLFSSL_SUCCESS if ConnectionID was correctly copied, error code | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ConnectionID is not copied. |
||
otherwise | ||
|
||
\param ssl A WOLFSSL object pointern | ||
\param cid Pointer that will be set to the internal memory that holds the CID | ||
|
||
\sa wolfSSL_dtls_cid_get_rx | ||
\sa wolfSSL_dtls_cid_use | ||
\sa wolfSSL_dtls_cid_is_enabled | ||
\sa wolfSSL_dtls_cid_set | ||
\sa wolfSSL_dtls_cid_get_rx_size | ||
\sa wolfSSL_dtls_cid_get_tx_size | ||
\sa wolfSSL_dtls_cid_get_tx | ||
*/ | ||
int wolfSSL_dtls_cid_get0_rx(WOLFSSL* ssl, unsigned char** cid); | ||
|
||
/*! | ||
|
||
\brief Get the size of the ConnectionID used to send records in this | ||
connection. See RFC 9146 and RFC 9147. The size is stored in the parameter size. | ||
|
||
|
@@ -14998,6 +15194,7 @@ available size need to be provided in bufferSz. | |
\param buffer A buffer where the ConnectionID will be copied | ||
\param bufferSz available space in buffer | ||
|
||
\sa wolfSSL_dtls_cid_get0_tx | ||
\sa wolfSSL_dtls_cid_use | ||
\sa wolfSSL_dtls_cid_is_enabled | ||
\sa wolfSSL_dtls_cid_set | ||
|
@@ -15008,6 +15205,50 @@ available size need to be provided in bufferSz. | |
int wolfSSL_dtls_cid_get_tx(WOLFSSL* ssl, unsigned char* buffer, | ||
unsigned int bufferSz); | ||
|
||
/*! | ||
|
||
\brief Get the ConnectionID used when sending records in this connection. See | ||
RFC 9146 and RFC 9147. | ||
|
||
\return WOLFSSL_SUCCESS if ConnectionID was correctly retrieved, error code | ||
otherwise | ||
|
||
\param ssl A WOLFSSL object pointern | ||
\param cid Pointer that will be set to the internal memory that holds the CID | ||
|
||
\sa wolfSSL_dtls_cid_get_tx | ||
\sa wolfSSL_dtls_cid_use | ||
\sa wolfSSL_dtls_cid_is_enabled | ||
\sa wolfSSL_dtls_cid_set | ||
\sa wolfSSL_dtls_cid_get_rx_size | ||
\sa wolfSSL_dtls_cid_get_rx | ||
\sa wolfSSL_dtls_cid_get_tx_size | ||
*/ | ||
int wolfSSL_dtls_cid_get0_tx(WOLFSSL* ssl, unsigned char** cid); | ||
|
||
/*! | ||
|
||
\brief Extract the ConnectionID from a record datagram/message. See | ||
RFC 9146 and RFC 9147. | ||
|
||
\param msg buffer holding the datagram read from the network | ||
\param msgSz size of msg in bytes | ||
\param cid pointer to the start of the CID inside the msg buffer | ||
\param cidSz the expected size of the CID. The record layer does not have a CID | ||
size field so we have to know beforehand the size of the CID. It is recommended | ||
to use a constant CID for all connections. | ||
|
||
\sa wolfSSL_dtls_cid_get_tx | ||
\sa wolfSSL_dtls_cid_use | ||
\sa wolfSSL_dtls_cid_is_enabled | ||
\sa wolfSSL_dtls_cid_set | ||
\sa wolfSSL_dtls_cid_get_rx_size | ||
\sa wolfSSL_dtls_cid_get_rx | ||
\sa wolfSSL_dtls_cid_get_tx_size | ||
*/ | ||
void wolfSSL_dtls_cid_parse(const unsigned char* msg, unsigned int msgSz, | ||
const unsigned char** cid, unsigned int cidSz); | ||
|
||
/*! | ||
\ingroup TLS | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't expose the internal cid.
Prefer to add an API to compare to the ssl cid object if afraid of performance loss of copying the cid.
(like
wolfSSL_dtls_cid_cmp(WOLFSSL*ssl,byte *cid, int cidSz)
)