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

Commit

Permalink
Update to 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jbobotek committed Dec 14, 2020
1 parent cd716a6 commit 14c7ba8
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 38 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AzureIoTUtility
version=1.3.9
version=1.5.0
author=Microsoft
maintainer=Microsoft <[email protected]>
sentence=Azure C shared utility library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing.
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIoTUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
#include "azure_c_shared_utility/tlsio.h"
#include "azure_c_shared_utility/xlogging.h"

#define AzureIoTUtilityVersion "1.3.9"
#define AzureIoTUtilityVersion "1.5.0"

#endif //AZUREIOTUTILITY_H
5 changes: 2 additions & 3 deletions src/adapters/sslClient_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ uint8_t sslClient_connected(void)
return (uint8_t)sslClient.connected();
}

int sslClient_connect(uint32_t ipAddress, uint16_t port)
int sslClient_connect(const char* name, uint16_t port)
{
#ifdef ARDUINO_ARCH_ESP8266
sslClient.setTrustAnchors(&cert);
#endif
IPAddress ip = IPAddress(ipAddress);
return (int)sslClient.connect(ip, port);
return (int)sslClient.connect(name, port);
}

void sslClient_stop(void)
Expand Down
2 changes: 1 addition & 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*, name, 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 Down
27 changes: 3 additions & 24 deletions src/adapters/tlsio_arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const size_t WEBSOCKET_HEADER_NO_CERT_PARAM_SIZE = sizeof(WEBSOCKET_HEADER_NO_CE
typedef enum TLSIO_STATE_TAG
{
TLSIO_STATE_CLOSED,
TLSIO_STATE_OPENING_WAITING_DNS,
TLSIO_STATE_OPENING_WAITING_SOCKET,
TLSIO_STATE_OPENING_WAITING_SSL,
TLSIO_STATE_OPEN,
Expand All @@ -55,8 +54,7 @@ typedef enum TLSIO_STATE_TAG

bool is_an_opening_state(TLSIO_STATE state)
{
return state == TLSIO_STATE_OPENING_WAITING_DNS ||
state == TLSIO_STATE_OPENING_WAITING_SOCKET ||
return state == TLSIO_STATE_OPENING_WAITING_SOCKET ||
state == TLSIO_STATE_OPENING_WAITING_SSL;
}

Expand All @@ -70,7 +68,6 @@ typedef struct TLS_IO_INSTANCE_TAG
void* on_open_complete_context;
TLSIO_STATE tlsio_state;
STRING_HANDLE hostname;
uint32_t remote_addr;
uint16_t port;
SINGLYLINKEDLIST_HANDLE pending_transmission_list;
TLSIO_OPTIONS options;
Expand Down Expand Up @@ -234,7 +231,6 @@ static CONCRETE_IO_HANDLE tlsio_arduino_create(void* io_create_parameters)
result->hostname = NULL;
result->port = (uint16_t)tls_io_config->port;
result->tlsio_state = TLSIO_STATE_CLOSED;
result->hostname = NULL;
result->pending_transmission_list = NULL;
tlsio_options_initialize(&result->options, TLSIO_OPTION_BIT_TRUSTED_CERTS);

Expand Down Expand Up @@ -328,7 +324,7 @@ static int tlsio_arduino_open_async(CONCRETE_IO_HANDLE tls_io,

/* Codes_SRS_TLSIO_30_035: [ On tlsio_open success the adapter shall enter TLSIO_STATE_EX_OPENING and return 0. ]*/
// All the real work happens in dowork
tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_DNS;
tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_SOCKET;
result = 0;
}
}
Expand Down Expand Up @@ -477,19 +473,6 @@ static void dowork_send(TLS_IO_INSTANCE* tls_io_instance)
}
}

static void dowork_poll_dns(TLS_IO_INSTANCE* tls_io_instance)
{
/* Codes_SRS_TLSIO_ARDUINO_21_018: [ The tlsio_arduino_create shall convert the provide hostName to an IP address. ]*/
if (sslClient_hostByName(STRING_c_str(tls_io_instance->hostname), &(tls_io_instance->remote_addr)))
{
tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_SOCKET;
}
else
{
LogError("Host %s not found", STRING_c_str(tls_io_instance->hostname));
}
}

