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
iothub_client_authorization.c@62:5a4cdacf5090, 2017-03-24 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Mar 24 16:35:32 2017 -0700
- Revision:
- 62:5a4cdacf5090
- Child:
- 63:1bf1c2d60aab
1.1.10
Who changed what in which revision?
User | Revision | Line number | New 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 | 62:5a4cdacf5090 | 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 | 62:5a4cdacf5090 | 13 | |
AzureIoTClient | 62:5a4cdacf5090 | 14 | #include "iothub_client_authorization.h" |
AzureIoTClient | 62:5a4cdacf5090 | 15 | |
AzureIoTClient | 62:5a4cdacf5090 | 16 | #define DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS 3600 |
AzureIoTClient | 62:5a4cdacf5090 | 17 | #define INDEFINITE_TIME ((time_t)(-1)) |
AzureIoTClient | 62:5a4cdacf5090 | 18 | |
AzureIoTClient | 62:5a4cdacf5090 | 19 | typedef struct IOTHUB_AUTHORIZATION_DATA_TAG |
AzureIoTClient | 62:5a4cdacf5090 | 20 | { |
AzureIoTClient | 62:5a4cdacf5090 | 21 | char* device_sas_token; |
AzureIoTClient | 62:5a4cdacf5090 | 22 | char* device_key; |
AzureIoTClient | 62:5a4cdacf5090 | 23 | char* device_id; |
AzureIoTClient | 62:5a4cdacf5090 | 24 | size_t token_expiry_time_sec; |
AzureIoTClient | 62:5a4cdacf5090 | 25 | IOTHUB_CREDENTIAL_TYPE cred_type; |
AzureIoTClient | 62:5a4cdacf5090 | 26 | } IOTHUB_AUTHORIZATION_DATA; |
AzureIoTClient | 62:5a4cdacf5090 | 27 | |
AzureIoTClient | 62:5a4cdacf5090 | 28 | static int get_seconds_since_epoch(size_t* seconds) |
AzureIoTClient | 62:5a4cdacf5090 | 29 | { |
AzureIoTClient | 62:5a4cdacf5090 | 30 | int result; |
AzureIoTClient | 62:5a4cdacf5090 | 31 | time_t current_time; |
AzureIoTClient | 62:5a4cdacf5090 | 32 | if ((current_time = get_time(NULL)) == INDEFINITE_TIME) |
AzureIoTClient | 62:5a4cdacf5090 | 33 | { |
AzureIoTClient | 62:5a4cdacf5090 | 34 | LogError("Failed getting the current local time (get_time() failed)"); |
AzureIoTClient | 62:5a4cdacf5090 | 35 | result = __LINE__; |
AzureIoTClient | 62:5a4cdacf5090 | 36 | } |
AzureIoTClient | 62:5a4cdacf5090 | 37 | else |
AzureIoTClient | 62:5a4cdacf5090 | 38 | { |
AzureIoTClient | 62:5a4cdacf5090 | 39 | *seconds = (size_t)get_difftime(current_time, (time_t)0); |
AzureIoTClient | 62:5a4cdacf5090 | 40 | result = 0; |
AzureIoTClient | 62:5a4cdacf5090 | 41 | } |
AzureIoTClient | 62:5a4cdacf5090 | 42 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 43 | } |
AzureIoTClient | 62:5a4cdacf5090 | 44 | |
AzureIoTClient | 62:5a4cdacf5090 | 45 | IOTHUB_AUTHORIZATION_HANDLE IoTHubClient_Auth_Create(const char* device_key, const char* device_id, const char* device_sas_token) |
AzureIoTClient | 62:5a4cdacf5090 | 46 | { |
AzureIoTClient | 62:5a4cdacf5090 | 47 | IOTHUB_AUTHORIZATION_DATA* result; |
AzureIoTClient | 62:5a4cdacf5090 | 48 | /* Codes_SRS_IoTHub_Authorization_07_001: [if device_id is NULL IoTHubClient_Auth_Create, shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 49 | if (device_id == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 50 | { |
AzureIoTClient | 62:5a4cdacf5090 | 51 | LogError("Invalid Parameter device_id: %p", device_key, device_id); |
AzureIoTClient | 62:5a4cdacf5090 | 52 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 53 | } |
AzureIoTClient | 62:5a4cdacf5090 | 54 | else |
AzureIoTClient | 62:5a4cdacf5090 | 55 | { |
AzureIoTClient | 62:5a4cdacf5090 | 56 | /* Codes_SRS_IoTHub_Authorization_07_002: [IoTHubClient_Auth_Create shall allocate a IOTHUB_AUTHORIZATION_HANDLE that is needed for subsequent calls. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 57 | result = (IOTHUB_AUTHORIZATION_DATA*)malloc(sizeof(IOTHUB_AUTHORIZATION_DATA) ); |
AzureIoTClient | 62:5a4cdacf5090 | 58 | if (result == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 59 | { |
AzureIoTClient | 62:5a4cdacf5090 | 60 | /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 61 | LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA"); |
AzureIoTClient | 62:5a4cdacf5090 | 62 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 63 | } |
AzureIoTClient | 62:5a4cdacf5090 | 64 | else |
AzureIoTClient | 62:5a4cdacf5090 | 65 | { |
AzureIoTClient | 62:5a4cdacf5090 | 66 | memset(result, 0, sizeof(IOTHUB_AUTHORIZATION_DATA) ); |
AzureIoTClient | 62:5a4cdacf5090 | 67 | result->token_expiry_time_sec = DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS; |
AzureIoTClient | 62:5a4cdacf5090 | 68 | |
AzureIoTClient | 62:5a4cdacf5090 | 69 | if (device_key != NULL && mallocAndStrcpy_s(&result->device_key, device_key) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 70 | { |
AzureIoTClient | 62:5a4cdacf5090 | 71 | /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 72 | LogError("Failed allocating device_key"); |
AzureIoTClient | 62:5a4cdacf5090 | 73 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 74 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 75 | } |
AzureIoTClient | 62:5a4cdacf5090 | 76 | else if (mallocAndStrcpy_s(&result->device_id, device_id) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 77 | { |
AzureIoTClient | 62:5a4cdacf5090 | 78 | /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 79 | LogError("Failed allocating device_key"); |
AzureIoTClient | 62:5a4cdacf5090 | 80 | free(result->device_key); |
AzureIoTClient | 62:5a4cdacf5090 | 81 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 82 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 83 | } |
AzureIoTClient | 62:5a4cdacf5090 | 84 | else |
AzureIoTClient | 62:5a4cdacf5090 | 85 | { |
AzureIoTClient | 62:5a4cdacf5090 | 86 | if (device_sas_token == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 87 | { |
AzureIoTClient | 62:5a4cdacf5090 | 88 | /* 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 | 89 | result->cred_type = IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY; |
AzureIoTClient | 62:5a4cdacf5090 | 90 | result->device_sas_token = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 91 | } |
AzureIoTClient | 62:5a4cdacf5090 | 92 | else |
AzureIoTClient | 62:5a4cdacf5090 | 93 | { |
AzureIoTClient | 62:5a4cdacf5090 | 94 | /* Codes_SRS_IoTHub_Authorization_07_020: [ else IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 95 | result->cred_type = IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN; |
AzureIoTClient | 62:5a4cdacf5090 | 96 | if (mallocAndStrcpy_s(&result->device_sas_token, device_sas_token) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 97 | { |
AzureIoTClient | 62:5a4cdacf5090 | 98 | /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 99 | LogError("Failed allocating device_key"); |
AzureIoTClient | 62:5a4cdacf5090 | 100 | free(result->device_key); |
AzureIoTClient | 62:5a4cdacf5090 | 101 | free(result->device_id); |
AzureIoTClient | 62:5a4cdacf5090 | 102 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 103 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 104 | } |
AzureIoTClient | 62:5a4cdacf5090 | 105 | } |
AzureIoTClient | 62:5a4cdacf5090 | 106 | } |
AzureIoTClient | 62:5a4cdacf5090 | 107 | } |
AzureIoTClient | 62:5a4cdacf5090 | 108 | } |
AzureIoTClient | 62:5a4cdacf5090 | 109 | /* Codes_SRS_IoTHub_Authorization_07_004: [ If successful IoTHubClient_Auth_Create shall return a IOTHUB_AUTHORIZATION_HANDLE value. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 110 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 111 | } |
AzureIoTClient | 62:5a4cdacf5090 | 112 | |
AzureIoTClient | 62:5a4cdacf5090 | 113 | |
AzureIoTClient | 62:5a4cdacf5090 | 114 | void IoTHubClient_Auth_Destroy(IOTHUB_AUTHORIZATION_HANDLE handle) |
AzureIoTClient | 62:5a4cdacf5090 | 115 | { |
AzureIoTClient | 62:5a4cdacf5090 | 116 | /* Codes_SRS_IoTHub_Authorization_07_005: [ if handle is NULL IoTHubClient_Auth_Destroy shall do nothing. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 117 | if (handle != NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 118 | { |
AzureIoTClient | 62:5a4cdacf5090 | 119 | /* Codes_SRS_IoTHub_Authorization_07_006: [ IoTHubClient_Auth_Destroy shall free all resources associated with the IOTHUB_AUTHORIZATION_HANDLE handle. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 120 | free(handle->device_key); |
AzureIoTClient | 62:5a4cdacf5090 | 121 | free(handle->device_id); |
AzureIoTClient | 62:5a4cdacf5090 | 122 | free(handle->device_sas_token); |
AzureIoTClient | 62:5a4cdacf5090 | 123 | free(handle); |
AzureIoTClient | 62:5a4cdacf5090 | 124 | } |
AzureIoTClient | 62:5a4cdacf5090 | 125 | } |
AzureIoTClient | 62:5a4cdacf5090 | 126 | |
AzureIoTClient | 62:5a4cdacf5090 | 127 | IOTHUB_CREDENTIAL_TYPE IoTHubClient_Auth_Get_Credential_Type(IOTHUB_AUTHORIZATION_HANDLE handle) |
AzureIoTClient | 62:5a4cdacf5090 | 128 | { |
AzureIoTClient | 62:5a4cdacf5090 | 129 | IOTHUB_CREDENTIAL_TYPE result; |
AzureIoTClient | 62:5a4cdacf5090 | 130 | /* Codes_SRS_IoTHub_Authorization_07_007: [ if handle is NULL IoTHub_Auth_Get_Credential_Type shall return IOTHUB_CREDENTIAL_TYPE_UNKNOWN. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 131 | if (handle == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 132 | { |
AzureIoTClient | 62:5a4cdacf5090 | 133 | LogError("Invalid Parameter handle: %p", handle); |
AzureIoTClient | 62:5a4cdacf5090 | 134 | result = IOTHUB_CREDENTIAL_TYPE_UNKNOWN; |
AzureIoTClient | 62:5a4cdacf5090 | 135 | } |
AzureIoTClient | 62:5a4cdacf5090 | 136 | else |
AzureIoTClient | 62:5a4cdacf5090 | 137 | { |
AzureIoTClient | 62:5a4cdacf5090 | 138 | /* Codes_SRS_IoTHub_Authorization_07_008: [ IoTHub_Auth_Get_Credential_Type shall return the credential type that is set upon creation. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 139 | result = handle->cred_type; |
AzureIoTClient | 62:5a4cdacf5090 | 140 | } |
AzureIoTClient | 62:5a4cdacf5090 | 141 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 142 | } |
AzureIoTClient | 62:5a4cdacf5090 | 143 | |
AzureIoTClient | 62:5a4cdacf5090 | 144 | char* IoTHubClient_Auth_Get_SasToken(IOTHUB_AUTHORIZATION_HANDLE handle, const char* scope, size_t expire_time) |
AzureIoTClient | 62:5a4cdacf5090 | 145 | { |
AzureIoTClient | 62:5a4cdacf5090 | 146 | char* result; |
AzureIoTClient | 62:5a4cdacf5090 | 147 | /* Codes_SRS_IoTHub_Authorization_07_009: [ if handle or scope are NULL, IoTHubClient_Auth_Get_ConnString shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 148 | if (handle == NULL || scope == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 149 | { |
AzureIoTClient | 62:5a4cdacf5090 | 150 | LogError("Invalid Parameter handle: %p, scope: %p", handle, scope); |
AzureIoTClient | 62:5a4cdacf5090 | 151 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 152 | } |
AzureIoTClient | 62:5a4cdacf5090 | 153 | else |
AzureIoTClient | 62:5a4cdacf5090 | 154 | { |
AzureIoTClient | 62:5a4cdacf5090 | 155 | const char* key_name = ""; |
AzureIoTClient | 62:5a4cdacf5090 | 156 | STRING_HANDLE sas_token; |
AzureIoTClient | 62:5a4cdacf5090 | 157 | size_t sec_since_epoch; |
AzureIoTClient | 62:5a4cdacf5090 | 158 | |
AzureIoTClient | 62:5a4cdacf5090 | 159 | /* Codes_SRS_IoTHub_Authorization_07_010: [ IoTHubClient_Auth_Get_ConnString shall construct the expiration time using the expire_time. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 160 | if (get_seconds_since_epoch(&sec_since_epoch) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 161 | { |
AzureIoTClient | 62:5a4cdacf5090 | 162 | /* Codes_SRS_IoTHub_Authorization_07_020: [ If any error is encountered IoTHubClient_Auth_Get_ConnString shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 163 | LogError("failure getting seconds from epoch"); |
AzureIoTClient | 62:5a4cdacf5090 | 164 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 165 | } |
AzureIoTClient | 62:5a4cdacf5090 | 166 | else |
AzureIoTClient | 62:5a4cdacf5090 | 167 | { |
AzureIoTClient | 62:5a4cdacf5090 | 168 | /* Codes_SRS_IoTHub_Authorization_07_011: [ IoTHubClient_Auth_Get_ConnString shall call SASToken_CreateString to construct the sas token. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 169 | size_t expiry_time = sec_since_epoch+expire_time; |
AzureIoTClient | 62:5a4cdacf5090 | 170 | if ( (sas_token = SASToken_CreateString(handle->device_key, scope, key_name, expiry_time)) == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 171 | { |
AzureIoTClient | 62:5a4cdacf5090 | 172 | /* Codes_SRS_IoTHub_Authorization_07_020: [ If any error is encountered IoTHubClient_Auth_Get_ConnString shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 173 | LogError("Failed creating sas_token"); |
AzureIoTClient | 62:5a4cdacf5090 | 174 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 175 | } |
AzureIoTClient | 62:5a4cdacf5090 | 176 | else |
AzureIoTClient | 62:5a4cdacf5090 | 177 | { |
AzureIoTClient | 62:5a4cdacf5090 | 178 | /* Codes_SRS_IoTHub_Authorization_07_012: [ On success IoTHubClient_Auth_Get_ConnString shall allocate and return the sas token in a char*. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 179 | if (mallocAndStrcpy_s(&result, STRING_c_str(sas_token) ) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 180 | { |
AzureIoTClient | 62:5a4cdacf5090 | 181 | /* Codes_SRS_IoTHub_Authorization_07_020: [ If any error is encountered IoTHubClient_Auth_Get_ConnString shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 182 | LogError("Failed copying result"); |
AzureIoTClient | 62:5a4cdacf5090 | 183 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 184 | } |
AzureIoTClient | 62:5a4cdacf5090 | 185 | STRING_delete(sas_token); |
AzureIoTClient | 62:5a4cdacf5090 | 186 | } |
AzureIoTClient | 62:5a4cdacf5090 | 187 | } |
AzureIoTClient | 62:5a4cdacf5090 | 188 | } |
AzureIoTClient | 62:5a4cdacf5090 | 189 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 190 | } |
AzureIoTClient | 62:5a4cdacf5090 | 191 | |
AzureIoTClient | 62:5a4cdacf5090 | 192 | const char* IoTHubClient_Auth_Get_DeviceId(IOTHUB_AUTHORIZATION_HANDLE handle) |
AzureIoTClient | 62:5a4cdacf5090 | 193 | { |
AzureIoTClient | 62:5a4cdacf5090 | 194 | const char* result; |
AzureIoTClient | 62:5a4cdacf5090 | 195 | if (handle == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 196 | { |
AzureIoTClient | 62:5a4cdacf5090 | 197 | /* Codes_SRS_IoTHub_Authorization_07_013: [ if handle is NULL, IoTHubClient_Auth_Get_DeviceId shall return NULL. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 198 | LogError("Invalid Parameter handle: %p", handle); |
AzureIoTClient | 62:5a4cdacf5090 | 199 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 200 | } |
AzureIoTClient | 62:5a4cdacf5090 | 201 | else |
AzureIoTClient | 62:5a4cdacf5090 | 202 | { |
AzureIoTClient | 62:5a4cdacf5090 | 203 | /* Codes_SRS_IoTHub_Authorization_07_014: [ IoTHubClient_Auth_Get_DeviceId shall return the device_id specified upon creation. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 204 | result = handle->device_id; |
AzureIoTClient | 62:5a4cdacf5090 | 205 | } |
AzureIoTClient | 62:5a4cdacf5090 | 206 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 207 | } |
AzureIoTClient | 62:5a4cdacf5090 | 208 | |
AzureIoTClient | 62:5a4cdacf5090 | 209 | bool IoTHubClient_Auth_Is_SasToken_Valid(IOTHUB_AUTHORIZATION_HANDLE handle) |
AzureIoTClient | 62:5a4cdacf5090 | 210 | { |
AzureIoTClient | 62:5a4cdacf5090 | 211 | bool result; |
AzureIoTClient | 62:5a4cdacf5090 | 212 | if (handle == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 213 | { |
AzureIoTClient | 62:5a4cdacf5090 | 214 | /* Codes_SRS_IoTHub_Authorization_07_015: [ if handle is NULL, IoTHubClient_Auth_Is_SasToken_Valid shall return false. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 215 | LogError("Invalid Parameter handle: %p", handle); |
AzureIoTClient | 62:5a4cdacf5090 | 216 | result = false; |
AzureIoTClient | 62:5a4cdacf5090 | 217 | } |
AzureIoTClient | 62:5a4cdacf5090 | 218 | else |
AzureIoTClient | 62:5a4cdacf5090 | 219 | { |
AzureIoTClient | 62:5a4cdacf5090 | 220 | if (handle->cred_type == IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN) |
AzureIoTClient | 62:5a4cdacf5090 | 221 | { |
AzureIoTClient | 62:5a4cdacf5090 | 222 | if (handle->device_sas_token == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 223 | { |
AzureIoTClient | 62:5a4cdacf5090 | 224 | /* Codes_SRS_IoTHub_Authorization_07_017: [ If the sas_token is NULL IoTHubClient_Auth_Is_SasToken_Valid shall return false. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 225 | result = false; |
AzureIoTClient | 62:5a4cdacf5090 | 226 | } |
AzureIoTClient | 62:5a4cdacf5090 | 227 | else |
AzureIoTClient | 62:5a4cdacf5090 | 228 | { |
AzureIoTClient | 62:5a4cdacf5090 | 229 | /* Codes_SRS_IoTHub_Authorization_07_018: [ otherwise IoTHubClient_Auth_Is_SasToken_Valid shall return the value returned by SASToken_Validate. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 230 | STRING_HANDLE strSasToken = STRING_construct(handle->device_sas_token); |
AzureIoTClient | 62:5a4cdacf5090 | 231 | result = SASToken_Validate(strSasToken); |
AzureIoTClient | 62:5a4cdacf5090 | 232 | STRING_delete(strSasToken); |
AzureIoTClient | 62:5a4cdacf5090 | 233 | } |
AzureIoTClient | 62:5a4cdacf5090 | 234 | } |
AzureIoTClient | 62:5a4cdacf5090 | 235 | else |
AzureIoTClient | 62:5a4cdacf5090 | 236 | { |
AzureIoTClient | 62:5a4cdacf5090 | 237 | /* Codes_SRS_IoTHub_Authorization_07_016: [ if credential type is not IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN IoTHubClient_Auth_Is_SasToken_Valid shall return true. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 238 | result = true; |
AzureIoTClient | 62:5a4cdacf5090 | 239 | } |
AzureIoTClient | 62:5a4cdacf5090 | 240 | } |
AzureIoTClient | 62:5a4cdacf5090 | 241 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 242 | } |