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/api/networksocket/securesocket.md
+19-25Lines changed: 19 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
1
## Secure Socket
2
2
3
-
Mbed OS provides easy interface for creating secure connections in form of TLS stream.
4
-
`TLSSocket` class provides the ability to secure any stream based socket connection, for example TCP stream. This allows existing protocol libraries to be used through secure connections.
3
+
Mbed OS provides an interface for creating secure connections in the form of TLS stream. The `TLSSocket` class provides the ability to secure any stream-based socket connection, for example TCP stream. This allows you to use existing protocol libraries through a secure connections.
5
4
6
-
`TLSSocket` is inheriting the `Socket` class, which allows any application that uses `Socket` to use `TLSSocket` instead.
7
-
Secure socket both uses Socket interface as its transport layer and implements it. This makes it transport independent and there is no direct dependency to IP stack. For example, we can use HTTP library and give `TLSSocket` for it, to covert it to HTTPS.
5
+
`TLSSocket` inherits the `Socket` class, which allows any application that uses `Socket` to use `TLSSocket` instead. Secure socket both uses Socket interface as its transport layer and implements it. This makes it transport independent, and there is no direct dependency on the IP stack. For example, you can use the HTTP library and give `TLSSocket` to it to covert it to HTTPS.
6
+
7
+
### API
8
+
9
+
`TLSSocketWrapper` implements Mbed OS Socket API and extends it with functions that allow configuring security certificates. Please note that for most of the use cases, you are using these methods through `TLSSocket` class.
8
10
9
11
### Usage example
10
12
11
-
TLSSocket API follows Socket API so it is easy to use after setting up:
13
+
The TLSSocket API follows the Socket API, so it is straightforward to use after setting up:
Please note that internal TLS structures require over 1 kB of RAM, so each TLSSocket should be allocated from heap using `new` command, instead of using stack or statically allocating it.
24
-
25
+
Please note that internal TLS structures require over 1 kB of RAM, so you need to allocate each TLSSocket from the heap by using the `new` command, instead of using stack or statically allocating it.
25
26
26
27
### Design
27
28
28
-
Internally `TLSSocket`consist of two classes `TLSSocketWrapper` and `TLSSocket` as shown in the following diagram:
29
+
Internally `TLSSocket`consists of two classes,`TLSSocketWrapper` and `TLSSocket`, as shown in the following diagram:
29
30
30
31

31
32
32
-
The `TLSSocketWrapper`is able to use any `Socket` as its transport. `TLSSocket` is a helper that uses directly `TCPSocket` for its transport, making it easy to adopt existing TCP based applications to TLS.
33
+
The `TLSSocketWrapper`can use any `Socket` as its transport. `TLSSocket` is a helper that uses directly `TCPSocket` for its transport, so you can adopt existing TCP based applications to TLS.
33
34
34
35
One use case of `TLSSocketWrapper` is that existing TCP socket can be upgraded to TLS, by wrapping it like this:
35
36
@@ -50,13 +51,9 @@ tls.connect();
50
51
tls.send("HELLO", 5);
51
52
```
52
53
53
-
### API
54
-
55
-
`TLSSocketWrapper` implements Mbed OS Socket API and extends it with functions that allow configuring security certificates. Please note that for most of the use cases, you are using these methods through `TLSSocket` class.
56
-
57
54
#### Configuring certificates
58
55
59
-
`TLSSocketWrapper` provides following API to set server certificate. You can use either BASE64 formatted PEM certificate, or binary DER certificates. Later form of these functions just assumes `root_ca_pem` or `client_cert_pem` to be standard C string and counts its lenght and passes to method which takes just`void*` and `len`.
56
+
`TLSSocketWrapper` provides the following API to set server certificate. You can use either BASE64 formatted PEM certificate or binary DER certificates. The later form of these functions assumes `root_ca_pem` or `client_cert_pem` to be standard C string, counts its length and passes to method, which takes only`void*` and `len`.
60
57
61
58
```
62
59
/** Sets the certification of Root CA.
@@ -73,7 +70,7 @@ nsapi_error_t TLSSocketWrapper::set_root_ca_cert(const void *root_ca, size_t len
Also closes the transport socket, unless [transport mode](#transport-modes) is set to `TRANSPORT_KEEP` or `TRANSPORT_CONNECT`.
105
-
100
+
Destroys the memory allocated by TLS library. Also closes the transport socket, unless [transport mode](#transport-modes) is set to `TRANSPORT_KEEP` or `TRANSPORT_CONNECT`.
Initiates the TCP connection and continues to TLS hanshake. If [transport mode](#transport-modes) is either `TRANSPORT_KEEP` or `TRANSPORT_CLOSE`, TCP is assumed to be open and state directly goes into TLS handshake.
112
-
This is currently forced to blocking mode. After succesfully connecting, you can set it to non-blockin mode.
106
+
Initiates the TCP connection and continues to TLS hanshake. If [transport mode](#transport-modes) is either `TRANSPORT_KEEP` or `TRANSPORT_CLOSE`, TCP is assumed to be open and state directly goes into TLS handshake. This is currently forced to blocking mode. After succesfully connecting, you can set it to non-blockin mode.
These work as expected, but `SocketAddress` parameters are ignored. TLS connection cannot
121
-
change the peer. Also `recvfrom()` call does not set the peer address.
122
114
123
-
Mbed TLS error codes `MBEDTLS_ERR_SSL_WANT_READ` and `MBEDTLS_ERR_SSL_WANT_WRITE` are
124
-
translated to `NSAPI_ERROR_WOULD_BLOCK` before passing to user.
115
+
These work as expected, but `SocketAddress` parameters are ignored. TLS connection cannot change the peer. Also `recvfrom()` call does not set the peer address.
116
+
117
+
Mbed TLS error codes `MBEDTLS_ERR_SSL_WANT_READ` and `MBEDTLS_ERR_SSL_WANT_WRITE` are translated to `NSAPI_ERROR_WOULD_BLOCK` before passing to user.
125
118
126
119
`MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY` is ignored and zero is returned to user (connection closed). Other error codes are passed through.
0 commit comments