Skip to content

Commit

Permalink
OK
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Dec 16, 2024
1 parent 12ed712 commit 3a6ea7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 54 deletions.
6 changes: 3 additions & 3 deletions app/src/commands/enclave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ fn run_list_keys<E: EnclaveCommandAPI<S>, S: CommitStore>(
"type": "dcap",
"address": eki.address.to_hex_string(),
"attested": true,
"report_data": dcap_quote.report_data().to_string(),
"isv_enclave_quote_status": dcap_quote.tcb_status.to_string(),
"report_data": dcap_quote.report_data()?.to_string(),
"isv_enclave_quote_status": dcap_quote.tcb_status,
"advisory_ids": dcap_quote.advisory_ids,
"attested_at": dcap_quote.attested_at,
"attested_at": dcap_quote.attested_at.to_string(),
}});
} else {
list_json.push(json! {{
Expand Down
55 changes: 4 additions & 51 deletions modules/attestation-report/src/dcap.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,18 @@
use crate::prelude::*;
use crate::serde_base64;
use crate::Error;
use crate::ReportData;
use lcp_types::Time;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct DCAPQuote {
#[serde(with = "serde_base64")]
pub raw: Vec<u8>,
pub tcb_status: TcbStatus,
pub tcb_status: String,
pub advisory_ids: Option<Vec<String>>,
pub attested_at: Time,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TcbStatus {
OK,
TcbSwHardeningNeeded,
TcbConfigurationAndSwHardeningNeeded,
TcbConfigurationNeeded,
TcbOutOfDate,
TcbOutOfDateConfigurationNeeded,
TcbRevoked,
TcbUnrecognized,
}

impl TcbStatus {
pub fn from_str(s: &str) -> Self {
return match s {
"UpToDate" => TcbStatus::OK,
"SWHardeningNeeded" => TcbStatus::TcbSwHardeningNeeded,
"ConfigurationAndSWHardeningNeeded" => TcbStatus::TcbConfigurationAndSwHardeningNeeded,
"ConfigurationNeeded" => TcbStatus::TcbConfigurationNeeded,
"OutOfDate" => TcbStatus::TcbOutOfDate,
"OutOfDateConfigurationNeeded" => TcbStatus::TcbOutOfDateConfigurationNeeded,
"Revoked" => TcbStatus::TcbRevoked,
_ => TcbStatus::TcbUnrecognized,
};
}
}

impl ToString for TcbStatus {
fn to_string(&self) -> String {
return match self {
TcbStatus::OK => "UpToDate".to_string(),
TcbStatus::TcbSwHardeningNeeded => "SWHardeningNeeded".to_string(),
TcbStatus::TcbConfigurationAndSwHardeningNeeded => {
"ConfigurationAndSWHardeningNeeded".to_string()
}
TcbStatus::TcbConfigurationNeeded => "ConfigurationNeeded".to_string(),
TcbStatus::TcbOutOfDate => "OutOfDate".to_string(),
TcbStatus::TcbOutOfDateConfigurationNeeded => {
"OutOfDateConfigurationNeeded".to_string()
}
TcbStatus::TcbRevoked => "Revoked".to_string(),
TcbStatus::TcbUnrecognized => "Unrecognized".to_string(),
};
}
}

impl DCAPQuote {
pub fn new(
raw_quote: Vec<u8>,
Expand All @@ -69,7 +22,7 @@ impl DCAPQuote {
) -> Self {
DCAPQuote {
raw: raw_quote,
tcb_status: TcbStatus::from_str(&tcb_status),
tcb_status,
advisory_ids,
attested_at,
}
Expand All @@ -84,9 +37,9 @@ impl DCAPQuote {
}

#[cfg(feature = "std")]
pub fn report_data(&self) -> ReportData {
pub fn report_data(&self) -> Result<crate::ReportData, Error> {
use dcap_rs::types::quotes::version_3::QuoteV3;
let quote = QuoteV3::from_bytes(&self.raw);
ReportData(quote.isv_enclave_report.report_data)
Ok(crate::ReportData(quote.isv_enclave_report.report_data))
}
}

0 comments on commit 3a6ea7d

Please sign in to comment.