@@ -843,6 +843,85 @@ def test_inquire_sec_context_by_oid_should_raise_error(self):
843843 gb .inquire_sec_context_by_oid .should_raise (gb .GSSError , client_ctx ,
844844 invalid_oid )
845845
846+ @ktu .gssapi_extension_test ('ggf' , 'Global Grid Forum' )
847+ @ktu .gssapi_extension_test ('password' , 'Add Credential with Password' )
848+ def test_set_sec_context_option (self ):
849+ ntlm_mech = gb .OID .from_int_seq ("1.3.6.1.4.1.311.2.2.10" )
850+ username = gb .import_name (name = b"user" ,
851+ name_type = gb .NameType .user )
852+ try :
853+ cred = gb .acquire_cred_with_password (name = username ,
854+ password = b"password" ,
855+ mechs = [ntlm_mech ])
856+ except gb .GSSError :
857+ self .skipTest ('You do not have the GSSAPI gss-ntlmssp mech '
858+ 'installed' )
859+
860+ server = gb .import_name (name = b"server" ,
861+ name_type = gb .NameType .hostbased_service )
862+ orig_context = gb .init_sec_context (server , creds = cred .creds ,
863+ mech = ntlm_mech )[0 ]
864+
865+ # GSS_NTLMSSP_RESET_CRYPTO_OID_STRING
866+ reset_mech = gb .OID .from_int_seq ("1.3.6.1.4.1.7165.655.1.3" )
867+ out_context = gb .set_sec_context_option (reset_mech ,
868+ context = orig_context ,
869+ value = b"\x00 " * 4 )
870+ out_context .should_be_a (gb .SecurityContext )
871+
872+ @ktu .gssapi_extension_test ('ggf' , 'Global Grid Forum' )
873+ @ktu .gssapi_extension_test ('password' , 'Add Credential with Password' )
874+ def test_set_sec_context_option_fail (self ):
875+ ntlm_mech = gb .OID .from_int_seq ("1.3.6.1.4.1.311.2.2.10" )
876+ username = gb .import_name (name = b"user" ,
877+ name_type = gb .NameType .user )
878+ try :
879+ cred = gb .acquire_cred_with_password (name = username ,
880+ password = b"password" ,
881+ mechs = [ntlm_mech ])
882+ except gb .GSSError :
883+ self .skipTest ('You do not have the GSSAPI gss-ntlmssp mech '
884+ 'installed' )
885+
886+ server = gb .import_name (name = b"server" ,
887+ name_type = gb .NameType .hostbased_service )
888+ context = gb .init_sec_context (server , creds = cred .creds ,
889+ mech = ntlm_mech )[0 ]
890+
891+ # GSS_NTLMSSP_RESET_CRYPTO_OID_STRING
892+ reset_mech = gb .OID .from_int_seq ("1.3.6.1.4.1.7165.655.1.3" )
893+
894+ # will raise a GSSError if no data was passed in
895+ gb .set_sec_context_option .should_raise (gb .GSSError , reset_mech ,
896+ context )
897+
898+ @ktu .gssapi_extension_test ('set_cred_opt' , 'Kitten Set Credential Option' )
899+ @ktu .krb_minversion_test ('1.14' ,
900+ 'GSS_KRB5_CRED_NO_CI_FLAGS_X was added in MIT '
901+ 'krb5 1.14' )
902+ def test_set_cred_option (self ):
903+ name = gb .import_name (SERVICE_PRINCIPAL ,
904+ gb .NameType .kerberos_principal )
905+ # GSS_KRB5_CRED_NO_CI_FLAGS_X
906+ no_ci_flags_x = gb .OID .from_int_seq ("1.2.752.43.13.29" )
907+ orig_cred = gb .acquire_cred (name ).creds
908+
909+ # nothing much we can test here apart from it doesn't fail and the
910+ # id of the return cred is the same as the input one
911+ output_cred = gb .set_cred_option (no_ci_flags_x , creds = orig_cred )
912+ output_cred .should_be_a (gb .Creds )
913+
914+ @ktu .gssapi_extension_test ('set_cred_opt' , 'Kitten Set Credential Option' )
915+ def test_set_cred_option_should_raise_error (self ):
916+ name = gb .import_name (SERVICE_PRINCIPAL ,
917+ gb .NameType .kerberos_principal )
918+ orig_cred = gb .acquire_cred (name ).creds
919+
920+ # this is a fake OID and shouldn't work at all
921+ invalid_oid = gb .OID .from_int_seq ("1.2.3.4.5.6.7.8.9" )
922+ gb .set_cred_option .should_raise (gb .GSSError , invalid_oid , orig_cred ,
923+ b"\x00 " )
924+
846925
847926class TestIntEnumFlagSet (unittest .TestCase ):
848927 def test_create_from_int (self ):
0 commit comments