Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Added support for "TrustedCerts". #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pal/inc/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: 6 additions & 3 deletions pal/src/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,7 @@ uint8_t sslClient_hostByName(const char* hostName, uint32_t* ipAddress)
return result;
}

void sslClient_setCACert(const char *rootCA)
{
sslClient.setCACert(rootCA);
}
9 changes: 7 additions & 2 deletions pal/src/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