1212//! - <https://download.01.org/intel-sgx/dcap-1.1/linux/docs/Intel_SGX_PCK_Certificate_CRL_Spec-1.1.pdf>
1313
1414use 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} ;
1818use rustc_serialize:: hex:: ToHex ;
@@ -269,9 +269,10 @@ impl PckCrlApi {
269269}
270270
271271impl < ' 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>
281282impl < ' 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
0 commit comments