"Fossies" - the Fresh Open Source Software Archive

Member "mod_auth_gssapi-1.6.3/tests/t_spnego_proxy.py" (15 May 2020, 1002 Bytes) of package /linux/www/apache_httpd_modules/mod_auth_gssapi-1.6.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "t_spnego_proxy.py": 1.6.2_vs_1.6.3.

    1 #!/usr/bin/env python
    2 # Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license.
    3 
    4 import os
    5 from base64 import b64encode
    6 
    7 import gssapi
    8 
    9 import requests
   10 
   11 
   12 def getAuthToken(target):
   13     spnego_mech = gssapi.raw.OID.from_int_seq('1.3.6.1.5.5.2')
   14 
   15     name = gssapi.Name('HTTP@%s' % target,
   16                        gssapi.NameType.hostbased_service)
   17 
   18     ctx = gssapi.SecurityContext(name=name, mech=spnego_mech)
   19     token = ctx.step()
   20 
   21     return 'Negotiate %s' % b64encode(token).decode()
   22 
   23 
   24 if __name__ == '__main__':
   25     s = requests.Session()
   26 
   27     target = os.environ['NSS_WRAPPER_HOSTNAME']
   28     url = 'http://%s/spnego/' % target
   29 
   30     proxy = 'http://%s:%s' % (target, os.environ['WRAP_PROXY_PORT'])
   31     proxies = {"http": proxy, }
   32 
   33     s.headers.update({'Proxy-Authorization': getAuthToken(target)})
   34     s.headers.update({'Authorization': getAuthToken(target)})
   35 
   36     r = s.get(url, proxies=proxies)
   37     if r.status_code != 200:
   38         raise ValueError('Spnego Proxy Auth Failed')