From 012f36834898ab9f5f73249b8d64b30be642587a Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Mon, 6 May 2024 19:27:21 +0530 Subject: [PATCH 01/13] Adding Logging callback. --- src/dcap_provider.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dcap_provider.h b/src/dcap_provider.h index 6848dbf7..9bb48053 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -116,6 +116,12 @@ typedef void ( typedef sgx_plat_error_t (*sgx_ql_set_logging_function_t)( sgx_ql_logging_function_t logger); + const std::string customParam = "customParameter"; +/// Set the callback used for recording log information. +typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( + sgx_ql_logging_function_t logger); + + #endif // #ifndef PLATFORM_QUOTE_PROVIDER_H From 04a75edd2fa112791e61198a6763741102c211b6 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Tue, 27 Jul 2021 18:21:19 -0700 Subject: [PATCH 02/13] Adding Logging callback. --- src/UnitTest/test_quote_prov.cpp | 13 +++++++++++++ src/Windows/dll/dcap_provider.def | 1 + src/dcap_provider.cpp | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index d833535a..017ca841 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -104,6 +104,7 @@ static sgx_ql_get_revocation_info_t sgx_ql_get_revocation_info; static sgx_ql_free_quote_config_t sgx_ql_free_quote_config; static sgx_ql_get_quote_config_t sgx_ql_get_quote_config; static sgx_ql_set_logging_function_t sgx_ql_set_logging_function; +static sgx_ql_set_logging_callback_t sgx_ql_set_logging_callback; static sgx_ql_free_quote_verification_collateral_t sgx_ql_free_quote_verification_collateral; static tdx_ql_free_quote_verification_collateral_t @@ -348,6 +349,11 @@ static HINSTANCE LoadFunctions() GetProcAddress(hLibCapdll, "sgx_ql_set_logging_function")); EXPECT_NE(sgx_ql_set_logging_function, nullptr); + sgx_ql_set_logging_callback = + reinterpret_cast( + GetProcAddress(hLibCapdll, "sgx_ql_set_logging_callback")); + EXPECT_NE(sgx_ql_set_logging_callback, nullptr); + sgx_ql_free_quote_verification_collateral = reinterpret_cast( GetProcAddress( @@ -959,6 +965,7 @@ void ReloadLibrary(libary_type_t* library, bool set_logging_callback = true) if (set_logging_callback) { ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); } } @@ -1290,6 +1297,7 @@ TEST(testQuoteProv, quoteProviderTestsData) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service @@ -1308,6 +1316,7 @@ TEST(testQuoteProv, quoteProviderTestsV2DataFromService) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service @@ -1329,6 +1338,7 @@ TEST(testQuoteProv, quoteProviderTestsV2Data) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service @@ -1371,6 +1381,7 @@ TEST(testQuoteProv, quoteProviderTestsV3Data) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service @@ -1429,6 +1440,7 @@ TEST(testQuoteProv, testWithoutLogging) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service @@ -1449,6 +1461,7 @@ TEST(testQuoteProv, testRestrictAccessToFilesystem) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service diff --git a/src/Windows/dll/dcap_provider.def b/src/Windows/dll/dcap_provider.def index 428e9748..47e5d02a 100644 --- a/src/Windows/dll/dcap_provider.def +++ b/src/Windows/dll/dcap_provider.def @@ -5,6 +5,7 @@ EXPORTS sgx_ql_get_revocation_info sgx_ql_free_revocation_info sgx_ql_set_logging_function + sgx_ql_set_logging_callback sgx_ql_free_quote_verification_collateral; tdx_ql_free_quote_verification_collateral; sgx_ql_free_qve_identity; diff --git a/src/dcap_provider.cpp b/src/dcap_provider.cpp index d5419536..0e631170 100644 --- a/src/dcap_provider.cpp +++ b/src/dcap_provider.cpp @@ -2308,7 +2308,14 @@ extern "C" sgx_plat_error_t sgx_ql_set_logging_function( return SGX_PLAT_ERROR_OK; } -quote3_error_t ql_free_quote_verification_collateral( +extern "C" quote3_error_t sgx_ql_set_logging_callback( + sgx_ql_logging_function_t logger) +{ + logger_callback = logger; + return SGX_QL_SUCCESS; +} + +extern "C" quote3_error_t sgx_ql_free_quote_verification_collateral( sgx_ql_qve_collateral_t* p_quote_collateral) { delete[] p_quote_collateral->pck_crl; From bc02f1003a08db7b4a05d0dfef811041a17f05d6 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Wed, 28 Jul 2021 16:11:59 -0700 Subject: [PATCH 03/13] Resolving linking issues. --- src/UnitTest/test_quote_prov.cpp | 7 +++++++ src/dcap_provider.h | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index 017ca841..c38d7a6d 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -50,6 +50,9 @@ typedef quote3_error_t (*sgx_ql_get_quote_config_t)( const sgx_ql_pck_cert_id_t* p_pck_cert_id, sgx_ql_config_t** pp_quote_config); +typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( + sgx_ql_logging_function_t logger); + typedef quote3_error_t (*sgx_ql_free_quote_config_t)( sgx_ql_config_t* p_quote_config); @@ -313,6 +316,10 @@ static void* LoadFunctions() sgx_ql_get_root_ca_crl = reinterpret_cast( dlsym(library, "sgx_ql_get_root_ca_crl")); EXPECT_NE(sgx_ql_get_root_ca_crl, nullptr); + + sgx_ql_set_logging_callback = reinterpret_cast( + dlsym(library, "sgx_ql_set_logging_callback")); + EXPECT_NE(sgx_ql_set_logging_callback, nullptr); return library; } #else diff --git a/src/dcap_provider.h b/src/dcap_provider.h index 9bb48053..63ca9386 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -116,12 +116,9 @@ typedef void ( typedef sgx_plat_error_t (*sgx_ql_set_logging_function_t)( sgx_ql_logging_function_t logger); - const std::string customParam = "customParameter"; /// Set the callback used for recording log information. typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( sgx_ql_logging_function_t logger); - - #endif // #ifndef PLATFORM_QUOTE_PROVIDER_H From 40e45e6e7e99351ebabe910b6c1d3227d31b3d77 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Mon, 6 May 2024 20:02:25 +0530 Subject: [PATCH 04/13] Resolving rebasing conflicts. --- src/UnitTest/test_quote_prov.cpp | 117 ++++++++---------- .../dcap_provider_tests/easy_curl_tests.cpp | 2 +- src/Windows/dll/dcap_provider.def | 3 +- src/dcap_provider.cpp | 3 +- src/dcap_provider.h | 1 + src/logging.cpp | 29 ++++- src/private.h | 1 + 7 files changed, 80 insertions(+), 76 deletions(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index c38d7a6d..dc3cd711 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -5,7 +5,6 @@ #include "../local_cache.h" #include "dcap_provider.h" -#include "sgx_ql_lib_common.h" #include #include @@ -50,9 +49,6 @@ typedef quote3_error_t (*sgx_ql_get_quote_config_t)( const sgx_ql_pck_cert_id_t* p_pck_cert_id, sgx_ql_config_t** pp_quote_config); -typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( - sgx_ql_logging_function_t logger); - typedef quote3_error_t (*sgx_ql_free_quote_config_t)( sgx_ql_config_t* p_quote_config); @@ -108,7 +104,7 @@ static sgx_ql_free_quote_config_t sgx_ql_free_quote_config; static sgx_ql_get_quote_config_t sgx_ql_get_quote_config; static sgx_ql_set_logging_function_t sgx_ql_set_logging_function; static sgx_ql_set_logging_callback_t sgx_ql_set_logging_callback; -static sgx_ql_free_quote_verification_collateral_t +static sgx_ql_free_quote_verification_collateral_t sgx_ql_free_quote_verification_collateral; static tdx_ql_free_quote_verification_collateral_t tdx_ql_free_quote_verification_collateral; @@ -137,43 +133,41 @@ const uint16_t incorrect_custom_param_length = 24; const char* incorrect_custom_param = "tcbEvaluationDataNum=11"; // Test input (choose an arbitrary Azure server) -static uint8_t qe_id[16] = { - 0x00, - 0xfb, - 0xe6, - 0x73, - 0x33, - 0x36, - 0xea, - 0xf7, - 0xa4, - 0xe3, - 0xd8, - 0xb9, - 0x66, - 0xa8, - 0x2e, - 0x64}; - -static sgx_cpu_svn_t cpusvn = { - 0x04, - 0x04, - 0x02, - 0x04, - 0xff, - 0x80, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00}; - -static sgx_isv_svn_t pcesvn = 6; +static uint8_t qe_id[16] = {0x00, + 0xfb, + 0xe6, + 0x73, + 0x33, + 0x36, + 0xea, + 0xf7, + 0xa4, + 0xe3, + 0xd8, + 0xb9, + 0x66, + 0xa8, + 0x2e, + 0x64}; + +static sgx_cpu_svn_t cpusvn = {0x04, + 0x04, + 0x02, + 0x04, + 0xff, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}; + +static sgx_isv_svn_t pcesvn = 11; static sgx_ql_pck_cert_id_t id = {qe_id, sizeof(qe_id), &cpusvn, &pcesvn, 0}; @@ -254,8 +248,7 @@ static void* LoadFunctions() abort(); } - sgx_ql_free_revocation_info = - reinterpret_cast( + sgx_ql_free_revocation_info = reinterpret_cast( dlsym(library, "sgx_ql_free_revocation_info")); EXPECT_NE(sgx_ql_free_revocation_info, nullptr); @@ -271,13 +264,15 @@ static void* LoadFunctions() dlsym(library, "sgx_ql_get_quote_config")); EXPECT_NE(sgx_ql_get_quote_config, nullptr); - sgx_ql_set_logging_function = - reinterpret_cast( + sgx_ql_set_logging_function = reinterpret_cast( dlsym(library, "sgx_ql_set_logging_function")); EXPECT_NE(sgx_ql_set_logging_function, nullptr); - sgx_ql_free_quote_verification_collateral = - reinterpret_cast( + sgx_ql_set_logging_callback = reinterpret_cast( + dlsym(library, "sgx_ql_set_logging_callback")); + EXPECT_NE(sgx_ql_set_callback_function, nullptr); + + sgx_ql_free_quote_verification_collateral = reinterpret_cast( dlsym(library, "sgx_ql_free_quote_verification_collateral")); EXPECT_NE(sgx_ql_free_quote_verification_collateral, nullptr); @@ -301,6 +296,7 @@ static void* LoadFunctions() sgx_ql_get_quote_verification_collateral = reinterpret_cast( + dlsym(library, "sgx_ql_get_quote_verification_collateral")); EXPECT_NE(sgx_ql_get_quote_verification_collateral, nullptr); @@ -316,10 +312,6 @@ static void* LoadFunctions() sgx_ql_get_root_ca_crl = reinterpret_cast( dlsym(library, "sgx_ql_get_root_ca_crl")); EXPECT_NE(sgx_ql_get_root_ca_crl, nullptr); - - sgx_ql_set_logging_callback = reinterpret_cast( - dlsym(library, "sgx_ql_set_logging_callback")); - EXPECT_NE(sgx_ql_set_logging_callback, nullptr); return library; } #else @@ -334,8 +326,7 @@ static HINSTANCE LoadFunctions() abort(); } - sgx_ql_free_revocation_info = - reinterpret_cast( + sgx_ql_free_revocation_info = reinterpret_cast( GetProcAddress(hLibCapdll, "sgx_ql_free_revocation_info")); EXPECT_NE(sgx_ql_free_revocation_info, nullptr); @@ -351,20 +342,16 @@ static HINSTANCE LoadFunctions() GetProcAddress(hLibCapdll, "sgx_ql_get_quote_config")); EXPECT_NE(sgx_ql_get_quote_config, nullptr); - sgx_ql_set_logging_function = - reinterpret_cast( + sgx_ql_set_logging_function = reinterpret_cast( GetProcAddress(hLibCapdll, "sgx_ql_set_logging_function")); EXPECT_NE(sgx_ql_set_logging_function, nullptr); - sgx_ql_set_logging_callback = - reinterpret_cast( + sgx_ql_set_logging_callback = reinterpret_cast( GetProcAddress(hLibCapdll, "sgx_ql_set_logging_callback")); EXPECT_NE(sgx_ql_set_logging_callback, nullptr); - sgx_ql_free_quote_verification_collateral = - reinterpret_cast( - GetProcAddress( - hLibCapdll, "sgx_ql_free_quote_verification_collateral")); + sgx_ql_free_quote_verification_collateral = reinterpret_cast( + GetProcAddress(hLibCapdll, "sgx_ql_free_quote_verification_collateral")); EXPECT_NE(sgx_ql_free_quote_verification_collateral, nullptr); tdx_ql_free_quote_verification_collateral = @@ -381,10 +368,8 @@ static HINSTANCE LoadFunctions() GetProcAddress(hLibCapdll, "sgx_ql_free_root_ca_crl")); EXPECT_NE(sgx_ql_free_root_ca_crl, nullptr); - sgx_ql_get_quote_verification_collateral = - reinterpret_cast( - GetProcAddress( - hLibCapdll, "sgx_ql_get_quote_verification_collateral")); + sgx_ql_get_quote_verification_collateral = reinterpret_cast( + GetProcAddress(hLibCapdll, "sgx_ql_get_quote_verification_collateral")); EXPECT_NE(sgx_ql_get_quote_verification_collateral, nullptr); sgx_ql_get_quote_verification_collateral_with_params = reinterpret_cast< diff --git a/src/Windows/dcap_provider_tests/easy_curl_tests.cpp b/src/Windows/dcap_provider_tests/easy_curl_tests.cpp index cde9c629..ed8e93d2 100644 --- a/src/Windows/dcap_provider_tests/easy_curl_tests.cpp +++ b/src/Windows/dcap_provider_tests/easy_curl_tests.cpp @@ -23,7 +23,7 @@ static void DefaultLogCallback(sgx_ql_log_level_t level, const char* message) TEST_MODULE_INITIALIZE(InitializeModule) { - logger_callback = DefaultLogCallback; + logger_function = DefaultLogCallback; } namespace dcap_provider_tests diff --git a/src/Windows/dll/dcap_provider.def b/src/Windows/dll/dcap_provider.def index 47e5d02a..8905e710 100644 --- a/src/Windows/dll/dcap_provider.def +++ b/src/Windows/dll/dcap_provider.def @@ -5,7 +5,6 @@ EXPORTS sgx_ql_get_revocation_info sgx_ql_free_revocation_info sgx_ql_set_logging_function - sgx_ql_set_logging_callback sgx_ql_free_quote_verification_collateral; tdx_ql_free_quote_verification_collateral; sgx_ql_free_qve_identity; @@ -17,4 +16,4 @@ EXPORTS sgx_ql_get_root_ca_crl; sgx_get_qe_identity_info sgx_free_qe_identity_info - + sgx_ql_set_logging_callback diff --git a/src/dcap_provider.cpp b/src/dcap_provider.cpp index 0e631170..cbaaa834 100644 --- a/src/dcap_provider.cpp +++ b/src/dcap_provider.cpp @@ -20,7 +20,6 @@ #include #include -#include "sgx_ql_lib_common.h" #include "environment.h" #ifdef __LINUX__ @@ -2304,7 +2303,7 @@ extern "C" void sgx_ql_free_revocation_info( extern "C" sgx_plat_error_t sgx_ql_set_logging_function( sgx_ql_logging_function_t logger) { - logger_callback = logger; + logger_function = logger; return SGX_PLAT_ERROR_OK; } diff --git a/src/dcap_provider.h b/src/dcap_provider.h index 63ca9386..92279411 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -121,4 +121,5 @@ const std::string customParam = "customParameter"; /// Set the callback used for recording log information. typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( sgx_ql_logging_function_t logger); + #endif // #ifndef PLATFORM_QUOTE_PROVIDER_H diff --git a/src/logging.cpp b/src/logging.cpp index 36d8c0c7..d616f094 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -23,8 +23,8 @@ #include "environment.h" using namespace std; - sgx_ql_logging_function_t logger_callback = nullptr; +sgx_ql_logging_function_t logger_function = nullptr; static sgx_ql_log_level_t debug_log_level = SGX_QL_LOG_NONE; static bool debug_log_initialized = false; static mutex log_init_mutex; @@ -96,10 +96,19 @@ static inline void enable_debug_logging(string level) debug_log_level = sgx_level; auto logging_enabled_message = "Debug Logging Enabled"; - if (logger_callback != nullptr) + if ((logger_function != nullptr) && (logger_callback != nullptr)) { + logger_function(SGX_QL_LOG_INFO, logging_enabled_message); logger_callback(SGX_QL_LOG_INFO, logging_enabled_message); } + else if (logger_callback != nullptr) + { + logger_callback(SGX_QL_LOG_INFO, logging_enabled_message); + } + else if (logger_function != nullptr) + { + logger_function(SGX_QL_LOG_INFO, logging_enabled_message); + } else { printf( @@ -137,7 +146,6 @@ void init_debug_log() // void log_message(sgx_ql_log_level_t level, const char* message) { - auto now = chrono::system_clock::now(); time_t nowTimeT = chrono::system_clock::to_time_t(now); char date[100]; @@ -181,10 +189,20 @@ void log_message(sgx_ql_log_level_t level, const char* message) } #endif - if (logger_callback != nullptr) + + if ((logger_function != nullptr) && (logger_callback != nullptr)) { + logger_function(level, message); logger_callback(level, message); } + else if (logger_callback != nullptr) + { + logger_callback(level, message); + } + else if (logger_function != nullptr) + { + logger_function(level, message); + } else { init_debug_log(); @@ -234,7 +252,8 @@ void log(sgx_ql_log_level_t level, const char* fmt, ...) va_list args; va_start(args, fmt); #pragma warning(suppress : 25141) // all fmt buffers come from static strings - vsnprintf(message, sizeof(message), fmt, args); + vsnprintf(message, sizeof(message), + fmt, args); va_end(args); // ensure buf is always null-terminated diff --git a/src/private.h b/src/private.h index cc361357..049749d3 100644 --- a/src/private.h +++ b/src/private.h @@ -8,6 +8,7 @@ #include "dcap_provider.h" #include +extern sgx_ql_logging_function_t logger_function; extern sgx_ql_logging_function_t logger_callback; /////////////////////////////////////////////////////////////////////////////// From 689a1eaebc8cbedc9b5b2f2e94a09f0e026de3eb Mon Sep 17 00:00:00 2001 From: msft-gumunjal <81185076+msft-gumunjal@users.noreply.github.com> Date: Mon, 31 Jan 2022 17:37:06 -0800 Subject: [PATCH 05/13] Resolving rebase conflicts. --- src/UnitTest/test_quote_prov.cpp | 42 +++++++++++++++++--------------- src/dcap_provider.h | 6 +++++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index dc3cd711..ddd38318 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -150,24 +150,25 @@ static uint8_t qe_id[16] = {0x00, 0x2e, 0x64}; -static sgx_cpu_svn_t cpusvn = {0x04, - 0x04, - 0x02, - 0x04, - 0xff, - 0x80, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00}; - -static sgx_isv_svn_t pcesvn = 11; +static sgx_cpu_svn_t cpusvn = { + 0x0f, + 0x0f, + 0x02, + 0x04, + 0x01, + 0x80, + 0x07, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}; + +static sgx_isv_svn_t pcesvn = 10; static sgx_ql_pck_cert_id_t id = {qe_id, sizeof(qe_id), &cpusvn, &pcesvn, 0}; @@ -268,9 +269,9 @@ static void* LoadFunctions() dlsym(library, "sgx_ql_set_logging_function")); EXPECT_NE(sgx_ql_set_logging_function, nullptr); - sgx_ql_set_logging_callback = reinterpret_cast( + sgx_ql_set_logging_callback = reinterpret_cast( dlsym(library, "sgx_ql_set_logging_callback")); - EXPECT_NE(sgx_ql_set_callback_function, nullptr); + EXPECT_NE(sgx_ql_set_logging_callback, nullptr); sgx_ql_free_quote_verification_collateral = reinterpret_cast( dlsym(library, "sgx_ql_free_quote_verification_collateral")); @@ -1351,6 +1352,7 @@ TEST(testQuoteProv, quoteProviderTestsV3DataFromService) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // // Get the data from the service diff --git a/src/dcap_provider.h b/src/dcap_provider.h index 92279411..f576ff31 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -1,6 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +#ifdef __LINUX__ +#include "sgx_ql_lib_common.h" +#else +#include "Windows\ext\intel\sgx_ql_lib_common.h" +#endif + #pragma once #ifndef PLATFORM_QUOTE_PROVIDER_H #define PLATFORM_QUOTE_PROVIDER_H From 120cc676d7fcdb4f5ee06ae185a5aa667fda5196 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Thu, 12 Aug 2021 12:11:19 -0700 Subject: [PATCH 06/13] Updating logging code flow. --- src/dcap_provider.h | 5 ++++- src/logging.cpp | 53 ++++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/dcap_provider.h b/src/dcap_provider.h index f576ff31..bb5e52e8 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -118,6 +118,9 @@ typedef enum _sgx_ql_log_level_t { typedef void ( *sgx_ql_logging_function_t)(sgx_ql_log_level_t level, const char* message); +typedef void ( + *sgx_ql_logging_callback_t)(sgx_ql_log_level_t level, const char* message); + /// Set the callback used for recording log information. typedef sgx_plat_error_t (*sgx_ql_set_logging_function_t)( sgx_ql_logging_function_t logger); @@ -126,6 +129,6 @@ const std::string customParam = "customParameter"; /// Set the callback used for recording log information. typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( - sgx_ql_logging_function_t logger); + sgx_ql_logging_callback_t logger); #endif // #ifndef PLATFORM_QUOTE_PROVIDER_H diff --git a/src/logging.cpp b/src/logging.cpp index d616f094..1d1f0b5e 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -96,26 +96,21 @@ static inline void enable_debug_logging(string level) debug_log_level = sgx_level; auto logging_enabled_message = "Debug Logging Enabled"; - if ((logger_function != nullptr) && (logger_callback != nullptr)) - { - logger_function(SGX_QL_LOG_INFO, logging_enabled_message); - logger_callback(SGX_QL_LOG_INFO, logging_enabled_message); - } - else if (logger_callback != nullptr) - { - logger_callback(SGX_QL_LOG_INFO, logging_enabled_message); - } - else if (logger_function != nullptr) - { - logger_function(SGX_QL_LOG_INFO, logging_enabled_message); - } - else + if ((logger_callback == nullptr) && (logger_function == nullptr)) { printf( "Azure Quote Provider: libdcap_quoteprov.so [%s]: %s\n", log_level_string(SGX_QL_LOG_INFO).c_str(), logging_enabled_message); } + else if (logger_callback != nullptr) + { + logger_callback(SGX_QL_LOG_INFO, logging_enabled_message); + } + else + { + logger_function(SGX_QL_LOG_INFO, logging_enabled_message); + } } } @@ -190,31 +185,29 @@ void log_message(sgx_ql_log_level_t level, const char* message) #endif - if ((logger_function != nullptr) && (logger_callback != nullptr)) - { - logger_function(level, message); - logger_callback(level, message); - } - else if (logger_callback != nullptr) - { - logger_callback(level, message); - } - else if (logger_function != nullptr) - { - logger_function(level, message); - } - else + if ((logger_function == nullptr) && (logger_callback == nullptr)) { init_debug_log(); if (debug_log_level != SGX_QL_LOG_NONE) { if (level <= debug_log_level) { - printf("%s", logMessage.c_str()); + printf( + "Azure Quote Provider: libdcap_quoteprov.so [%s]: %s\n", + log_level_string(level).c_str(), + message); } } } - fflush(stdout); + else if (logger_callback != nullptr) + { + logger_callback(level, message); + } + else + { + logger_function(level, message); + } + fflush(stdout); #ifndef __LINUX__ // Emitting Events only in Windows From cca0ee2d235f985fd652ffd5dfc6e933f31ffcd8 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Tue, 17 Aug 2021 09:11:51 -0700 Subject: [PATCH 07/13] Updating function signature. --- src/dcap_provider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dcap_provider.cpp b/src/dcap_provider.cpp index cbaaa834..3b9194fe 100644 --- a/src/dcap_provider.cpp +++ b/src/dcap_provider.cpp @@ -2308,7 +2308,7 @@ extern "C" sgx_plat_error_t sgx_ql_set_logging_function( } extern "C" quote3_error_t sgx_ql_set_logging_callback( - sgx_ql_logging_function_t logger) + sgx_ql_logging_callback_t logger) { logger_callback = logger; return SGX_QL_SUCCESS; From 51dcc5928db611829e05dae20f91de7bf9f7be22 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Mon, 6 May 2024 21:13:10 +0530 Subject: [PATCH 08/13] rebasing conflict --- src/dcap_provider.h | 3 +-- src/logging.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/dcap_provider.h b/src/dcap_provider.h index bb5e52e8..f544a106 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -122,8 +122,7 @@ typedef void ( *sgx_ql_logging_callback_t)(sgx_ql_log_level_t level, const char* message); /// Set the callback used for recording log information. -typedef sgx_plat_error_t (*sgx_ql_set_logging_function_t)( - sgx_ql_logging_function_t logger); +typedef sgx_plat_error_t (*sgx_ql_set_logging_function_t)(sgx_ql_logging_function_t logger); const std::string customParam = "customParameter"; diff --git a/src/logging.cpp b/src/logging.cpp index 1d1f0b5e..d7558ba6 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -23,7 +23,7 @@ #include "environment.h" using namespace std; -sgx_ql_logging_function_t logger_callback = nullptr; +sgx_ql_logging_callback_t logger_callback = nullptr; sgx_ql_logging_function_t logger_function = nullptr; static sgx_ql_log_level_t debug_log_level = SGX_QL_LOG_NONE; static bool debug_log_initialized = false; @@ -103,11 +103,11 @@ static inline void enable_debug_logging(string level) log_level_string(SGX_QL_LOG_INFO).c_str(), logging_enabled_message); } - else if (logger_callback != nullptr) + if (logger_callback != nullptr) { logger_callback(SGX_QL_LOG_INFO, logging_enabled_message); } - else + if (logger_function != nullptr) { logger_function(SGX_QL_LOG_INFO, logging_enabled_message); } @@ -199,11 +199,11 @@ void log_message(sgx_ql_log_level_t level, const char* message) } } } - else if (logger_callback != nullptr) + if (logger_callback != nullptr) { logger_callback(level, message); } - else + if (logger_function != nullptr) { logger_function(level, message); } From f1d657d1909cdcbca494e1765adb455dee7324e3 Mon Sep 17 00:00:00 2001 From: msft-gumunjal <81185076+msft-gumunjal@users.noreply.github.com> Date: Mon, 31 Jan 2022 12:46:51 -0800 Subject: [PATCH 09/13] Updating function signature. --- src/private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/private.h b/src/private.h index 049749d3..21f24535 100644 --- a/src/private.h +++ b/src/private.h @@ -9,7 +9,7 @@ #include extern sgx_ql_logging_function_t logger_function; -extern sgx_ql_logging_function_t logger_callback; +extern sgx_ql_logging_callback_t logger_callback; /////////////////////////////////////////////////////////////////////////////// // Various internal functions which are not exported. From d9d18985a32a83668de4078f6c81365fc772c8a6 Mon Sep 17 00:00:00 2001 From: msft-gumunjal <81185076+msft-gumunjal@users.noreply.github.com> Date: Tue, 1 Feb 2022 15:59:38 -0800 Subject: [PATCH 10/13] updating cpusvn and pcesvn value for testing. --- src/UnitTest/test_quote_prov.cpp | 37 +++++++++---------- .../dcap_provider_tests/easy_curl_tests.cpp | 1 + 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index ddd38318..308569ba 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -150,25 +150,24 @@ static uint8_t qe_id[16] = {0x00, 0x2e, 0x64}; -static sgx_cpu_svn_t cpusvn = { - 0x0f, - 0x0f, - 0x02, - 0x04, - 0x01, - 0x80, - 0x07, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00}; - -static sgx_isv_svn_t pcesvn = 10; +static sgx_cpu_svn_t cpusvn = {0x04, + 0x04, + 0x02, + 0x04, + 0xff, + 0x80, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}; + +static sgx_isv_svn_t pcesvn = 6; static sgx_ql_pck_cert_id_t id = {qe_id, sizeof(qe_id), &cpusvn, &pcesvn, 0}; diff --git a/src/Windows/dcap_provider_tests/easy_curl_tests.cpp b/src/Windows/dcap_provider_tests/easy_curl_tests.cpp index ed8e93d2..766b252e 100644 --- a/src/Windows/dcap_provider_tests/easy_curl_tests.cpp +++ b/src/Windows/dcap_provider_tests/easy_curl_tests.cpp @@ -24,6 +24,7 @@ static void DefaultLogCallback(sgx_ql_log_level_t level, const char* message) TEST_MODULE_INITIALIZE(InitializeModule) { logger_function = DefaultLogCallback; + logger_callback = DefaultLogCallback; } namespace dcap_provider_tests From b8d8d90d2002f44cfa854bd56c6f862b8d79cefa Mon Sep 17 00:00:00 2001 From: msft-gumunjal <81185076+msft-gumunjal@users.noreply.github.com> Date: Wed, 2 Feb 2022 15:44:59 -0800 Subject: [PATCH 11/13] Removing duplicate logging caused due to 2 logging callbacks. --- src/UnitTest/test_quote_prov.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index 308569ba..7d49060a 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -1289,8 +1289,6 @@ TEST(testQuoteProv, quoteProviderTestsData) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); - // // Get the data from the service // @@ -1307,7 +1305,6 @@ TEST(testQuoteProv, quoteProviderTestsData) TEST(testQuoteProv, quoteProviderTestsV2DataFromService) { libary_type_t library = LoadFunctions(); - ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // @@ -1330,8 +1327,6 @@ TEST(testQuoteProv, quoteProviderTestsV2Data) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); - // // Get the data from the service // @@ -1350,7 +1345,6 @@ TEST(testQuoteProv, quoteProviderTestsV2Data) TEST(testQuoteProv, quoteProviderTestsV3DataFromService) { libary_type_t library = LoadFunctions(); - ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); // @@ -1374,8 +1368,6 @@ TEST(testQuoteProv, quoteProviderTestsV3Data) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); - // // Get the data from the service // @@ -1433,8 +1425,6 @@ TEST(testQuoteProv, testWithoutLogging) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); - // // Get the data from the service // @@ -1454,8 +1444,6 @@ TEST(testQuoteProv, testRestrictAccessToFilesystem) { libary_type_t library = LoadFunctions(); ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); - // // Get the data from the service // From c8ab2077a40b3b0cde2a467aa89289049e664639 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Wed, 8 May 2024 18:25:44 +0530 Subject: [PATCH 12/13] Adding logging callback. --- src/dcap_provider.cpp | 2 +- src/dcap_provider.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dcap_provider.cpp b/src/dcap_provider.cpp index 3b9194fe..314f3a70 100644 --- a/src/dcap_provider.cpp +++ b/src/dcap_provider.cpp @@ -2314,7 +2314,7 @@ extern "C" quote3_error_t sgx_ql_set_logging_callback( return SGX_QL_SUCCESS; } -extern "C" quote3_error_t sgx_ql_free_quote_verification_collateral( +quote3_error_t ql_free_quote_verification_collateral( sgx_ql_qve_collateral_t* p_quote_collateral) { delete[] p_quote_collateral->pck_crl; diff --git a/src/dcap_provider.h b/src/dcap_provider.h index f544a106..152a83f0 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -4,7 +4,7 @@ #ifdef __LINUX__ #include "sgx_ql_lib_common.h" #else -#include "Windows\ext\intel\sgx_ql_lib_common.h" +#include "sgx_ql_lib_common.h" #endif #pragma once From 7511bbf7aa453950730e7b57fce7fc50f1a9fda1 Mon Sep 17 00:00:00 2001 From: Gunjan Munjal Date: Tue, 4 Jun 2024 17:36:00 +0530 Subject: [PATCH 13/13] Adding second param for sgx_ql_set_logging_callback --- src/UnitTest/test_quote_prov.cpp | 14 ++++++++++---- src/dcap_provider.cpp | 4 +++- src/dcap_provider.h | 3 ++- src/private.h | 1 + src/sgx_ql_lib_common.h | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/UnitTest/test_quote_prov.cpp b/src/UnitTest/test_quote_prov.cpp index 7d49060a..551a503c 100644 --- a/src/UnitTest/test_quote_prov.cpp +++ b/src/UnitTest/test_quote_prov.cpp @@ -128,6 +128,7 @@ static constexpr uint8_t TDX_TEST_FMSPC[] = const uint16_t custom_param_length = 45; const char* custom_param = "tcbEvaluationDataNumber=11;region=us central"; std::string tcbEvaluationDataNumber = "11"; +static const sgx_ql_log_level_t LEVEL_ERROR = SGX_QL_LOG_ERROR; const uint16_t incorrect_custom_param_length = 24; const char* incorrect_custom_param = "tcbEvaluationDataNum=11"; @@ -956,8 +957,11 @@ void ReloadLibrary(libary_type_t* library, bool set_logging_callback = true) #endif if (set_logging_callback) { - ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); + ASSERT_TRUE( + SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log)); + ASSERT_TRUE( + SGX_QL_SUCCESS == + sgx_ql_set_logging_callback(Log, SGX_QL_LOG_INFO)); } } @@ -1305,7 +1309,8 @@ TEST(testQuoteProv, quoteProviderTestsData) TEST(testQuoteProv, quoteProviderTestsV2DataFromService) { libary_type_t library = LoadFunctions(); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); + ASSERT_TRUE( + SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log, SGX_QL_LOG_INFO)); // // Get the data from the service @@ -1345,7 +1350,8 @@ TEST(testQuoteProv, quoteProviderTestsV2Data) TEST(testQuoteProv, quoteProviderTestsV3DataFromService) { libary_type_t library = LoadFunctions(); - ASSERT_TRUE(SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log)); + ASSERT_TRUE( + SGX_QL_SUCCESS == sgx_ql_set_logging_callback(Log, SGX_QL_LOG_INFO)); // // Get the data from the service diff --git a/src/dcap_provider.cpp b/src/dcap_provider.cpp index 314f3a70..36b75f8d 100644 --- a/src/dcap_provider.cpp +++ b/src/dcap_provider.cpp @@ -2308,9 +2308,11 @@ extern "C" sgx_plat_error_t sgx_ql_set_logging_function( } extern "C" quote3_error_t sgx_ql_set_logging_callback( - sgx_ql_logging_callback_t logger) + sgx_ql_logging_callback_t logger, + sgx_ql_log_level_t loglevel) { logger_callback = logger; + g_loglevel = loglevel; return SGX_QL_SUCCESS; } diff --git a/src/dcap_provider.h b/src/dcap_provider.h index 152a83f0..f45f6d80 100644 --- a/src/dcap_provider.h +++ b/src/dcap_provider.h @@ -128,6 +128,7 @@ const std::string customParam = "customParameter"; /// Set the callback used for recording log information. typedef quote3_error_t (*sgx_ql_set_logging_callback_t)( - sgx_ql_logging_callback_t logger); + sgx_ql_logging_callback_t logger, + sgx_ql_log_level_t loglevel); #endif // #ifndef PLATFORM_QUOTE_PROVIDER_H diff --git a/src/private.h b/src/private.h index 21f24535..8d2dea8c 100644 --- a/src/private.h +++ b/src/private.h @@ -10,6 +10,7 @@ extern sgx_ql_logging_function_t logger_function; extern sgx_ql_logging_callback_t logger_callback; +extern sgx_ql_log_level_t g_loglevel; /////////////////////////////////////////////////////////////////////////////// // Various internal functions which are not exported. diff --git a/src/sgx_ql_lib_common.h b/src/sgx_ql_lib_common.h index a5431d16..d5b34a1b 100644 --- a/src/sgx_ql_lib_common.h +++ b/src/sgx_ql_lib_common.h @@ -39,7 +39,7 @@ #ifndef _SGX_QL_LIB_COMMON_H_ #define _SGX_QL_LIB_COMMON_H_ -#include "sgx_key.h" +#include ".\Windows\ext\intel\sgx_key.h" #define SGX_QL_MK_ERROR(x) (0x0000E000|(x))