Skip to content

Commit 7c65002

Browse files
Amanda ButlerSeppo Takalo
authored andcommitted
Make initial edits on securesocket.md
Complete initial copy edits.
1 parent e938731 commit 7c65002

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

docs/api/networksocket/securesocket.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
## Secure Socket
22

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.
54

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.
810

911
### Usage example
1012

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:
1214

1315
```
1416
TLSSocket *socket = new TLSSocket();
@@ -20,16 +22,15 @@ socket->connect(HOST_NAME, PORT)
2022
socket->send(data, size);
2123
```
2224

23-
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.
2526

2627
### Design
2728

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:
2930

3031
![TLSSocket UML](tlssocket.png)
3132

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.
3334

3435
One use case of `TLSSocketWrapper` is that existing TCP socket can be upgraded to TLS, by wrapping it like this:
3536

@@ -50,13 +51,9 @@ tls.connect();
5051
tls.send("HELLO", 5);
5152
```
5253

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-
5754
#### Configuring certificates
5855

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`.
6057

6158
```
6259
/** 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
7370
nsapi_error_t TLSSocketWrapper::set_root_ca_cert(const char *root_ca_pem);
7471
```
7572

76-
If client authentication is required, following API allows you to set the client certificate and private key:
73+
If client authentication is required, the following API allows you to set the client certificate and private key:
7774

7875
```
7976
/** Sets client certificate, and client private key.
@@ -100,28 +97,24 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const char *client_cert_pem,
10097
virtual nsapi_error_t close();
10198
```
10299

103-
Destroys the memory allocated by TLS library.
104-
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`.
106101

107102
```
108103
virtual nsapi_error_t connect(const SocketAddress &address);
109104
```
110105

111-
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.
113107

114108
```
115109
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size);
116110
virtual nsapi_size_or_error_t recv(void *data, nsapi_size_t size);
117111
virtual nsapi_size_or_error_t sendto(const SocketAddress &address, const void *data, nsapi_size_t size);
118112
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, void *data, nsapi_size_t size);
119113
```
120-
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.
122114

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.
125118

126119
`MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY` is ignored and zero is returned to user (connection closed). Other error codes are passed through.
127120

@@ -133,13 +126,14 @@ virtual void sigio(mbed::Callback<void()> func);
133126
virtual nsapi_error_t setsockopt(int level, int optname, const void *optval, unsigned optlen);
134127
virtual nsapi_error_t getsockopt(int level, int optname, void *optval, unsigned *optlen);
135128
```
136-
These are passed through to transport socket.
137129

130+
These are passed through to transport socket.
138131

139132
```
140133
virtual Socket *accept(nsapi_error_t *error = NULL);
141134
virtual nsapi_error_t listen(int backlog = 1);
142135
```
136+
143137
These are returning `NSAPI_ERROR_UNSUPPORTED` as TLS socket cannot be set to listening mode.
144138

145139
#### Transport modes

0 commit comments

Comments
 (0)