-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SPNEGO mechanism by default (#41)
Use the correct mechanism as described by * RFC 4559, section 4: The "Negotiate" auth-scheme calls for the use of SPNEGO GSSAPI tokens that the specific mechanism type specifies. * RFC 4178, section 3.2: The GSS-API initiator invokes GSS_Init_sec_context() as normal, but requests that SPNEGO be used. SPNEGO can either be explicitly requested or accepted as the default mechanism. Since both MIT Kerberos and Heimdal use Kerberos 5 as their default mechanism we must explicitly request SPNEGO. Passing raw Kerberos tokens to the acceptor is a violation of these RFCs and some implementations complain about, thus they always need to be wrapped. This closes #41 Signed-off-by: Michael Osipov <[email protected]>
- Loading branch information
Showing
5 changed files
with
30 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import unittest | ||
|
||
from requests_gssapi import REQUIRED | ||
from requests_gssapi import SPNEGO | ||
|
||
# Note: we're not using the @mock.patch decorator: | ||
# > My only word of warning is that in the past, the patch decorator hides | ||
|
@@ -110,7 +111,7 @@ def test_generate_request_header(self): | |
b64_negotiate_response) | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
creds=None, mech=None, flags=gssflags, usage="initiate") | ||
creds=None, mech=SPNEGO, flags=gssflags, usage="initiate") | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_generate_request_header_init_error(self): | ||
|
@@ -125,7 +126,7 @@ def test_generate_request_header_init_error(self): | |
auth.generate_request_header, response, host) | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
|
||
def test_generate_request_header_step_error(self): | ||
with patch.multiple("gssapi.SecurityContext", __init__=fake_init, | ||
|
@@ -139,7 +140,7 @@ def test_generate_request_header_step_error(self): | |
auth.generate_request_header, response, host) | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
fail_resp.assert_called_with(b"token") | ||
|
||
def test_authenticate_user(self): | ||
|
@@ -176,7 +177,7 @@ def test_authenticate_user(self): | |
raw.release_conn.assert_called_with() | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
flags=gssflags, usage="initiate", creds=None, mech=None) | ||
flags=gssflags, usage="initiate", creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_handle_401(self): | ||
|
@@ -213,7 +214,7 @@ def test_handle_401(self): | |
raw.release_conn.assert_called_with() | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
creds=None, mech=None, flags=gssflags, usage="initiate") | ||
creds=None, mech=SPNEGO, flags=gssflags, usage="initiate") | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_authenticate_server(self): | ||
|
@@ -452,7 +453,7 @@ def test_handle_response_401(self): | |
raw.release_conn.assert_called_with() | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_handle_response_401_rejected(self): | ||
|
@@ -495,7 +496,7 @@ def connection_send(self, *args, **kwargs): | |
raw.release_conn.assert_called_with() | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_generate_request_header_custom_service(self): | ||
|
@@ -509,7 +510,7 @@ def test_generate_request_header_custom_service(self): | |
auth.generate_request_header(response, host), | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_delegation(self): | ||
|
@@ -547,7 +548,7 @@ def test_delegation(self): | |
raw.release_conn.assert_called_with() | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssdelegflags, creds=None, mech=None) | ||
usage="initiate", flags=gssdelegflags, creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_principal_override(self): | ||
|
@@ -566,7 +567,7 @@ def test_principal_override(self): | |
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, | ||
creds=b"fake creds", mech=None) | ||
creds=b"fake creds", mech=SPNEGO) | ||
|
||
def test_realm_override(self): | ||
with patch.multiple("gssapi.SecurityContext", __init__=fake_init, | ||
|
@@ -580,7 +581,7 @@ def test_realm_override(self): | |
auth.generate_request_header(response, host) | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_opportunistic_auth(self): | ||
|
@@ -610,7 +611,7 @@ def test_explicit_creds(self): | |
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, | ||
creds=b"fake creds", mech=None) | ||
creds=b"fake creds", mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
def test_explicit_mech(self): | ||
|
@@ -642,7 +643,7 @@ def test_target_name(self): | |
auth.generate_request_header(response, host) | ||
fake_init.assert_called_with( | ||
name=gssapi_sname("[email protected]"), | ||
usage="initiate", flags=gssflags, creds=None, mech=None) | ||
usage="initiate", flags=gssflags, creds=None, mech=SPNEGO) | ||
fake_resp.assert_called_with(b"token") | ||
|
||
|
||
|