CMS 3D CMS Logo

authentication.py
Go to the documentation of this file.
1 ################################################################################
2 # RelMon: a tool for automatic Release Comparison
3 # https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
4 #
5 # This is a code manipulation of a component of the DQMCompare tool of
6 # Marco Rovere and Luca Malgeri.
7 #
8 #
9 #
10 # Danilo Piparo CERN - danilo.piparo@cern.ch
11 #
12 ################################################################################
13 
14 from os import getenv
15 from os.path import exists
16 from httplib import HTTPSConnection
17 from urllib2 import AbstractHTTPHandler
18 #-------------------------------------------------------------------------------
19 
20 class X509CertAuth(HTTPSConnection):
21  '''Class to authenticate via Grid Certificate'''
22  def __init__(self, host, *args, **kwargs):
23  key_file = None
24  cert_file = None
25 
26  x509_path = getenv("X509_USER_PROXY", None)
27  if x509_path and exists(x509_path):
28  key_file = cert_file = x509_path
29 
30  if not key_file:
31  x509_path = getenv("X509_USER_KEY", None)
32  if x509_path and exists(x509_path):
33  key_file = x509_path
34 
35  if not cert_file:
36  x509_path = getenv("X509_USER_CERT", None)
37  if x509_path and exists(x509_path):
38  cert_file = x509_path
39 
40  if not key_file:
41  x509_path = getenv("HOME") + "/.globus/userkey.pem"
42  if exists(x509_path):
43  key_file = x509_path
44 
45  if not cert_file:
46  x509_path = getenv("HOME") + "/.globus/usercert.pem"
47  if exists(x509_path):
48  cert_file = x509_path
49 
50  if not key_file or not exists(key_file):
51  print >>stderr, "No certificate private key file found"
52  exit(1)
53 
54  if not cert_file or not exists(cert_file):
55  print >>stderr, "No certificate public key file found"
56  exit(1)
57 
58  #print "Using SSL private key", key_file
59  #print "Using SSL public key", cert_file
60 
61  HTTPSConnection.__init__(self,
62  host,
63  key_file = key_file,
64  cert_file = cert_file,
65  **kwargs)
66 
67 #-----------------------------------------------------------------------------
68 
69 class X509CertOpen(AbstractHTTPHandler):
70  def default_open(self, req):
71  return self.do_open(X509CertAuth, req)
def __init__(self, host, args, kwargs)