@@ -3757,7 +3757,6 @@ fn aes_cmac_verify_impl(key: [u8; 16], message: &[u8], expected_mac: [u8; 16]) -
3757
3757
Ok ( ( ) )
3758
3758
}
3759
3759
3760
- /// AES-CMAC test vectors from RFC 4493
3761
3760
#[ test]
3762
3761
#[ serial]
3763
3762
fn unique_id ( ) -> TestResult {
@@ -3835,3 +3834,83 @@ fn unique_id() -> TestResult {
3835
3834
3836
3835
Ok ( ( ) )
3837
3836
}
3837
+
3838
+ #[ test]
3839
+ #[ serial]
3840
+ fn validation ( ) -> TestResult {
3841
+ let ( pkcs11, slot) = init_pins ( ) ;
3842
+ let session = pkcs11. open_rw_session ( slot) ?;
3843
+ session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
3844
+
3845
+ let key: [ u8 ; 16 ] = [
3846
+ 0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 , 0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f ,
3847
+ 0x3c ,
3848
+ ] ;
3849
+
3850
+ // Can not create object with ObjectValidationFlags
3851
+ let key_template = vec ! [
3852
+ Attribute :: Class ( ObjectClass :: SECRET_KEY ) ,
3853
+ Attribute :: KeyType ( KeyType :: AES ) ,
3854
+ Attribute :: Token ( true ) ,
3855
+ Attribute :: Sensitive ( true ) ,
3856
+ Attribute :: Private ( true ) ,
3857
+ Attribute :: Value ( key. into( ) ) ,
3858
+ Attribute :: ObjectValidationFlags ( 0x03 . into( ) ) ,
3859
+ ] ;
3860
+ let res = session. create_object ( & key_template) ;
3861
+ assert ! ( res. is_err( ) ) ;
3862
+ assert ! ( matches!(
3863
+ res,
3864
+ Err ( Error :: Pkcs11 (
3865
+ RvError :: AttributeTypeInvalid ,
3866
+ Function :: CreateObject
3867
+ ) )
3868
+ ) ) ;
3869
+
3870
+ let generate_template = vec ! [
3871
+ Attribute :: Token ( true ) ,
3872
+ Attribute :: ValueLen ( 32 . into( ) ) ,
3873
+ Attribute :: Encrypt ( true ) ,
3874
+ ] ;
3875
+
3876
+ // generate a secret key
3877
+ let key = session. generate_key ( & Mechanism :: AesKeyGen , & generate_template) ?;
3878
+
3879
+ // we can get the ObjectValidationFlags attribute
3880
+ let attrs = session. get_attributes ( key, & [ AttributeType :: ObjectValidationFlags ] ) ?;
3881
+ if is_softhsm ( ) {
3882
+ // SoftHSM does not support this attribute at all
3883
+ assert_eq ! ( attrs. len( ) , 0 ) ;
3884
+ } else {
3885
+ // Kryoptic supports the ObjectValidationFlag only if it is built as a FIPS provider
3886
+ //assert!(matches!(attrs.first(), Some(Attribute::ObjectValidationFlags(_))));
3887
+ assert_eq ! ( attrs. len( ) , 0 ) ;
3888
+ }
3889
+
3890
+ // we can not set the ObjectValidationFlags attribute
3891
+ let update_template = vec ! [ Attribute :: ObjectValidationFlags ( 0x03 . into( ) ) ] ;
3892
+ let res = session. update_attributes ( key, & update_template) ;
3893
+ assert ! ( res. is_err( ) ) ;
3894
+ if is_softhsm ( ) {
3895
+ // SoftHSM does not support this attribute at all
3896
+ assert ! ( matches!(
3897
+ res,
3898
+ Err ( Error :: Pkcs11 (
3899
+ RvError :: AttributeTypeInvalid ,
3900
+ Function :: SetAttributeValue
3901
+ ) )
3902
+ ) ) ;
3903
+ } else {
3904
+ assert ! ( matches!(
3905
+ res,
3906
+ Err ( Error :: Pkcs11 (
3907
+ RvError :: ActionProhibited ,
3908
+ Function :: SetAttributeValue
3909
+ ) )
3910
+ ) ) ;
3911
+ }
3912
+
3913
+ session. destroy_object ( key) ?;
3914
+
3915
+ Ok ( ( ) )
3916
+ }
0 commit comments