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

Implement changes for registrar call #158

Merged
merged 5 commits into from
Mar 9, 2021
Merged

Conversation

lkatalin
Copy link
Contributor

@lkatalin lkatalin commented Feb 4, 2021

This PR adds relevant prerequisites and then uses create_ek() to retrieve the EK cert and pubkey and adds functions to retrieve the AK pubkey as well. It sends all of this data to the registrar. Much of it was written or co-written by @lukehinds so I have included him on those commits. Supersedes #149 .

Fixes #119
Fixes #95

@lukehinds @puiterwijk I'm especially interested in making sure the create_ak() function is correct.

src/main.rs Show resolved Hide resolved
@lkatalin lkatalin force-pushed the registrar branch 5 times, most recently from 3fc62de to 152c848 Compare February 4, 2021 19:12
@lkatalin lkatalin requested a review from ashcrow February 4, 2021 19:28
@lkatalin lkatalin marked this pull request as ready for review February 4, 2021 19:29
@ashcrow
Copy link
Contributor

ashcrow commented Feb 4, 2021

This looks good from my POV!

Copy link
Member

@puiterwijk puiterwijk left a comment

Choose a reason for hiding this comment

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

Unfortunately, the types are somewhat vague, so we'll need some fixes :(.
I'll send you my fixes so you can use that.


#[derive(Debug, Serialize, Deserialize)]
pub struct Register<'a> {
ek: &'a [u8],
Copy link
Member

Choose a reason for hiding this comment

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

This is an str, since it's PEM encoded

ekcert: &'a [u8],
#[serde(serialize_with = "serialize_as_base64")]
ek_tpm: &'a [u8],
aik: &'a [u8],
Copy link
Member

Choose a reason for hiding this comment

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

This is &str as well.

.json(&data)
.send()
.await?
.json()
Copy link
Member

Choose a reason for hiding this comment

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

This will fail if the server returned an error, because then code is non-200 and status is not success, and it won't have a results block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the status code check to be before this .json() is called and just used the built-in reqwest::StatusCode method.

@lkatalin lkatalin marked this pull request as draft February 10, 2021 22:33
@lkatalin lkatalin marked this pull request as ready for review February 25, 2021 17:12
@lkatalin
Copy link
Contributor Author

@puiterwijk Let me know when you have a good idea of the changes you have / want on this one in addition to your comments above.

@lkatalin lkatalin force-pushed the registrar branch 2 times, most recently from b914ab6 to 01e6c2a Compare February 26, 2021 01:15
@lkatalin lkatalin requested a review from puiterwijk February 26, 2021 01:31
@keylime-bot keylime-bot assigned ashcrow and unassigned lkatalin Feb 26, 2021
@lkatalin lkatalin force-pushed the registrar branch 2 times, most recently from 2f81d37 to 5fa2f9a Compare March 3, 2021 01:00
let resp = reqwest::Client::new().put(&addr).json(&data).send().await?;

if !resp.status().is_success() {
return Err(anyhow!(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it makes sense to use one of our custom error types here instead of anyhow? I could see a case for either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up using a custom type so that we can check the status codes.

config_get("/etc/keylime.conf", "cloud_agent", "agent_uuid")?;
let agent_uuid = get_uuid(&agent_uuid_config);

{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@puiterwijk What is the purpose of this bracket? I believe this is from your changes.

Copy link
Member

Choose a reason for hiding this comment

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

that does not look like a strange scope, is the compiler not complaining about this?

Copy link
Member

Choose a reason for hiding this comment

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

So, that was a bracket I put in place to make the scope for keyblob smaller. That means that outside of the closing bracket, the keyblob is no longer valid.
Given that the Rust compiler calls drop as soon as something goes out of scope, that means that as soon as the closing bracket is hit, the keyblob is erased from memory (since it's Zeroize).

Copy link
Member

Choose a reason for hiding this comment

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

This was basically because this activation step is in the main() function, which keeps running until the entire agent terminates.
And I didn't want to have secrets lingering in memory during the full runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! Good thinking.

lkatalin and others added 5 commits March 4, 2021 16:59
Signed-off-by: Lily Sturmann <[email protected]>
Co-authored-by: Luke Hinds <[email protected]>
Signed-off-by: Lily Sturmann <[email protected]>
Co-authored-by: Luke Hinds <[email protected]>,
Patrick Uiterwijk <[email protected]>
Signed-off-by: Lily Sturmann <[email protected]>
Co-authored-by: Luke Hinds <[email protected]>
Signed-off-by: Lily Sturmann <[email protected]>
Co-authored-by: Patrick Uiterwijk <[email protected]>
Signed-off-by: Lily Sturmann <[email protected]>
Co-authored-by: Luke Hinds <[email protected]>,
Patrick Uiterwijk <[email protected]>
@lkatalin
Copy link
Contributor Author

lkatalin commented Mar 4, 2021

I've added some unit testing for do_register_agent and do_activate_agent. I ended up using wiremock for this, as it's better documented than reqwest_mock and seems to have more features (not just a client, etc.).

config_get("/etc/keylime.conf", "cloud_agent", "agent_uuid")?;
let agent_uuid = get_uuid(&agent_uuid_config);

{
Copy link
Member

Choose a reason for hiding this comment

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

that does not look like a strange scope, is the compiler not complaining about this?

&auth_tag,
)
.await?;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is the closing bracket: after we activate, we no longer need keyblob.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I did notice it created its own scope that lasted until this line, I just wasn't sure why.

@lkatalin lkatalin requested a review from puiterwijk March 9, 2021 16:03
Copy link
Member

@puiterwijk puiterwijk left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@lkatalin lkatalin merged commit 23cd0d0 into keylime:master Mar 9, 2021
@lkatalin lkatalin deleted the registrar branch July 16, 2021 17:16
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.

Create AIK Implement Agent registration
4 participants