Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

Location:
azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/httpapi_compact.c

    r457 r464  
    5151    char*           x509ClientCertificate;
    5252    char*           x509ClientPrivateKey;
    53     const char*     proxy_host;
    54     int             proxy_port;
    55     const char*     proxy_username;
    56     const char*     proxy_password;
    5753    XIO_HANDLE      xio_handle;
    5854    size_t          received_bytes_count;
     
    205201{
    206202    HTTP_HANDLE_DATA* http_instance;
     203    TLSIO_CONFIG tlsio_config;
    207204
    208205    if (hostName == NULL)
     
    226223            LogError("There is no memory to control the http connection");
    227224        }
    228         else if(mallocAndStrcpy_s((char**)&(http_instance->hostName), hostName) != 0)
    229         {
    230             LogError("failure allocate host name");
     225        else if (mallocAndStrcpy_s(&http_instance->hostName, hostName) != 0)
     226        {
     227            LogError("Failed copying hostname");
    231228            free(http_instance);
    232229            http_instance = NULL;
     
    234231        else
    235232        {
    236             http_instance->xio_handle = NULL;
    237             http_instance->is_connected = 0;
    238             http_instance->is_io_error = 0;
    239             http_instance->received_bytes_count = 0;
    240             http_instance->received_bytes = NULL;
    241             http_instance->certificate = NULL;
    242             http_instance->x509ClientCertificate = NULL;
    243             http_instance->x509ClientPrivateKey = NULL;
    244             http_instance->proxy_host = NULL;
    245             http_instance->proxy_port = 0;
    246             http_instance->proxy_username = NULL;
    247             http_instance->proxy_password = NULL;
     233            tlsio_config.hostname = http_instance->hostName;
     234            tlsio_config.port = 443;
     235            tlsio_config.underlying_io_interface = NULL;
     236            tlsio_config.underlying_io_parameters = NULL;
     237
     238            http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
     239
     240            /*Codes_SRS_HTTPAPI_COMPACT_21_016: [ If the HTTPAPI_CreateConnection failed to create the connection, it shall return NULL as the handle. ]*/
     241            if (http_instance->xio_handle == NULL)
     242            {
     243                LogError("Create connection failed");
     244                free(http_instance->hostName);
     245                free(http_instance);
     246                http_instance = NULL;
     247            }
     248            else
     249            {
     250                http_instance->is_connected = 0;
     251                http_instance->is_io_error = 0;
     252                http_instance->received_bytes_count = 0;
     253                http_instance->received_bytes = NULL;
     254                http_instance->certificate = NULL;
     255                http_instance->x509ClientCertificate = NULL;
     256                http_instance->x509ClientPrivateKey = NULL;
     257            }
    248258        }
    249259    }
     
    311321        }
    312322
    313         if (http_instance->hostName != NULL)
    314         {
    315             free((void*)http_instance->hostName);
    316         }
    317 
    318323#ifndef DO_NOT_COPY_TRUSTED_CERTS_STRING
    319324        /*Codes_SRS_HTTPAPI_COMPACT_21_018: [ If there is a certificate associated to this connection, the HTTPAPI_CloseConnection shall free all allocated memory for the certificate. ]*/
     
    336341        }
    337342
    338         if (http_instance->proxy_host != NULL)
    339         {
    340             free((void*)http_instance->proxy_host);
    341         }
    342         if (http_instance->proxy_username != NULL)
    343         {
    344             free((void*)http_instance->proxy_username);
    345         }
    346         if (http_instance->proxy_password != NULL)
    347         {
    348             free((void*)http_instance->proxy_password);
     343        if (http_instance->hostName)
     344        {
     345            free(http_instance->hostName);
    349346        }
    350347
     
    714711{
    715712    HTTPAPI_RESULT result;
    716     TLSIO_CONFIG tlsio_config;
    717     HTTP_PROXY_IO_CONFIG http_proxy_io_config;
    718713
    719714    if (http_instance->is_connected != 0)
     
    725720    {
    726721        http_instance->is_io_error = 0;
    727         tlsio_config.hostname = http_instance->hostName;
    728         tlsio_config.port = 443;
    729 
    730         if (http_instance->proxy_host != NULL) {
    731             tlsio_config.underlying_io_interface = http_proxy_io_get_interface_description();
    732         }
    733         else {
    734             tlsio_config.underlying_io_interface = NULL;
    735         }
    736 
    737         if (tlsio_config.underlying_io_interface != NULL) {
    738             tlsio_config.underlying_io_parameters = (void*)&http_proxy_io_config;
    739 
    740             http_proxy_io_config.proxy_hostname = http_instance->proxy_host;
    741             http_proxy_io_config.proxy_port = http_instance->proxy_port;
    742             http_proxy_io_config.username = http_instance->proxy_username;
    743             http_proxy_io_config.password = http_instance->proxy_password;
    744             http_proxy_io_config.hostname = http_instance->hostName;
    745             http_proxy_io_config.port = 443;
    746         }
    747         else {
    748             tlsio_config.underlying_io_parameters = NULL;
    749         }
    750 
    751         http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
    752 
    753         if (http_instance->xio_handle == NULL)
    754         {
    755             LogError("Create connection failed");
    756             free(http_instance);
    757             http_instance = NULL;
    758             result = HTTPAPI_ERROR;
    759         }
     722
    760723        /*Codes_SRS_HTTPAPI_COMPACT_21_022: [ If a Certificate was provided, the HTTPAPI_ExecuteRequest shall set this option on the transport layer. ]*/
    761         else if ((http_instance->certificate != NULL) &&
     724        if ((http_instance->certificate != NULL) &&
    762725            (xio_setoption(http_instance->xio_handle, OPTION_TRUSTED_CERT, http_instance->certificate) != 0))
    763726        {
     
    777740            (xio_setoption(http_instance->xio_handle, SU_OPTION_X509_PRIVATE_KEY, http_instance->x509ClientPrivateKey) != 0))
    778741        {
     742
    779743            /*Codes_SRS_HTTPAPI_COMPACT_06_006: [ If the transport failed setting the client certificate private key, the HTTPAPI_ExecuteRequest shall not send any request and return HTTPAPI_SET_OPTION_FAILED. ] */
    780744            result = HTTPAPI_SET_OPTION_FAILED;
     
    800764                {
    801765                    xio_dowork(http_instance->xio_handle);
    802                     //LogInfo("Waiting for TLS connection");
     766                    LogInfo("Waiting for TLS connection");
    803767                    if ((countRetry--) < 0)
    804768                    {
     
    13471311#endif // DO_NOT_COPY_TRUSTED_CERTS_STRING
    13481312    }
    1349     else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0)
     1313    else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0)
    13501314    {
    13511315        int len;
     
    13701334        }
    13711335    }
    1372     else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0)
     1336    else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0)
    13731337    {
    13741338        int len;
     
    13951359    else if (strcmp(OPTION_HTTP_PROXY, optionName) == 0)
    13961360    {
    1397         HTTP_PROXY_OPTIONS* proxy_data = (HTTP_PROXY_OPTIONS*)value;
    1398         if (proxy_data->host_address == NULL || proxy_data->port <= 0)
    1399         {
    1400             LogError("invalid proxy_data values ( host_address = %p, port = %d)", proxy_data->host_address, proxy_data->port);
     1361        TLSIO_CONFIG tlsio_config;
     1362        HTTP_PROXY_IO_CONFIG proxy_config;
     1363        HTTP_PROXY_OPTIONS* proxy_options = (HTTP_PROXY_OPTIONS*)value;
     1364
     1365        if (proxy_options->host_address == NULL)
     1366        {
     1367            LogError("NULL host_address in proxy options");
    14011368            result = HTTPAPI_ERROR;
    14021369        }
     1370        else if (((proxy_options->username == NULL) || (proxy_options->password == NULL)) &&
     1371                (proxy_options->username != proxy_options->password))
     1372        {
     1373            LogError("Only one of username and password for proxy settings was NULL");
     1374            result = HTTPAPI_ERROR;
     1375        }
    14031376        else
    14041377        {
    1405             if(http_instance->proxy_host != NULL)
    1406             {
    1407                 free((void*)http_instance->proxy_host);
    1408                 http_instance->proxy_host = NULL;
    1409             }
    1410             if(mallocAndStrcpy_s((char**)&(http_instance->proxy_host), (const char*)proxy_data->host_address) != 0)
    1411             {
    1412                 LogError("failure allocate proxy host");
     1378
     1379            /* Workaround: xio interface is already created when HTTPAPI_CreateConnection is call without proxy support
     1380             * need to destroy the interface and create a new one with proxy information
     1381             */
     1382            OPTIONHANDLER_HANDLE xio_options;
     1383            if ((xio_options = xio_retrieveoptions(http_instance->xio_handle)) == NULL)
     1384            {
     1385                LogError("failed saving underlying I/O transport options");
    14131386                result = HTTPAPI_ERROR;
    14141387            }
    14151388            else
    14161389            {
    1417                 http_instance->proxy_port = proxy_data->port;
    1418 
    1419                 if (proxy_data->username != NULL && proxy_data->password != NULL)
    1420                 {
    1421                     if(http_instance->proxy_username != NULL)
     1390                xio_destroy(http_instance->xio_handle);
     1391
     1392                proxy_config.hostname = http_instance->hostName;
     1393                proxy_config.proxy_hostname = proxy_options->host_address;
     1394                proxy_config.password = proxy_options->password;
     1395                proxy_config.username = proxy_options->username;
     1396                proxy_config.proxy_port = proxy_options->port;
     1397                proxy_config.port = 443;
     1398
     1399                tlsio_config.hostname = http_instance->hostName;
     1400                tlsio_config.port = 443;
     1401                tlsio_config.underlying_io_interface =  http_proxy_io_get_interface_description();
     1402                tlsio_config.underlying_io_parameters = &proxy_config;
     1403
     1404                http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
     1405
     1406                if (http_instance->xio_handle == NULL)
     1407                {
     1408                    LogError("Failed to create xio handle with proxy configuration");
     1409                    result = HTTPAPI_ERROR;
     1410                }
     1411                else
     1412                {
     1413                    if (OptionHandler_FeedOptions(xio_options, http_instance->xio_handle) != OPTIONHANDLER_OK)
    14221414                    {
    1423                         free((void*)http_instance->proxy_username);
    1424                         http_instance->proxy_username = NULL;
    1425                     }
    1426                     if(mallocAndStrcpy_s((char**)&(http_instance->proxy_username), (const char*)proxy_data->username) != 0)
    1427                     {
    1428                         LogError("failure allocate proxy username");
    1429                         free((void*)http_instance->proxy_host);
    1430                         http_instance->proxy_host = NULL;
     1415                        LogError("Failed feeding existing options to new xio instance.");
    14311416                        result = HTTPAPI_ERROR;
    14321417                    }
    14331418                    else
    14341419                    {
    1435                         if(http_instance->proxy_password != NULL)
    1436                         {
    1437                           free((void*)http_instance->proxy_password);
    1438                           http_instance->proxy_password = NULL;
    1439                         }
    1440                         if(mallocAndStrcpy_s((char**)&(http_instance->proxy_password), (const char*)proxy_data->password) != 0)
    1441                         {
    1442                             LogError("failure allocate proxy password");
    1443                             free((void*)http_instance->proxy_host);
    1444                             http_instance->proxy_host = NULL;
    1445                             free((void*)http_instance->proxy_username);
    1446                             http_instance->proxy_username = NULL;
    1447                             result = HTTPAPI_ERROR;
    1448                         }
    1449                         else
    1450                         {
    1451                           result = HTTPAPI_OK;
    1452                         }
     1420                        result = HTTPAPI_OK;
    14531421                    }
    14541422                }
    1455                 else
    1456                 {
    1457                     result = HTTPAPI_OK;
    1458                 }
     1423
     1424                OptionHandler_Destroy(xio_options);
    14591425            }
    14601426        }
     
    14661432        LogInfo("unknown option %s", optionName);
    14671433    }
     1434
    14681435    return result;
    14691436}
     
    15101477#endif // DO_NOT_COPY_TRUSTED_CERTS_STRING
    15111478    }
    1512     else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0)
     1479    else if (strcmp(SU_OPTION_X509_CERT, optionName) == 0 || strcmp(OPTION_X509_ECC_CERT, optionName) == 0)
    15131480    {
    15141481        certLen = strlen((const char*)value);
     
    15271494        }
    15281495    }
    1529     else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0)
     1496    else if (strcmp(SU_OPTION_X509_PRIVATE_KEY, optionName) == 0 || strcmp(OPTION_X509_ECC_KEY, optionName) == 0)
    15301497    {
    15311498        certLen = strlen((const char*)value);
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/platform_toppers.c

    r457 r464  
    5252const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void)
    5353{
    54         //return tlsio_esp_at_get_interface_description();
    55         return tlsio_wolfssl_get_interface_description();
     54        return tlsio_esp_at_get_interface_description();
     55        //return tlsio_wolfssl_get_interface_description();
    5656}
    5757
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/adapters/tlsio_wolfssl.c

    r457 r464  
    1919#include "azure_c_shared_utility/xlogging.h"
    2020#include "azure_c_shared_utility/shared_util_options.h"
    21 #include "azure_c_shared_utility/threadapi.h"
    2221
    2322typedef enum TLSIO_STATE_ENUM_TAG
     
    5352    char* x509privatekey;
    5453    int wolfssl_device_id;
    55     size_t socket_reads;
     54    char* hostname;
     55    bool ignore_host_name_check;
    5656} TLS_IO_INSTANCE;
    5757
    5858STATIC_VAR_UNUSED const char* const OPTION_WOLFSSL_SET_DEVICE_ID = "SetDeviceId";
    59 static const size_t SOCKET_READ_LIMIT = 10000; // 10,000 ms ?
     59static const size_t SOCKET_READ_LIMIT = 5;
    6060
    6161/*this function will clone an option given by name and value*/
     
    106106            }
    107107        }
     108        #ifdef INVALID_DEVID
     109        else if(strcmp(name, OPTION_WOLFSSL_SET_DEVICE_ID) == 0 )
     110        {
     111             int* value_clone;
     112
     113             if ((value_clone = malloc(sizeof(int))) == NULL)
     114             {
     115                 LogError("unable to clone device id option");
     116             }
     117             else
     118             {
     119                 *value_clone = *(int*)value;
     120             }
     121
     122             result = value_clone;
     123        }
     124        #endif
    108125        else
    109126        {
     
    127144        if ((strcmp(name, OPTION_TRUSTED_CERT) == 0) ||
    128145            (strcmp(name, SU_OPTION_X509_CERT) == 0) ||
    129             (strcmp(name, SU_OPTION_X509_PRIVATE_KEY) == 0))
     146            (strcmp(name, SU_OPTION_X509_PRIVATE_KEY) == 0) ||
     147            (strcmp(name, OPTION_WOLFSSL_SET_DEVICE_ID) == 0))
    130148        {
    131149            free((void*)value);
     
    185203                result = NULL;
    186204            }
     205            #ifdef INVALID_DEVID
     206            else if (
     207                (tls_io_instance->wolfssl_device_id != INVALID_DEVID) &&
     208                (OptionHandler_AddOption(result, OPTION_WOLFSSL_SET_DEVICE_ID, &tls_io_instance->wolfssl_device_id) != OPTIONHANDLER_OK)
     209                )
     210            {
     211                LogError("unable to save deviceid option");
     212                OptionHandler_Destroy(result);
     213                result = NULL;
     214            }
     215            #endif
    187216            else
    188217            {
     
    258287        int res;
    259288        tls_io_instance->tlsio_state = TLSIO_STATE_IN_HANDSHAKE;
    260         tls_io_instance->socket_reads = 0;
    261289
    262290        res = wolfSSL_connect(tls_io_instance->ssl);
    263291        if (res != SSL_SUCCESS)
    264292        {
    265             LogError("WolfSSL connect failed");
     293            // Error codes explained in https://www.wolfssl.com/docs/wolfssl-manual/appendix-c/
     294            LogError("WolfSSL connect failed (%d)", wolfSSL_get_error(tls_io_instance->ssl, res));
    266295            indicate_open_complete(tls_io_instance, IO_OPEN_ERROR);
    267296            tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
     
    355384        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
    356385        unsigned char* new_socket_io_read_bytes;
     386        size_t socket_reads = 0;
    357387
    358388        AZURE_UNREFERENCED_PARAMETER(ssl);
    359         if (tls_io_instance->socket_io_read_byte_count == 0)
    360         {
    361             if (tls_io_instance->socket_reads >= SOCKET_READ_LIMIT) {
    362                 return WOLFSSL_CBIO_ERR_TIMEOUT;
    363             }
     389        while (tls_io_instance->socket_io_read_byte_count == 0 && socket_reads < SOCKET_READ_LIMIT)
     390        {
    364391            xio_dowork(tls_io_instance->socket_io);
    365             if (tls_io_instance->tlsio_state == TLSIO_STATE_IN_HANDSHAKE)
    366             {
    367                 tls_io_instance->socket_reads++;
    368                 ThreadAPI_Sleep(1);
    369                 return 0;
    370             }
     392            if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
     393            {
     394                break;
     395            }
     396            socket_reads++;
    371397        }
    372398
     
    417443}
    418444
    419 static void on_send_complete(void* context, IO_SEND_RESULT send_result)
    420 {
    421         TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
    422         if ((tls_io_instance == NULL) || (tls_io_instance->on_send_complete == NULL))
    423                 return;
    424 
    425         tls_io_instance->on_send_complete(tls_io_instance->on_send_complete_callback_context, send_result);
    426 
    427         tls_io_instance->on_send_complete = NULL;
    428         tls_io_instance->on_send_complete_callback_context = NULL;
    429 }
    430 
    431445static int on_io_send(WOLFSSL *ssl, char *buf, int sz, void *context)
    432446{
    433     int result, ret;
     447    int result;
    434448    AZURE_UNREFERENCED_PARAMETER(ssl);
    435449
    436450    TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
    437451
    438     if ((ret = xio_send(tls_io_instance->socket_io, buf, sz, on_send_complete, tls_io_instance)) != 0)
    439     {
    440         LogError("Failed sending bytes through underlying IO %d", ret);
     452    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)
     453    {
     454        LogError("Failed sending bytes through underlying IO");
    441455        tls_io_instance->tlsio_state = TLSIO_STATE_ERROR;
    442456        indicate_error(tls_io_instance);
    443         result = 0;
     457        result = WOLFSSL_CBIO_ERR_GENERAL;
    444458    }
    445459    else
     
    455469    AZURE_UNREFERENCED_PARAMETER(ssl);
    456470    TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context;
    457     if (tls_io_instance->tlsio_state == TLSIO_STATE_OPEN) {
    458         LogInfo("on_handshake_done called in TLSIO_STATE_OPEN state");
    459     }
    460     else if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
     471    if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE)
    461472    {
    462473        LogInfo("on_handshake_done called when not in IN_HANDSHAKE state");
     
    558569}
    559570
     571static int enable_domain_check(TLS_IO_INSTANCE* tls_io_instance)
     572{
     573    int result = 0;
     574
     575    if (!tls_io_instance->ignore_host_name_check)
     576    {
     577        if (wolfSSL_check_domain_name(tls_io_instance->ssl, tls_io_instance->hostname) != WOLFSSL_SUCCESS)
     578        {
     579            result = MU_FAILURE;
     580        }
     581    }
     582
     583    return result;
     584}
     585
    560586static int prepare_wolfssl_open(TLS_IO_INSTANCE* tls_io_instance)
    561587{
    562588    int result;
    563     if (add_certificate_to_store(tls_io_instance) != 0)
     589
     590    if (enable_domain_check(tls_io_instance))
     591    {
     592        LogError("Failed to configure domain name verification");
     593        result = MU_FAILURE;
     594    }
     595    else if (add_certificate_to_store(tls_io_instance) != 0)
    564596    {
    565597        LogError("Failed to add certificates to store");
     
    575607        result = MU_FAILURE;
    576608    }
    577 #ifdef INVALID_DEVID
    578     else if (tls_io_instance->wolfssl_device_id != INVALID_DEVID && wolfSSL_SetDevId(tls_io_instance->ssl, tls_io_instance->wolfssl_device_id) != WOLFSSL_SUCCESS)
    579     {
    580         LogError("Failure setting device id");
    581         result = MU_FAILURE;
    582     }
    583 #endif
    584609    else
    585610    {
     
    628653            {
    629654                LogError("Cannot create the wolfSSL context");
     655                free(result);
     656                result = NULL;
     657            }
     658            else if (mallocAndStrcpy_s(&result->hostname, tls_io_config->hostname) != 0)
     659            {
     660                LogError("Failed copying the target hostname.");
    630661                free(result);
    631662                result = NULL;
     
    660691                    LogError("Failed getting socket IO interface description.");
    661692                    wolfSSL_CTX_free(result->ssl_context);
     693                    free(result->hostname);
    662694                    free(result);
    663695                    result = NULL;
     
    670702                        LogError("Failure connecting to underlying socket_io");
    671703                        wolfSSL_CTX_free(result->ssl_context);
     704                        free(result->hostname);
    672705                        free(result);
    673706                        result = NULL;
     
    677710                        LogError("Failure connecting to underlying socket_io");
    678711                        wolfSSL_CTX_free(result->ssl_context);
     712                        free(result->hostname);
    679713                        free(result);
    680714                        result = NULL;
     
    719753
    720754        xio_destroy(tls_io_instance->socket_io);
     755        free(tls_io_instance->hostname);
    721756        free(tls_io);
    722757    }
     
    843878            result = MU_FAILURE;
    844879        }
    845         if (tls_io_instance->on_send_complete != NULL)
    846         {
    847             LogError("Error writing data");
    848             result = MU_FAILURE;
    849         }
    850880        else
    851881        {
     
    882912            (tls_io_instance->tlsio_state != TLSIO_STATE_ERROR))
    883913        {
    884             if (tls_io_instance->tlsio_state != TLSIO_STATE_OPENING_UNDERLYING_IO)
    885                 decode_ssl_received_bytes(tls_io_instance);
     914            decode_ssl_received_bytes(tls_io_instance);
    886915            xio_dowork(tls_io_instance->socket_io);
    887916        }
     
    892921static int process_option(char** destination, const char* name, const char* value)
    893922{
     923
     924    (void) name;
     925   
    894926    int result;
    895927    if (*destination != NULL)
     
    944976        {
    945977            int device_id = *((int *)value);
    946             if (tls_io_instance->ssl != NULL)
    947             {
    948                 if (tls_io_instance->ssl != NULL && wolfSSL_SetDevId(tls_io_instance->ssl, device_id) != WOLFSSL_SUCCESS)
    949                 {
    950                     LogError("Failure setting device id on ssl");
    951                     result = MU_FAILURE;
    952                 }
    953                 else
    954                 {
    955                     result = 0;
    956                 }
     978            if (tls_io_instance->ssl != NULL && wolfSSL_SetDevId(tls_io_instance->ssl, device_id) != WOLFSSL_SUCCESS)
     979            {
     980                LogError("Failure setting device id on ssl");
     981                result = MU_FAILURE;
    957982            }
    958983            else
    959984            {
    960                 // Save the id till we create the ssl object
     985                // Save the device Id even if ssl object not yet created.
    961986                tls_io_instance->wolfssl_device_id = device_id;
    962987                result = 0;
     
    964989        }
    965990#endif
     991        else if (strcmp("ignore_host_name_check", optionName) == 0)
     992        {
     993            bool* server_name_check = (bool*)value;
     994            tls_io_instance->ignore_host_name_check = *server_name_check;
     995            result = 0;
     996        }
    966997        else
    967998        {
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/inc/azure_c_shared_utility/crt_abstractions.h

    r457 r464  
    66
    77#ifdef __cplusplus
     8#include <cstdint>
    89#include <cstdio>
    910#include <cstring>
     
    1112#include <cmath>
    1213#else // __cplusplus
     14#include <stdint.h>
    1315#include <stdio.h>
    1416#include <string.h>
     
    9698MOCKABLE_FUNCTION(, int, unsignedIntToString, char*, destination, size_t, destinationSize, unsigned int, value);
    9799MOCKABLE_FUNCTION(, int, size_tToString, char*, destination, size_t, destinationSize, size_t, value);
     100MOCKABLE_FUNCTION(, int, uint64_tToString, char*, destination, size_t, destinationSize, uint64_t, value);
    98101
    99102/*following logic shall define the TOUPPER and ISDIGIT, we do that because the SDK is not happy with some Arduino implementation of it.*/
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/inc/azure_c_shared_utility/sastoken.h

    r457 r464  
    44#ifndef SASTOKEN_H
    55#define SASTOKEN_H
     6
     7#include <stdint.h>
    68
    79#ifdef __cplusplus
     
    1820
    1921    MOCKABLE_FUNCTION(, bool, SASToken_Validate, STRING_HANDLE, sasToken);
    20     MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_Create, STRING_HANDLE, key, STRING_HANDLE, scope, STRING_HANDLE, keyName, size_t, expiry);
    21     MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_CreateString, const char*, key, const char*, scope, const char*, keyName, size_t, expiry);
     22    MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_Create, STRING_HANDLE, key, STRING_HANDLE, scope, STRING_HANDLE, keyName, uint64_t, expiry);
     23    MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_CreateString, const char*, key, const char*, scope, const char*, keyName, uint64_t, expiry);
    2224
    2325#ifdef __cplusplus
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/inc/azure_c_shared_utility/shared_util_options.h

    r457 r464  
    2929    static STATIC_VAR_UNUSED const char* const OPTION_OPENSSL_CIPHER_SUITE = "CipherSuite";
    3030
     31    static STATIC_VAR_UNUSED const char* const OPTION_OPENSSL_ENGINE = "Engine";
     32    static STATIC_VAR_UNUSED const char* const OPTION_OPENSSL_PRIVATE_KEY_TYPE = "x509PrivatekeyType";
     33
     34    typedef enum OPTION_OPENSSL_KEY_TYPE_TAG
     35    {
     36        KEY_TYPE_DEFAULT,
     37        KEY_TYPE_ENGINE
     38    } OPTION_OPENSSL_KEY_TYPE;
     39
    3140    static STATIC_VAR_UNUSED const char* const SU_OPTION_X509_CERT = "x509certificate";
    3241    static STATIC_VAR_UNUSED const char* const SU_OPTION_X509_PRIVATE_KEY = "x509privatekey";
     
    4554    static STATIC_VAR_UNUSED const char* const OPTION_SET_TLS_RENEGOTIATION = "tls_renegotiation";
    4655
    47     // DEPRECATED: The underlying security library for your platform will use a secure TLS version 
     56    // DEPRECATED: The underlying security library for your platform will use a secure TLS version
    4857    // that in general  should not be overridden with OPTION_TLS_VERSION.
    4958    static STATIC_VAR_UNUSED const char* const OPTION_TLS_VERSION = "tls_version";
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/inc/azure_c_shared_utility/tickcounter.h

    r457 r464  
    1818#endif /* __cplusplus */
    1919
    20 #if defined(_WIN32) || defined(__MBED__) || defined(__APPLE__)
    2120    typedef uint_fast64_t tickcounter_ms_t; // Use 64-bit because of 32-bit is going to roll over back to zero after roughly 49.7 days that is not good for IoT devices which need keep running for months
    22 #else
    23     typedef uint_fast32_t tickcounter_ms_t;
    24 #endif
    2521    typedef struct TICK_COUNTER_INSTANCE_TAG *TICK_COUNTER_HANDLE;
    2622
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/src/buffer.c

    r457 r464  
    541541        {
    542542            //put b2 ahead of b1: [b2][b1], return b1
    543             if (b2->size ==0)
     543            if (b2->size == 0)
    544544            {
    545545                // do nothing
    546546                result = 0;
     547            }
     548            else if (b1->size + b2->size < b2->size)
     549            {
     550                LogError("Failure: size_t overflow.");
     551                result = MU_FAILURE;
    547552            }
    548553            else
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/src/crt_abstractions.c

    r457 r464  
    66#include <stdlib.h>
    77#include <stdarg.h>
     8#include <stdint.h>
    89#include <string.h>
    910#include <limits.h>
     
    598599        case FST_NUMBER:
    599600            val = fraction * pow(10.0, (double)exponential) * (double)signal;
    600             if ((val >= (FLT_MAX * (-1.0f))) && (val <= FLT_MAX))
     601            if ((val >= ((double)FLT_MAX * (-1.0))) && (val <= (double)FLT_MAX))
    601602            {
    602603                /*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.]*/
     
    836837    return result;
    837838}
     839
     840/*takes "value" and transforms it into a decimal string*/
     841/*10 => "10"*/
     842/*return 0 when everything went ok*/
     843int uint64_tToString(char* destination, size_t destinationSize, uint64_t value)
     844{
     845    int result;
     846    size_t pos;
     847    /*the below loop gets the number in reverse order*/
     848    if (
     849        (destination == NULL) ||
     850        (destinationSize < 2) /*because the smallest number is '0\0' which requires 2 characters*/
     851        )
     852    {
     853        result = MU_FAILURE;
     854    }
     855    else
     856    {
     857        pos = 0;
     858        do
     859        {
     860            destination[pos++] = '0' + (value % 10);
     861            value /= 10;
     862        } while ((value > 0) && (pos < (destinationSize - 1)));
     863
     864        if (value == 0)
     865        {
     866            size_t w;
     867            destination[pos] = '\0';
     868            /*all converted and they fit*/
     869            for (w = 0; w <= (pos - 1) >> 1; w++)
     870            {
     871                char temp;
     872                temp = destination[w];
     873                destination[w] = destination[pos - 1 - w];
     874                destination[pos - 1 - w] = temp;
     875            }
     876            result = 0;
     877        }
     878        else
     879        {
     880            result = MU_FAILURE;
     881        }
     882    }
     883    return result;
     884}
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/src/httpapiexsas.c

    r457 r464  
    107107{
    108108    /*Codes_SRS_HTTPAPIEXSAS_06_005: [If the parameter handle is NULL then HTTAPIEX_SAS_Destroy shall do nothing and return.]*/
    109     if (handle)
     109    HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle;
     110    if (state)
    110111    {
    111         HTTPAPIEX_SAS_STATE* state = (HTTPAPIEX_SAS_STATE*)handle;
    112112        /*Codes_SRS_HTTPAPIEXSAS_06_006: [HTTAPIEX_SAS_Destroy shall deallocate any structures denoted by the parameter handle.]*/
    113113        if (state->key)
     
    159159                        /*Codes_SRS_HTTPAPIEXSAS_06_011: [SASToken_Create shall be invoked.]*/
    160160                        /*Codes_SRS_HTTPAPIEXSAS_06_012: [If the return result of SASToken_Create is NULL then fallthrough.]*/
    161                         size_t expiry = (size_t)(difftime(currentTime, 0) + 3600);
     161                        uint64_t expiry = (uint64_t)(difftime(currentTime, 0) + 3600);
    162162                        newSASToken = SASToken_CreateString(state->key, state->uriResource, state->keyName, expiry);
    163163                    }
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/src/sastoken.c

    r457 r464  
    2424        if (expiryASCII[i] >= '0' && expiryASCII[i] <= '9')
    2525        {
    26             value = value * 10 + (double)(expiryASCII[i] - '0');
     26            value = value * 10 + ((double)expiryASCII[i] - (double)'0');
    2727        }
    2828        else
     
    203203}
    204204
    205 static STRING_HANDLE construct_sas_token(const char* key, const char* scope, const char* keyname, size_t expiry)
     205static STRING_HANDLE construct_sas_token(const char* key, const char* scope, const char* keyname, uint64_t expiry)
    206206{
    207207    STRING_HANDLE result;
     
    221221    {
    222222        /*Codes_SRS_SASTOKEN_06_026: [If the conversion to string form fails for any reason then SASToken_Create shall return NULL.]*/
    223         if (size_tToString(tokenExpirationTime, sizeof(tokenExpirationTime), expiry) != 0)
     223        if (uint64_tToString(tokenExpirationTime, sizeof(tokenExpirationTime), expiry) != 0)
    224224        {
    225225            LogError("For some reason converting seconds to a string failed.  No SAS can be generated.");
     
    303303}
    304304
    305 STRING_HANDLE SASToken_Create(STRING_HANDLE key, STRING_HANDLE scope, STRING_HANDLE keyName, size_t expiry)
     305STRING_HANDLE SASToken_Create(STRING_HANDLE key, STRING_HANDLE scope, STRING_HANDLE keyName, uint64_t expiry)
    306306{
    307307    STRING_HANDLE result;
     
    326326}
    327327
    328 STRING_HANDLE SASToken_CreateString(const char* key, const char* scope, const char* keyName, size_t expiry)
     328STRING_HANDLE SASToken_CreateString(const char* key, const char* scope, const char* keyName, uint64_t expiry)
    329329{
    330330    STRING_HANDLE result;
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/c-utility/src/sha384-512.c

    r457 r464  
    469469    if (!length)
    470470        return shaSuccess;
     471   
     472    if (length > (sizeof(context->Message_Block) / sizeof(context->Message_Block[0])))
     473        return shaBadParam;
    471474
    472475    if (!context || !message_array)
Note: See TracChangeset for help on using the changeset viewer.