Skip to content

Commit 68aa759

Browse files
authored
Merge pull request fortanix#756 from fortanix/raoul/rte-447-pckcrl
[RTE-447] pckcrl
2 parents 06f358f + 2e9f94a commit 68aa759

File tree

15 files changed

+370
-127
lines changed

15 files changed

+370
-127
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intel-sgx/dcap-artifact-retrieval/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dcap-artifact-retrieval"
3-
version = "0.3.7"
3+
version = "0.4.0"
44
authors = ["Fortanix, Inc."]
55
license = "MPL-2.0"
66
edition = "2018"

intel-sgx/dcap-artifact-retrieval/src/cli.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::path::{Path, PathBuf};
99

1010
use clap::clap_app;
11-
use pcs::PckID;
11+
use pcs::{PckID, DcapArtifactIssuer};
1212
use reqwest::Url;
1313
use rustc_serialize::hex::ToHex;
1414
use serde::de::{value, IntoDeserializer};
@@ -132,12 +132,19 @@ fn download_dcap_artifacts(
132132
}
133133
}
134134
let pckcrl = prov_client
135-
.pckcrl()
136-
.and_then(|crl| crl.write_to_file(output_dir).map_err(|e| e.into()))?;
135+
.pckcrl(DcapArtifactIssuer::PCKProcessorCA)
136+
.and_then(|crl| crl.write_to_file_as(output_dir, DcapArtifactIssuer::PCKProcessorCA).map_err(|e| e.into()))?;
137137
if verbose {
138138
println!("==[ generic ]==");
139139
println!(" pckcrl: {}", pckcrl);
140140
}
141+
142+
let pckcrl = prov_client
143+
.pckcrl(DcapArtifactIssuer::PCKPlatformCA)
144+
.and_then(|crl| crl.write_to_file_as(output_dir, DcapArtifactIssuer::PCKPlatformCA).map_err(|e| e.into()))?;
145+
if verbose {
146+
println!(" pckcrl: {}", pckcrl);
147+
}
141148
Ok(())
142149
}
143150

