IO::Soc...::Utils(3)
β¨ NAME β¨
IO::Socket::SSL::Utils β loading, storing, creating certificates and keys π
πΈ SYNOPSIS πΈ
okay bestie, here's the vibe, literally copy-paste ready:
use IO::Socket::SSL::Utils;
$cert = PEM_file2cert('cert.pem'); # load certificate from file
my $hash = CERT_asHash($cert); # get details from certificate
PEM_cert2file($cert,'cert.pem'); # write certificate to file
CERT_free($cert); # free memory within OpenSSL
@certs = PEM_file2certs('chain.pem'); # load multiple certificates from file
PEM_certs2file('chain.pem', @certs); # write multiple certificates to file
CERT_free(@certs); # free memory for all within OpenSSL
my $cert = PEM_string2cert($pem); # load certificate from PEM string
$pem = PEM_cert2string($cert); # convert certificate to PEM string
$key = KEY_create_rsa(2048); # create new 2048-bit RSA key
PEM_key2file($key,"key.pem"); # and write it to file
KEY_free($key); # free memory within OpenSSL
π¦ DESCRIPTION π¦
so this module is basically your little helper squad for certificates and private keys π«Ά it hands you a bunch of utility functions so you don't have to rawdog the complexity of the underlying Net::SSLeay and OpenSSL. it's giving "let me handle the scary parts for you", and honestly? iconic.
π FUNCTIONS π
π Functions converting between string or file and certificates and keys
these do the convert-y stuff. heads up: they croak if the operation cannot be completed, so like, no silent failing, she will tell you. π€
PEM_file2cert(file) -> cert
PEM_cert2file(cert,file)
PEM_file2certs(file) -> @certs
PEM_certs2file(file,@certs)
PEM_string2cert(string) -> cert
PEM_cert2string(cert) -> string
PEM_file2key(file) -> key
PEM_key2file(key,file)
PEM_string2key(string) -> key
PEM_key2string(key) -> string
π§ Functions for cleaning up
the memory hygiene era β¨ every cert and key you load or create must be freed, otherwise you're just leaking memory like it's a broken faucet. not cute.
CERT_free(@certs)
KEY_free(@keys)
π₯ KEY_create_rsa(bits) -> key
creates an RSA key pair. bits defaults to 2048 πͺ
π KEY_create_ec(curve) -> key
creates an EC key. curve defaults to "prime256v1" πΏ
π CERT_asHash(cert,[digest_algo]) -> hash
extracts all the info out of the certificate into a hash, and uses the given digest_algo (default: SHA-256) to figure out the digest of pubkey and cert. the resulting hash contains:
subjectβ hash with the parts of the subject, e.g.commonName,countryName,organizationName,stateOrProvinceName,localityName. if there are multiple values for any of these parts, the hash value will be an array ref with the values in order instead of just a scalar. periodt.subjectAltNamesβ array with list of alternative names. each entry in the list is of"[type,value]", where"type"can beOTHERNAME,EMAIL,DNS,X400,DIRNAME,EDIPARTY,URI,IPorRID.issuerβ hash with the parts of the issuer, e.g.commonName,countryName,organizationName,stateOrProvinceName,localityName. if there are multiple values for any of these parts the hash value will be an array ref with the values in order instead of just a scalar.not_before,not_afterβ the time frame where the certificate is valid, astime_t, e.g. can be converted withlocaltimeor similar functions. β°serialβ the serial numbercrl_uriβ list of URIs for CRL distribution.ocsp_uriβ list of URIs for revocation checking using OCSP.keyusageβ list ofkeyUsageinformation in the certificate.extkeyusageβ list of extended key usage information from the certificate. each entry in this list consists of a hash withoid,nid,lnandsn.pubkey_digest_xxxβ binary digest of the pubkey using the given digest algorithm, e.g.pubkey_digest_sha256if (the default)SHA-256was used.x509_digest_xxxβ binary digest of the X.509 certificate using the given digest algorithm, e.g.x509_digest_sha256if (the default)SHA-256was used.fingerprint_xxxβ fingerprint of the certificate using the given digest algorithm, e.g.fingerprint_sha256if (the default)SHA-256was used. contrary todigest_*this is an ASCII string with a list if hexadecimal numbers, e.g."73:59:75:5C:6D...".signature_algβ algorithm used to sign certificate, e.g."sha256WithRSAEncryption".extβ list of extensions. each entry in the list is a hash withoid,nid,sn, critical flag (boolean) anddata(string representation given byX509V3_EXT_print).versionβ certificate version, usually2(x509v3)
π CERT_create(hash) -> (cert,key)
creates a certificate based on the given hash. if the issuer is not specified, the certificate will be self-signed (main character energy, no permission needed π
). the following keys can be given:
subjectβ hash with the parts of the subject, e.g.commonName,countryName, ... as described in"CERT_asHash". default points toIO::Socket::SSL.not_beforeβ atime_tvalue when the certificate starts to be valid. defaults to current time.not_afterβ atime_tvalue when the certificate ends to be valid. defaults to current time plus one 365 days.serialβ the serial number. if not given a random number will be used. π²versionβ the version of the certificate, default2(x509v3).CAtrue|falseβ if true declare certificate as CA, defaults tofalse.purposestring|array|hashβ set the purpose of the certificate. the different purposes can be given as a string separated by non-word character, as array or hash. with string or array each purpose can be prefixed with'+'(enable) or'-'(disable) and same can be done with the value when given as a hash. by default enabling the purpose is assumed.
if the CA option is given and true the defaults "ca,sslca,emailca,objca" are assumed, but can be overridden with explicit purpose. if the CA option is given and false the defaults "server,client" are assumed. if no CA option and no purpose is given it defaults to "server,client".
purpose affects basicConstraints, keyUsage, extKeyUsage and netscapeCertType. the following purposes are defined (case is not important):
client
server
email
objsign
CA
sslCA
emailCA
objCA
emailProtection
codeSigning
timeStamping
digitalSignature
nonRepudiation
keyEncipherment
dataEncipherment
keyAgreement
keyCertSign
cRLSign
encipherOnly
decipherOnly
examples:
# root-CA for SSL certificates
purpose => 'sslCA' # or CA => 1
# server certificate and CA (typically self-signed)
purpose => 'sslCA,server'
# client certificate
purpose => 'client',
ext[{ sn => .., data => ... }, ... ]β list of extensions. the type of the extension can be specified as name with"sn"or as NID with"nid"and the data with"data". these data must be in the same syntax as expected withinopenssl.cnf, e.g. something like"OCSP;URI=http://...". additionally the critical flag can be set with"critical =" 1>.keyβ key use given key as key for certificate, otherwise a new one will be generated and returnedissuer_certcert β set issuer for new certificateissuer_keykey β sign new certificate with given keyissuer[ cert, key ]β instead of givingissuer_keyandissuer_certas separate arguments they can be given both together.digestalgorithm β specify the algorithm used to sign the certificate, defaultSHA-256.ignore_invalid_argsβ ignore any unknown arguments which might be in the argument list (which might be in the arguments for example as result fromCERT_asHash)
π AUTHOR π
Steffen Ullrich β thank you for your service, king π«‘
okay that's the whole page bestie, no cap π this was IO::Socket::SSL::Utils in section 3, shipped with perl v5.42.0, dated 2026-01-17, and yes the header/footer were out here like IO::Soc...::Utils(3) because even man pages gotta abbreviate sometimes π slay, go free your certs πΈ
π¦ where this page comes from
- fedora 44: perl-IO-Socket-SSL 2.098-2.fc44 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms