Microsoft Azure IoTHub client libraries

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Thu Oct 04 09:15:49 2018 -0700
Revision:
93:7c0bbb86b167
Parent:
92:97148cf9aa2a
1.2.10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 62:5a4cdacf5090 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 62:5a4cdacf5090 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 62:5a4cdacf5090 3
AzureIoTClient 62:5a4cdacf5090 4 #include <stdlib.h>
AzureIoTClient 62:5a4cdacf5090 5 #include "azure_c_shared_utility/gballoc.h"
AzureIoTClient 62:5a4cdacf5090 6 #include "azure_c_shared_utility/macro_utils.h"
AzureIoTClient 62:5a4cdacf5090 7 #include "azure_c_shared_utility/umock_c_prod.h"
AzureIoTClient 62:5a4cdacf5090 8 #include "azure_c_shared_utility/crt_abstractions.h"
AzureIoTClient 92:97148cf9aa2a 9 #include "azure_c_shared_utility/agenttime.h"
AzureIoTClient 62:5a4cdacf5090 10 #include "azure_c_shared_utility/xlogging.h"
AzureIoTClient 62:5a4cdacf5090 11 #include "azure_c_shared_utility/strings.h"
AzureIoTClient 62:5a4cdacf5090 12 #include "azure_c_shared_utility/sastoken.h"
AzureIoTClient 75:86205ca63a59 13 #include "azure_c_shared_utility/shared_util_options.h"
AzureIoTClient 75:86205ca63a59 14
AzureIoTClient 78:74a8d3068204 15 #ifdef USE_PROV_MODULE
AzureIoTClient 88:248736be106e 16 #include "azure_prov_client/internal/iothub_auth_client.h"
AzureIoTClient 75:86205ca63a59 17 #endif
AzureIoTClient 62:5a4cdacf5090 18
AzureIoTClient 88:248736be106e 19 #include "internal/iothub_client_authorization.h"
AzureIoTClient 62:5a4cdacf5090 20
AzureIoTClient 62:5a4cdacf5090 21 #define DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS 3600
AzureIoTClient 62:5a4cdacf5090 22 #define INDEFINITE_TIME ((time_t)(-1))
AzureIoTClient 62:5a4cdacf5090 23
AzureIoTClient 62:5a4cdacf5090 24 typedef struct IOTHUB_AUTHORIZATION_DATA_TAG
AzureIoTClient 62:5a4cdacf5090 25 {
AzureIoTClient 62:5a4cdacf5090 26 char* device_sas_token;
AzureIoTClient 62:5a4cdacf5090 27 char* device_key;
AzureIoTClient 62:5a4cdacf5090 28 char* device_id;
AzureIoTClient 89:a2ed767a532e 29 char* module_id;
AzureIoTClient 62:5a4cdacf5090 30 size_t token_expiry_time_sec;
AzureIoTClient 62:5a4cdacf5090 31 IOTHUB_CREDENTIAL_TYPE cred_type;
AzureIoTClient 78:74a8d3068204 32 #ifdef USE_PROV_MODULE
AzureIoTClient 75:86205ca63a59 33 IOTHUB_SECURITY_HANDLE device_auth_handle;
AzureIoTClient 75:86205ca63a59 34 #endif
AzureIoTClient 62:5a4cdacf5090 35 } IOTHUB_AUTHORIZATION_DATA;
AzureIoTClient 62:5a4cdacf5090 36
AzureIoTClient 62:5a4cdacf5090 37 static int get_seconds_since_epoch(size_t* seconds)
AzureIoTClient 62:5a4cdacf5090 38 {
AzureIoTClient 62:5a4cdacf5090 39 int result;
AzureIoTClient 62:5a4cdacf5090 40 time_t current_time;
AzureIoTClient 62:5a4cdacf5090 41 if ((current_time = get_time(NULL)) == INDEFINITE_TIME)
AzureIoTClient 62:5a4cdacf5090 42 {
AzureIoTClient 62:5a4cdacf5090 43 LogError("Failed getting the current local time (get_time() failed)");
AzureIoTClient 75:86205ca63a59 44 result = __FAILURE__;
AzureIoTClient 62:5a4cdacf5090 45 }
AzureIoTClient 62:5a4cdacf5090 46 else
AzureIoTClient 62:5a4cdacf5090 47 {
AzureIoTClient 62:5a4cdacf5090 48 *seconds = (size_t)get_difftime(current_time, (time_t)0);
AzureIoTClient 62:5a4cdacf5090 49 result = 0;
AzureIoTClient 62:5a4cdacf5090 50 }
AzureIoTClient 62:5a4cdacf5090 51 return result;
AzureIoTClient 62:5a4cdacf5090 52 }
AzureIoTClient 62:5a4cdacf5090 53
AzureIoTClient 89:a2ed767a532e 54 IOTHUB_AUTHORIZATION_HANDLE IoTHubClient_Auth_Create(const char* device_key, const char* device_id, const char* device_sas_token, const char *module_id)
AzureIoTClient 62:5a4cdacf5090 55 {
AzureIoTClient 62:5a4cdacf5090 56 IOTHUB_AUTHORIZATION_DATA* result;
AzureIoTClient 62:5a4cdacf5090 57 /* Codes_SRS_IoTHub_Authorization_07_001: [if device_id is NULL IoTHubClient_Auth_Create, shall return NULL. ] */
AzureIoTClient 62:5a4cdacf5090 58 if (device_id == NULL)
AzureIoTClient 62:5a4cdacf5090 59 {
AzureIoTClient 75:86205ca63a59 60 LogError("Invalid Parameter device_id: %p", device_id);
AzureIoTClient 62:5a4cdacf5090 61 result = NULL;
AzureIoTClient 62:5a4cdacf5090 62 }
AzureIoTClient 62:5a4cdacf5090 63 else
AzureIoTClient 62:5a4cdacf5090 64 {
AzureIoTClient 62:5a4cdacf5090 65 /* Codes_SRS_IoTHub_Authorization_07_002: [IoTHubClient_Auth_Create shall allocate a IOTHUB_AUTHORIZATION_HANDLE that is needed for subsequent calls. ] */
AzureIoTClient 62:5a4cdacf5090 66 result = (IOTHUB_AUTHORIZATION_DATA*)malloc(sizeof(IOTHUB_AUTHORIZATION_DATA) );
AzureIoTClient 62:5a4cdacf5090 67 if (result == NULL)
AzureIoTClient 62:5a4cdacf5090 68 {
AzureIoTClient 62:5a4cdacf5090 69 /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */
AzureIoTClient 62:5a4cdacf5090 70 LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA");
AzureIoTClient 62:5a4cdacf5090 71 result = NULL;
AzureIoTClient 62:5a4cdacf5090 72 }
AzureIoTClient 62:5a4cdacf5090 73 else
AzureIoTClient 62:5a4cdacf5090 74 {
AzureIoTClient 62:5a4cdacf5090 75 memset(result, 0, sizeof(IOTHUB_AUTHORIZATION_DATA) );
AzureIoTClient 62:5a4cdacf5090 76 result->token_expiry_time_sec = DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS;
AzureIoTClient 62:5a4cdacf5090 77
AzureIoTClient 62:5a4cdacf5090 78 if (device_key != NULL && mallocAndStrcpy_s(&result->device_key, device_key) != 0)
AzureIoTClient 62:5a4cdacf5090 79 {
AzureIoTClient 62:5a4cdacf5090 80 /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */
AzureIoTClient 62:5a4cdacf5090 81 LogError("Failed allocating device_key");
AzureIoTClient 62:5a4cdacf5090 82 free(result);
AzureIoTClient 62:5a4cdacf5090 83 result = NULL;
AzureIoTClient 62:5a4cdacf5090 84 }
AzureIoTClient 62:5a4cdacf5090 85 else if (mallocAndStrcpy_s(&result->device_id, device_id) != 0)
AzureIoTClient 62:5a4cdacf5090 86 {
AzureIoTClient 62:5a4cdacf5090 87 /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */
AzureIoTClient 62:5a4cdacf5090 88 LogError("Failed allocating device_key");
AzureIoTClient 62:5a4cdacf5090 89 free(result->device_key);
AzureIoTClient 62:5a4cdacf5090 90 free(result);
AzureIoTClient 62:5a4cdacf5090 91 result = NULL;
AzureIoTClient 62:5a4cdacf5090 92 }
AzureIoTClient 89:a2ed767a532e 93 else if (module_id != NULL && mallocAndStrcpy_s(&result->module_id, module_id) != 0)
AzureIoTClient 89:a2ed767a532e 94 {
AzureIoTClient 89:a2ed767a532e 95 /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */
AzureIoTClient 89:a2ed767a532e 96 LogError("Failed allocating module_id");
AzureIoTClient 89:a2ed767a532e 97 free(result->device_id);
AzureIoTClient 89:a2ed767a532e 98 free(result->device_key);
AzureIoTClient 89:a2ed767a532e 99 free(result);
AzureIoTClient 89:a2ed767a532e 100 result = NULL;
AzureIoTClient 89:a2ed767a532e 101 }
AzureIoTClient 62:5a4cdacf5090 102 else
AzureIoTClient 62:5a4cdacf5090 103 {
AzureIoTClient 63:1bf1c2d60aab 104 if (device_key != NULL)
AzureIoTClient 62:5a4cdacf5090 105 {
AzureIoTClient 62:5a4cdacf5090 106 /* Codes_SRS_IoTHub_Authorization_07_003: [ IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY if the device_sas_token is NULL. ]*/
AzureIoTClient 62:5a4cdacf5090 107 result->cred_type = IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY;
AzureIoTClient 62:5a4cdacf5090 108 }
AzureIoTClient 63:1bf1c2d60aab 109 else if (device_sas_token != NULL)
AzureIoTClient 62:5a4cdacf5090 110 {
AzureIoTClient 62:5a4cdacf5090 111 /* Codes_SRS_IoTHub_Authorization_07_020: [ else IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN. ] */
AzureIoTClient 62:5a4cdacf5090 112 result->cred_type = IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN;
AzureIoTClient 62:5a4cdacf5090 113 if (mallocAndStrcpy_s(&result->device_sas_token, device_sas_token) != 0)
AzureIoTClient 62:5a4cdacf5090 114 {
AzureIoTClient 62:5a4cdacf5090 115 /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */
AzureIoTClient 62:5a4cdacf5090 116 LogError("Failed allocating device_key");
AzureIoTClient 62:5a4cdacf5090 117 free(result->device_key);
AzureIoTClient 62:5a4cdacf5090 118 free(result->device_id);
AzureIoTClient 89:a2ed767a532e 119 free(result->module_id);
AzureIoTClient 62:5a4cdacf5090 120 free(result);
AzureIoTClient 62:5a4cdacf5090 121 result = NULL;
AzureIoTClient 62:5a4cdacf5090 122 }
AzureIoTClient 62:5a4cdacf5090 123 }
AzureIoTClient 63:1bf1c2d60aab 124 else
AzureIoTClient 63:1bf1c2d60aab 125 {
AzureIoTClient 63:1bf1c2d60aab 126 /* Codes_SRS_IoTHub_Authorization_07_024: [ if device_sas_token and device_key are NULL IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_UNKNOWN. ] */
AzureIoTClient 63:1bf1c2d60aab 127 result->cred_type = IOTHUB_CREDENTIAL_TYPE_UNKNOWN;
AzureIoTClient 63:1bf1c2d60aab 128 }
AzureIoTClient 62:5a4cdacf5090 129 }
AzureIoTClient 62:5a4cdacf5090 130 }
AzureIoTClient 62:5a4cdacf5090 131 }
AzureIoTClient 62:5a4cdacf5090 132 /* Codes_SRS_IoTHub_Authorization_07_004: [ If successful IoTHubClient_Auth_Create shall return a IOTHUB_AUTHORIZATION_HANDLE value. ] */
AzureIoTClient 62:5a4cdacf5090 133 return result;
AzureIoTClient 62:5a4cdacf5090 134 }
AzureIoTClient 62:5a4cdacf5090 135
AzureIoTClient 89:a2ed767a532e 136 IOTHUB_AUTHORIZATION_HANDLE IoTHubClient_Auth_CreateFromDeviceAuth(const char* device_id, const char* module_id)
AzureIoTClient 75:86205ca63a59 137 {
AzureIoTClient 75:86205ca63a59 138 IOTHUB_AUTHORIZATION_DATA* result;
AzureIoTClient 75:86205ca63a59 139 if (device_id == NULL)
AzureIoTClient 75:86205ca63a59 140 {
AzureIoTClient 75:86205ca63a59 141 LogError("Invalid Parameter device_id: %p", device_id);
AzureIoTClient 75:86205ca63a59 142 result = NULL;
AzureIoTClient 75:86205ca63a59 143 }
AzureIoTClient 75:86205ca63a59 144 else
AzureIoTClient 75:86205ca63a59 145 {
AzureIoTClient 78:74a8d3068204 146 #ifdef USE_PROV_MODULE
AzureIoTClient 75:86205ca63a59 147 result = (IOTHUB_AUTHORIZATION_DATA*)malloc(sizeof(IOTHUB_AUTHORIZATION_DATA));
AzureIoTClient 75:86205ca63a59 148 if (result == NULL)
AzureIoTClient 75:86205ca63a59 149 {
AzureIoTClient 75:86205ca63a59 150 LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA");
AzureIoTClient 75:86205ca63a59 151 result = NULL;
AzureIoTClient 75:86205ca63a59 152 }
AzureIoTClient 75:86205ca63a59 153 else
AzureIoTClient 75:86205ca63a59 154 {
AzureIoTClient 75:86205ca63a59 155 memset(result, 0, sizeof(IOTHUB_AUTHORIZATION_DATA));
AzureIoTClient 75:86205ca63a59 156
AzureIoTClient 75:86205ca63a59 157 result->device_auth_handle = iothub_device_auth_create();
AzureIoTClient 75:86205ca63a59 158 if (result->device_auth_handle == NULL)
AzureIoTClient 75:86205ca63a59 159 {
AzureIoTClient 75:86205ca63a59 160 LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA");
AzureIoTClient 75:86205ca63a59 161 free(result);
AzureIoTClient 75:86205ca63a59 162 result = NULL;
AzureIoTClient 75:86205ca63a59 163 }
AzureIoTClient 75:86205ca63a59 164 else if (mallocAndStrcpy_s(&result->device_id, device_id) != 0)
AzureIoTClient 75:86205ca63a59 165 {
AzureIoTClient 89:a2ed767a532e 166 LogError("Failed allocating device_id");
AzureIoTClient 75:86205ca63a59 167 iothub_device_auth_destroy(result->device_auth_handle);
AzureIoTClient 75:86205ca63a59 168 free(result);
AzureIoTClient 75:86205ca63a59 169 result = NULL;
AzureIoTClient 75:86205ca63a59 170 }
AzureIoTClient 89:a2ed767a532e 171 else if ((module_id != NULL) && (mallocAndStrcpy_s(&result->module_id, module_id) != 0))
AzureIoTClient 89:a2ed767a532e 172 {
AzureIoTClient 89:a2ed767a532e 173 LogError("Failed allocating module_id");
AzureIoTClient 89:a2ed767a532e 174 iothub_device_auth_destroy(result->device_auth_handle);
AzureIoTClient 89:a2ed767a532e 175 free(result->device_id);
AzureIoTClient 89:a2ed767a532e 176 free(result);
AzureIoTClient 89:a2ed767a532e 177 result = NULL;
AzureIoTClient 89:a2ed767a532e 178 }
AzureIoTClient 75:86205ca63a59 179 else
AzureIoTClient 75:86205ca63a59 180 {
AzureIoTClient 93:7c0bbb86b167 181 DEVICE_AUTH_TYPE auth_type = iothub_device_auth_get_type(result->device_auth_handle);
AzureIoTClient 93:7c0bbb86b167 182 if (auth_type == AUTH_TYPE_SAS || auth_type == AUTH_TYPE_SYMM_KEY)
AzureIoTClient 75:86205ca63a59 183 {
AzureIoTClient 75:86205ca63a59 184 result->cred_type = IOTHUB_CREDENTIAL_TYPE_DEVICE_AUTH;
AzureIoTClient 75:86205ca63a59 185 }
AzureIoTClient 75:86205ca63a59 186 else
AzureIoTClient 75:86205ca63a59 187 {
AzureIoTClient 75:86205ca63a59 188 result->cred_type = IOTHUB_CREDENTIAL_TYPE_X509_ECC;
AzureIoTClient 75:86205ca63a59 189 }
AzureIoTClient 75:86205ca63a59 190 }
AzureIoTClient 75:86205ca63a59 191 }
AzureIoTClient 75:86205ca63a59 192 #else
AzureIoTClient 89:a2ed767a532e 193 (void)module_id;
AzureIoTClient 78:74a8d3068204 194 LogError("Failed HSM module is not supported");
AzureIoTClient 75:86205ca63a59 195 result = NULL;
AzureIoTClient 75:86205ca63a59 196 #endif
AzureIoTClient 75:86205ca63a59 197 }
AzureIoTClient 75:86205ca63a59 198 return result;
AzureIoTClient 75:86205ca63a59 199 }
AzureIoTClient 62:5a4cdacf5090 200
AzureIoTClient 62:5a4cdacf5090 201 void IoTHubClient_Auth_Destroy(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 62:5a4cdacf5090 202 {
AzureIoTClient 62:5a4cdacf5090 203 /* Codes_SRS_IoTHub_Authorization_07_005: [ if handle is NULL IoTHubClient_Auth_Destroy shall do nothing. ] */
AzureIoTClient 62:5a4cdacf5090 204 if (handle != NULL)
AzureIoTClient 62:5a4cdacf5090 205 {
AzureIoTClient 62:5a4cdacf5090 206 /* Codes_SRS_IoTHub_Authorization_07_006: [ IoTHubClient_Auth_Destroy shall free all resources associated with the IOTHUB_AUTHORIZATION_HANDLE handle. ] */
AzureIoTClient 78:74a8d3068204 207 #ifdef USE_PROV_MODULE
AzureIoTClient 75:86205ca63a59 208 iothub_device_auth_destroy(handle->device_auth_handle);
AzureIoTClient 75:86205ca63a59 209 #endif
AzureIoTClient 62:5a4cdacf5090 210 free(handle->device_key);
AzureIoTClient 62:5a4cdacf5090 211 free(handle->device_id);
AzureIoTClient 89:a2ed767a532e 212 free(handle->module_id);
AzureIoTClient 62:5a4cdacf5090 213 free(handle->device_sas_token);
AzureIoTClient 62:5a4cdacf5090 214 free(handle);
AzureIoTClient 62:5a4cdacf5090 215 }
AzureIoTClient 62:5a4cdacf5090 216 }
AzureIoTClient 62:5a4cdacf5090 217
AzureIoTClient 63:1bf1c2d60aab 218 IOTHUB_CREDENTIAL_TYPE IoTHubClient_Auth_Set_x509_Type(IOTHUB_AUTHORIZATION_HANDLE handle, bool enable_x509)
AzureIoTClient 63:1bf1c2d60aab 219 {
AzureIoTClient 63:1bf1c2d60aab 220 IOTHUB_CREDENTIAL_TYPE result;
AzureIoTClient 63:1bf1c2d60aab 221 if (handle != NULL)
AzureIoTClient 63:1bf1c2d60aab 222 {
AzureIoTClient 63:1bf1c2d60aab 223 if (enable_x509)
AzureIoTClient 63:1bf1c2d60aab 224 {
AzureIoTClient 63:1bf1c2d60aab 225 result = handle->cred_type = IOTHUB_CREDENTIAL_TYPE_X509;
AzureIoTClient 63:1bf1c2d60aab 226 }
AzureIoTClient 63:1bf1c2d60aab 227 else
AzureIoTClient 63:1bf1c2d60aab 228 {
AzureIoTClient 63:1bf1c2d60aab 229 if (handle->device_sas_token == NULL)
AzureIoTClient 63:1bf1c2d60aab 230 {
AzureIoTClient 63:1bf1c2d60aab 231 result = handle->cred_type = IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY;
AzureIoTClient 63:1bf1c2d60aab 232 }
AzureIoTClient 63:1bf1c2d60aab 233 else if (handle->device_key == NULL)
AzureIoTClient 63:1bf1c2d60aab 234 {
AzureIoTClient 63:1bf1c2d60aab 235 result = handle->cred_type = IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN;
AzureIoTClient 63:1bf1c2d60aab 236 }
AzureIoTClient 63:1bf1c2d60aab 237 else
AzureIoTClient 63:1bf1c2d60aab 238 {
AzureIoTClient 63:1bf1c2d60aab 239 result = handle->cred_type = IOTHUB_CREDENTIAL_TYPE_UNKNOWN;
AzureIoTClient 63:1bf1c2d60aab 240 }
AzureIoTClient 63:1bf1c2d60aab 241 }
AzureIoTClient 63:1bf1c2d60aab 242 }
AzureIoTClient 63:1bf1c2d60aab 243 else
AzureIoTClient 63:1bf1c2d60aab 244 {
AzureIoTClient 63:1bf1c2d60aab 245 result = IOTHUB_CREDENTIAL_TYPE_UNKNOWN;
AzureIoTClient 63:1bf1c2d60aab 246 }
AzureIoTClient 63:1bf1c2d60aab 247 return result;
AzureIoTClient 63:1bf1c2d60aab 248 }
AzureIoTClient 63:1bf1c2d60aab 249
AzureIoTClient 75:86205ca63a59 250 int IoTHubClient_Auth_Set_xio_Certificate(IOTHUB_AUTHORIZATION_HANDLE handle, XIO_HANDLE xio)
AzureIoTClient 75:86205ca63a59 251 {
AzureIoTClient 75:86205ca63a59 252 int result;
AzureIoTClient 75:86205ca63a59 253 if (handle == NULL || xio == NULL)
AzureIoTClient 75:86205ca63a59 254 {
AzureIoTClient 75:86205ca63a59 255 LogError("Invalid Parameter handle: %p xio: %p", handle, xio);
AzureIoTClient 75:86205ca63a59 256 result = __FAILURE__;
AzureIoTClient 75:86205ca63a59 257 }
AzureIoTClient 75:86205ca63a59 258 else if (handle->cred_type != IOTHUB_CREDENTIAL_TYPE_X509_ECC)
AzureIoTClient 75:86205ca63a59 259 {
AzureIoTClient 75:86205ca63a59 260 LogError("Invalid credential types for this operation");
AzureIoTClient 75:86205ca63a59 261 result = __FAILURE__;
AzureIoTClient 75:86205ca63a59 262 }
AzureIoTClient 75:86205ca63a59 263 else
AzureIoTClient 75:86205ca63a59 264 {
AzureIoTClient 78:74a8d3068204 265 #ifdef USE_PROV_MODULE
AzureIoTClient 75:86205ca63a59 266 CREDENTIAL_RESULT* cred_result = iothub_device_auth_generate_credentials(handle->device_auth_handle, NULL);
AzureIoTClient 75:86205ca63a59 267 if (cred_result == NULL)
AzureIoTClient 75:86205ca63a59 268 {
AzureIoTClient 75:86205ca63a59 269 LogError("Failure generating credentials");
AzureIoTClient 75:86205ca63a59 270 result = __FAILURE__;
AzureIoTClient 75:86205ca63a59 271 }
AzureIoTClient 75:86205ca63a59 272 else
AzureIoTClient 75:86205ca63a59 273 {
AzureIoTClient 75:86205ca63a59 274 if (xio_setoption(xio, OPTION_X509_ECC_CERT, cred_result->auth_cred_result.x509_result.x509_cert) != 0)
AzureIoTClient 75:86205ca63a59 275 {
AzureIoTClient 75:86205ca63a59 276 LogError("Failure setting x509 cert on xio");
AzureIoTClient 75:86205ca63a59 277 result = __FAILURE__;
AzureIoTClient 75:86205ca63a59 278 }
AzureIoTClient 75:86205ca63a59 279 else if (xio_setoption(xio, OPTION_X509_ECC_KEY, cred_result->auth_cred_result.x509_result.x509_alias_key) != 0)
AzureIoTClient 75:86205ca63a59 280 {
AzureIoTClient 75:86205ca63a59 281 LogError("Failure setting x509 key on xio");
AzureIoTClient 75:86205ca63a59 282 result = __FAILURE__;
AzureIoTClient 75:86205ca63a59 283 }
AzureIoTClient 75:86205ca63a59 284 else
AzureIoTClient 75:86205ca63a59 285 {
AzureIoTClient 75:86205ca63a59 286 result = 0;
AzureIoTClient 75:86205ca63a59 287 }
AzureIoTClient 75:86205ca63a59 288 free(cred_result);
AzureIoTClient 75:86205ca63a59 289 }
AzureIoTClient 75:86205ca63a59 290 #else
AzureIoTClient 78:74a8d3068204 291 LogError("Failed HSM module is not supported");
AzureIoTClient 75:86205ca63a59 292 result = __FAILURE__;
AzureIoTClient 75:86205ca63a59 293 #endif
AzureIoTClient 75:86205ca63a59 294 }
AzureIoTClient 75:86205ca63a59 295 return result;
AzureIoTClient 75:86205ca63a59 296 }
AzureIoTClient 75:86205ca63a59 297
AzureIoTClient 62:5a4cdacf5090 298 IOTHUB_CREDENTIAL_TYPE IoTHubClient_Auth_Get_Credential_Type(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 62:5a4cdacf5090 299 {
AzureIoTClient 62:5a4cdacf5090 300 IOTHUB_CREDENTIAL_TYPE result;
AzureIoTClient 62:5a4cdacf5090 301 /* Codes_SRS_IoTHub_Authorization_07_007: [ if handle is NULL IoTHub_Auth_Get_Credential_Type shall return IOTHUB_CREDENTIAL_TYPE_UNKNOWN. ] */
AzureIoTClient 62:5a4cdacf5090 302 if (handle == NULL)
AzureIoTClient 62:5a4cdacf5090 303 {
AzureIoTClient 62:5a4cdacf5090 304 LogError("Invalid Parameter handle: %p", handle);
AzureIoTClient 62:5a4cdacf5090 305 result = IOTHUB_CREDENTIAL_TYPE_UNKNOWN;
AzureIoTClient 62:5a4cdacf5090 306 }
AzureIoTClient 62:5a4cdacf5090 307 else
AzureIoTClient 62:5a4cdacf5090 308 {
AzureIoTClient 62:5a4cdacf5090 309 /* Codes_SRS_IoTHub_Authorization_07_008: [ IoTHub_Auth_Get_Credential_Type shall return the credential type that is set upon creation. ] */
AzureIoTClient 62:5a4cdacf5090 310 result = handle->cred_type;
AzureIoTClient 62:5a4cdacf5090 311 }
AzureIoTClient 62:5a4cdacf5090 312 return result;
AzureIoTClient 62:5a4cdacf5090 313 }
AzureIoTClient 62:5a4cdacf5090 314
AzureIoTClient 88:248736be106e 315 char* IoTHubClient_Auth_Get_SasToken(IOTHUB_AUTHORIZATION_HANDLE handle, const char* scope, size_t expiry_time_relative_seconds, const char* key_name)
AzureIoTClient 62:5a4cdacf5090 316 {
AzureIoTClient 62:5a4cdacf5090 317 char* result;
AzureIoTClient 63:1bf1c2d60aab 318 /* Codes_SRS_IoTHub_Authorization_07_009: [ if handle or scope are NULL, IoTHubClient_Auth_Get_SasToken shall return NULL. ] */
AzureIoTClient 63:1bf1c2d60aab 319 if (handle == NULL)
AzureIoTClient 62:5a4cdacf5090 320 {
AzureIoTClient 63:1bf1c2d60aab 321 LogError("Invalid Parameter handle: %p", handle);
AzureIoTClient 62:5a4cdacf5090 322 result = NULL;
AzureIoTClient 62:5a4cdacf5090 323 }
AzureIoTClient 62:5a4cdacf5090 324 else
AzureIoTClient 62:5a4cdacf5090 325 {
AzureIoTClient 75:86205ca63a59 326 if (handle->cred_type == IOTHUB_CREDENTIAL_TYPE_DEVICE_AUTH)
AzureIoTClient 62:5a4cdacf5090 327 {
AzureIoTClient 78:74a8d3068204 328 #ifdef USE_PROV_MODULE
AzureIoTClient 75:86205ca63a59 329 DEVICE_AUTH_CREDENTIAL_INFO dev_auth_cred;
AzureIoTClient 63:1bf1c2d60aab 330 size_t sec_since_epoch;
AzureIoTClient 63:1bf1c2d60aab 331
AzureIoTClient 63:1bf1c2d60aab 332 if (get_seconds_since_epoch(&sec_since_epoch) != 0)
AzureIoTClient 62:5a4cdacf5090 333 {
AzureIoTClient 63:1bf1c2d60aab 334 LogError("failure getting seconds from epoch");
AzureIoTClient 62:5a4cdacf5090 335 result = NULL;
AzureIoTClient 62:5a4cdacf5090 336 }
AzureIoTClient 92:97148cf9aa2a 337 else
AzureIoTClient 62:5a4cdacf5090 338 {
AzureIoTClient 88:248736be106e 339 memset(&dev_auth_cred, 0, sizeof(DEVICE_AUTH_CREDENTIAL_INFO));
AzureIoTClient 76:943524fee0b7 340 size_t expiry_time = sec_since_epoch+expiry_time_relative_seconds;
AzureIoTClient 75:86205ca63a59 341 dev_auth_cred.sas_info.expiry_seconds = expiry_time;
AzureIoTClient 75:86205ca63a59 342 dev_auth_cred.sas_info.token_scope = scope;
AzureIoTClient 88:248736be106e 343 dev_auth_cred.sas_info.key_name = key_name;
AzureIoTClient 75:86205ca63a59 344 dev_auth_cred.dev_auth_type = AUTH_TYPE_SAS;
AzureIoTClient 75:86205ca63a59 345
AzureIoTClient 75:86205ca63a59 346 CREDENTIAL_RESULT* cred_result = iothub_device_auth_generate_credentials(handle->device_auth_handle, &dev_auth_cred);
AzureIoTClient 75:86205ca63a59 347 if (cred_result == NULL)
AzureIoTClient 62:5a4cdacf5090 348 {
AzureIoTClient 75:86205ca63a59 349 LogError("failure getting credentials from device auth module");
AzureIoTClient 62:5a4cdacf5090 350 result = NULL;
AzureIoTClient 62:5a4cdacf5090 351 }
AzureIoTClient 63:1bf1c2d60aab 352 else
AzureIoTClient 63:1bf1c2d60aab 353 {
AzureIoTClient 75:86205ca63a59 354 if (mallocAndStrcpy_s(&result, cred_result->auth_cred_result.sas_result.sas_token) != 0)
AzureIoTClient 75:86205ca63a59 355 {
AzureIoTClient 75:86205ca63a59 356 LogError("failure allocating Sas Token");
AzureIoTClient 75:86205ca63a59 357 result = NULL;
AzureIoTClient 75:86205ca63a59 358 }
AzureIoTClient 75:86205ca63a59 359 free(cred_result);
AzureIoTClient 75:86205ca63a59 360 }
AzureIoTClient 75:86205ca63a59 361 }
AzureIoTClient 75:86205ca63a59 362 #else
AzureIoTClient 78:74a8d3068204 363 LogError("Failed HSM module is not supported");
AzureIoTClient 75:86205ca63a59 364 result = NULL;
AzureIoTClient 75:86205ca63a59 365 #endif
AzureIoTClient 75:86205ca63a59 366 }
AzureIoTClient 75:86205ca63a59 367 else if (handle->cred_type == IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN)
AzureIoTClient 75:86205ca63a59 368 {
AzureIoTClient 75:86205ca63a59 369 /* Codes_SRS_IoTHub_Authorization_07_021: [If the device_sas_token is NOT NULL IoTHubClient_Auth_Get_SasToken shall return a copy of the device_sas_token. ] */
AzureIoTClient 75:86205ca63a59 370 if (handle->device_sas_token != NULL)
AzureIoTClient 75:86205ca63a59 371 {
AzureIoTClient 75:86205ca63a59 372 if (mallocAndStrcpy_s(&result, handle->device_sas_token) != 0)
AzureIoTClient 75:86205ca63a59 373 {
AzureIoTClient 75:86205ca63a59 374 LogError("failure allocating sas token");
AzureIoTClient 75:86205ca63a59 375 result = NULL;
AzureIoTClient 75:86205ca63a59 376 }
AzureIoTClient 75:86205ca63a59 377 }
AzureIoTClient 75:86205ca63a59 378 else
AzureIoTClient 75:86205ca63a59 379 {
AzureIoTClient 75:86205ca63a59 380 LogError("failure device sas token is NULL");
AzureIoTClient 75:86205ca63a59 381 result = NULL;
AzureIoTClient 75:86205ca63a59 382 }
AzureIoTClient 75:86205ca63a59 383 }
AzureIoTClient 75:86205ca63a59 384 else if (handle->cred_type == IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY)
AzureIoTClient 75:86205ca63a59 385 {
AzureIoTClient 75:86205ca63a59 386 /* Codes_SRS_IoTHub_Authorization_07_009: [ if handle or scope are NULL, IoTHubClient_Auth_Get_SasToken shall return NULL. ] */
AzureIoTClient 75:86205ca63a59 387 if (scope == NULL)
AzureIoTClient 75:86205ca63a59 388 {
AzureIoTClient 75:86205ca63a59 389 LogError("Invalid Parameter scope: %p", scope);
AzureIoTClient 75:86205ca63a59 390 result = NULL;
AzureIoTClient 75:86205ca63a59 391 }
AzureIoTClient 75:86205ca63a59 392 else
AzureIoTClient 75:86205ca63a59 393 {
AzureIoTClient 75:86205ca63a59 394 STRING_HANDLE sas_token;
AzureIoTClient 75:86205ca63a59 395 size_t sec_since_epoch;
AzureIoTClient 75:86205ca63a59 396
AzureIoTClient 76:943524fee0b7 397 /* Codes_SRS_IoTHub_Authorization_07_010: [ IoTHubClient_Auth_Get_SasToken` shall construct the expiration time using the expiry_time_relative_seconds added to epoch time. ] */
AzureIoTClient 75:86205ca63a59 398 if (get_seconds_since_epoch(&sec_since_epoch) != 0)
AzureIoTClient 75:86205ca63a59 399 {
AzureIoTClient 75:86205ca63a59 400 /* Codes_SRS_IoTHub_Authorization_07_020: [ If any error is encountered IoTHubClient_Auth_Get_ConnString shall return NULL. ] */
AzureIoTClient 75:86205ca63a59 401 LogError("failure getting seconds from epoch");
AzureIoTClient 75:86205ca63a59 402 result = NULL;
AzureIoTClient 75:86205ca63a59 403 }
AzureIoTClient 92:97148cf9aa2a 404 else
AzureIoTClient 75:86205ca63a59 405 {
AzureIoTClient 75:86205ca63a59 406 /* Codes_SRS_IoTHub_Authorization_07_011: [ IoTHubClient_Auth_Get_ConnString shall call SASToken_CreateString to construct the sas token. ] */
AzureIoTClient 76:943524fee0b7 407 size_t expiry_time = sec_since_epoch+expiry_time_relative_seconds;
AzureIoTClient 75:86205ca63a59 408 if ( (sas_token = SASToken_CreateString(handle->device_key, scope, key_name, expiry_time)) == NULL)
AzureIoTClient 63:1bf1c2d60aab 409 {
AzureIoTClient 63:1bf1c2d60aab 410 /* Codes_SRS_IoTHub_Authorization_07_020: [ If any error is encountered IoTHubClient_Auth_Get_ConnString shall return NULL. ] */
AzureIoTClient 75:86205ca63a59 411 LogError("Failed creating sas_token");
AzureIoTClient 63:1bf1c2d60aab 412 result = NULL;
AzureIoTClient 63:1bf1c2d60aab 413 }
AzureIoTClient 75:86205ca63a59 414 else
AzureIoTClient 75:86205ca63a59 415 {
AzureIoTClient 75:86205ca63a59 416 /* Codes_SRS_IoTHub_Authorization_07_012: [ On success IoTHubClient_Auth_Get_ConnString shall allocate and return the sas token in a char*. ] */
AzureIoTClient 75:86205ca63a59 417 if (mallocAndStrcpy_s(&result, STRING_c_str(sas_token) ) != 0)
AzureIoTClient 75:86205ca63a59 418 {
AzureIoTClient 75:86205ca63a59 419 /* Codes_SRS_IoTHub_Authorization_07_020: [ If any error is encountered IoTHubClient_Auth_Get_ConnString shall return NULL. ] */
AzureIoTClient 75:86205ca63a59 420 LogError("Failed copying result");
AzureIoTClient 75:86205ca63a59 421 result = NULL;
AzureIoTClient 75:86205ca63a59 422 }
AzureIoTClient 75:86205ca63a59 423 STRING_delete(sas_token);
AzureIoTClient 75:86205ca63a59 424 }
AzureIoTClient 63:1bf1c2d60aab 425 }
AzureIoTClient 62:5a4cdacf5090 426 }
AzureIoTClient 62:5a4cdacf5090 427 }
AzureIoTClient 75:86205ca63a59 428 else
AzureIoTClient 75:86205ca63a59 429 {
AzureIoTClient 75:86205ca63a59 430 LogError("Failed getting sas token invalid credential type");
AzureIoTClient 75:86205ca63a59 431 result = NULL;
AzureIoTClient 75:86205ca63a59 432 }
AzureIoTClient 62:5a4cdacf5090 433 }
AzureIoTClient 62:5a4cdacf5090 434 return result;
AzureIoTClient 62:5a4cdacf5090 435 }
AzureIoTClient 62:5a4cdacf5090 436
AzureIoTClient 62:5a4cdacf5090 437 const char* IoTHubClient_Auth_Get_DeviceId(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 62:5a4cdacf5090 438 {
AzureIoTClient 62:5a4cdacf5090 439 const char* result;
AzureIoTClient 62:5a4cdacf5090 440 if (handle == NULL)
AzureIoTClient 62:5a4cdacf5090 441 {
AzureIoTClient 62:5a4cdacf5090 442 /* Codes_SRS_IoTHub_Authorization_07_013: [ if handle is NULL, IoTHubClient_Auth_Get_DeviceId shall return NULL. ] */
AzureIoTClient 62:5a4cdacf5090 443 LogError("Invalid Parameter handle: %p", handle);
AzureIoTClient 62:5a4cdacf5090 444 result = NULL;
AzureIoTClient 62:5a4cdacf5090 445 }
AzureIoTClient 62:5a4cdacf5090 446 else
AzureIoTClient 62:5a4cdacf5090 447 {
AzureIoTClient 62:5a4cdacf5090 448 /* Codes_SRS_IoTHub_Authorization_07_014: [ IoTHubClient_Auth_Get_DeviceId shall return the device_id specified upon creation. ] */
AzureIoTClient 62:5a4cdacf5090 449 result = handle->device_id;
AzureIoTClient 62:5a4cdacf5090 450 }
AzureIoTClient 62:5a4cdacf5090 451 return result;
AzureIoTClient 62:5a4cdacf5090 452 }
AzureIoTClient 62:5a4cdacf5090 453
AzureIoTClient 89:a2ed767a532e 454 const char* IoTHubClient_Auth_Get_ModuleId(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 89:a2ed767a532e 455 {
AzureIoTClient 89:a2ed767a532e 456 const char* result;
AzureIoTClient 89:a2ed767a532e 457 if (handle == NULL)
AzureIoTClient 89:a2ed767a532e 458 {
AzureIoTClient 89:a2ed767a532e 459 /* Codes_SRS_IoTHub_Authorization_31_025: [ if handle is NULL, IoTHubClient_Auth_Get_ModuleId shall return NULL. ] */
AzureIoTClient 89:a2ed767a532e 460 LogError("Invalid Parameter handle: %p", handle);
AzureIoTClient 89:a2ed767a532e 461 result = NULL;
AzureIoTClient 89:a2ed767a532e 462 }
AzureIoTClient 89:a2ed767a532e 463 else
AzureIoTClient 89:a2ed767a532e 464 {
AzureIoTClient 89:a2ed767a532e 465 /* Codes_SRS_IoTHub_Authorization_31_026: [ IoTHubClient_Auth_Get_ModuleId shall return the module_id specified upon creation. ] */
AzureIoTClient 89:a2ed767a532e 466 result = handle->module_id;
AzureIoTClient 89:a2ed767a532e 467 }
AzureIoTClient 89:a2ed767a532e 468 return result;
AzureIoTClient 89:a2ed767a532e 469 }
AzureIoTClient 89:a2ed767a532e 470
AzureIoTClient 63:1bf1c2d60aab 471 const char* IoTHubClient_Auth_Get_DeviceKey(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 62:5a4cdacf5090 472 {
AzureIoTClient 63:1bf1c2d60aab 473 const char* result;
AzureIoTClient 63:1bf1c2d60aab 474 if (handle == NULL)
AzureIoTClient 63:1bf1c2d60aab 475 {
AzureIoTClient 63:1bf1c2d60aab 476 /* Codes_SRS_IoTHub_Authorization_07_022: [ if handle is NULL, IoTHubClient_Auth_Get_DeviceKey shall return NULL. ] */
AzureIoTClient 63:1bf1c2d60aab 477 LogError("Invalid Parameter handle: %p", handle);
AzureIoTClient 63:1bf1c2d60aab 478 result = NULL;
AzureIoTClient 63:1bf1c2d60aab 479 }
AzureIoTClient 63:1bf1c2d60aab 480 else
AzureIoTClient 63:1bf1c2d60aab 481 {
AzureIoTClient 63:1bf1c2d60aab 482 /* Codes_SRS_IoTHub_Authorization_07_023: [ IoTHubClient_Auth_Get_DeviceKey shall return the device_key specified upon creation. ] */
AzureIoTClient 63:1bf1c2d60aab 483 result = handle->device_key;
AzureIoTClient 63:1bf1c2d60aab 484 }
AzureIoTClient 63:1bf1c2d60aab 485 return result;
AzureIoTClient 63:1bf1c2d60aab 486 }
AzureIoTClient 63:1bf1c2d60aab 487
AzureIoTClient 63:1bf1c2d60aab 488 SAS_TOKEN_STATUS IoTHubClient_Auth_Is_SasToken_Valid(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 63:1bf1c2d60aab 489 {
AzureIoTClient 63:1bf1c2d60aab 490 SAS_TOKEN_STATUS result;
AzureIoTClient 62:5a4cdacf5090 491 if (handle == NULL)
AzureIoTClient 62:5a4cdacf5090 492 {
AzureIoTClient 62:5a4cdacf5090 493 /* Codes_SRS_IoTHub_Authorization_07_015: [ if handle is NULL, IoTHubClient_Auth_Is_SasToken_Valid shall return false. ] */
AzureIoTClient 62:5a4cdacf5090 494 LogError("Invalid Parameter handle: %p", handle);
AzureIoTClient 63:1bf1c2d60aab 495 result = SAS_TOKEN_STATUS_FAILED;
AzureIoTClient 62:5a4cdacf5090 496 }
AzureIoTClient 62:5a4cdacf5090 497 else
AzureIoTClient 62:5a4cdacf5090 498 {
AzureIoTClient 62:5a4cdacf5090 499 if (handle->cred_type == IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN)
AzureIoTClient 62:5a4cdacf5090 500 {
AzureIoTClient 62:5a4cdacf5090 501 if (handle->device_sas_token == NULL)
AzureIoTClient 62:5a4cdacf5090 502 {
AzureIoTClient 62:5a4cdacf5090 503 /* Codes_SRS_IoTHub_Authorization_07_017: [ If the sas_token is NULL IoTHubClient_Auth_Is_SasToken_Valid shall return false. ] */
AzureIoTClient 63:1bf1c2d60aab 504 LogError("Failure: device_sas_toke is NULL");
AzureIoTClient 63:1bf1c2d60aab 505 result = SAS_TOKEN_STATUS_FAILED;
AzureIoTClient 62:5a4cdacf5090 506 }
AzureIoTClient 62:5a4cdacf5090 507 else
AzureIoTClient 62:5a4cdacf5090 508 {
AzureIoTClient 62:5a4cdacf5090 509 /* Codes_SRS_IoTHub_Authorization_07_018: [ otherwise IoTHubClient_Auth_Is_SasToken_Valid shall return the value returned by SASToken_Validate. ] */
AzureIoTClient 62:5a4cdacf5090 510 STRING_HANDLE strSasToken = STRING_construct(handle->device_sas_token);
AzureIoTClient 63:1bf1c2d60aab 511 if (strSasToken != NULL)
AzureIoTClient 63:1bf1c2d60aab 512 {
AzureIoTClient 63:1bf1c2d60aab 513 if (!SASToken_Validate(strSasToken))
AzureIoTClient 63:1bf1c2d60aab 514 {
AzureIoTClient 63:1bf1c2d60aab 515 result = SAS_TOKEN_STATUS_INVALID;
AzureIoTClient 63:1bf1c2d60aab 516 }
AzureIoTClient 63:1bf1c2d60aab 517 else
AzureIoTClient 63:1bf1c2d60aab 518 {
AzureIoTClient 63:1bf1c2d60aab 519 result = SAS_TOKEN_STATUS_VALID;
AzureIoTClient 63:1bf1c2d60aab 520 }
AzureIoTClient 63:1bf1c2d60aab 521 STRING_delete(strSasToken);
AzureIoTClient 63:1bf1c2d60aab 522 }
AzureIoTClient 63:1bf1c2d60aab 523 else
AzureIoTClient 63:1bf1c2d60aab 524 {
AzureIoTClient 63:1bf1c2d60aab 525 LogError("Failure constructing SAS Token");
AzureIoTClient 63:1bf1c2d60aab 526 result = SAS_TOKEN_STATUS_FAILED;
AzureIoTClient 63:1bf1c2d60aab 527 }
AzureIoTClient 62:5a4cdacf5090 528 }
AzureIoTClient 62:5a4cdacf5090 529 }
AzureIoTClient 62:5a4cdacf5090 530 else
AzureIoTClient 62:5a4cdacf5090 531 {
AzureIoTClient 88:248736be106e 532 /* Codes_SRS_IoTHub_Authorization_07_016: [ if credential type is not IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN IoTHubClient_Auth_Is_SasToken_Valid shall return SAS_TOKEN_STATUS_VALID. ] */
AzureIoTClient 88:248736be106e 533 result = SAS_TOKEN_STATUS_VALID;
AzureIoTClient 62:5a4cdacf5090 534 }
AzureIoTClient 62:5a4cdacf5090 535 }
AzureIoTClient 62:5a4cdacf5090 536 return result;
AzureIoTClient 62:5a4cdacf5090 537 }
AzureIoTClient 89:a2ed767a532e 538
AzureIoTClient 89:a2ed767a532e 539
AzureIoTClient 89:a2ed767a532e 540 #ifdef USE_EDGE_MODULES
AzureIoTClient 89:a2ed767a532e 541 char* IoTHubClient_Auth_Get_TrustBundle(IOTHUB_AUTHORIZATION_HANDLE handle)
AzureIoTClient 89:a2ed767a532e 542 {
AzureIoTClient 92:97148cf9aa2a 543 char* result;
AzureIoTClient 92:97148cf9aa2a 544 if (handle == NULL)
AzureIoTClient 92:97148cf9aa2a 545 {
AzureIoTClient 92:97148cf9aa2a 546 LogError("Security Handle is NULL");
AzureIoTClient 92:97148cf9aa2a 547 result = NULL;
AzureIoTClient 92:97148cf9aa2a 548 }
AzureIoTClient 92:97148cf9aa2a 549 else
AzureIoTClient 92:97148cf9aa2a 550 {
AzureIoTClient 92:97148cf9aa2a 551 result = iothub_device_auth_get_trust_bundle(handle->device_auth_handle);
AzureIoTClient 92:97148cf9aa2a 552 }
AzureIoTClient 92:97148cf9aa2a 553 return result;
AzureIoTClient 89:a2ed767a532e 554 }
AzureIoTClient 89:a2ed767a532e 555 #endif
AzureIoTClient 89:a2ed767a532e 556