Skip to content

Commit

Permalink
Added support for "TrustedCerts".
Browse files Browse the repository at this point in the history
  • Loading branch information
larsvliet committed Apr 26, 2019
1 parent 4e7eec9 commit 9816080
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/adapters/sslClient_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ uint8_t sslClient_connected(void)
return (uint8_t)sslClient.connected();
}

int sslClient_connect(uint32_t ipAddress, uint16_t port)
int sslClient_connect(const char *host, uint16_t port)
{
IPAddress ip = IPAddress(ipAddress);
return (int)sslClient.connect(ip, port);
return (int)sslClient.connect(host, port);
}

void sslClient_stop(void)
Expand Down Expand Up @@ -68,3 +67,8 @@ uint8_t sslClient_hostByName(const char* hostName, uint32_t* ipAddress)
return result;
}

void sslClient_setCACert(const char *rootCA)
{
sslClient.setCACert(rootCA);
}

4 changes: 3 additions & 1 deletion src/adapters/sslClient_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" {

MOCKABLE_FUNCTION(, void, sslClient_setTimeout, unsigned long, timeout);
MOCKABLE_FUNCTION(, uint8_t, sslClient_connected);
MOCKABLE_FUNCTION(, int, sslClient_connect, uint32_t, ipAddress, uint16_t, port);
MOCKABLE_FUNCTION(, int, sslClient_connect, const char*, host, uint16_t, port);
MOCKABLE_FUNCTION(, void, sslClient_stop);
MOCKABLE_FUNCTION(, size_t, sslClient_write, const uint8_t*, buf, size_t, size);
MOCKABLE_FUNCTION(, size_t, sslClient_print, const char*, str);
Expand All @@ -26,6 +26,8 @@ MOCKABLE_FUNCTION(, int, sslClient_available);

MOCKABLE_FUNCTION(, uint8_t, sslClient_hostByName, const char*, hostName, uint32_t*, ipAddress);

MOCKABLE_FUNCTION(, void, sslClient_setCACert, const char*, rootCA);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
9 changes: 7 additions & 2 deletions src/adapters/tlsio_arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static CONCRETE_IO_HANDLE tlsio_arduino_create(void* io_create_parameters)
result->tlsio_state = TLSIO_STATE_CLOSED;
result->hostname = NULL;
result->pending_transmission_list = NULL;
tlsio_options_initialize(&result->options, TLSIO_OPTION_BIT_NONE);
tlsio_options_initialize(&result->options, TLSIO_OPTION_BIT_TRUSTED_CERTS);
/* Codes_SRS_TLSIO_30_016: [ tlsio_create shall make a copy of the hostname member of io_create_parameters to allow deletion of hostname immediately after the call. ]*/
if (NULL == (result->hostname = STRING_construct(tls_io_config->hostname)))
{
Expand Down Expand Up @@ -483,7 +483,12 @@ static void dowork_poll_socket(TLS_IO_INSTANCE* tls_io_instance)

static void dowork_poll_open_ssl(TLS_IO_INSTANCE* tls_io_instance)
{
if (sslClient_connect(tls_io_instance->remote_addr, tls_io_instance->port))
if (tls_io_instance->options.trusted_certs != NULL)
{
sslClient_setCACert(tls_io_instance->options.trusted_certs);
}

if (sslClient_connect(STRING_c_str(tls_io_instance->hostname), tls_io_instance->port))
{
/* Codes_SRS_TLSIO_30_080: [ The tlsio_dowork shall establish a TLS connection using the hostName and port provided during tlsio_open. ]*/
// Connect succeeded
Expand Down

0 comments on commit 9816080

Please sign in to comment.