IO::Socket::SSL::Utils -- loading, storing, creating certificates and keys
use IO::Socket::SSL::Utils; my $cert = PEM_file2cert('cert.pem'); my $string = PEM_cert2string($cert); CERT_free($cert); my $key = KEY_create_rsa(2048); PEM_string2file($key); KEY_free($key);
This module provides various utility functions to work with certificates and private keys, shielding some of the complexity of the underlying Net::SSLeay and OpenSSL.
Creates an RSA key pair, bits defaults to 2048.
Extracts the information from the certificate into a hash and uses the given digest_algo (default: SHA-256) to determine digest of pubkey and cert. The resulting hash contains:
Hash with the parts of the subject, e.g. commonName, countryName, organizationName, stateOrProvinceName, localityName.
Array with list of alternative names. Each entry in the list is of
type can be OTHERNAME, EMAIL, DNS, X400, DIRNAME, EDIPARTY, URI, IP or RID.
Hash with the parts of the issuer, e.g. commonName, countryName, organizationName, stateOrProvinceName, localityName.
The time frame, where the certificate is valid, as time_t, e.g. can be converted with localtime or similar functions.
The serial number
List if URIs for CRL distribution.
List if URIs for revocation checking using OCSP.
List of keyUsage information in the certificate.
List of extended key usage information from the certificate. Each entry in this list consists of a hash with oid, nid, ln and sn.
Binary digest of the pubkey using the given digest algorithm, e.g. pubkey_digest_sha256 if (the default) SHA-256 was used.
Binary digest of the certificate using the given digest algorithm, e.g. cert_digest_sha256 if (the default) SHA-256 was used.
Fingerprint of the certificate using the given digest algorithm, e.g. fingerprint_sha256 if (the default) SHA-256 was used. Contrary to digest_* this is an ASCII string with a list if hexadecimal numbers, e.g. "73:59:75:5C:6D...".
List of extensions. Each entry in the list is a hash with oid, nid, sn, critical flag (boolean) and data (string representation given by X509V3_EXT_print).
Certificate version, usually 2 (x509v3)
Creates a certificate based on the given hash. If the issuer is not specified the certificate will be self-signed. The following keys can be given:
Hash with the parts of the subject, e.g. commonName, countryName, ... as described in
CERT_asHash. Default points to IO::Socket::SSL.
A time_t value when the certificate starts to be valid. Defaults to current time.
A time_t value when the certificate ends to be valid. Defaults to current time plus one 365 days.
The serial number. If not given a random number will be used.
The version of the certificate, default 2 (x509v3).
if true declare certificate as CA, defaults to false
use given key as key for certificate, otherwise a new one will be generated and returned
set issuer for new certificate
sign new certificate with given key
Instead of giving issuer_key and issuer_cert as separate arguments they can be given both together.
specify the algorithm used to sign the certificate, default SHA-256.