Skip to content

Commit b3d1d1f

Browse files
Add DTLS in Connectivity's design document
1 parent 5f495db commit b3d1d1f

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

docs/design-documents/features/connectivity/TLSSocket - Design document.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# TLSSocket - design document
22
## Overview and background
33

4-
This document describes the design of the TLSSocket class, which provides an interface for an Mbed OS user to create TLS connections over a TCP socket.
4+
This document describes the design of the TLSSocket and DTLSSocket classes, which provide an interface for an Mbed OS user to create TLS connections over a TCP socket or DTLS over a UDP socket.
55

66
Mbed OS provides two different implementations for TLS sockets; Mbed TLS based (default) or offloaded TLS socket when used network stack (for example, a cellular modem target driver) supports it.
77

88
This class greatly simplifies the use of TLS but limits itself to only one use case. This design limitation is accepted as other users can continue using Mbed TLS API directly. Mbed TLS based TLSSocket also exposes internal Mbed TLS structures allowing use of Mbed TLS API to configure the underlying library.
99

10+
DTLSSocket shares most of its functionality with TLSSocket (via `TLSSocketWrapper` class), just using UDP instead of TCP as transport socket and handling connection differently.
11+
1012
The high-level goal is to demonstrate that secure connections are not hard to do.
1113

1214
## Design limitations
@@ -26,10 +28,12 @@ Offloaded vs. Mbed TLS based TLSSocket:
2628

2729
# System architecture and high-level design
2830

29-
The Mbed TLS based secure socket consists of two classes:
31+
The Mbed TLS based secure socket consists of four classes:
3032

3133
* `TLSSocketWrapper`, which handles initialization of TLS library, does the TLS handsake and takes any Socket as a transport.
3234
* `TLSSocket`, which inherits TLSSocketWrapper, has TCP socket as a transport and adds `connect(char *hostname)` for initiating the TCP and TLS handshakes at one call.
35+
* `DTLSSocketWrapper`, which inherits from TLSSocketWrapper and adds a few auxiliary functions.
36+
* `DTLSSocket`, which inherits DTLSSocketWrapper, has UDP socket as a transport and adds `connect(char *hostname)` for initiating the UDP and DTLS handshakes at one call.
3337

3438
```
3539
,--------------.
@@ -52,14 +56,21 @@ The Mbed TLS based secure socket consists of two classes:
5256
|void set_hostname(...); |
5357
|int do_handshake(); |
5458
`-----------------------------'
55-
|
56-
,----------------------------.
57-
|TLSSocket |
58-
|----------------------------|
59-
|TCPSocket transport |
60-
|----------------------------|
61-
|int connect(char *hostname);|
62-
`----------------------------'
59+
|______________________________
60+
| |
61+
| ,----------------------------.
62+
| |DTLSSocketWrapper |
63+
| |----------------------------|
64+
| |timer-related functions |
65+
| `----------------------------'
66+
| |
67+
,----------------------------. ,----------------------------.
68+
|TLSSocket | |DTLSSocket |
69+
|----------------------------| |----------------------------|
70+
|TCPSocket transport | |UDPSocket transport |
71+
|----------------------------| |----------------------------|
72+
|int connect(char *hostname);| |int connect(char *hostname);|
73+
`----------------------------' `----------------------------'
6374
```
6475

6576
Offloaded TLS socket:
@@ -94,6 +105,8 @@ The offloaded secure socket shares the same API as Mbed TLS based TLSSocket as m
94105

95106
When TLSSocket implements the Socket API, it can be used instead of TCP connection in any Mbed OS library. For example, the MQTT library is made secure without any code changes: https://github.com/coisme/Mbed-to-Azure-IoT-Hub/tree/new-TLSSocket
96107

108+
The `DTLSSocket` class implements TLS handshake for UDPSocket.
109+
97110
## High-level design goal 2: Only certificate-based authentication
98111

99112
The aim is to first support only certificate-based authentication, so we implement only `set_root_ca_cert()` and `set_client_cert_key()` functions. Later on, different types of authentication methods can be added.
@@ -148,7 +161,7 @@ This destroys the memory allocated by the TLS library. It also closes the transp
148161
virtual nsapi_error_t connect(const SocketAddress &address);
149162
```
150163

151-
This initiates the TCP connection and continues to the TLS hanshake.
164+
This initiates the TCP/UDP connection and continues to the TLS hanshake.
152165

153166
This is currently forced to blocking mode.
154167

@@ -313,14 +326,6 @@ No tool changes required.
313326

314327
By default, the system is configured to use the Mbed TLS based secure socket because only a few network stacks support offloaded TLS socket. You can enable the offloaded TLS socket in the application json configuration file by setting: `"nsapi.offload-tlssocket": true`.
315328

316-
## Reusability
317-
318-
Mbed TLS secure socket:
319-
Parts of the state machine are probably relevant when implementing DTLS socket. TLSSocketWrapper is entirely reusable when doing the TLS handshake using any socket type. It does not have tight bindings to TCP.
320-
321-
Offloaded secure socket:
322-
The current implementation is for TLS only and does not support DTLS.
323-
324329
## Assumptions
325330

326331
We assume the server certificate is given from the application to `TLSSocket::set_root_ca_cert()` interface in a format that is understood by Mbed TLS or, in the case of the offloaded TLS socket, the implementation of TLS socket in the network stack.

0 commit comments

Comments
 (0)