File indexing completed on 2024-11-26 02:34:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 from sys import version_info
0015 from os import getenv
0016 from os.path import exists
0017 if version_info[0]==2:
0018 from httplib import HTTPSConnection
0019 from urllib2 import AbstractHTTPHandler
0020 else:
0021 from http.client import HTTPSConnection
0022 from urllib.request import AbstractHTTPHandler
0023
0024
0025 class X509CertAuth(HTTPSConnection):
0026 '''Class to authenticate via Grid Certificate'''
0027 def __init__(self, host, *args, **kwargs):
0028 key_file = None
0029 cert_file = None
0030
0031 x509_path = getenv("X509_USER_PROXY", None)
0032 if x509_path and exists(x509_path):
0033 key_file = cert_file = x509_path
0034
0035 if not key_file:
0036 x509_path = getenv("X509_USER_KEY", None)
0037 if x509_path and exists(x509_path):
0038 key_file = x509_path
0039
0040 if not cert_file:
0041 x509_path = getenv("X509_USER_CERT", None)
0042 if x509_path and exists(x509_path):
0043 cert_file = x509_path
0044
0045 if not key_file:
0046 x509_path = getenv("HOME") + "/.globus/userkey.pem"
0047 if exists(x509_path):
0048 key_file = x509_path
0049
0050 if not cert_file:
0051 x509_path = getenv("HOME") + "/.globus/usercert.pem"
0052 if exists(x509_path):
0053 cert_file = x509_path
0054
0055 if not key_file or not exists(key_file):
0056 print("No certificate private key file found", file=stderr)
0057 exit(1)
0058
0059 if not cert_file or not exists(cert_file):
0060 print("No certificate public key file found", file=stderr)
0061 exit(1)
0062
0063
0064
0065
0066 HTTPSConnection.__init__(self,
0067 host,
0068 key_file = key_file,
0069 cert_file = cert_file,
0070 **kwargs)
0071
0072
0073
0074 class X509CertOpen(AbstractHTTPHandler):
0075 def default_open(self, req):
0076 return self.do_open(X509CertAuth, req)