12
12
//! - <https://download.01.org/intel-sgx/dcap-1.1/linux/docs/Intel_SGX_PCK_Certificate_CRL_Spec-1.1.pdf>
13
13
14
14
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 ,
16
16
TcbInfo , RawTcbEvaluationDataNumbers , Unverified ,
17
17
} ;
18
18
use rustc_serialize:: hex:: ToHex ;
@@ -269,9 +269,10 @@ impl PckCrlApi {
269
269
}
270
270
271
271
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 {
273
273
PckCrlIn {
274
274
api_version : self . api_version . clone ( ) ,
275
+ ca,
275
276
}
276
277
}
277
278
}
@@ -280,12 +281,19 @@ impl<'inp> PckCrlService<'inp> for PckCrlApi {
280
281
/// See: <https://api.portal.trustedservices.intel.com/documentation#pcs-revocation-v4>
281
282
impl < ' inp > ProvisioningServiceApi < ' inp > for PckCrlApi {
282
283
type Input = PckCrlIn ;
283
- type Output = PckCrl ;
284
+ type Output = PckCrl < Unverified > ;
284
285
285
286
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
+ } ;
286
294
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 ,
289
297
) ;
290
298
Ok ( ( url, Vec :: new ( ) ) )
291
299
}
@@ -565,7 +573,7 @@ mod tests {
565
573
use std:: path:: PathBuf ;
566
574
use std:: time:: Duration ;
567
575
568
- use pcs:: { EnclaveIdentity , Fmspc , PckID , Platform , TcbEvaluationDataNumbers , RawTcbEvaluationDataNumbers } ;
576
+ use pcs:: { DcapArtifactIssuer , EnclaveIdentity , Fmspc , PckID , Platform , TcbEvaluationDataNumbers , RawTcbEvaluationDataNumbers } ;
569
577
570
578
use crate :: provisioning_client:: {
571
579
test_helpers, IntelProvisioningClientBuilder , PcsVersion , ProvisioningClient ,
@@ -704,6 +712,8 @@ mod tests {
704
712
intel_builder. set_api_key ( pcs_api_key ( ) ) ;
705
713
}
706
714
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 ( ) ;
707
717
for pckid in PckID :: parse_file ( & PathBuf :: from ( PCKID_TEST_FILE ) . as_path ( ) )
708
718
. unwrap ( )
709
719
. iter ( )
@@ -717,7 +727,9 @@ mod tests {
717
727
None ,
718
728
)
719
729
. 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 ( ) ;
721
733
722
734
// The cache should be populated after initial service call
723
735
{
@@ -746,7 +758,7 @@ mod tests {
746
758
pck. fmspc( ) . unwrap( ) ,
747
759
cached_pck
748
760
. clone( )
749
- . verify( & root_cas)
761
+ . verify( & root_cas, None )
750
762
. unwrap( )
751
763
. fmspc( )
752
764
. unwrap( )
@@ -769,7 +781,7 @@ mod tests {
769
781
pck. fmspc( ) . unwrap( ) ,
770
782
pck_from_service
771
783
. clone( )
772
- . verify( & root_cas)
784
+ . verify( & root_cas, None )
773
785
. unwrap( )
774
786
. fmspc( )
775
787
. unwrap( )
@@ -877,55 +889,59 @@ mod tests {
877
889
878
890
#[ test]
879
891
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( ) ) ;
885
904
}
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( ) ) ;
891
905
}
892
906
}
893
907
894
908
#[ test]
895
909
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 ( ) ;
904
919
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 ( ) ;
908
923
909
- assert ! ( cache. len( ) > 0 ) ;
924
+ assert ! ( cache. len( ) > 0 ) ;
910
925
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) ;
915
930
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
+ } ;
921
936
922
- assert_eq ! ( pckcrl, cached_pckcrl) ;
923
- }
937
+ assert_eq ! ( pckcrl, cached_pckcrl) ;
938
+ }
924
939
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 ( ) ;
927
942
928
- assert_eq ! ( pckcrl, pckcrl_from_service) ;
943
+ assert_eq ! ( pckcrl, pckcrl_from_service) ;
944
+ }
929
945
}
930
946
}
931
947
0 commit comments