28
28
29
29
TLSSocketWrapper::TLSSocketWrapper (Socket *transport, const char *hostname, control_transport control) :
30
30
_transport(transport),
31
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
31
32
_cacert (NULL ),
32
33
_clicert(NULL ),
34
+ #endif
33
35
_ssl_conf (NULL ),
34
36
_connect_transport(control==TRANSPORT_CONNECT || control==TRANSPORT_CONNECT_AND_CLOSE),
35
37
_close_transport(control==TRANSPORT_CLOSE || control==TRANSPORT_CONNECT_AND_CLOSE),
@@ -57,20 +59,24 @@ TLSSocketWrapper::~TLSSocketWrapper() {
57
59
mbedtls_ssl_free (&_ssl);
58
60
mbedtls_pk_free (&_pkctx);
59
61
62
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
60
63
set_own_cert (NULL );
61
64
set_ca_chain (NULL );
65
+ #endif
62
66
set_ssl_config (NULL );
63
67
}
64
68
65
69
void TLSSocketWrapper::set_hostname (const char *hostname)
66
70
{
71
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
67
72
mbedtls_ssl_set_hostname (&_ssl, hostname);
73
+ #endif
68
74
}
69
75
70
76
nsapi_error_t TLSSocketWrapper::set_root_ca_cert (const void *root_ca, size_t len)
71
77
{
72
78
#if !defined(MBEDTLS_X509_CRT_PARSE_C)
73
- return NSAPI_ERROR_UNSUPPORTED
79
+ return NSAPI_ERROR_UNSUPPORTED;
74
80
#else
75
81
mbedtls_x509_crt *crt;
76
82
@@ -108,7 +114,7 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, siz
108
114
const void *client_private_key_pem, size_t client_private_key_len)
109
115
{
110
116
#if !defined(MBEDTLS_X509_CRT_PARSE_C)
111
- return NSAPI_ERROR_UNSUPPORTED
117
+ return NSAPI_ERROR_UNSUPPORTED;
112
118
#else
113
119
114
120
int ret;
@@ -173,8 +179,12 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
173
179
174
180
mbedtls_ssl_set_bio (&_ssl, this , ssl_send, ssl_recv, NULL );
175
181
182
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
176
183
/* Start the handshake, the rest will be done in onReceive() */
177
184
tr_info (" Starting TLS handshake with %s" , _ssl.hostname );
185
+ #else
186
+ tr_info (" Starting TLS handshake" );
187
+ #endif
178
188
179
189
do {
180
190
ret = mbedtls_ssl_handshake (&_ssl);
@@ -185,9 +195,14 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
185
195
return ret;
186
196
}
187
197
198
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
188
199
/* It also means the handshake is done, time to print info */
189
- tr_info (" TLS connection to %s established\r\n " , _ssl.hostname );
200
+ tr_info (" TLS connection to %s established" , _ssl.hostname );
201
+ #else
202
+ tr_info (" TLS connection established" );
203
+ #endif
190
204
205
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
191
206
/* Prints the server certificate and verify it. */
192
207
const size_t buf_size = 1024 ;
193
208
char * buf = new char [buf_size];
@@ -205,6 +220,7 @@ nsapi_error_t TLSSocketWrapper::do_handshake() {
205
220
tr_info (" Certificate verification passed" );
206
221
}
207
222
delete[] buf;
223
+ #endif
208
224
209
225
_handshake_completed = true ;
210
226
@@ -368,6 +384,7 @@ int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len)
368
384
return size;
369
385
}
370
386
387
+ #ifdef MBEDTLS_X509_CRT_PARSE_C
371
388
372
389
mbedtls_x509_crt *TLSSocketWrapper::get_own_cert ()
373
390
{
@@ -408,6 +425,8 @@ void TLSSocketWrapper::set_ca_chain(mbedtls_x509_crt *crt)
408
425
mbedtls_ssl_conf_ca_chain (get_ssl_config (), _cacert, NULL );
409
426
}
410
427
428
+ #endif /* MBEDTLS_X509_CRT_PARSE_C */
429
+
411
430
mbedtls_ssl_config *TLSSocketWrapper::get_ssl_config ()
412
431
{
413
432
if (!_ssl_conf) {
0 commit comments