Skip to content

Commit 1540fa2

Browse files
committed
Actually use acceptor creds when passed in
Previously, the condition on acceptor credentials was inverted, such that when `acceptor_creds` was `None`, it would attempt to use the value of the underlying raw `gss_cred_id_t`, and when it was not `None`, the actual credentials passed in would be `GSS_C_NO_CREDENTIAL`. This has been corrected. Additionally, two new tests have been added. One checks that passing None for acceptor credentials is ok, and the second properly tests that `accept_sec_context` received S4U2Proxy delegated credentials in the appropriate circumstances.
1 parent e9f5a97 commit 1540fa2

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

gssapi/raw/sec_contexts.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def accept_sec_context(input_token not None, Creds acceptor_creds=None,
297297
output_context = SecurityContext()
298298

299299
cdef gss_cred_id_t act_acceptor_cred
300-
if acceptor_creds is None:
300+
if acceptor_creds is not None:
301301
act_acceptor_cred = acceptor_creds.raw_creds
302302
else:
303303
act_acceptor_cred = GSS_C_NO_CREDENTIAL

gssapi/tests/test_raw.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import gssapi.raw as gb
1010
import gssapi.raw.misc as gbmisc
11-
from gssapi.tests._utils import _extension_test
11+
from gssapi.tests._utils import _extension_test, _minversion_test
1212
from gssapi.tests import k5test as kt
1313

1414

@@ -307,6 +307,27 @@ def test_acquire_creds_impersonate_name(self):
307307
# no need to explicitly release any more -- we can just rely on
308308
# __dealloc__ (b/c cython)
309309

310+
@_extension_test('s4u', 'S4U')
311+
@_minversion_test('1.11', 'returning delegated S4U2Proxy credentials')
312+
def test_always_get_delegated_creds(self):
313+
svc_princ = SERVICE_PRINCIPAL.decode("UTF-8")
314+
self.realm.kinit(svc_princ, flags=['-k', '-f'])
315+
316+
target_name = gb.import_name(TARGET_SERVICE_NAME,
317+
gb.NameType.hostbased_service)
318+
319+
client_token = gb.init_sec_context(target_name).token
320+
321+
# if our acceptor creds have a usage of both, we get
322+
# s4u2proxy delegated credentials
323+
server_creds = gb.acquire_cred(None, usage='both').creds
324+
server_ctx_resp = gb.accept_sec_context(client_token,
325+
acceptor_creds=server_creds)
326+
327+
server_ctx_resp.shouldnt_be_none()
328+
server_ctx_resp.delegated_creds.shouldnt_be_none()
329+
server_ctx_resp.delegated_creds.should_be_a(gb.Creds)
330+
310331
@_extension_test('rfc5588', 'RFC 5588')
311332
def test_store_cred_acquire_cred(self):
312333
# we need to acquire a forwardable ticket
@@ -699,6 +720,33 @@ def tearDown(self):
699720
if self.server_ctx is not None:
700721
gb.delete_sec_context(self.server_ctx)
701722

723+
def test_basic_accept_context_no_acceptor_creds(self):
724+
server_resp = gb.accept_sec_context(self.client_token)
725+
server_resp.shouldnt_be_none()
726+
727+
(self.server_ctx, name, mech_type, out_token,
728+
out_req_flags, out_ttl, delegated_cred, cont_needed) = server_resp
729+
730+
self.server_ctx.shouldnt_be_none()
731+
self.server_ctx.should_be_a(gb.SecurityContext)
732+
733+
name.shouldnt_be_none()
734+
name.should_be_a(gb.Name)
735+
736+
mech_type.should_be(gb.MechType.kerberos)
737+
738+
out_token.shouldnt_be_empty()
739+
740+
out_req_flags.should_be_a(collections.Set)
741+
out_req_flags.should_be_at_least_length(2)
742+
743+
out_ttl.should_be_greater_than(0)
744+
745+
if delegated_cred is not None:
746+
delegated_cred.should_be_a(gb.Creds)
747+
748+
cont_needed.should_be_a(bool)
749+
702750
def test_basic_accept_context(self):
703751
server_resp = gb.accept_sec_context(self.client_token,
704752
acceptor_creds=self.server_creds)

0 commit comments

Comments
 (0)