Package M2Crypto :: Module X509 :: Class X509
[frames] | no frames]

Class X509



X.509 Certificate

Instance Methods
 
m2_x509_free(...)
 
__init__(self, x509=None, _pyfree=0)
 
__del__(self)
 
as_text(self)
 
as_der(self)
 
as_pem(self)
 
save_pem(self, filename)
save_pem
 
save(self, filename, format=1)
Saves X.509 certificate to a file.
int
set_version(self, version)
Set version.
 
set_not_before(self, asn1_utctime)
 
set_not_after(self, asn1_utctime)
 
set_subject_name(self, name)
 
set_issuer_name(self, name)
 
get_version(self)
 
get_serial_number(self)
 
set_serial_number(self, serial)
Set serial number.
 
get_not_before(self)
 
get_not_after(self)
 
get_pubkey(self)
 
set_pubkey(self, pkey)
Set the public key for the certificate
 
get_issuer(self)
 
set_issuer(self, name)
Set issuer name.
 
get_subject(self)
 
set_subject(self, name)
Set subject name.
 
add_ext(self, ext)
Add X509 extension to this certificate.
 
get_ext(self, name)
Get X509 extension by name.
 
get_ext_at(self, index)
Get X509 extension by index.
 
get_ext_count(self)
Get X509 extension count.
 
sign(self, pkey, md)
Sign the certificate.
 
verify(self, pkey=None)
 
check_ca(self)
Check if the certificate is a Certificate Authority (CA) certificate.
 
check_purpose(self, id, ca)
Check if the certificate's purpose matches the asked purpose.
 
get_fingerprint(self, md='md5')
Get the fingerprint of the certificate.
Method Details

save(self, filename, format=1)

 

Saves X.509 certificate to a file. Default output format is PEM.

Parameters:
  • filename (string) - Name of the file the cert will be saved to.
  • format (int) - Controls what output format is used to save the cert. Either FORMAT_PEM or FORMAT_DER to save in PEM or DER format. Raises a ValueError if an unknow format is used.

set_version(self, version)

 

Set version.

Parameters:
  • version (int) - Version number.
Returns: int
Returns 0 on failure.

set_serial_number(self, serial)

 

Set serial number.

Parameters:
  • serial (int) - Serial number.

set_pubkey(self, pkey)

 

Set the public key for the certificate

Parameters:
  • pkey (EVP_PKEY) - Public key

set_issuer(self, name)

 

Set issuer name.

Parameters:
  • name (X509_Name) - subjectName field.

set_subject(self, name)

 

Set subject name.

Parameters:
  • name (X509_Name) - subjectName field.

add_ext(self, ext)

 

Add X509 extension to this certificate.

Parameters:
  • ext (X509_Extension) - Extension

get_ext(self, name)

 

Get X509 extension by name.

Parameters:
  • name (Name of the extension) - str
Returns:
X509_Extension

get_ext_at(self, index)

 

Get X509 extension by index.

Parameters:
  • index (Name of the extension) - int
Returns:
X509_Extension

sign(self, pkey, md)

 

Sign the certificate.

Parameters:
  • pkey (EVP_PKEY) - Public key
  • md (str) - Message digest algorithm to use for signing, for example 'sha1'.

check_ca(self)

 

Check if the certificate is a Certificate Authority (CA) certificate.

Returns:
0 if the certificate is not CA, nonzero otherwise.

Requires: OpenSSL 0.9.8 or newer

check_purpose(self, id, ca)

 

Check if the certificate's purpose matches the asked purpose.

Parameters:
  • id - Purpose id. See X509_PURPOSE_* constants.
  • ca - 1 if the certificate should be CA, 0 otherwise.
Returns:
0 if the certificate purpose does not match, nonzero otherwise.

get_fingerprint(self, md='md5')

 

Get the fingerprint of the certificate.

Parameters:
  • md - Message digest algorithm to use.
Returns:
String containing the fingerprint in hex format.