static void dowork_poll_socket(TLS_IO_INSTANCE* tls_io_instance)
{
// Nothing to do here
Expand All @@ -498,7 +481,7 @@ static void dowork_poll_socket(TLS_IO_INSTANCE* tls_io_instance)

static void dowork_poll_open_ssl(TLS_IO_INSTANCE* tls_io_instance)
{
int connect_success = sslClient_connect(tls_io_instance->remote_addr, tls_io_instance->port);
int connect_success = sslClient_connect(STRING_c_str(tls_io_instance->hostname), tls_io_instance->port);
if (connect_success)
{
/* Codes_SRS_TLSIO_30_080: [ The tlsio_dowork shall establish a TLS connection using the hostName and port provided during tlsio_open. ]*/
Expand Down Expand Up @@ -534,10 +517,6 @@ static void tlsio_arduino_dowork(CONCRETE_IO_HANDLE tls_io)
/* Codes_SRS_TLSIO_30_075: [ If the adapter is in TLSIO_STATE_EXT_CLOSED then tlsio_dowork shall do nothing. ]*/
// Waiting to be opened, nothing to do
break;
case TLSIO_STATE_OPENING_WAITING_DNS:
LogInfo("dowork TLSIO_STATE_OPENING_WAITING_DNS");
dowork_poll_dns(tls_io_instance);
break;
case TLSIO_STATE_OPENING_WAITING_SOCKET:
LogInfo("dowork TLSIO_STATE_OPENING_WAITING_SOCKET");
dowork_poll_socket(tls_io_instance);
Expand Down
1 change: 1 addition & 0 deletions src/adapters/tlsio_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ static void mbedtls_uninit(TLS_IO_INSTANCE *tls_io_instance)
{
// mbedTLS cleanup...
mbedtls_ssl_free(&tls_io_instance->ssl);
mbedtls_ssl_session_free(&tls_io_instance->ssn);
mbedtls_ssl_config_free(&tls_io_instance->config);
mbedtls_x509_crt_free(&tls_io_instance->trusted_certificates_parsed);
mbedtls_x509_crt_free(&tls_io_instance->owncert);
Expand Down
7 changes: 6 additions & 1 deletion src/azure_c_shared_utility/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,16 @@ int BUFFER_prepend(BUFFER_HANDLE handle1, BUFFER_HANDLE handle2)
else
{
//put b2 ahead of b1: [b2][b1], return b1
if (b2->size ==0)
if (b2->size == 0)
{
// do nothing
result = 0;
}
else if (b1->size + b2->size < b2->size)
{
LogError("Failure: size_t overflow.");
result = MU_FAILURE;
}
else
{
// b2->size != 0
Expand Down
7 changes: 4 additions & 3 deletions src/azure_c_shared_utility/constbuffer_array_batcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL
}

/* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_007: [ constbuffer_array_batcher_batch shall allocate enough memory for all the buffer handles in all the arrays + one extra header buffer handle. ]*/
all_buffers = malloc(sizeof(CONSTBUFFER_HANDLE) * (total_buffer_count + 1));
uint32_t all_buffers_array_size = total_buffer_count + 1;
all_buffers = malloc(sizeof(CONSTBUFFER_HANDLE) * ((size_t)all_buffers_array_size));
if (all_buffers == NULL)
{
/* Codes_SRS_CONSTBUFFER_ARRAY_BATCHER_01_010: [ If any error occurrs, constbuffer_array_batcher_batch shall fail and return NULL. ]*/
Expand Down Expand Up @@ -109,8 +110,8 @@ CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDL
}
}

result = constbuffer_array_create(all_buffers, total_buffer_count + 1);
for (i = 0; i < current_index; i++)
result = constbuffer_array_create(all_buffers, all_buffers_array_size);
for (i = 0; i < all_buffers_array_size; i++)
{
CONSTBUFFER_DecRef(all_buffers[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/azure_c_shared_utility/crt_abstractions.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ float strtof_s(const char* nptr, char** endptr)
break;
case FST_NUMBER:
val = fraction * pow(10.0, (double)exponential) * (double)signal;
if ((val >= (FLT_MAX * (-1.0f))) && (val <= FLT_MAX))
if ((val >= ((double)FLT_MAX * (-1.0))) && (val <= (double)FLT_MAX))
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_016: [The strtof_s must return the float that represents the value in the initial part of the string. If any.]*/
result = (float)val;
Expand Down
4 changes: 2 additions & 2 deletions src/azure_c_shared_utility/httpapiexsas.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ HTTPAPIEX_SAS_HANDLE HTTPAPIEX_SAS_Create(STRING_HANDLE key, STRING_HANDLE uriRe
void HTTPAPIEX_SAS_Destroy(HTTPAPIEX_SAS_HANDLE handle)
{
/*Codes_SRS_HTTPAPIEXSAS_06_005: [If the parameter handle is NULL then HTTAPIEX_SAS_Destroy shall do nothing and return.]*/
if (handle)
HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle;
if (state)
{
HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle;
/*Codes_SRS_HTTPAPIEXSAS_06_006: [HTTAPIEX_SAS_Destroy shall deallocate any structures denoted by the parameter handle.]*/
if (state->key)
{
Expand Down
2 changes: 1 addition & 1 deletion src/azure_c_shared_utility/sastoken.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static double getExpiryValue(const char* expiryASCII)
{
if (expiryASCII[i] >= '0' && expiryASCII[i] <= '9')
{
value = value * 10 + (double)(expiryASCII[i] - '0');
value = value * 10 + ((double)expiryASCII[i] - (double)'0');
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/azure_c_shared_utility/sha384-512.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ int SHA512Input(SHA512Context *context,
uint64_t addTemp;
if (!length)
return shaSuccess;

if (length > (sizeof(context->Message_Block) / sizeof(context->Message_Block[0])))
return shaBadParam;

if (!context || !message_array)
return shaNull;
Expand Down

0 comments on commit 14c7ba8

Please sign in to comment.