39
39
*/
40
40
class TLSSocketWrapper : public Socket {
41
41
public:
42
+ /* * Transport modes */
42
43
enum control_transport {
43
- TRANSPORT_KEEP,
44
- TRANSPORT_CONNECT_AND_CLOSE,
45
- TRANSPORT_CONNECT,
46
- TRANSPORT_CLOSE,
44
+ TRANSPORT_KEEP, /* *< Doesn't call connect() or close() on transport socket */
45
+ TRANSPORT_CONNECT_AND_CLOSE, /* *< Does call connect() and close() on transport socket */
46
+ TRANSPORT_CONNECT, /* *< Does call only connect() on transport socket */
47
+ TRANSPORT_CLOSE, /* *< Does call close() on transport socket */
47
48
};
48
49
49
- /* Create a TLSSocketWrapper
50
+ /* * Create a TLSSocketWrapper.
50
51
*
51
- * @param transport Underlying transport socket to wrap
52
- * @param hostname Hostname of the remote host, used for certificate checking
52
+ * @param transport Underlying transport socket to wrap.
53
+ * @param hostname Hostname of the remote host, used for certificate checking.
54
+ * @param control Transport control mode. See @ref control_transport.
53
55
*/
54
56
TLSSocketWrapper (Socket *transport, const char *hostname = NULL , control_transport control = TRANSPORT_CONNECT_AND_CLOSE);
55
57
56
- /* * Destroy a socket wrapper
58
+ /* * Destroy a socket wrapper.
57
59
*
58
- * Closes socket wrapper if the socket wrapper is still open
60
+ * Closes socket wrapper if the socket wrapper is still open.
59
61
*/
60
62
virtual ~TLSSocketWrapper ();
61
63
@@ -64,28 +66,33 @@ class TLSSocketWrapper : public Socket {
64
66
* TLSSocket requires hostname that is used to verify the certificate.
65
67
* If hostname is not given in constructor, this function must be used before
66
68
* starting the TLS handshake.
69
+ *
70
+ * @param hostname Hostname of the remote host, used for certificate checking.
67
71
*/
68
72
void set_hostname (const char *hostname);
69
73
70
74
/* * Sets the certification of Root CA.
71
75
*
72
76
* @param root_ca Root CA Certificate in any mbed-TLS supported format.
73
77
* @param len Length of certificate (including terminating 0 for PEM).
78
+ * @return 0 on success, negative error code on failure.
74
79
*/
75
80
nsapi_error_t set_root_ca_cert (const void *root_ca, size_t len);
76
81
77
82
/* * Sets the certification of Root CA.
78
83
*
79
- * @param root_ca_pem Root CA Certificate in PEM format
84
+ * @param root_ca_pem Root CA Certificate in PEM format.
85
+ * @return 0 on success, negative error code on failure.
80
86
*/
81
87
nsapi_error_t set_root_ca_cert (const char *root_ca_pem);
82
88
83
89
/* * Sets client certificate, and client private key.
84
90
*
85
91
* @param client_cert client certification in PEM or DER format.
86
92
* @param client_cert_len certificate size including the terminating null byte for PEM data.
87
- * @param client_private_key_pem client private key in PEM or DER format
93
+ * @param client_private_key_pem client private key in PEM or DER format.
88
94
* @param client_private_key_len key size including the terminating null byte for PEM data
95
+ * @return 0 on success, negative error code on failure.
89
96
*/
90
97
nsapi_error_t set_client_cert_key (const void *client_cert, size_t client_cert_len,
91
98
const void *client_private_key_pem, size_t client_private_key_len);
@@ -94,6 +101,7 @@ class TLSSocketWrapper : public Socket {
94
101
*
95
102
* @param client_cert_pem Client certification in PEM format.
96
103
* @param client_private_key_pem Client private key in PEM format.
104
+ * @return 0 on success, negative error code on failure.
97
105
*/
98
106
nsapi_error_t set_client_cert_key (const char *client_cert_pem, const char *client_private_key_pem);
99
107
@@ -102,20 +110,19 @@ class TLSSocketWrapper : public Socket {
102
110
* The socket must be connected to a remote host. Returns the number of
103
111
* bytes sent from the buffer.
104
112
*
105
- * @param data Buffer of data to send to the host
106
- * @param size Size of the buffer in bytes
107
- * @return Number of sent bytes on success, negative error
108
- * code on failure
113
+ * @param data Buffer of data to send to the host.
114
+ * @param size Size of the buffer in bytes.
115
+ * @return Number of sent bytes on success, negative error code on failure.
109
116
*/
110
117
virtual nsapi_error_t send (const void *data, nsapi_size_t size);
111
118
112
- /* * Receive data over a TLS socket
119
+ /* * Receive data over a TLS socket.
113
120
*
114
121
* The socket must be connected to a remote host. Returns the number of
115
122
* bytes received into the buffer.
116
123
*
117
- * @param data Destination buffer for data received from the host
118
- * @param size Size of the buffer in bytes
124
+ * @param data Destination buffer for data received from the host.
125
+ * @param size Size of the buffer in bytes.
119
126
* @return Number of received bytes on success, negative error
120
127
* code on failure. If no data is available to be received
121
128
* and the peer has performed an orderly shutdown,
@@ -140,48 +147,55 @@ class TLSSocketWrapper : public Socket {
140
147
virtual nsapi_error_t getpeername (SocketAddress *address);
141
148
142
149
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(DOXYGEN_ONLY)
143
- /* * Get own certificate directly from Mbed TLS
144
- * @return internal Mbed TLS X509 structure
150
+ /* * Get own certificate directly from Mbed TLS.
151
+ *
152
+ * @return internal Mbed TLS X509 structure.
145
153
*/
146
154
mbedtls_x509_crt *get_own_cert ();
147
155
148
- /* * Set own certificate directly to Mbed TLS
156
+ /* * Set own certificate directly to Mbed TLS.
157
+ *
149
158
* @param crt Mbed TLS X509 certificate chain.
150
- * @return error code from mbedtls_ssl_conf_own_cert()
159
+ * @return error code from mbedtls_ssl_conf_own_cert().
151
160
*/
152
161
int set_own_cert (mbedtls_x509_crt *crt);
153
162
154
163
/* * Get CA chain structure.
164
+ *
155
165
* @return Mbed TLS X509 certificate chain.
156
166
*/
157
167
mbedtls_x509_crt *get_ca_chain ();
158
168
159
- /* * Set CA chain directly to Mbed TLS
169
+ /* * Set CA chain directly to Mbed TLS.
170
+ *
160
171
* @param crt Mbed TLS X509 certificate chain.
161
172
*/
162
173
void set_ca_chain (mbedtls_x509_crt *crt);
163
174
#endif
164
175
165
- /* * Get internal Mbed TLS configuration structure
166
- * @return Mbed TLS SSL config
176
+ /* * Get internal Mbed TLS configuration structure.
177
+ *
178
+ * @return Mbed TLS SSL config.
167
179
*/
168
180
mbedtls_ssl_config *get_ssl_config ();
169
181
170
182
/* * Override Mbed TLS configuration.
171
- * @param conf Mbed TLS SSL configuration structure
183
+ *
184
+ * @param conf Mbed TLS SSL configuration structure.
172
185
*/
173
186
void set_ssl_config (mbedtls_ssl_config *conf);
174
187
175
188
/* * Get internal Mbed TLS context structure.
176
- * @return SSL context
189
+ *
190
+ * @return SSL context.
177
191
*/
178
192
mbedtls_ssl_context *get_ssl_context ();
179
193
180
194
protected:
181
- /* * Initiates TLS Handshake
195
+ /* * Initiates TLS Handshake.
182
196
*
183
- * Initiates a TLS handshake to a remote peer
184
- * Underlying transport socket should already be connected
197
+ * Initiates a TLS handshake to a remote peer.
198
+ * Underlying transport socket should already be connected.
185
199
*
186
200
* Root CA certification must be set by set_ssl_ca_pem() before
187
201
* call this function.
0 commit comments