You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/design-documents/features/connectivity/TLSSocket - Design document.md
+24-19Lines changed: 24 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
# TLSSocket - design document
2
2
## Overview and background
3
3
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.
5
5
6
6
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.
7
7
8
8
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.
9
9
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
+
10
12
The high-level goal is to demonstrate that secure connections are not hard to do.
11
13
12
14
## Design limitations
@@ -26,10 +28,12 @@ Offloaded vs. Mbed TLS based TLSSocket:
26
28
27
29
# System architecture and high-level design
28
30
29
-
The Mbed TLS based secure socket consists of two classes:
31
+
The Mbed TLS based secure socket consists of four classes:
30
32
31
33
*`TLSSocketWrapper`, which handles initialization of TLS library, does the TLS handsake and takes any Socket as a transport.
32
34
*`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.
33
37
34
38
```
35
39
,--------------.
@@ -52,14 +56,21 @@ The Mbed TLS based secure socket consists of two classes:
@@ -94,6 +105,8 @@ The offloaded secure socket shares the same API as Mbed TLS based TLSSocket as m
94
105
95
106
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
96
107
108
+
The `DTLSSocket` class implements TLS handshake for UDPSocket.
109
+
97
110
## High-level design goal 2: Only certificate-based authentication
98
111
99
112
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
This initiates the TCP connection and continues to the TLS hanshake.
164
+
This initiates the TCP/UDP connection and continues to the TLS hanshake.
152
165
153
166
This is currently forced to blocking mode.
154
167
@@ -313,14 +326,6 @@ No tool changes required.
313
326
314
327
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`.
315
328
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
-
324
329
## Assumptions
325
330
326
331
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