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

Calling into thim agent to get collateral. #149

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
9 changes: 7 additions & 2 deletions src/Linux/curl_easy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ char const* curl_easy::error::what() const noexcept
///////////////////////////////////////////////////////////////////////////////
// curl_easy implementation
///////////////////////////////////////////////////////////////////////////////
std::unique_ptr<curl_easy> curl_easy::create(const std::string& url, const std::string* const p_body)
std::unique_ptr<curl_easy> curl_easy::create(const std::string& url, const std::string* const p_body, LPCWSTR httpVerb))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why use LPCWSTR instead of const std::string& ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for this file is to keep the structure consistent with the other curl_easy.cpp file(in src/Windows). The variable is used by "WinHttpOpenRequest" in src/Windows/curl_easy.cpp file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is Linux specific. Other parameters are std::string, so not appreciating the need for consistency with the windows version

Copy link
Collaborator Author

@msft-gumunjal msft-gumunjal Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is used by "WinHttpOpenRequest" and the data type is supposed to be "LPCWSTR". Either I can pass a string to the function and then convert it inside the function or just pass the desired data type. I chose the latter one because I thought that's the better out of the two. I can update if required.

{
std::unique_ptr<curl_easy> easy(new curl_easy);

Expand All @@ -92,7 +92,12 @@ std::unique_ptr<curl_easy> curl_easy::create(const std::string& url, const std::

if (p_body != nullptr && !p_body->empty())
{
easy->set_opt_or_throw(CURLOPT_CUSTOMREQUEST, "GET");
if (httpVerb == L"POST") {
msft-gumunjal marked this conversation as resolved.
Show resolved Hide resolved
easy->set_opt_or_throw(CURLOPT_POST, 1L);
}
else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we have a style checker integrated into the VS solution. If we do and it passes, then ignore this comment. The convention I see in other parts of the file is to throw opening curly braces on the line after the if/else statement. We should probably keep doing that to stay consistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we have a style checker. Let me try to add one.

easy->set_opt_or_throw(CURLOPT_HTTPGET, 1L);
}
easy->set_opt_or_throw(CURLOPT_COPYPOSTFIELDS, p_body->c_str());
}

Expand Down
5 changes: 4 additions & 1 deletion src/Linux/curl_easy.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class curl_easy
char function[128]{};
};

static std::unique_ptr<curl_easy> create(const std::string& url, const std::string* const p_body);
static std::unique_ptr<curl_easy> create(
const std::string& url,
const std::string* const p_body,
LPCWSTR httpVerb = L"GET");

~curl_easy();

Expand Down
14 changes: 11 additions & 3 deletions src/UnitTest/test_quote_prov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ static void GetCrlTest()
{
// This is the CRL DP used by Intel for leaf certs
static const char* TEST_CRL_URL =
"https://api.trustedservices.intel.com/sgx/certification/v1/"
"https://api.trustedservices.intel.com/sgx/certification/v3/"
"pckcrl?ca=processor";

sgx_ql_get_revocation_info_params_t params = {
Expand Down Expand Up @@ -927,7 +927,11 @@ void SetupEnvironment(std::string version)
#if defined __LINUX__
setenv(
"AZDCAP_BASE_CERT_URL",
"https://global.acccache.azure.net/sgx/certificates",
"https://global.acccache.azure.net/sgx/certificates/",
1);
setenv(
"AZDCAP_THIM_AGENT_URL",
"http://127.0.0.1:90/metadata/THIM/sgx/certificates?",
1);
setenv("AZDCAP_CLIENT_ID", "AzureDCAPTestsLinux", 1);
if (!version.empty())
Expand All @@ -943,7 +947,10 @@ void SetupEnvironment(std::string version)
}
EXPECT_TRUE(SetEnvironmentVariableA(
"AZDCAP_BASE_CERT_URL",
"https://global.acccache.azure.net/sgx/certificates"));
"https://global.acccache.azure.net/sgx/certificates/"));
EXPECT_TRUE(SetEnvironmentVariableA(
"AZDCAP_THIM_AGENT_URL",
"http://127.0.0.1:90/metadata/THIM/sgx/certificates?"));
EXPECT_TRUE(
SetEnvironmentVariableA("AZDCAP_CLIENT_ID", "AzureDCAPTestsWindows"));
#endif
Expand Down Expand Up @@ -997,6 +1004,7 @@ TEST(testQuoteProv, quoteProviderTestsV2DataFromService)
// Get the data from the service
//
SetupEnvironment("v2");

ASSERT_TRUE(RunQuoteProviderTests());
ASSERT_TRUE(GetQveIdentityTest());

Expand Down
13 changes: 8 additions & 5 deletions src/Windows/curl_easy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
///////////////////////////////////////////////////////////////////////////////
// Constants
///////////////////////////////////////////////////////////////////////////////
static constexpr int maximum_retries = 5;
static constexpr int initial_retry_delay_ms = 20;
static constexpr int maximum_retries = 3;
static constexpr int initial_retry_delay_ms = 2000;
static constexpr WCHAR content_type_header[] =
L"Content-Type: application/json";

Expand Down Expand Up @@ -128,7 +128,9 @@ std::wstring UnicodeStringFromUtf8String(_In_ const std::string& ansiString)
///////////////////////////////////////////////////////////////////////////////
std::unique_ptr<curl_easy> curl_easy::create(
const std::string& url,
const std::string* const p_body)
const std::string* const p_body,
DWORD dwFlags,
LPCWSTR httpVerb)
{
struct make_unique_enabler : public curl_easy
{
Expand Down Expand Up @@ -191,12 +193,12 @@ std::unique_ptr<curl_easy> curl_easy::create(

curl->request.reset(WinHttpOpenRequest(
curl->connectionHandle.get(),
L"GET",
httpVerb,
urlToRetrieve.c_str(),
nullptr,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE));
dwFlags));

if (!curl->request)
{
Expand Down Expand Up @@ -419,6 +421,7 @@ void curl_easy::set_headers(
}
}


int8_t Int8FromHexAscii(char ch)
{
int8_t byteValue;
Expand Down
4 changes: 3 additions & 1 deletion src/Windows/curl_easy.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class curl_easy
};
static std::unique_ptr<curl_easy> create(
const std::string& url,
const std::string* const p_body);
const std::string* const p_body,
DWORD dwFlags = WINHTTP_FLAG_SECURE,
LPCWSTR httpVerb = L"GET");

~curl_easy();

Expand Down
Loading