Azure IoT common library
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
Diff: tlsio_wolfssl.c
- Revision:
- 42:0cc3c211ad26
- Parent:
- 40:3f3af6cd8a01
- Child:
- 46:fde927ea2e72
diff -r dc93369d5ed4 -r 0cc3c211ad26 tlsio_wolfssl.c --- a/tlsio_wolfssl.c Mon Mar 05 17:43:09 2018 -0800 +++ b/tlsio_wolfssl.c Tue Mar 20 10:31:23 2018 -0700 @@ -6,6 +6,7 @@ #include "wolfssl/options.h" #include "wolfssl/ssl.h" #include "wolfssl/error-ssl.h" +#include "wolfssl/wolfcrypt/types.h" #include <stdio.h> #include <stdbool.h> #include <string.h> @@ -49,8 +50,11 @@ char* certificate; char* x509certificate; char* x509privatekey; + int wolfssl_device_id; } TLS_IO_INSTANCE; +STATIC_VAR_UNUSED const char* const OPTION_WOLFSSL_SET_DEVICE_ID = "SetDeviceId"; + /*this function will clone an option given by name and value*/ static void* tlsio_wolfssl_CloneOption(const char* name, const void* value) { @@ -348,7 +352,7 @@ TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context; unsigned char* new_socket_io_read_bytes; - (void)ssl; + AZURE_UNREFERENCED_PARAMETER(ssl); while (tls_io_instance->socket_io_read_byte_count == 0) { xio_dowork(tls_io_instance->socket_io); @@ -403,9 +407,10 @@ static int on_io_send(WOLFSSL *ssl, char *buf, int sz, void *context) { int result; + AZURE_UNREFERENCED_PARAMETER(ssl); + TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context; - (void)ssl; if (xio_send(tls_io_instance->socket_io, buf, sz, tls_io_instance->on_send_complete, tls_io_instance->on_send_complete_callback_context) != 0) { LogError("Failed sending bytes through underlying IO"); @@ -423,8 +428,8 @@ static int on_handshake_done(WOLFSSL* ssl, void* context) { + AZURE_UNREFERENCED_PARAMETER(ssl); TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context; - (void)ssl; if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE) { LogInfo("on_handshake_done called when not in IN_HANDSHAKE state"); @@ -511,6 +516,9 @@ tls_io_instance->socket_io_read_byte_count = 0; tls_io_instance->on_send_complete = NULL; tls_io_instance->on_send_complete_callback_context = NULL; +#ifdef INVALID_DEVID + tls_io_instance->wolfssl_device_id = INVALID_DEVID; +#endif wolfSSL_set_using_nonblock(tls_io_instance->ssl, 1); wolfSSL_SetIOSend(tls_io_instance->ssl_context, on_io_send); @@ -542,6 +550,13 @@ LogError("unable to use x509 authentication"); result = __FAILURE__; } +#ifdef INVALID_DEVID + else if (tls_io_instance->wolfssl_device_id != INVALID_DEVID && wolfSSL_SetDevId(tls_io_instance->ssl, tls_io_instance->wolfssl_device_id) != WOLFSSL_SUCCESS) + { + LogError("Failure setting device id"); + result = __FAILURE__; + } +#endif else { result = 0; @@ -593,6 +608,7 @@ } else { + SOCKETIO_CONFIG socketio_config; const IO_INTERFACE_DESCRIPTION* underlying_io_interface; void* io_interface_parameters; @@ -603,8 +619,6 @@ } else { - SOCKETIO_CONFIG socketio_config; - socketio_config.hostname = tls_io_config->hostname; socketio_config.port = tls_io_config->port; socketio_config.accepted_socket = NULL; @@ -890,6 +904,30 @@ { result = process_option(&tls_io_instance->x509privatekey, optionName, value); } +#ifdef INVALID_DEVID + else if (strcmp(OPTION_WOLFSSL_SET_DEVICE_ID, optionName) == 0) + { + int device_id = *((int *)value); + if (tls_io_instance->ssl != NULL) + { + if (tls_io_instance->ssl != NULL && wolfSSL_SetDevId(tls_io_instance->ssl, device_id) != WOLFSSL_SUCCESS) + { + LogError("Failure setting device id on ssl"); + result = __FAILURE__; + } + else + { + result = 0; + } + } + else + { + // Save the id till we create the ssl object + tls_io_instance->wolfssl_device_id = device_id; + result = 0; + } + } +#endif else { if (tls_io_instance->socket_io == NULL)