forked from Azure/iotedge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 846969: Make a iothsm-tpm library that links in TPM functio…
…nality. Adds the TPM code from C_SDK fixed up to work with iothsm needs, including adding `hsm_tpm_derive_and_sign_with_identity`, TPM as a device is selectable at runtime by setting "IOTEDGE_USE_TPM_DEVICE" to "ON".
- Loading branch information
Showing
25 changed files
with
2,308 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "edgelet/hsm-sys/azure-iot-hsm-c/azure-c-shared-utility"] | ||
path = edgelet/hsm-sys/azure-iot-hsm-c/azure-c-shared-utility | ||
url = https://github.com/Azure/azure-c-shared-utility | ||
[submodule "edgelet/hsm-sys/azure-iot-hsm-c/deps/azure-c-shared-utility"] | ||
path = edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared | ||
url = https://github.com/Azure/azure-c-shared-utility.git | ||
[submodule "edgelet/hsm-sys/azure-iot-hsm-c/deps/azure-utpm-c"] | ||
path = edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm | ||
url = https://github.com/Azure/azure-utpm-c.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule azure-c-shared-utility
deleted from
f714f0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
edgelet/hsm-sys/azure-iot-hsm-c/src/edge_sas_perform_sign_with_key.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
#include "azure_c_shared_utility/buffer_.h" | ||
#include "azure_c_shared_utility/gballoc.h" | ||
#include "azure_c_shared_utility/hmacsha256.h" | ||
#include "azure_c_shared_utility/macro_utils.h" | ||
|
||
#include "hsm_log.h" | ||
|
||
int perform_sign_with_key | ||
( | ||
const unsigned char* key, | ||
size_t key_len, | ||
const unsigned char* data_to_be_signed, | ||
size_t data_to_be_signed_size, | ||
unsigned char** digest, | ||
size_t* digest_size | ||
) | ||
{ | ||
int result; | ||
BUFFER_HANDLE signed_payload_handle; | ||
|
||
if ((signed_payload_handle = BUFFER_new()) == NULL) | ||
{ | ||
LOG_ERROR("Error allocating new buffer handle"); | ||
result = __FAILURE__; | ||
} | ||
else | ||
{ | ||
size_t signed_payload_size; | ||
unsigned char *result_digest, *src_digest; | ||
int status = HMACSHA256_ComputeHash(key, key_len, data_to_be_signed, | ||
data_to_be_signed_size, signed_payload_handle); | ||
if (status != HMACSHA256_OK) | ||
{ | ||
LOG_ERROR("Error computing HMAC256SHA signature"); | ||
result = __FAILURE__; | ||
} | ||
else if ((signed_payload_size = BUFFER_length(signed_payload_handle)) == 0) | ||
{ | ||
LOG_ERROR("Error computing HMAC256SHA. Signature size is 0"); | ||
result = __FAILURE__; | ||
} | ||
else if ((src_digest = BUFFER_u_char(signed_payload_handle)) == NULL) | ||
{ | ||
LOG_ERROR("Error obtaining underlying uchar buffer"); | ||
result = __FAILURE__; | ||
} | ||
else if ((result_digest = (unsigned char*)malloc(signed_payload_size)) == NULL) | ||
{ | ||
LOG_ERROR("Error allocating memory for digest"); | ||
result = __FAILURE__; | ||
} | ||
else | ||
{ | ||
memcpy(result_digest, src_digest, signed_payload_size); | ||
*digest = result_digest; | ||
*digest_size = signed_payload_size; | ||
result = 0; | ||
} | ||
BUFFER_delete(signed_payload_handle); | ||
} | ||
return result; | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
edgelet/hsm-sys/azure-iot-hsm-c/src/edge_sas_perform_sign_with_key.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include "azure_c_shared_utility/umock_c_prod.h" | ||
|
||
MOCKABLE_FUNCTION(,int, perform_sign_with_key, const unsigned char *, key, size_t, key_len, | ||
const unsigned char *, data_to_be_signed, size_t, data_to_be_signed_size, | ||
unsigned char **, digest, size_t *, digest_size); | ||
|
Oops, something went wrong.