-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable access TPM in memory interface (#1059)
Remove ability to configure an in memory TPM vs a HW TPM via an environment variable and added tests. This has caused failures when users have tried to use the in memory implementation which is useful only for testing. Essentially environment variable IOTEDGE_USE_TPM_DEVICE will be ignored by libiothsm and by default is built for use with a TPM device. To use the in memory implementation the library must be built using cmake flag USE_TEST_TPM_INTERFACE_IN_MEM.
- Loading branch information
Showing
13 changed files
with
324 additions
and
294 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ cmake = "0.1" | |
|
||
[dev-dependencies] | ||
num_cpus = "1.0" | ||
|
||
[features] | ||
in_memory = [] |
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 |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
*.a | ||
|
||
cmake*/ | ||
build/ | ||
build*/ | ||
|
||
|
||
# Doxygen output | ||
html/ | ||
|
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
116 changes: 15 additions & 101 deletions
116
edgelet/hsm-sys/azure-iot-hsm-c/src/hsm_client_tpm_select.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 |
---|---|---|
@@ -1,125 +1,39 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
#include <stdlib.h> | ||
#include <ctype.h> | ||
#include <stdbool.h> | ||
#include "hsm_utils.h" | ||
#include "hsm_log.h" | ||
|
||
#include "hsm_client_tpm_device.h" | ||
#include "hsm_client_tpm_in_mem.h" | ||
|
||
extern const char* const ENV_TPM_SELECT; | ||
|
||
static int strcmp_i(const char* lhs, const char* rhs) | ||
{ | ||
char lc, rc; | ||
int cmp = 0; | ||
do | ||
{ | ||
lc = *lhs++; | ||
rc = *rhs++; | ||
if ((tolower(lc) - tolower(rc)) != 0) | ||
{ | ||
cmp = 1; | ||
} | ||
} while (lc != 0 && rc != 0); | ||
|
||
return cmp; | ||
} | ||
|
||
// IF ENV_TPM_SELECT is set and not empty, "NO", "OFF" or "FALSE", then user wants to use the | ||
// TPM device for TPM functionality. | ||
static int use_tpm_device(bool *use_tpm) | ||
{ | ||
static const char * user_says_no[] = { "", "off", "no", "false" }; | ||
int array_size = sizeof(user_says_no)/sizeof(user_says_no[0]); | ||
int result; | ||
char * env_use_tpm; | ||
|
||
*use_tpm = false; | ||
if (hsm_get_env(ENV_TPM_SELECT, &env_use_tpm) != 0) | ||
{ | ||
LOG_ERROR("Could not lookup env variable %s", ENV_TPM_SELECT); | ||
result = __FAILURE__; | ||
} | ||
else | ||
{ | ||
if (env_use_tpm != NULL) | ||
{ | ||
*use_tpm = true; | ||
for(int no = 0; no < array_size; no++) | ||
{ | ||
if (strcmp_i(env_use_tpm, user_says_no[no]) == 0) | ||
{ | ||
*use_tpm = false; | ||
break; | ||
} | ||
} | ||
free(env_use_tpm); | ||
} | ||
else | ||
{ | ||
*use_tpm = false; | ||
} | ||
result = 0; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static bool g_use_tpm_device = false; | ||
|
||
int hsm_client_tpm_init(void) | ||
{ | ||
int result; | ||
bool use_tpm_flag = false; | ||
|
||
if (use_tpm_device(&use_tpm_flag) != 0) | ||
{ | ||
result = __FAILURE__; | ||
} | ||
else | ||
{ | ||
if (use_tpm_flag) | ||
{ | ||
result = hsm_client_tpm_device_init(); | ||
if (result == 0) | ||
{ | ||
g_use_tpm_device = true; | ||
} | ||
} | ||
else | ||
{ | ||
result = hsm_client_tpm_store_init(); | ||
} | ||
} | ||
#ifdef TEST_TPM_INTERFACE_IN_MEM | ||
result = hsm_client_tpm_store_init(); | ||
#else | ||
result = hsm_client_tpm_device_init(); | ||
#endif | ||
|
||
return result; | ||
} | ||
|
||
void hsm_client_tpm_deinit(void) | ||
{ | ||
if (g_use_tpm_device) | ||
{ | ||
hsm_client_tpm_device_deinit(); | ||
} | ||
else | ||
{ | ||
#ifdef TEST_TPM_INTERFACE_IN_MEM | ||
hsm_client_tpm_store_deinit(); | ||
} | ||
#else | ||
hsm_client_tpm_device_deinit(); | ||
#endif | ||
} | ||
|
||
const HSM_CLIENT_TPM_INTERFACE* hsm_client_tpm_interface(void) | ||
{ | ||
const HSM_CLIENT_TPM_INTERFACE* result; | ||
if (g_use_tpm_device) | ||
{ | ||
result = hsm_client_tpm_device_interface(); | ||
} | ||
else | ||
{ | ||
#ifdef TEST_TPM_INTERFACE_IN_MEM | ||
result = hsm_client_tpm_store_interface(); | ||
} | ||
#else | ||
result = hsm_client_tpm_device_interface(); | ||
#endif | ||
|
||
return result; | ||
} |
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
31 changes: 12 additions & 19 deletions
31
edgelet/hsm-sys/azure-iot-hsm-c/tests/hsm_tpm_select_ut/CMakeLists.txt
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,34 +1,27 @@ | ||
#Copyright (c) Microsoft. All rights reserved. | ||
#Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#this is CMakeLists.txt for edge_hsm_tpm_ut | ||
#this is CMakeLists.txt for hsm_tpm_select_ut | ||
cmake_minimum_required(VERSION 2.8.11) | ||
|
||
compileAsC11() | ||
|
||
set(theseTestsName hspm_tpm_select_ut) | ||
|
||
include_directories(../../src ../test_utils) | ||
include_directories(../../src) | ||
|
||
add_definitions(-DGB_DEBUG_ALLOC) | ||
compileAsC11() | ||
set(theseTestsName hsm_tpm_select_ut) | ||
|
||
set(${theseTestsName}_test_files | ||
${theseTestsName}.c | ||
) | ||
|
||
set(${theseTestsName}_c_files | ||
../../src/hsm_client_tpm_select.c | ||
../../src/hsm_log.c | ||
../../src/hsm_utils.c | ||
../../src/constants.c | ||
../test_utils/test_utils.c | ||
${theseTestsName}.c | ||
) | ||
|
||
set(${theseTestsName}_h_files | ||
../../src/hsm_client_tpm_device.h | ||
../../src/hsm_client_tpm_in_mem.h | ||
) | ||
|
||
build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") | ||
|
||
if(WIN32) | ||
target_link_libraries(${theseTestsName}_exe iothsm aziotsharedutil $ENV{OPENSSL_ROOT_DIR}/lib/ssleay32.lib $ENV{OPENSSL_ROOT_DIR}/lib/libeay32.lib) | ||
else() | ||
target_link_libraries(${theseTestsName}_exe iothsm aziotsharedutil ${OPENSSL_LIBRARIES}) | ||
endif(WIN32) | ||
|
||
copy_iothsm_dll(${theseTestsName}_exe ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration)) | ||
build_c_test_artifacts(${theseTestsName} ON "tests") |
Oops, something went wrong.