Skip to content

Commit 971b190

Browse files
Amanda ButlerSeppo Takalo
authored andcommitted
Edit securesocket.md
Edit file for minor grammar and formatting nits.
1 parent 5bb054f commit 971b190

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

docs/reference/technology/connectivity/securesocket.md

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

3-
Mbed OS provides an interface for creating secure connections in the form of TLS stream. The `TLSSocketWrapper` 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.
3+
Mbed OS provides an interface for creating secure connections in the form of TLS stream. The `TLSSocketWrapper` class gives you the ability to secure any stream-based socket connection, for example TCP stream. This allows you to use existing protocol libraries through secure connections.
44

5-
`TLSSocketWrapper` inherits the `Socket` class, which allows any application that uses `Socket` to use `TLSSocketWrapper` 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 `TLSSocketWrapper` to it to covert it to HTTPS.
5+
`TLSSocketWrapper` inherits the `Socket` class, which allows any application that uses `Socket` to use `TLSSocketWrapper` instead. Secure socket both uses the 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 `TLSSocketWrapper` to it to covert it to HTTPS.
66

7-
For easy to use API there is helper class called `TLSSocket` that contains internal TCP socket for transport stream.
7+
The helper class called `TLSSocket` contains internal TCP socket for transport stream.
88

99
### Usage example
1010

11-
`TLSSocketWrapper` implements Mbed OS Socket API and extends it with functions that allow configuring security certificates, so it is straightforward to use after setting up. Please note that for most of the use cases, you are using these methods through `TLSSocket` class.
11+
`TLSSocketWrapper` implements the Mbed OS Socket API and extends it with functions that allow configuring security certificates, so it is straightforward to use after setting up. Please note that for most of the use cases, you are using these methods through `TLSSocket` class:
1212

1313
```
1414
TLSSocket *socket = new TLSSocket();
@@ -26,11 +26,11 @@ Please note that internal TLS structures require over 1 kB of RAM, so you need t
2626

2727
Internally `TLSSocket` consists of two classes, `TLSSocketWrapper` and `TLSSocket`, as shown in the following diagram:
2828

29-
![TLSSocket UML](tlssocket.png)
29+
<span class="images">![TLSSocket UML](https://s3-us-west-2.amazonaws.com/mbed-os-docs-images/tlssocket.png)<span>TLSSocket UML</span></span>
3030

3131
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.
3232

33-
One use case of `TLSSocketWrapper` is that existing TCP socket can be upgraded to TLS, by wrapping it like this:
33+
One use case of `TLSSocketWrapper` is that you can upgrade the existing TCP socket to TLS, by wrapping it like this:
3434

3535
```
3636
TCPSocket connection;
@@ -52,7 +52,7 @@ tls.send("HELLO", 5);
5252

5353
#### Configuring certificates
5454

55-
`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`.
55+
`TLSSocketWrapper` provides the following API to set server certificate. You can use either BASE64 formatted PEM certificate or binary DER certificates. The latter 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`.
5656

5757
```
5858
/** Sets the certification of Root CA.
@@ -90,19 +90,19 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const char *client_cert_pem,
9090

9191
#### Socket API
9292

93-
`TLSSocketWrapper` implements [Mbed OS Socket API](../apis/network-socket.html) as follows.
93+
`TLSSocketWrapper` implements the [Mbed OS Socket API](../apis/network-socket.html):
9494

9595
```
9696
virtual nsapi_error_t close();
9797
```
9898

99-
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`.
99+
This destroys the memory the TLS library allocates. It also closes the transport socket, unless [transport mode](#transport-modes) is set to `TRANSPORT_KEEP` or `TRANSPORT_CONNECT`:
100100

101101
```
102102
virtual nsapi_error_t connect(const SocketAddress &address);
103103
```
104104

105-
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.
105+
The code above 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 nonblocking mode:
106106

107107
```
108108
virtual nsapi_size_or_error_t send(const void *data, nsapi_size_t size);
@@ -111,11 +111,11 @@ virtual nsapi_size_or_error_t sendto(const SocketAddress &address, const void *d
111111
virtual nsapi_size_or_error_t recvfrom(SocketAddress *address, void *data, nsapi_size_t size);
112112
```
113113

114-
These work as expected, but `SocketAddress` parameters are ignored. TLS connection cannot change the peer. Also `recvfrom()` call does not set the peer address.
114+
These work as expected, but `SocketAddress` parameters are ignored. The TLS connection cannot change the peer. Also, `recvfrom()` call does not set the peer address.
115115

116116
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.
117117

118-
`MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY` is ignored and zero is returned to user (connection closed). Other error codes are passed through.
118+
`MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY` is ignored, and zero is returned to you (connection closed). Other error codes are passed through:
119119

120120
```
121121
virtual nsapi_error_t bind(const SocketAddress &address);
@@ -133,25 +133,24 @@ virtual Socket *accept(nsapi_error_t *error = NULL);
133133
virtual nsapi_error_t listen(int backlog = 1);
134134
```
135135

136-
These are returning `NSAPI_ERROR_UNSUPPORTED` as TLS socket cannot be set to listening mode.
136+
These are returning `NSAPI_ERROR_UNSUPPORTED` as you can't set TLS socket to listening mode.
137137

138138
#### Transport modes
139139

140-
`TLSSocketWrapper` has four modes that are given in the constructor and affect how the transport Socket is used in connection and closing phases.
140+
`TLSSocketWrapper` has four modes that are given in the constructor and affect how the transport Socket is used in connection and closing phases:
141141

142-
|Mode|Behaviour on trasport socket|
142+
|Mode|Behavior on trasport socket|
143143
|----|----------------------------|
144144
|TRANSPORT_KEEP | Keep the transport as it is. Does not call `connect()` or `close()` methods. |
145145
|TRANSPORT_CONNECT_AND_CLOSE | Both `connect()` and `close()` are called. (default) |
146-
|TRANSPORT_CONNECT | Call `connect()` but do not close the connection when finished. |
146+
|TRANSPORT_CONNECT | Call `connect()`, but do not close the connection when finished. |
147147
|TRANSPORT_CLOSE | Call `close()` when connection is finished. |
148148

149-
Default mode is `TRANSPORT_CONNECT_AND_CLOSE`.
149+
The default mode is `TRANSPORT_CONNECT_AND_CLOSE`.
150150

151+
#### Advanced use: using internal Mbed TLS structures
151152

152-
#### Advanced usage: using internal Mbed TLS structures
153-
154-
User may choose to use internal Mbed TLS structures to configure the TLS instance. This is supported by exposing some Mbed TLS structures like this:
153+
You may choose to use internal Mbed TLS structures to configure the TLS instance. This is supported by exposing some Mbed TLS structures like this:
155154

156155
```
157156
mbedtls_x509_crt *get_own_cert();
@@ -162,10 +161,10 @@ mbedtls_ssl_config *get_ssl_config();
162161
void set_ssl_config(mbedtls_ssl_config *);
163162
```
164163

165-
For guidance of how to use these, please refer to Mbed TLS documentation.
164+
For guidance of how to use these, please refer to the [Mbed TLS documentation](../apis/tls.html).
166165

167166
## Related content
168167

169-
- [Security Overview](../apis/security.html)
168+
- [Security overview](../apis/security.html).
170169
- [TLSSocket](../apis/tlssocket.html) API reference.
171-
- [DTLSSocket](../apis/dtlssocket.html) API reference
170+
- [DTLSSocket](../apis/dtlssocket.html) API reference.

0 commit comments

Comments
 (0)