Changeset 2932 for TI12-security/trunk/python/ndg.security.common/ndg/security/common/m2CryptoSSLUtility.py
- Timestamp:
- 08/10/07 09:17:08 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/m2CryptoSSLUtility.py
r2931 r2932 22 22 class InvalidCertSignature(SSL.Checker.SSLVerificationError): 23 23 """Raise if verification against CA cert public key fails""" 24 24 25 class InvalidCertDN(SSL.Checker.SSLVerificationError): 26 """Raise if verification against a list acceptable DNs fails""" 27 25 28 26 29 class HostCheck(SSL.Checker.Checker, object): … … 30 33 def __init__(self, 31 34 peerCertDN=None, 32 peerCertCN=None, 35 peerCertCN=None, 36 acceptedDNs=[], 33 37 caCertList=[], 34 38 caCertFilePathList=[], … … 40 44 @param peerCertDN: Set the expected Distinguished Name of the 41 45 server to avoid errors matching hostnames. This is useful 42 where the hostname is not fully qualified. Alternatively set a list 43 of acceptable DNs. This enables validation where the expected DN is 44 could be one a number of different identities. 46 where the hostname is not fully qualified. 47 48 *param acceptedDNs: a list of acceptable DNs. This enables validation where the expected DN is 49 where against a limited list of certs. 45 50 46 51 @type peerCertCN: string … … 61 66 self.peerCertDN = peerCertDN 62 67 self.peerCertCN = peerCertCN 68 self.acceptedDNs = acceptedDNs 69 63 70 if caCertList: 64 71 self.caCertList = caCertList … … 73 80 @param host: name of host to check 74 81 """ 75 82 peerCertDN = '/'+peerCert.get_subject().as_text().replace(', ', '/') 76 83 try: 77 84 SSL.Checker.Checker.__call__(self, peerCert, host=self.peerCertCN) 78 85 79 86 except SSL.Checker.WrongHost, e: 80 # Try match against peerCertDN set 81 # file setting 82 peerCertDN='/'+peerCert.get_subject().as_text().replace(', ', '/') 83 84 if isinstance(self.peerCertDN, list): 85 # At least one match should be found in the list 86 if not len([dn for dn in self.peerCertDN if peerCertDN==dn]): 87 raise e 88 else: 89 if peerCertDN != self.peerCertDN: 90 raise e 87 # Try match against peerCertDN set 88 if peerCertDN != self.peerCertDN: 89 raise e 90 91 # At least one match should be found in the list 92 if self.acceptedDNs and \ 93 not len([dn for dn in self.acceptedDNs if peerCertDN==dn]): 94 raise InvalidCertDN, \ 95 "Peer cert DN %s doesn't match verification list" % peerCertDN 91 96 92 97 if len(self.__caCertStack) > 0:
Note: See TracChangeset
for help on using the changeset viewer.