Python functions for generate a X509 client certificate for XMPP or HTTP WebID authentication (including WebId and XMPP id at SubjectAltName).
author: | Julia Anaya |
---|---|
organization: | xmppwebid community |
copyright: | author |
license: | GNU GPL version 3 or any later version (details at http://www.gnu.org) |
contact: | julia dot anaya at gmail dot com |
dependencies: | python (>= version 2.6), m2crypto (>= version 0.20), pyopenssl (>= version 0.12) |
change log: |
Todo
Get serial number from file
Parameters: | serial_path (string) – serial file path |
---|---|
Returns: | serial number |
Return type: | int |
Set certificate serial number
Parameters: |
|
---|
Set certificate valid time
Parameters: |
|
---|
Create RSA key pair Equivalent to: openssl genrsa -des3 -out client.key 1024
Parameters: | bits (int) – key bits length |
---|---|
Returns: | key |
Return type: | EVP.PKey |
Create an x509 CSR (Certificate Signing Request) Equivalent to: openssl req -new -key client.key -out client.csr
Parameters: | pkey (EVP.PKey) – key |
---|---|
Returns: | x509 request |
Return type: | X509.Request |
Set the CSR Subject data
Parameters: | |
---|---|
Returns: | x509 request |
Return type: | X509.Request |
Set the CSR SubjectAltName and Subject
Parameters: | |
---|---|
Returns: | x509 request |
Return type: | X509.Request |
Sign the CSR
Parameters: |
|
---|---|
Returns: | x509 request, key |
Return type: | X509.Request, EVP.PKey |
Create an x509 certificate from CSR with default values
Parameters: | |
---|---|
Returns: | x509 certificate |
Return type: | X509.X509 |
Set the SubjectAltName, Issuer and Subject
Parameters: | |
---|---|
Returns: | x509 certificate |
Return type: | X509.X509 |
Sign the cert
Parameters: |
|
---|---|
Returns: | x509 certificate, key |
Return type: | X509.X509, EVP.PKey |
Save cert and pkey to files
Parameters: | |
---|---|
Returns: | x509 certificate path, key path |
Return type: | tuple (string, string) |
Create an x509 self-signed certificate
Equivalent to: openssl x509 -req -days 365 -in client.csr -signkey client.key -out client.crt
Parameters: | |
---|---|
Returns: | x509 self-signed certificate, key |
Return type: | tuple (X509.X509, EVP.PKey) |
Create an x509 self-signed certificate and save it as PEM file
Parameters: | |
---|---|
Returns: | x509 certificate path, key path |
Return type: | tuple (string, string) |
Set the SubjectAltName, Issuer and Subject
Parameters: | |
---|---|
Returns: | x509 certificate |
Return type: | X509.X509 |
Set the CA contraint to true
Parameters: | cert (X509.X509) – x509 certificate |
---|---|
Returns: | x509 certificate |
Return type: | X509.X509 |
Create an x509 CA certificate
Parameters: |
|
---|---|
Returns: | x509 self-signed certificate, key |
Return type: | tuple (X509.X509, EVP.PKey) |
Create an x509 CA certificate and save it as PEM file
Parameters: |
|
---|---|
Returns: | x509 certificate path, key path |
Return type: | tuple (string, string) |
Create an x509 CA-signed certificate
Parameters: | |
---|---|
Returns: | x509 self-signed certificate, private key |
Return type: | tuple (X509.X509, EVP.PKey) |
Create an x509 CA-signed certificate and save it as PEM file
Parameters: | |
---|---|
Returns: | x509 certificate path, key path |
Return type: | tuple (string, string) |
Create a PKCS12 certificate from x509 certificate and key
Parameters: |
|
---|---|
Returns: | PKCS12 certificate |
Return type: | OpenSSL.crypto.PKCS12 |
Todo
create pkcs12 m2crypto function (http://osdir.com/ml/python.cryptography/2004-05/msg00001.html)
Todo
create pkcs12 with password interactively
Save PKCS12 certificate to file
Parameters: |
|
---|---|
Returns: | PKCS12 certificate path |
Return type: | string |
Create a PKCS12 certificate and save it from x509 certificate and key files as PEM
Parameters: | |
---|---|
Returns: | PKCS12 certificate path |
Return type: | string |
Get PKCS12 from file
Parameters: | p12cert_path (string) – key path |
---|---|
Returns: | PKCS12 certificate |
Return type: | OpenSSL.crypto.PKCS12 |
Get X509 certificate and key from PKCS12
Parameters: | p12 (OpenSSL.crypto.PKCS12) – PKCS12 certificate |
---|---|
Returns: | x509 self-signed certificate, key |
Return type: | tuple (OpenSSL.crypto.X509, OpenSSL.crypto.PKey) |
Get X509 certificate and key from PKCS12 file and save them as PEM key files as PEM
Parameters: |
---|
Get certificate from file
Parameters: | cert_path (string) – certificate path |
---|---|
Returns: | x509 certificate |
Return type: | X509.X509 |
Get key from file
Parameters: | key_path (string) – key path |
---|---|
Returns: | key |
Return type: | EVP.PKey |
Create a PEM file with X509 certificate and key from PEM files
Parameters: | |
---|---|
Returns: | PEM file with X509 certificate and key path |
Return type: | string |
Get the modulus and exponent of RSA key from a PEM Certificate and key files m2.rsa_get_e(rsa.rsa) return something like ‘’ so to get the decimal value (65537), two crufty methods
Parameters: | |
---|---|
Returns: | tuple(modulus, exponent) |
Return type: | tuple (hex, int) |
Todo
replace the exponent method with something cleaner
Get the modulus and exponent of RSA key from a PEM Certificate file
m2.rsa_get_e(rsa.rsa) return something like ‘’ so to get the decimal value (65537), two crufty methods
Parameters: | cert_path (string) – certificate path |
---|---|
Returns: | tuple(modulus, exponent) |
Return type: | tuple (hex, int) |
Todo
replace the exponent method with something cleaner