Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Matthews <[email protected]>
  • Loading branch information
Isaac-Matthews committed Sep 19, 2023
1 parent 418902f commit 3201cd3
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 184 deletions.
28 changes: 22 additions & 6 deletions keylime-agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,28 @@ impl EnvConfig {
_ = agent.insert("ek_handle".to_string(), v.to_string().into());
}
if let Some(ref v) = self.enable_iak_idevid {
_ = agent.insert("enable_iak_idevid".to_string(), v.to_string().into());
_ = agent.insert(
"enable_iak_idevid".to_string(),
v.to_string().into(),
);
}
if let Some(ref v) = self.iak_idevid_asymmetric_alg {
_ = agent.insert("iak_idevid_asymmetric_alg".to_string(), v.to_string().into());
_ = agent.insert(
"iak_idevid_asymmetric_alg".to_string(),
v.to_string().into(),
);
}
if let Some(ref v) = self.iak_idevid_name_alg {
_ = agent.insert("iak_idevid_name_alg".to_string(), v.to_string().into());
_ = agent.insert(
"iak_idevid_name_alg".to_string(),
v.to_string().into(),
);
}
if let Some(ref v) = self.iak_idevid_template {
_ = agent.insert("iak_idevid_template".to_string(), v.to_string().into());
_ = agent.insert(
"iak_idevid_template".to_string(),
v.to_string().into(),
);
}
if let Some(ref v) = self.run_as {
_ = agent.insert("run_as".to_string(), v.to_string().into());
Expand Down Expand Up @@ -545,7 +557,8 @@ impl Default for AgentConfig {
tpm_ownerpassword: DEFAULT_TPM_OWNERPASSWORD.to_string(),
ek_handle: DEFAULT_EK_HANDLE.to_string(),
enable_iak_idevid: DEFAULT_ENABLE_IAK_IDEVID,
iak_idevid_asymmetric_alg: DEFAULT_IAK_IDEVID_ASYMMETRIC_ALG.to_string(),
iak_idevid_asymmetric_alg: DEFAULT_IAK_IDEVID_ASYMMETRIC_ALG
.to_string(),
iak_idevid_name_alg: DEFAULT_IAK_IDEVID_NAME_ALG.to_string(),
iak_idevid_template: DEFAULT_IAK_IDEVID_TEMPLATE.to_string(),
}
Expand Down Expand Up @@ -1016,7 +1029,10 @@ mod tests {
("TPM_SIGNING_ALG", "override_tpm_signing_alg"),
("EK_HANDLE", "override_ek_handle"),
("ENABLE_IAK_IDEVID", "true"),
("IAK_IDEVID_ASYMMETRIC_ALG", "override_iak_idevid_asymmetric_alg"),
(
"IAK_IDEVID_ASYMMETRIC_ALG",
"override_iak_idevid_asymmetric_alg",
),
("IAK_IDEVID_NAME_ALG", "override_iak_idevid_name_alg"),
("IAK_IDEVID_TEMPLATE", "override_iak_idevid_template"),
("RUN_AS", "override_run_as"),
Expand Down
32 changes: 23 additions & 9 deletions keylime-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use tss_esapi::{
handles::KeyHandle,
interface_types::algorithm::{AsymmetricAlgorithm, HashingAlgorithm},
interface_types::resource_handles::Hierarchy,
structures::{Auth, PublicBuffer, Data, Digest, MaxBuffer},
structures::{Auth, Data, Digest, MaxBuffer, PublicBuffer},
traits::Marshall,
Context,
};
Expand Down Expand Up @@ -437,7 +437,11 @@ async fn main() -> Result<()> {

let (attest, signature) = if config.agent.enable_iak_idevid {
let qualifying_data = config.agent.uuid.as_bytes();
let (attest, signature) = ctx.certify_credential_with_iak(Data::try_from(qualifying_data).unwrap(), ak_handle, iak.as_ref().unwrap().handle)?;
let (attest, signature) = ctx.certify_credential_with_iak(
Data::try_from(qualifying_data).unwrap(),
ak_handle,
iak.as_ref().unwrap().handle,
)?;
info!("AK certified with IAK.");

// // For debugging certify(), the following checks the generated signature
Expand Down Expand Up @@ -563,28 +567,37 @@ async fn main() -> Result<()> {

{
// Request keyblob material
let keyblob = if config.agent.enable_iak_idevid{
let keyblob = if config.agent.enable_iak_idevid {
registrar_agent::do_register_agent(
config.agent.registrar_ip.as_ref(),
config.agent.registrar_port,
&agent_uuid,
&PublicBuffer::try_from(ek_result.public.clone())?.marshall()?,
&PublicBuffer::try_from(ek_result.public.clone())?
.marshall()?,
ek_result.ek_cert,
&PublicBuffer::try_from(ak.public)?.marshall()?,
Some(&PublicBuffer::try_from(iak.unwrap().public.clone())?.marshall()?),
Some(&PublicBuffer::try_from(idevid.unwrap().public.clone())?.marshall()?),
Some(
&PublicBuffer::try_from(iak.unwrap().public.clone())?
.marshall()?,
),
Some(
&PublicBuffer::try_from(idevid.unwrap().public.clone())?
.marshall()?,
),
Some(attest.unwrap().marshall()?),
Some(signature.unwrap().marshall()?),
mtls_cert,
config.agent.contact_ip.as_ref(),
config.agent.contact_port,
).await?
)
.await?
} else {
registrar_agent::do_register_agent(
config.agent.registrar_ip.as_ref(),
config.agent.registrar_port,
&agent_uuid,
&PublicBuffer::try_from(ek_result.public.clone())?.marshall()?,
&PublicBuffer::try_from(ek_result.public.clone())?
.marshall()?,
ek_result.ek_cert,
&PublicBuffer::try_from(ak.public)?.marshall()?,
None,
Expand All @@ -594,7 +607,8 @@ async fn main() -> Result<()> {
mtls_cert,
config.agent.contact_ip.as_ref(),
config.agent.contact_port,
).await?
)
.await?
};

info!("SUCCESS: Agent {} registered", &agent_uuid);
Expand Down
20 changes: 16 additions & 4 deletions keylime-agent/src/registrar_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ struct Register<'a> {
ek_tpm: &'a [u8],
#[serde(serialize_with = "serialize_as_base64")]
aik_tpm: &'a [u8],
#[serde(serialize_with = "serialize_option_base64", skip_serializing_if = "Option::is_none")]
#[serde(
serialize_with = "serialize_option_base64",
skip_serializing_if = "Option::is_none"
)]
iak_tpm: Option<&'a [u8]>,
#[serde(serialize_with = "serialize_option_base64", skip_serializing_if = "Option::is_none")]
#[serde(
serialize_with = "serialize_option_base64",
skip_serializing_if = "Option::is_none"
)]
idevid_tpm: Option<&'a [u8]>,
#[serde(serialize_with = "serialize_maybe_base64", skip_serializing_if = "Option::is_none")]
#[serde(
serialize_with = "serialize_maybe_base64",
skip_serializing_if = "Option::is_none"
)]
iak_attest: Option<Vec<u8>>,
#[serde(serialize_with = "serialize_maybe_base64", skip_serializing_if = "Option::is_none")]
#[serde(
serialize_with = "serialize_maybe_base64",
skip_serializing_if = "Option::is_none"
)]
iak_sign: Option<Vec<u8>>,
#[serde(skip_serializing_if = "Option::is_none")]
mtls_cert: Option<String>,
Expand Down
Loading

0 comments on commit 3201cd3

Please sign in to comment.