-
Notifications
You must be signed in to change notification settings - Fork 2.1k
RFC: (TLSMAN) API for handling all the (D)TLS stacks for the user #7649
Description
This is the proposition of the second API (See #7397) for handling secure communication with RIOT O.S. This API has as objective to binding all the SSL/TLS protocols available (tinyDTLS, WolfSSL, etc.) with the intention of making their use invisible to the user. With this approach the user only needs to use secure_sock and configure the (D)TLS stack by means of the Makefile.
I had the good luck of meeting @kaleb-himes during the RIOT summit and we had a brief discussion about the feasibility of this approach for the tinyDTLS and WolfSSL stacks.
General scheme
---------------------------------------------------
| |
| Application / Library |
| |
---------------------------------------------------
|
| secure_sock_api
---------------------------------------------------
| |
| Secure_Sock |
| |
| ---------------------------------- |
| | TLSMAN | |
| | | |
| | ------------- ------------- | |
| | | tinydtls | | WolfSSL | | |
| | | | | | | |
| | ------------- ------------- | |
| ---------------------------------- |
---------------------------------------------------
| |
| sock_tcp | sock_udp
| |
. .
. .
. .
API: TLSMAN ((D)TLS stack Manager)
API used directly by secure_sock for handling the communication between the
TLS/DTLS stack and the corresponding sock_tcp and sock_udp.
/* Structure defined according to the (D)TLS */
typedef struct {
...
remote_peer
local_peer
secure_sock_key_peer_t keys
union sock {
sock_upd udp;
sock_tcp tcp
}
wolf_session
tinydtls_session
} tlsman_session_t
/*
* Load the TLS/DTLS stack(s) available.
* TODO: Handling the selection of cipher suites at this point.
*/
size_t tlsman_load_stack(int **ciphers)
/*
* Start a DTLS handshake between the peers defined by session.
*
* NOTE: This can be optional
*
* @session The secure session to use.
* @flags If SECURE_SOCK_NONBLOCK is set, this function ends after sending
* the first handshake flight. Otherwise, blocks until the handshake
* is completed.
* @return: 0 on success, otherwise error code.
*/
size_t tlsman_client_open_channel(tlsman_session_t *session, unsigned int flags)
/*
* Starts listening for any (D)TLS record message.
* NOTE: See tlsman_retrieve_data_app() for the Data App record.
* @session The secure session to use.
* @flags If SECURE_SOCK_NONBLOCK is set (default) the function ends after
* sending the first handshake flight. Otherwise, blocks until the
* handshake is completed.
* @return: 0 on success, otherwise error code.
*/
tlsman_server_open_channel(tlsman_session_t *session, unsigned int flags,
secure_sock_key_peer_t keys )
/*
* Returns the last error occurred in the local peer (Alerts, retransmission,
* wrong cipher suites, etc.).
* @return: Error code (0 if nothing)
*/
ssize_t tlsman_return_last_known_error()
/*
* Process the @error_id and identifies if the (D)TLS session must be terminated.
* @error_id Error ID
* @return 0 if error is non-fatal.
*/
ssize_t tlsman_process_error_code (site_t error_id)
/*
* Checks if there is a (D)TLS Data Application record pending to be passed to
* secure_sock.
*
* NOTE: This can be optional
*
* @returns 0 if not.
*/
size_t tlsman_is_dtls_data_app_ready( )
/*
* Process the last (D)TLS Data Application record available.
* @session The secure session to use.
* @data Pointer where the received data should be stored.
* @max_len Maximum space available at @data.
* @secure_handler Callback for handling the upper layer data (can be NULL)
* @returns Number of bytes retrieved or error code.
*/
ssize_t tlsman_retrieve_data_app(tlsman_session_t *session,
void *data,
size_t max_len,
sec_data_handler secure_handler )
/*
* Send upper layer data as a (D)TLS Data Application record.
* @session The secure session to use.
* @data Pointer to data to send
* @data_size Size of @data.
* @returns 0 on success or error code.
*/
size_t tlsman_send_data_app(tlsman_session_t *session, const void *data,
size_t data_size )
/*
* Close the (D) TLS channel established between the peers of the session.
* This also sends a last DTLS Alert record and releases memory used for the
* session.
* @returns 0 on success or error code.
*/
size_t tlsman_close_channel(tlsman_session_t *session)The API can be configured to work with synchronous or asynchronous being the latest the default setting. In the case of tlsman_retrieve_data_app () it should be called by secure_sock_send () when asynchronous is used and by secure_sock_rcvd () otherwise.
For the first PR the support will be tested only for tinyDTLS because WolfSSL is still being integrated to RIOT.
Any suggestions or comments? (like better names for this API)