Package ndg :: Package saml :: Package utils :: Module m2crypto :: Class X509Cert
[hide private]

Class X509Cert

source code


NDG X509 Certificate Handling

Instance Methods [hide private]
 
__init__(self, filePath=None, m2CryptoX509=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
read(self, filePath=None, format=None, warningStackLevel=3, **isValidTimeKw)
Read a certificate from PEM encoded DER format file
source code
 
parse(self, certTxt, format=None, warningStackLevel=3, **isValidTimeKw)
Read a certificate input as a string
source code
 
__setM2CryptoX509(self, m2CryptoX509=None)
Private method allows class members to be updated from the current M2Crypto object.
source code
 
__getM2CryptoX509(self, m2CryptoX509=None)
Return M2Crypto X.509 cert object
source code
 
toString(self, **kw)
Return certificate file content as a PEM format string
source code
 
asPEM(self, filePath=None)
Return certificate file content as a PEM format string
source code
 
asDER(self)
Return certificate file content in DER format
source code
 
__getDN(self)
Get X500 Distinguished Name.
source code
 
__getVersion(self)
Get X.509 Certificate version
source code
 
__getSerialNumber(self)
Get Serial Number
source code
 
__getNotBefore(self)
Get not before validity time as datetime type
source code
 
__getNotAfter(self)
Get not after validity time as datetime type
source code
M2Crypto.RSA.RSA_pub
__getPubKey(self)
Get public key
source code
 
__getIssuer(self)
Get Certificate issuer
source code
 
__getSubject(self)
Get Certificate subject
source code
 
isValidTime(self, raiseExcep=False, expiryWarning=True, nDaysBeforeExpiryLimit=30, warningStackLevel=2)
Check Certificate for expiry
source code
 
__m2CryptoUTC2datetime(self, m2CryptoUTC)
Convert M2Crypto UTC time string as returned by get_not_before/ get_not_after methods into datetime type
source code
bool
verify(self, pubKey, **kw)
Verify a certificate against the public key of the issuer
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
Read(cls, filePath, warningStackLevel=4, **isValidTimeKw)
Create a new X509 certificate read in from a file
source code
 
Parse(cls, x509CertTxt, warningStackLevel=4, **isValidTimeKw)
Create a new X509 certificate from string of file content
source code
 
fromM2Crypto(cls, m2CryptoX509)
Convenience method to instantiate a new object from an M2Crypto X.509 certificate object
source code
Class Variables [hide private]
  formatPEM = 1
  formatDER = 0
Properties [hide private]
  m2CryptoX509
M2Crypto.X509.X509 type
  dn
X.509 Distinguished Name
  version
X.509 Certificate version
  serialNumber
X.509 Certificate Serial Number
  notBefore
Not before validity time as datetime type
  notAfter
Not after validity time as datetime type
  pubKey
Public Key
  issuer
Certificate Issuer
  subject
Certificate subject

Inherited from object: __class__

Method Details [hide private]

__init__(self, filePath=None, m2CryptoX509=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

read(self, filePath=None, format=None, warningStackLevel=3, **isValidTimeKw)

source code 

Read a certificate from PEM encoded DER format file

Parameters:
  • filePath (basestring) - file path of PEM format file to be read
  • format (int) - format of input file - PEM is the default. Set to X509Cert.formatDER for DER format
  • isValidTimeKw (dict) - keywords to isValidTime() call

parse(self, certTxt, format=None, warningStackLevel=3, **isValidTimeKw)

source code 

Read a certificate input as a string

Parameters:
  • certTxt (basestring) - PEM encoded certificate to parse
  • format (int) - format of input file - PEM is the default. Set to X509Cert.formatDER for DER format
  • isValidTimeKw (dict) - keywords to isValidTime() call

__setM2CryptoX509(self, m2CryptoX509=None)

source code 

Private method allows class members to be updated from the current M2Crypto object. __m2CryptoX509 must have been set.

__getPubKey(self)

source code 

Get public key

Returns: M2Crypto.RSA.RSA_pub
RSA public key for certificate

isValidTime(self, raiseExcep=False, expiryWarning=True, nDaysBeforeExpiryLimit=30, warningStackLevel=2)

source code 

Check Certificate for expiry

Parameters:
  • raiseExcep (bool) - set True to raise an exception if certificate is invalid
  • expiryWarning (bool) - set to True to output a warning message if the certificate is due to expire in less than nDaysBeforeExpiryLimit days. Message is sent using warnings.warn and through logging.warning. No message is set if the certificate has an otherwise invalid time
  • nDaysBeforeExpiryLimit (int) - used in conjunction with the expiryWarning flag. Set the number of days in advance of certificate expiry from which to start outputing warnings
  • warningStackLevel (int) - set where in the stack to flag the warning from. Level 2 will flag it at the level of the caller of this method. Level 3 would flag at the level of the caller of the caller and so on.
Raises:

verify(self, pubKey, **kw)

source code 

Verify a certificate against the public key of the issuer

Parameters:
  • pubKey (M2Crypto.RSA.RSA_pub) - public key of cert that issued self
  • **kw - keywords to pass to M2Crypto.X509.X509 - 'pkey'
Returns: bool
True if verifies OK, False otherwise

Property Details [hide private]

m2CryptoX509

M2Crypto.X509.X509 type

Get Method:
__getM2CryptoX509(self, m2CryptoX509=None) - Return M2Crypto X.509 cert object
Set Method:
__setM2CryptoX509(self, m2CryptoX509=None) - Private method allows class members to be updated from the current M2Crypto object.

dn

X.509 Distinguished Name

Get Method:
__getDN(self) - Get X500 Distinguished Name.

version

X.509 Certificate version

Get Method:
__getVersion(self) - Get X.509 Certificate version

serialNumber

X.509 Certificate Serial Number

Get Method:
__getSerialNumber(self) - Get Serial Number

notBefore

Not before validity time as datetime type

Get Method:
__getNotBefore(self) - Get not before validity time as datetime type

notAfter

Not after validity time as datetime type

Get Method:
__getNotAfter(self) - Get not after validity time as datetime type

pubKey

Public Key

Get Method:
__getPubKey(self) - Get public key

issuer

Certificate Issuer

Get Method:
__getIssuer(self) - Get Certificate issuer

subject

Certificate subject

Get Method:
__getSubject(self) - Get Certificate subject