intel-sgx/dcap-artifact-retrieval/src/provisioning_client/azure.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod tests {
197197
use pcs::PckID;
198198

199199
use crate::provisioning_client::{
200-
test_helpers, AzureProvisioningClientBuilder, PcsVersion, ProvisioningClient,
200+
test_helpers, AzureProvisioningClientBuilder, DcapArtifactIssuer, PcsVersion, ProvisioningClient,
201201
};
202202
use crate::reqwest_client;
203203

@@ -228,7 +228,7 @@ mod tests {
228228
)
229229
.unwrap();
230230

231-
let pck = pck.verify(&root_cas).unwrap();
231+
let pck = pck.verify(&root_cas, None).unwrap();
232232
assert_eq!(
233233
test_helpers::get_cert_subject(&pck.ca_chain().last().unwrap()),
234234
"Intel SGX Root CA"
@@ -248,7 +248,8 @@ mod tests {
248248
let client = AzureProvisioningClientBuilder::new(PcsVersion::V3)
249249
.set_retry_timeout(TIME_RETRY_TIMEOUT)
250250
.build(reqwest_client());
251-
assert!(client.pckcrl().is_ok());
251+
assert!(client.pckcrl(DcapArtifactIssuer::PCKProcessorCA).is_ok());
252+
assert!(client.pckcrl(DcapArtifactIssuer::PCKPlatformCA).is_ok());
252253
}
253254

254255
#[test]

intel-sgx/dcap-artifact-retrieval/src/provisioning_client/intel.rs

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! - <https://download.01.org/intel-sgx/dcap-1.1/linux/docs/Intel_SGX_PCK_Certificate_CRL_Spec-1.1.pdf>
1313
1414
use pcs::{
15-
CpuSvn, EncPpid, Fmspc, PceId, PceIsvsvn, PckCert, PckCerts, PckCrl, QeId, QeIdentitySigned,
15+
CpuSvn, DcapArtifactIssuer, EncPpid, Fmspc, PceId, PceIsvsvn, PckCert, PckCerts, PckCrl, QeId, QeIdentitySigned,
1616
TcbInfo, RawTcbEvaluationDataNumbers, Unverified,
1717
};
1818
use rustc_serialize::hex::ToHex;
@@ -269,9 +269,10 @@ impl PckCrlApi {
269269
}
270270

271271
impl<'inp> PckCrlService<'inp> for PckCrlApi {
272-
fn build_input(&'inp self) -> <Self as ProvisioningServiceApi<'inp>>::Input {
272+
fn build_input(&'inp self, ca: DcapArtifactIssuer) -> <Self as ProvisioningServiceApi<'inp>>::Input {
273273
PckCrlIn {
274274
api_version: self.api_version.clone(),
275+
ca,
275276
}
276277
}
277278
}
@@ -280,12 +281,19 @@ impl<'inp> PckCrlService<'inp> for PckCrlApi {
280281
/// See: <https://api.portal.trustedservices.intel.com/documentation#pcs-revocation-v4>
281282
impl<'inp> ProvisioningServiceApi<'inp> for PckCrlApi {
282283
type Input = PckCrlIn;
283-
type Output = PckCrl;
284+
type Output = PckCrl<Unverified>;
284285

285286
fn build_request(&self, input: &Self::Input) -> Result<(String, Vec<(String, String)>), Error> {
287+
let ca = match input.ca {
288+
DcapArtifactIssuer::PCKProcessorCA => "processor",
289+
DcapArtifactIssuer::PCKPlatformCA => "platform",
290+
DcapArtifactIssuer::SGXRootCA => {
291+
return Err(Error::PCSError(StatusCode::BadRequest, "Invalid ca parameter"));
292+
},
293+
};
286294
let url = format!(
287-
"{}/sgx/certification/v{}/pckcrl?ca=processor&encoding=pem",
288-
INTEL_BASE_URL, input.api_version as u8,
295+
"{}/sgx/certification/v{}/pckcrl?ca={}&encoding=pem",
296+
INTEL_BASE_URL, input.api_version as u8, ca,
289297
);
290298
Ok((url, Vec::new()))
291299
}
@@ -565,7 +573,7 @@ mod tests {
565573
use std::path::PathBuf;
566574
use std::time::Duration;
567575

568-
use pcs::{EnclaveIdentity, Fmspc, PckID, Platform, TcbEvaluationDataNumbers, RawTcbEvaluationDataNumbers};
576+
use pcs::{DcapArtifactIssuer, EnclaveIdentity, Fmspc, PckID, Platform, TcbEvaluationDataNumbers, RawTcbEvaluationDataNumbers};
569577

570578
use crate::provisioning_client::{
571579
test_helpers, IntelProvisioningClientBuilder, PcsVersion, ProvisioningClient,
@@ -704,6 +712,8 @@ mod tests {
704712
intel_builder.set_api_key(pcs_api_key());
705713
}
706714
let client = intel_builder.build(reqwest_client());
715+
let crl_processor = client.pckcrl(DcapArtifactIssuer::PCKProcessorCA).unwrap().crl_as_pem().to_owned();
716+
let crl_platform = client.pckcrl(DcapArtifactIssuer::PCKPlatformCA).unwrap().crl_as_pem().to_owned();
707717
for pckid in PckID::parse_file(&PathBuf::from(PCKID_TEST_FILE).as_path())
708718
.unwrap()
709719
.iter()
@@ -717,7 +727,9 @@ mod tests {
717727
None,
718728
)
719729
.unwrap();
720-
let pck = pck.verify(&root_cas).unwrap();
730+
let pck = pck.clone().verify(&root_cas, Some(&crl_processor))
731+
.or(pck.clone().verify(&root_cas, Some(&crl_platform)))
732+
.unwrap();
721733

722734
// The cache should be populated after initial service call
723735
{
@@ -746,7 +758,7 @@ mod tests {
746758
pck.fmspc().unwrap(),
747759
cached_pck
748760
.clone()
749-
.verify(&root_cas)
761+
.verify(&root_cas, None)
750762
.unwrap()
751763
.fmspc()
752764
.unwrap()
@@ -769,7 +781,7 @@ mod tests {
769781
pck.fmspc().unwrap(),
770782
pck_from_service
771783
.clone()
772-
.verify(&root_cas)
784+
.verify(&root_cas, None)
773785
.unwrap()
774786
.fmspc()
775787
.unwrap()
@@ -877,55 +889,59 @@ mod tests {
877889

878890
#[test]
879891
pub fn pckcrl() {
880-
for api_version in [PcsVersion::V3, PcsVersion::V4] {
881-
let mut intel_builder = IntelProvisioningClientBuilder::new(api_version)
882-
.set_retry_timeout(TIME_RETRY_TIMEOUT);
883-
if api_version == PcsVersion::V3 {
884-
intel_builder.set_api_key(pcs_api_key());
892+
for ca in [DcapArtifactIssuer::PCKProcessorCA, DcapArtifactIssuer::PCKPlatformCA] {
893+
for api_version in [PcsVersion::V3, PcsVersion::V4] {
894+
let mut intel_builder = IntelProvisioningClientBuilder::new(api_version)
895+
.set_retry_timeout(TIME_RETRY_TIMEOUT);
896+
if api_version == PcsVersion::V3 {
897+
intel_builder.set_api_key(pcs_api_key());
898+
}
899+
let client = intel_builder.build(reqwest_client());
900+
assert!(client
901+
.pckcrl(ca)
902+
.and_then(|crl| { Ok(crl.write_to_file(OUTPUT_TEST_DIR).unwrap()) })
903+
.is_ok());
885904
}
886-
let client = intel_builder.build(reqwest_client());
887-
assert!(client
888-
.pckcrl()
889-
.and_then(|crl| { Ok(crl.write_to_file(OUTPUT_TEST_DIR).unwrap()) })
890-
.is_ok());
891905
}
892906
}
893907

894908
#[test]
895909
pub fn pckcrl_cached() {
896-
for api_version in [PcsVersion::V3, PcsVersion::V4] {
897-
let mut intel_builder = IntelProvisioningClientBuilder::new(api_version)
898-
.set_retry_timeout(TIME_RETRY_TIMEOUT);
899-
if api_version == PcsVersion::V3 {
900-
intel_builder.set_api_key(pcs_api_key());
901-
}
902-
let client = intel_builder.build(reqwest_client());
903-
let pckcrl = client.pckcrl().unwrap();
910+
for ca in [DcapArtifactIssuer::PCKProcessorCA, DcapArtifactIssuer::PCKPlatformCA] {
911+
for api_version in [PcsVersion::V3, PcsVersion::V4] {
912+
let mut intel_builder = IntelProvisioningClientBuilder::new(api_version)
913+
.set_retry_timeout(TIME_RETRY_TIMEOUT);
914+
if api_version == PcsVersion::V3 {
915+
intel_builder.set_api_key(pcs_api_key());
916+
}
917+
let client = intel_builder.build(reqwest_client());
918+
let pckcrl = client.pckcrl(ca).unwrap();
904919

905-
// The cache should be populated after initial service call
906-
{
907-
let mut cache = client.pckcrl_service.cache.lock().unwrap();
920+
// The cache should be populated after initial service call
921+
{
922+
let mut cache = client.pckcrl_service.cache.lock().unwrap();
908923

909-
assert!(cache.len() > 0);
924+
assert!(cache.len() > 0);
910925

911-
let (cached_pckcrl, _) = {
912-
let mut hasher = DefaultHasher::new();
913-
let input = client.pckcrl_service.pcs_service().build_input();
914-
input.hash(&mut hasher);
926+
let (cached_pckcrl, _) = {
927+
let mut hasher = DefaultHasher::new();
928+
let input = client.pckcrl_service.pcs_service().build_input(ca);
929+
input.hash(&mut hasher);
915930

916-
cache
917-
.get_mut(&hasher.finish())
918-
.expect("Can't find key in cache")
919-
.to_owned()
920-
};
931+
cache
932+
.get_mut(&hasher.finish())
933+
.expect("Can't find key in cache")
934+
.to_owned()
935+
};
921936

922-
assert_eq!(pckcrl, cached_pckcrl);
923-
}
937+
assert_eq!(pckcrl, cached_pckcrl);
938+
}
924939

925-
// Second service call should return value from cache
926-
let pckcrl_from_service = client.pckcrl().unwrap();
940+
// Second service call should return value from cache
941+
let pckcrl_from_service = client.pckcrl(ca).unwrap();
927942

928-
assert_eq!(pckcrl, pckcrl_from_service);
943+
assert_eq!(pckcrl, pckcrl_from_service);
944+
}
929945
}
930946
}
931947

intel-sgx/dcap-artifact-retrieval/src/provisioning_client/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::time::{Duration, SystemTime};
1515
use lru_cache::LruCache;
1616
use num_enum::TryFromPrimitive;
1717
use pcs::{
18-
CpuSvn, EncPpid, Fmspc, PceId, PceIsvsvn, PckCert, PckCerts, PckCrl, PckID, QeId,
18+
CpuSvn, DcapArtifactIssuer, EncPpid, Fmspc, PceId, PceIsvsvn, PckCert, PckCerts, PckCrl, PckID, QeId,
1919
QeIdentitySigned, TcbInfo, RawTcbEvaluationDataNumbers, Unverified,
2020
};
2121
#[cfg(feature = "reqwest")]
@@ -191,6 +191,7 @@ pub trait PckCertService<'inp>:
191191
#[derive(Hash)]
192192
pub struct PckCrlIn {
193193
api_version: PcsVersion,
194+
ca: DcapArtifactIssuer,
194195
}
195196

196197
impl WithApiVersion for PckCrlIn {
@@ -200,9 +201,9 @@ impl WithApiVersion for PckCrlIn {
200201
}
201202

202203
pub trait PckCrlService<'inp>:
203-
ProvisioningServiceApi<'inp, Input = PckCrlIn, Output = PckCrl>
204+
ProvisioningServiceApi<'inp, Input = PckCrlIn, Output = PckCrl<Unverified>>
204205
{
205-
fn build_input(&'inp self) -> <Self as ProvisioningServiceApi<'inp>>::Input;
206+
fn build_input(&'inp self, ca: DcapArtifactIssuer) -> <Self as ProvisioningServiceApi<'inp>>::Input;
206207
}
207208

208209
#[derive(Hash)]
@@ -467,7 +468,7 @@ pub struct Client<F: for<'a> Fetcher<'a>> {
467468
pckcerts_service: CachedService<PckCerts, dyn for<'a> PckCertsService<'a> + Sync + Send>,
468469
pckcert_service:
469470
CachedService<PckCert<Unverified>, dyn for<'a> PckCertService<'a> + Sync + Send>,
470-
pckcrl_service: CachedService<PckCrl, dyn for<'a> PckCrlService<'a> + Sync + Send>,
471+
pckcrl_service: CachedService<PckCrl<Unverified>, dyn for<'a> PckCrlService<'a> + Sync + Send>,
471472
qeid_service: CachedService<QeIdentitySigned, dyn for<'a> QeIdService<'a> + Sync + Send>,
472473
tcbinfo_service: CachedService<TcbInfo, dyn for<'a> TcbInfoService<'a> + Sync + Send>,
473474
tcb_evaluation_data_numbers_service: CachedService<RawTcbEvaluationDataNumbers, dyn for<'a> TcbEvaluationDataNumbersService<'a> + Sync + Send>,
@@ -563,7 +564,7 @@ pub trait ProvisioningClient {
563564

564565
fn tcbinfo(&self, fmspc: &Fmspc, evaluation_data_number: Option<u16>) -> Result<TcbInfo, Error>;
565566

566-
fn pckcrl(&self) -> Result<PckCrl, Error>;
567+
fn pckcrl(&self, ca: DcapArtifactIssuer) -> Result<PckCrl<Unverified>, Error>;
567568

568569
fn qe_identity(&self, evaluation_data_number: Option<u16>) -> Result<QeIdentitySigned, Error>;
569570

@@ -652,8 +653,8 @@ impl<F: for<'a> Fetcher<'a>> ProvisioningClient for Client<F> {
652653
self.tcbinfo_service.call_service(&self.fetcher, &input)
653654
}
654655

655-
fn pckcrl(&self) -> Result<PckCrl, Error> {
656-
let input = self.pckcrl_service.pcs_service().build_input();
656+
fn pckcrl(&self, ca: DcapArtifactIssuer) -> Result<PckCrl<Unverified>, Error> {
657+
let input = self.pckcrl_service.pcs_service().build_input(ca);
657658
self.pckcrl_service.call_service(&self.fetcher, &input)
658659
}
659660

0 commit comments

Comments
 (0)