Skip to content

Commit a2ad18d

Browse files
committed
OK
Signed-off-by: Jun Kimura <[email protected]>
1 parent 0059071 commit a2ad18d

File tree

3 files changed

+51
-49
lines changed

3 files changed

+51
-49
lines changed

Cargo.lock

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

modules/remote-attestation/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ crypto = { path = "../crypto", default-features = false }
3232
attestation-report = { path = "../attestation-report" }
3333
keymanager = { path = "../keymanager" }
3434

35-
[dev-dependencies]
36-
tokio = { version = "1", features = ["macros"] }
37-
3835
[features]
3936
default = []
4037
sgx-sw = ["rsa", "chrono"]

modules/remote-attestation/src/dcap.rs

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
use std::time::SystemTime;
2+
13
use crate::errors::Error;
24
use attestation_report::DCAPQuote;
35
use crypto::Address;
46
use dcap_rs::types::collaterals::IntelCollateral;
57
use dcap_rs::types::quotes::version_3::QuoteV3;
68
use dcap_rs::utils::cert::{extract_sgx_extension, parse_certchain, parse_pem};
9+
use dcap_rs::utils::quotes::version_3::verify_quote_dcapv3;
710
use keymanager::EnclaveKeyManager;
811
use lcp_types::Time;
912
use log::*;
1013
use sgx_types::{sgx_qe_get_quote, sgx_qe_get_quote_size, sgx_quote3_error_t, sgx_report_t};
1114

12-
const INTEL_ROOT_CA: &'static [u8] =
15+
const INTEL_ROOT_CA: &[u8] =
1316
include_bytes!("../assets/Intel_SGX_Provisioning_Certification_RootCA.der");
1417

1518
pub fn run_dcap_ra(
@@ -23,8 +26,24 @@ pub fn run_dcap_ra(
2326
)
2427
})?;
2528
let raw_quote = rsgx_qe_get_quote(&ek_info.report).unwrap();
29+
info!("Successfully get the quote: {}", hex::encode(&raw_quote));
30+
2631
let quote = QuoteV3::from_bytes(&raw_quote);
27-
println!("Successfully get the quote: {:?}", quote);
32+
33+
let collateral = get_collateral(
34+
"https://api.trustedservices.intel.com/",
35+
"https://certificates.trustedservices.intel.com/",
36+
&quote,
37+
);
38+
let output = verify_quote_dcapv3(
39+
&quote,
40+
&collateral,
41+
SystemTime::now()
42+
.duration_since(SystemTime::UNIX_EPOCH)
43+
.unwrap()
44+
.as_secs(),
45+
);
46+
info!("DCAP RA output: {:?}", output);
2847

2948
let current_time = Time::now();
3049
key_manager
@@ -54,7 +73,7 @@ fn rsgx_qe_get_quote(app_report: &sgx_report_t) -> Result<Vec<u8>, sgx_quote3_er
5473
}
5574
}
5675

