2 # Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license.
7 from base64 import b64encode
9 def getAuthToken(target):
10 spnego_mech = gssapi.raw.OID.from_int_seq('1.3.6.1.5.5.2')
12 name = gssapi.Name('HTTP@%s' % target,
13 gssapi.NameType.hostbased_service)
15 ctx = gssapi.SecurityContext(name=name, mech=spnego_mech)
18 return 'Negotiate %s' % b64encode(token)
21 if __name__ == '__main__':
22 s = requests.Session()
24 target = os.environ['NSS_WRAPPER_HOSTNAME']
25 url = 'http://%s/spnego/' % target
27 proxy = 'http://%s:%s' % (target, os.environ['WRAP_PROXY_PORT'])
28 proxies = { "http" : proxy, }
30 s.headers.update({'Proxy-Authorization': getAuthToken(target)})
31 s.headers.update({'Authorization': getAuthToken(target)})
33 r = s.get(url, proxies=proxies)
34 if r.status_code != 200:
35 raise ValueError('Spnego Proxy Auth Failed')