-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add appropairate authorization headers to test with SPNEGO too as discussed in #48 Requires recent version of python-gssapi module, see: pythongssapi/python-gssapi#74 Simo: Squashed original patches in one, removed trailing whitespaces and reworded the commit message. Reviewed-by: Simo Sorce <simo@redhat.com> Closes #49
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/python | ||
# Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license. | ||
|
||
import os | ||
import requests | ||
import gssapi | ||
from base64 import b64encode | ||
|
||
def getAuthToken(target): | ||
spnego_mech = gssapi.raw.OID.from_int_seq('1.3.6.1.5.5.2') | ||
|
||
name = gssapi.Name('HTTP@%s' % target, | ||
gssapi.NameType.hostbased_service) | ||
|
||
ctx = gssapi.SecurityContext(name=name, mech=spnego_mech) | ||
token = ctx.step() | ||
|
||
return 'Negotiate %s' % b64encode(token) | ||
|
||
|
||
if __name__ == '__main__': | ||
s = requests.Session() | ||
|
||
target = os.environ['NSS_WRAPPER_HOSTNAME'] | ||
url = 'http://%s/spnego/' % target | ||
|
||
proxy = 'http://%s:%s' % (target, os.environ['WRAP_PROXY_PORT']) | ||
proxies = { "http" : proxy, } | ||
|
||
s.headers.update({'Proxy-Authorization': getAuthToken(target)}) | ||
s.headers.update({'Authorization': getAuthToken(target)}) | ||
|
||
r = s.get(url, proxies=proxies) | ||
if r.status_code != 200: | ||
raise ValueError('Spnego Proxy Auth Failed') |