forked from CMSTrackerDPG/CosmicsCounter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx509auth.py
More file actions
71 lines (56 loc) · 2.07 KB
/
Copy pathx509auth.py
File metadata and controls
71 lines (56 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os, sys, urllib.request, urllib.error, urllib.parse, http.client, json
from ROOT import *
from array import *
serverurl = 'https://cmsweb.cern.ch/dqm/offline'
ident = "DQMToJson/1.0 python/%d.%d.%d" % sys.version_info[:3]
HTTPS = http.client.HTTPSConnection
class X509CertAuth(HTTPS):
ssl_key_file = None
ssl_cert_file = None
def __init__(self, host, *args, **kwargs):
HTTPS.__init__(self, host,
key_file = X509CertAuth.ssl_key_file,
cert_file = X509CertAuth.ssl_cert_file,
**kwargs)
class X509CertOpen(urllib.request.AbstractHTTPHandler):
def default_open(self, req):
return self.do_open(X509CertAuth, req)
def x509_params():
key_file = cert_file = None
x509_path = os.getenv("X509_USER_PROXY", None)
if x509_path and os.path.exists(x509_path):
## key_file = cert_file = x509_path
key_file = cert_file = "/tmp/x509up_u133079"
if not key_file:
x509_path = "/tmp/x509up_u133079"
if os.path.exists(x509_path):
key_file = x509_path
if not cert_file:
x509_path = "/tmp/x509up_u133079"
if os.path.exists(x509_path):
cert_file = x509_path
if not key_file:
x509_path = os.getenv("X509_USER_KEY", None)
if x509_path and os.path.exists(x509_path):
key_file = x509_path
if not cert_file:
x509_path = os.getenv("X509_USER_CERT", None)
if x509_path and os.path.exists(x509_path):
cert_file = x509_path
if not key_file:
x509_path = os.getenv("HOME") + "/private/userkey.pem"
if os.path.exists(x509_path):
key_file = x509_path
if not cert_file:
x509_path = os.getenv("HOME") + "/private/usercert.pem"
if os.path.exists(x509_path):
cert_file = x509_path
if not key_file or not os.path.exists(key_file):
print >>sys.stderr, "no certificate private key file found"
sys.exit(1)
if not cert_file or not os.path.exists(cert_file):
print >>sys.stderr, "no certificate public key file found"
sys.exit(1)
sys.stderr.write("Using SSL private key %s\n" % key_file)
sys.stderr.write("Using SSL public key %s\n" % cert_file)
return key_file, cert_file