@@ -894,3 +894,68 @@ mod test_policy_template {
894
894
assert_eq ! ( expected_policy_template, policy_digest) ;
895
895
}
896
896
}
897
+
898
+ mod test_policy_authorize_nv {
899
+ use crate :: common:: { create_ctx_with_session, write_nv_index} ;
900
+ use std:: convert:: TryFrom ;
901
+ use tss_esapi:: {
902
+ attributes:: SessionAttributesBuilder ,
903
+ constants:: SessionType ,
904
+ handles:: { NvIndexHandle , NvIndexTpmHandle } ,
905
+ interface_types:: {
906
+ algorithm:: HashingAlgorithm ,
907
+ resource_handles:: { NvAuth , Provision } ,
908
+ session_handles:: PolicySession ,
909
+ } ,
910
+ structures:: SymmetricDefinition ,
911
+ } ;
912
+
913
+ #[ test]
914
+ fn test_policy_authorize_nv ( ) {
915
+ let mut context = create_ctx_with_session ( ) ;
916
+ let trial_policy_auth_session = context
917
+ . start_auth_session (
918
+ None ,
919
+ None ,
920
+ None ,
921
+ SessionType :: Trial ,
922
+ SymmetricDefinition :: AES_256_CFB ,
923
+ HashingAlgorithm :: Sha256 ,
924
+ )
925
+ . expect ( "Start auth session failed" )
926
+ . expect ( "Start auth session returned a NONE handle" ) ;
927
+ let ( trial_policy_auth_session_attributes, trial_policy_auth_session_attributes_mask) =
928
+ SessionAttributesBuilder :: new ( )
929
+ . with_decrypt ( true )
930
+ . with_encrypt ( true )
931
+ . build ( ) ;
932
+
933
+ let nv_index = NvIndexTpmHandle :: new ( 0x01500015 ) . unwrap ( ) ;
934
+ let initial_owner_nv_index_handle = write_nv_index ( & mut context, nv_index) ;
935
+
936
+ context
937
+ . tr_sess_set_attributes (
938
+ trial_policy_auth_session,
939
+ trial_policy_auth_session_attributes,
940
+ trial_policy_auth_session_attributes_mask,
941
+ )
942
+ . expect ( "tr_sess_set_attributes call failed" ) ;
943
+ let trial_policy_session = PolicySession :: try_from ( trial_policy_auth_session)
944
+ . expect ( "Failed to convert auth session into policy session" ) ;
945
+ // There should be no algorithm prefix error or actual NV content check for a TRIAL session
946
+ let policy_result = context. policy_authorize_nv (
947
+ trial_policy_session,
948
+ NvAuth :: Owner ,
949
+ initial_owner_nv_index_handle,
950
+ ) ;
951
+
952
+ let owner_nv_index_handle = context
953
+ . tr_from_tpm_public ( nv_index. into ( ) )
954
+ . map_or_else ( |_| initial_owner_nv_index_handle, NvIndexHandle :: from) ;
955
+ context
956
+ . nv_undefine_space ( Provision :: Owner , owner_nv_index_handle)
957
+ . expect ( "Call to nv_undefine_space failed" ) ;
958
+
959
+ policy_result. unwrap ( ) ;
960
+ }
961
+ }
0 commit comments