Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/msft gumunjal/adding logging callback function #156

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
126 changes: 63 additions & 63 deletions src/UnitTest/test_quote_prov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "../local_cache.h"
#include "dcap_provider.h"
#include "sgx_ql_lib_common.h"

#include <sys/stat.h>
#include <chrono>
Expand Down Expand Up @@ -104,7 +103,8 @@ 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_free_quote_verification_collateral_t
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
tdx_ql_free_quote_verification_collateral;
Expand All @@ -128,46 +128,45 @@ 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";

// 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 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;

Expand Down Expand Up @@ -250,8 +249,7 @@ static void* LoadFunctions()
abort();
}

sgx_ql_free_revocation_info =
reinterpret_cast<sgx_ql_free_revocation_info_t>(
sgx_ql_free_revocation_info = reinterpret_cast<sgx_ql_free_revocation_info_t>(
dlsym(library, "sgx_ql_free_revocation_info"));
EXPECT_NE(sgx_ql_free_revocation_info, nullptr);

Expand All @@ -267,13 +265,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_t>(
sgx_ql_set_logging_function = reinterpret_cast<sgx_ql_set_logging_function_t>(
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_free_quote_verification_collateral_t>(
sgx_ql_set_logging_callback = reinterpret_cast<sgx_ql_set_logging_callback_t>(
dlsym(library, "sgx_ql_set_logging_callback"));
EXPECT_NE(sgx_ql_set_logging_callback, nullptr);

sgx_ql_free_quote_verification_collateral = reinterpret_cast<sgx_ql_free_quote_verification_collateral_t>(
dlsym(library, "sgx_ql_free_quote_verification_collateral"));
EXPECT_NE(sgx_ql_free_quote_verification_collateral, nullptr);

Expand All @@ -297,6 +297,7 @@ static void* LoadFunctions()

sgx_ql_get_quote_verification_collateral =
reinterpret_cast<sgx_ql_get_quote_verification_collateral_t>(

dlsym(library, "sgx_ql_get_quote_verification_collateral"));
EXPECT_NE(sgx_ql_get_quote_verification_collateral, nullptr);

Expand Down Expand Up @@ -326,8 +327,7 @@ static HINSTANCE LoadFunctions()
abort();
}

sgx_ql_free_revocation_info =
reinterpret_cast<sgx_ql_free_revocation_info_t>(
sgx_ql_free_revocation_info = reinterpret_cast<sgx_ql_free_revocation_info_t>(
GetProcAddress(hLibCapdll, "sgx_ql_free_revocation_info"));
EXPECT_NE(sgx_ql_free_revocation_info, nullptr);

Expand All @@ -343,15 +343,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_t>(
sgx_ql_set_logging_function = reinterpret_cast<sgx_ql_set_logging_function_t>(
GetProcAddress(hLibCapdll, "sgx_ql_set_logging_function"));
EXPECT_NE(sgx_ql_set_logging_function, nullptr);

sgx_ql_free_quote_verification_collateral =
reinterpret_cast<sgx_ql_free_quote_verification_collateral_t>(
GetProcAddress(
hLibCapdll, "sgx_ql_free_quote_verification_collateral"));
sgx_ql_set_logging_callback = reinterpret_cast<sgx_ql_set_logging_callback_t>(
GetProcAddress(hLibCapdll, "sgx_ql_set_logging_callback"));
EXPECT_NE(sgx_ql_set_logging_callback, nullptr);

sgx_ql_free_quote_verification_collateral = reinterpret_cast<sgx_ql_free_quote_verification_collateral_t>(
GetProcAddress(hLibCapdll, "sgx_ql_free_quote_verification_collateral"));
EXPECT_NE(sgx_ql_free_quote_verification_collateral, nullptr);

tdx_ql_free_quote_verification_collateral =
Expand All @@ -368,10 +369,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<sgx_ql_get_quote_verification_collateral_t>(
GetProcAddress(
hLibCapdll, "sgx_ql_get_quote_verification_collateral"));
sgx_ql_get_quote_verification_collateral = reinterpret_cast<sgx_ql_get_quote_verification_collateral_t>(
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<
Expand Down Expand Up @@ -958,7 +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_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log));
ASSERT_TRUE(
SGX_QL_SUCCESS ==
sgx_ql_set_logging_callback(Log, SGX_QL_LOG_INFO));
}
}

Expand Down Expand Up @@ -1290,7 +1293,6 @@ TEST(testQuoteProv, quoteProviderTestsData)
{
libary_type_t library = LoadFunctions();
ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log));

//
// Get the data from the service
//
Expand All @@ -1307,7 +1309,8 @@ 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, SGX_QL_LOG_INFO));

//
// Get the data from the service
Expand All @@ -1329,7 +1332,6 @@ TEST(testQuoteProv, quoteProviderTestsV2Data)
{
libary_type_t library = LoadFunctions();
ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log));

//
// Get the data from the service
//
Expand All @@ -1348,7 +1350,8 @@ 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, SGX_QL_LOG_INFO));

//
// Get the data from the service
Expand All @@ -1371,7 +1374,6 @@ TEST(testQuoteProv, quoteProviderTestsV3Data)
{
libary_type_t library = LoadFunctions();
ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log));

//
// Get the data from the service
//
Expand Down Expand Up @@ -1429,7 +1431,6 @@ TEST(testQuoteProv, testWithoutLogging)
{
libary_type_t library = LoadFunctions();
ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log));

//
// Get the data from the service
//
Expand All @@ -1449,7 +1450,6 @@ TEST(testQuoteProv, testRestrictAccessToFilesystem)
{
libary_type_t library = LoadFunctions();
ASSERT_TRUE(SGX_PLAT_ERROR_OK == sgx_ql_set_logging_function(Log));

//
// Get the data from the service
//
Expand Down
1 change: 1 addition & 0 deletions src/Windows/dcap_provider_tests/easy_curl_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void DefaultLogCallback(sgx_ql_log_level_t level, const char* message)

TEST_MODULE_INITIALIZE(InitializeModule)
{
logger_function = DefaultLogCallback;
logger_callback = DefaultLogCallback;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Windows/dll/dcap_provider.def
Original file line number Diff line number Diff line change
Expand Up @@ -16,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
12 changes: 10 additions & 2 deletions src/dcap_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <vector>
#include <unordered_map>

#include "sgx_ql_lib_common.h"
#include "environment.h"

#ifdef __LINUX__
Expand Down Expand Up @@ -2304,10 +2303,19 @@ 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;
}

extern "C" quote3_error_t sgx_ql_set_logging_callback(
sgx_ql_logging_callback_t logger,
sgx_ql_log_level_t loglevel)
{
logger_callback = logger;
g_loglevel = loglevel;
return SGX_QL_SUCCESS;
}

quote3_error_t ql_free_quote_verification_collateral(
sgx_ql_qve_collateral_t* p_quote_collateral)
{
Expand Down
17 changes: 15 additions & 2 deletions src/dcap_provider.h
Original file line number Diff line number Diff line change
@@ -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 "sgx_ql_lib_common.h"
#endif

#pragma once
#ifndef PLATFORM_QUOTE_PROVIDER_H
#define PLATFORM_QUOTE_PROVIDER_H
Expand Down Expand Up @@ -112,10 +118,17 @@ 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);
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_callback_t logger,
sgx_ql_log_level_t loglevel);

#endif // #ifndef PLATFORM_QUOTE_PROVIDER_H
Loading
Loading