Skip to content

Commit 12ed712

Browse files
committed
WIP
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent e790481 commit 12ed712

File tree

8 files changed

+110
-34
lines changed

8 files changed

+110
-34
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/commands/enclave.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,37 @@ fn run_list_keys<E: EnclaveCommandAPI<S>, S: CommitStore>(
121121
};
122122
let mut list_json = Vec::new();
123123
for eki in list {
124-
match eki.ias_report {
125-
Some(ias_report) => {
126-
let avr = ias_report.get_avr()?;
127-
let report_data = avr.parse_quote()?.report_data();
128-
list_json.push(json! {{
129-
"address": eki.address.to_hex_string(),
130-
"attested": true,
131-
"report_data": report_data.to_string(),
132-
"isv_enclave_quote_status": avr.isv_enclave_quote_status,
133-
"advisory_ids": avr.advisory_ids,
134-
"attested_at": avr.timestamp
135-
}});
136-
}
137-
None => {
138-
list_json.push(json! {{
139-
"address": eki.address.to_hex_string(),
140-
"attested": false,
141-
}});
142-
}
124+
let ias_attested = eki.ias_report.is_some();
125+
let dcap_attested = eki.dcap_quote.is_some();
126+
127+
if ias_attested {
128+
let avr = eki.ias_report.as_ref().unwrap().get_avr()?;
129+
let report_data = avr.parse_quote()?.report_data();
130+
list_json.push(json! {{
131+
"type": "ias",
132+
"address": eki.address.to_hex_string(),
133+
"attested": true,
134+
"report_data": report_data.to_string(),
135+
"isv_enclave_quote_status": avr.isv_enclave_quote_status,
136+
"advisory_ids": avr.advisory_ids,
137+
"attested_at": avr.timestamp
138+
}});
139+
} else if dcap_attested {
140+
let dcap_quote = eki.dcap_quote.as_ref().unwrap();
141+
list_json.push(json! {{
142+
"type": "dcap",
143+
"address": eki.address.to_hex_string(),
144+
"attested": true,
145+
"report_data": dcap_quote.report_data().to_string(),
146+
"isv_enclave_quote_status": dcap_quote.tcb_status.to_string(),
147+
"advisory_ids": dcap_quote.advisory_ids,
148+
"attested_at": dcap_quote.attested_at,
149+
}});
150+
} else {
151+
list_json.push(json! {{
152+
"address": eki.address.to_hex_string(),
153+
"attested": false,
154+
}});
143155
}
144156
}
145157
println!("{}", serde_json::to_string(&list_json).unwrap());

modules/attestation-report/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ base64 = { version = "0.22.1", default-features = false, features = ["alloc"] }
1616
pem = { version = "2.0", default-features = false }
1717
webpki = { version = "0.22", features = ["alloc"] }
1818

19+
dcap-rs = { git = "https://github.com/bluele/dcap-rs", rev = "71fe1e02f151a28bf5661b01dba5096730564840", optional = true }
20+
1921
[dev-dependencies]
2022
tokio = { version = "1.0", default-features = false, features = ["macros"] }
2123

2224
[features]
2325
default = ["std"]
2426
std = [
27+
"dcap-rs",
2528
"webpki/std",
2629
"flex-error/std",
2730
"lcp-types/std",

modules/attestation-report/src/dcap.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,76 @@
11
use crate::prelude::*;
22
use crate::serde_base64;
33
use crate::Error;
4+
use crate::ReportData;
45
use lcp_types::Time;
56
use serde::{Deserialize, Serialize};
67

78
#[derive(Debug, Serialize, Deserialize)]
89
pub struct DCAPQuote {
910
#[serde(with = "serde_base64")]
1011
pub raw: Vec<u8>,
12+
pub tcb_status: TcbStatus,
13+
pub advisory_ids: Option<Vec<String>>,
1114
pub attested_at: Time,
1215
}
1316

17+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
18+
pub enum TcbStatus {
19+
OK,
20+
TcbSwHardeningNeeded,
21+
TcbConfigurationAndSwHardeningNeeded,
22+
TcbConfigurationNeeded,
23+
TcbOutOfDate,
24+
TcbOutOfDateConfigurationNeeded,
25+
TcbRevoked,
26+
TcbUnrecognized,
27+
}
28+
29+
impl TcbStatus {
30+
pub fn from_str(s: &str) -> Self {
31+
return match s {
32+
"UpToDate" => TcbStatus::OK,
33+
"SWHardeningNeeded" => TcbStatus::TcbSwHardeningNeeded,
34+
"ConfigurationAndSWHardeningNeeded" => TcbStatus::TcbConfigurationAndSwHardeningNeeded,
35+
"ConfigurationNeeded" => TcbStatus::TcbConfigurationNeeded,
36+
"OutOfDate" => TcbStatus::TcbOutOfDate,
37+
"OutOfDateConfigurationNeeded" => TcbStatus::TcbOutOfDateConfigurationNeeded,
38+
"Revoked" => TcbStatus::TcbRevoked,
39+
_ => TcbStatus::TcbUnrecognized,
40+
};
41+
}
42+
}
43+
44+
impl ToString for TcbStatus {
45+
fn to_string(&self) -> String {
46+
return match self {
47+
TcbStatus::OK => "UpToDate".to_string(),
48+
TcbStatus::TcbSwHardeningNeeded => "SWHardeningNeeded".to_string(),
49+
TcbStatus::TcbConfigurationAndSwHardeningNeeded => {
50+
"ConfigurationAndSWHardeningNeeded".to_string()
51+
}
52+
TcbStatus::TcbConfigurationNeeded => "ConfigurationNeeded".to_string(),
53+
TcbStatus::TcbOutOfDate => "OutOfDate".to_string(),
54+
TcbStatus::TcbOutOfDateConfigurationNeeded => {
55+
"OutOfDateConfigurationNeeded".to_string()
56+
}
57+
TcbStatus::TcbRevoked => "Revoked".to_string(),
58+
TcbStatus::TcbUnrecognized => "Unrecognized".to_string(),
59+
};
60+
}
61+
}
62+
1463
impl DCAPQuote {
15-
pub fn new(raw_quote: Vec<u8>, attested_at: Time) -> Self {
64+
pub fn new(
65+
raw_quote: Vec<u8>,
66+
tcb_status: String,
67+
advisory_ids: Option<Vec<String>>,
68+
attested_at: Time,
69+
) -> Self {
1670
DCAPQuote {
1771
raw: raw_quote,
72+
tcb_status: TcbStatus::from_str(&tcb_status),
73+
advisory_ids,
1874
attested_at,
1975
}
2076
}
@@ -26,4 +82,11 @@ impl DCAPQuote {
2682
pub fn from_json(json: &str) -> Result<Self, Error> {
2783
serde_json::from_str(json).map_err(Error::serde_json)
2884
}
85+
86+
#[cfg(feature = "std")]
87+
pub fn report_data(&self) -> ReportData {
88+
use dcap_rs::types::quotes::version_3::QuoteV3;
89+
let quote = QuoteV3::from_bytes(&self.raw);
90+
ReportData(quote.isv_enclave_report.report_data)
91+
}
2992
}

modules/attestation-report/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ define_error! {
2323
format_args!("unexpected report data version: expected={} actual={}", e.expected, e.actual)
2424
},
2525

26-
InvalidReportDataSize
27-
{
28-
size: usize
29-
}
30-
|e| {
31-
format_args!("invalid report data size: size must be >= 20, but got {}", e.size)
32-
},
33-
3426
MrenclaveMismatch
3527
{
3628
expected: Mrenclave,

modules/attestation-report/src/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl From<DCAPQuote> for VerifiableQuote {
3838
/// ReportData is a 64-byte value that is embedded in the Quote
3939
/// | version: 1 byte | enclave key: 20 bytes | operator: 20 bytes | nonce: 22 bytes |
4040
#[derive(Debug, Clone, PartialEq)]
41-
pub struct ReportData([u8; 64]);
41+
pub struct ReportData(pub(crate) [u8; 64]);
4242

4343
impl ReportData {
4444
/// Creates a new report data

modules/remote-attestation/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ reqwest = { version = "0.12.9", default-features = false, features = [
2525
] }
2626
urlencoding = { version = "2" }
2727

28-
dcap-rs = { git = "https://github.com/bluele/dcap-rs", rev = "43f60654515fb3000ebdc11ac80e1af9caba1ff9" }
28+
dcap-rs = { git = "https://github.com/bluele/dcap-rs", rev = "71fe1e02f151a28bf5661b01dba5096730564840" }
2929

3030
lcp-types = { path = "../types" }
3131
crypto = { path = "../crypto", default-features = false }

modules/remote-attestation/src/dcap.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ pub fn run_dcap_ra(
4949
key_manager
5050
.save_verifiable_quote(
5151
target_enclave_key,
52-
DCAPQuote::new(raw_quote, current_time).into(),
52+
DCAPQuote::new(
53+
raw_quote,
54+
output.tcb_status.to_string(),
55+
output.advisory_ids,
56+
current_time,
57+
)
58+
.into(),
5359
)
5460
.map_err(|e| {
5561
Error::key_manager(format!("cannot save DCAP AVR: {}", target_enclave_key), e)
@@ -89,10 +95,9 @@ fn get_collateral(pccs_url: &str, certs_service_url: &str, quote: &QuoteV3) -> I
8995

9096
// get the SGX extension
9197
let sgx_extensions = extract_sgx_extension(pck_cert);
92-
let fmspc = hex::encode_upper(sgx_extensions.fmspc);
93-
9498
let mut collateral = IntelCollateral::new();
9599
{
100+
let fmspc = hex::encode_upper(sgx_extensions.fmspc);
96101
let res = reqwest::blocking::get(format!("{base_url}/tcb?fmspc={fmspc}")).unwrap();
97102
let issuer_chain = extract_raw_certs(
98103
get_header(&res, "TCB-Info-Issuer-Chain")

0 commit comments

Comments
 (0)