57-
async fn get_collateral(pccs_url: &str, quote: &QuoteV3) -> IntelCollateral {
76+
fn get_collateral(pccs_url: &str, certs_service_url: &str, quote: &QuoteV3) -> IntelCollateral {
5877
let base_url = format!("{}/sgx/certification/v4", pccs_url.trim_end_matches('/'));
5978
info!("base_url: {}", base_url);
6079
assert_eq!(
@@ -63,73 +82,58 @@ async fn get_collateral(pccs_url: &str, quote: &QuoteV3) -> IntelCollateral {
6382
);
6483
let certchain_pems = parse_pem(&quote.signature.qe_cert_data.cert_data).unwrap();
6584
let certchain = parse_certchain(&certchain_pems);
85+
assert_eq!(certchain.len(), 3, "QE Cert chain must have 3 certs");
6686

6787
// get the pck certificate, and check whether issuer common name is valid
6888
let pck_cert = &certchain[0];
6989

7090
// get the SGX extension
71-
let sgx_extensions = extract_sgx_extension(&pck_cert);
91+
let sgx_extensions = extract_sgx_extension(pck_cert);
7292
let fmspc = hex::encode_upper(sgx_extensions.fmspc);
7393

74-
let client = reqwest::Client::new();
7594
let mut collateral = IntelCollateral::new();
7695
{
77-
let res = client
78-
.get(format!("{base_url}/tcb?fmspc={fmspc}"))
79-
.send()
80-
.await
81-
.unwrap();
96+
let res = reqwest::blocking::get(format!("{base_url}/tcb?fmspc={fmspc}")).unwrap();
8297
let issuer_chain = extract_raw_certs(
8398
get_header(&res, "TCB-Info-Issuer-Chain")
8499
.unwrap()
85100
.as_bytes(),
86101
)
87102
.unwrap();
88103
collateral.set_sgx_tcb_signing_der(&issuer_chain[0]);
89-
collateral.set_tcbinfo_bytes(res.bytes().await.unwrap().as_ref());
104+
collateral.set_tcbinfo_bytes(res.bytes().unwrap().as_ref());
90105
}
91106

92107
{
93-
let res = client
94-
.get(format!("{base_url}/qe/identity"))
95-
.send()
96-
.await
97-
.unwrap();
98-
collateral.set_qeidentity_bytes(res.bytes().await.unwrap().as_ref());
108+
let res = reqwest::blocking::get(format!("{base_url}/qe/identity")).unwrap();
109+
collateral.set_qeidentity_bytes(res.bytes().unwrap().as_ref());
99110
}
100111
collateral.set_intel_root_ca_der(INTEL_ROOT_CA);
101112

102113
{
103-
let res = client
104-
.get("https://certificates.trustedservices.intel.com/IntelSGXRootCA.der")
105-
.send()
106-
.await
107-
.unwrap();
108-
let crl = res.bytes().await.unwrap();
109-
collateral.set_sgx_intel_root_ca_crl_der(&crl);
114+
let res = reqwest::blocking::get(format!(
115+
"{}/IntelSGXRootCA.der",
116+
certs_service_url.trim_end_matches('/')
117+
))
118+
.unwrap();
119+
collateral.set_sgx_intel_root_ca_crl_der(res.bytes().unwrap().as_ref());
110120
}
111121

112122
{
113-
let res = client
114-
.get(format!("{base_url}/pckcrl?ca=processor&encoding=der"))
115-
.send()
116-
.await
117-
.unwrap();
118-
collateral.set_sgx_processor_crl_der(res.bytes().await.unwrap().as_ref());
123+
let res =
124+
reqwest::blocking::get(format!("{base_url}/pckcrl?ca=processor&encoding=der")).unwrap();
125+
collateral.set_sgx_processor_crl_der(res.bytes().unwrap().as_ref());
119126
}
120127
{
121-
let res = client
122-
.get(format!("{base_url}/pckcrl?ca=platform&encoding=der"))
123-
.send()
124-
.await
125-
.unwrap();
126-
collateral.set_sgx_platform_crl_der(res.bytes().await.unwrap().as_ref());
128+
let res =
129+
reqwest::blocking::get(format!("{base_url}/pckcrl?ca=platform&encoding=der")).unwrap();
130+
collateral.set_sgx_platform_crl_der(res.bytes().unwrap().as_ref());
127131
}
128132

129133
collateral
130134
}
131135

132-
fn get_header(res: &reqwest::Response, name: &str) -> Result<String, String> {
136+
fn get_header(res: &reqwest::blocking::Response, name: &str) -> Result<String, String> {
133137
let value = res
134138
.headers()
135139
.get(name)
@@ -151,22 +155,24 @@ fn extract_raw_certs(cert_chain: &[u8]) -> Result<Vec<Vec<u8>>, Error> {
151155

152156
#[cfg(test)]
153157
mod tests {
154-
use std::time::SystemTime;
155-
156-
use dcap_rs::utils::quotes::version_3::verify_quote_dcapv3;
157-
158158
use super::*;
159+
use dcap_rs::{constants::SGX_TEE_TYPE, utils::quotes::version_3::verify_quote_dcapv3};
160+
use std::time::SystemTime;
159161

160162
#[test]
161163
fn test_quote() {
162164
QuoteV3::from_bytes(&get_test_quote());
163165
}
164166

165-
#[tokio::test]
166-
async fn test_dcap_collateral() {
167+
#[test]
168+
fn test_dcap_collateral() {
167169
let quote = get_test_quote();
168170
let quote = QuoteV3::from_bytes(&quote);
169-
let collateral = get_collateral("https://api.trustedservices.intel.com/", &quote).await;
171+
let collateral = get_collateral(
172+
"https://api.trustedservices.intel.com/",
173+
"https://certificates.trustedservices.intel.com/",
174+
&quote,
175+
);
170176
let output = verify_quote_dcapv3(
171177
&quote,
172178
&collateral,
@@ -175,7 +181,7 @@ mod tests {
175181
.unwrap()
176182
.as_secs(),
177183
);
178-
println!("{:?}", output);
184+
assert_eq!(output.tee_type, SGX_TEE_TYPE);
179185
}
180186

181187
fn get_test_quote() -> Vec<u8> {

0 commit comments

Comments
 (0)