Azure IoT common library
Fork of azure_c_shared_utility by
Diff: tlsio_wolfssl.c
- Revision:
- 21:b92006c5b9ff
- Parent:
- 19:2e0811512ceb
- Child:
- 22:10640b226104
--- a/tlsio_wolfssl.c Fri Feb 10 17:01:36 2017 -0800 +++ b/tlsio_wolfssl.c Fri Feb 24 14:01:41 2017 -0800 @@ -11,6 +11,7 @@ #include "azure_c_shared_utility/tlsio_wolfssl.h" #include "azure_c_shared_utility/socketio.h" #include "azure_c_shared_utility/crt_abstractions.h" +#include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/shared_util_options.h" @@ -426,7 +427,7 @@ if (res != SSL_SUCCESS) { LogError("wolfSSL_CTX_load_verify_buffer failed"); - result = __LINE__; + result = __FAILURE__; } else { @@ -447,18 +448,18 @@ if (wolfSSL_use_certificate_buffer(ssl, (unsigned char*)x509certificate, strlen(x509certificate) + 1, SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogError("unable to load x509 client certificate"); - result = __LINE__; + result = __FAILURE__; } else if (wolfSSL_use_PrivateKey_buffer(ssl, (unsigned char*)x509privatekey, strlen(x509privatekey) + 1, SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogError("unable to load x509 client private key"); - result = __LINE__; + result = __FAILURE__; } #ifdef HAVE_SECURE_RENEGOTIATION else if (wolfSSL_UseSecureRenegotiation(ssl) != SSL_SUCCESS) { LogError("unable to enable secure renegotiation"); - result = __LINE__; + result = __FAILURE__; } #endif else @@ -480,7 +481,7 @@ if (add_certificate_to_store(tls_io_instance) != 0) { LogError("Failed to add certificates to store"); - result = __LINE__; + result = __FAILURE__; } else { @@ -488,7 +489,7 @@ if (tls_io_instance->ssl == NULL) { LogError("Failed to add certificates to store"); - result = __LINE__; + result = __FAILURE__; } /*x509 authentication can only be build before underlying connection is realized*/ else if ((tls_io_instance->x509certificate != NULL) && @@ -497,7 +498,7 @@ { destroy_wolfssl_instance(tls_io_instance); LogError("unable to use x509 authentication"); - result = __LINE__; + result = __FAILURE__; } else { @@ -666,7 +667,7 @@ if (tls_io == NULL) { LogError("NULL tls_io instance"); - result = __LINE__; + result = __FAILURE__; } else { @@ -675,7 +676,7 @@ if (tls_io_instance->tlsio_state != TLSIO_STATE_NOT_OPEN) { LogError("Invalid state encountered."); - result = __LINE__; + result = __FAILURE__; } else { @@ -694,13 +695,13 @@ { LogError("Cannot create wolfssl instance."); tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN; - result = __LINE__; + result = __FAILURE__; } else if (xio_open(tls_io_instance->socket_io, on_underlying_io_open_complete, tls_io_instance, on_underlying_io_bytes_received, tls_io_instance, on_underlying_io_error, tls_io_instance) != 0) { LogError("Cannot open the underlying IO."); tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN; - result = __LINE__; + result = __FAILURE__; } else { @@ -708,7 +709,7 @@ if (tls_io_instance->tlsio_state != TLSIO_STATE_OPEN) { LogError("Failed to connect to server. The certificates may not be correct."); - result = __LINE__; + result = __FAILURE__; } else { @@ -728,7 +729,7 @@ if (tls_io == NULL) { LogError("NULL tls_io handle."); - result = __LINE__; + result = __FAILURE__; } else { @@ -738,7 +739,7 @@ (tls_io_instance->tlsio_state == TLSIO_STATE_CLOSING)) { LogError("Close called while not open."); - result = __LINE__; + result = __FAILURE__; } else { @@ -749,7 +750,7 @@ if (xio_close(tls_io_instance->socket_io, on_underlying_io_close_complete, tls_io_instance) != 0) { LogError("xio_close failed."); - result = __LINE__; + result = __FAILURE__; } else { @@ -769,7 +770,7 @@ if (tls_io == NULL) { LogError("NULL tls_io handle"); - result = __LINE__; + result = __FAILURE__; } else { @@ -778,7 +779,7 @@ if (tls_io_instance->tlsio_state != TLSIO_STATE_OPEN) { LogError("send called while not open"); - result = __LINE__; + result = __FAILURE__; } else { @@ -789,7 +790,7 @@ if ((res < 0) || ((size_t)res != size)) // Best way I can think of to safely compare an int to a size_t { LogError("Error writing data through WolfSSL"); - result = __LINE__; + result = __FAILURE__; } else { @@ -836,7 +837,7 @@ if (mallocAndStrcpy_s(destination, value) != 0) { LogError("unable to process option %s",name); - result = __LINE__; + result = __FAILURE__; } else { @@ -852,7 +853,7 @@ if (tls_io == NULL || optionName == NULL) { LogError("Bad arguments, tls_io = %p, optionName = %p", tls_io, optionName); - result = __LINE__; + result = __FAILURE__; } else { @@ -875,7 +876,7 @@ if (tls_io_instance->socket_io == NULL) { LogError("NULL underlying IO handle"); - result = __LINE__; + result = __FAILURE__; } else {