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

Conversation

msft-gumunjal
Copy link
Collaborator

  1. Adding call to thim agent for Get cert collateral.
  2. Updating the API call to THIM service to use the new noauth API introduced in the service.

Testing:

  1. Unit tests pass on Windows.

@msft-gumunjal msft-gumunjal marked this pull request as draft September 9, 2021 23:27
Copy link

@sidse-msft sidse-msft left a comment

Choose a reason for hiding this comment

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

First pass through code. I haven't looked at every file yet; wanted to get some of these resolved before doing another pass.

@@ -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.

src/Linux/curl_easy.cpp Outdated Show resolved Hide resolved
if (httpVerb == L"POST") {
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.

static char DEFAULT_CERT_URL[] =
"https://global.acccache.azure.net/sgx/certificates";
"https://global.acccache.azure.net/sgx/certificates/";

Choose a reason for hiding this comment

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

Once THIM Service deploys new controller to align with Intel, this should be updated. The final URL will be like:
https://global.acccache.azure.net/sgx/certification/v3/pckcert?qeid={}&cpusvn={}&pcesvn={}&pceid={}&encrypted_ppid={}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed! I coded this based on the current prod code. Will update this

Copy link
Collaborator

@Shivr-ctrl Shivr-ctrl Oct 20, 2021

Choose a reason for hiding this comment

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

The new URL is available now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey guys -- I see we've changed from certificates to "certification" -- in the last correspondence I read I saw
image
The ask was Thim agent to use "certificates" like THIM Service did.
-- Do I need to make a change to thim agent to stay consistent here then? I wasn't aware of this. Apologies if I missed something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No change needed, certificates is fine here.

src/dcap_provider.cpp Outdated Show resolved Hide resolved
src/dcap_provider.h Show resolved Hide resolved
src/dcap_provider.cpp Show resolved Hide resolved
@@ -54,12 +54,15 @@ static const std::map<std::string, std::string> default_values = {
// New API version used to request PEM encoded CRLs
constexpr char API_VERSION_LEGACY[] = "api-version=2018-10-01-preview";
constexpr char API_VERSION[] = "api-version=2020-02-12-preview";
Copy link

@sidse-msft sidse-msft Sep 13, 2021

Choose a reason for hiding this comment

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

We have a new API version for the THIM Agent APIs. However, I want to confirm -- what format CRL does Azure DCAP want now? It says 'New API version used to request PEM encoded CRLs', but I recall Shiv saying the new versions of DCAP expect DER, so I'm a bit confused.

Suggested change
constexpr char API_VERSION[] = "api-version=2020-02-12-preview";
constexpr char API_VERSION[] = "api-version=2021-07-22-preview";

Copy link

@sidse-msft sidse-msft Sep 13, 2021

Choose a reason for hiding this comment

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

Scratch that. I think what you might want to do is:
constexpr char API_VERSION_THIM_AGENT[] = "api-version=2021-07-22-preview";

You can use the new API version for the GetCert calls, and the existing API versions for the other collateral.

@@ -135,6 +138,25 @@ static std::string get_collateral_version()
}
}

static std::string get_agent_base_url()

Choose a reason for hiding this comment

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

Is this function necessary? It made sense with THIM cloud service because we could test different cloud endpoints (e.g. Europe vs. Americas). But THIM Agent will always be hosted at the same local IP address.

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 think this will be useful for dev box testing with IMDS and THIM agent running on the dev box.

src/dcap_provider.cpp Outdated Show resolved Hide resolved
static char DEFAULT_CERT_URL[] =
"https://global.acccache.azure.net/sgx/certificates";
"https://global.acccache.azure.net/sgx/certificates/";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey guys -- I see we've changed from certificates to "certification" -- in the last correspondence I read I saw
image
The ask was Thim agent to use "certificates" like THIM Service did.
-- Do I need to make a change to thim agent to stay consistent here then? I wasn't aware of this. Apologies if I missed something

src/dcap_provider.cpp Show resolved Hide resolved
const std::string cert_url = build_pck_cert_url(*p_pck_cert_id);
if (auto cache_hit = try_cache_get(cert_url))
collateral_fetch_url collateral_url;
build_pck_cert_url(*p_pck_cert_id, &collateral_url);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason this was done as a pointer instead of just as a reference?
You currently have it as:
build_pck_cert_url(..., &collateral_url) -- To satisfy ---- build_pck_cert_url(...., collateral_fetch_url* url)

Why not just use it as a reference?
build_pck_cert_url(..., collateral_url) -- To satisfy ---- build_pck_cert_url(...., collateral_fetch_url& url)

Your end result is the same but you don't end up having to worry about NULL issues and it seems like your goal is to update the existing variable here so my recommendation is to pass by reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This part of code was already there. I don't want to change whats already there, just adding functionality to call into THIM agent in this PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've added another comment above to indicate what I think you're adding in. Please let me know if I have some misunderstanding.

src/dcap_provider.cpp Outdated Show resolved Hide resolved
src/dcap_provider.cpp Outdated Show resolved Hide resolved
static std::string build_pck_cert_url(const sgx_ql_pck_cert_id_t& pck_cert_id)
static void build_pck_cert_url(
const sgx_ql_pck_cert_id_t& pck_cert_id,
collateral_fetch_url* collateral_url)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the part im referencing below. It doesn't seem legacy, it seems like you've introduced it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants