X509(3pm)
π NAME π
Crypt::OpenSSL::X509 β a Perl extension to OpenSSL's X509 API. (It's from the User Contributed Perl Documentation, iykyk β that's the manual name, bestie π)
β¨ SYNOPSIS β¨
use Crypt::OpenSSL::X509;
my $x509 = Crypt::OpenSSL::X509->new_from_file('cert.pem');
print $x509->pubkey() . "\n";
print $x509->subject() . "\n";
print $x509->hash() . "\n";
print $x509->email() . "\n";
print $x509->issuer() . "\n";
print $x509->issuer_hash() . "\n";
print $x509->notBefore() . "\n";
print $x509->notAfter() . "\n";
print $x509->modulus() . "\n";
print $x509->exponent() . "\n";
print $x509->fingerprint_md5() . "\n";
print $x509->fingerprint_sha256() . "\n";
print $x509->as_string() . "\n";
my $x509 = Crypt::OpenSSL::X509->new_from_string(
$der_encoded_data, Crypt::OpenSSL::X509::FORMAT_ASN1
);
# given a time offset of $seconds, will the certificate be valid?
if ($x509->checkend($seconds)) {
# cert is expired at $seconds offset
} else {
# cert is ok at $seconds offset
}
my $exts = $x509->extensions_by_oid();
foreach my $oid (keys %$exts) {
my $ext = $$exts{$oid};
print $oid, " ", $ext->object()->name(), ": ", $ext->value(), "\n";
}
π¦ ABSTRACT π¦
Crypt::OpenSSL::X509 β Perl extension to OpenSSL's X509 API. That's it, that's the vibe π
πΈ DESCRIPTION πΈ
Okay so this module implements a large majority of OpenSSL's useful X509 API. She's thorough, she's doing the most, we love her for it π
The email() method supports both certificates where the subject is of the form:
"... CN=Firstname lastname/emailAddress=user@domain"
β¦and also certificates where there's an X509v3 Extension of the form:
"X509v3 Subject Alternative Name: email=user@domain"
So like, either way you're getting that email, no cap π
π§ SUPPORTED OPENSSL VERSIONS π§
This module supports multiple versions of OpenSSL and maintains backward compatibility β she's not like other girls, she gets along with everyone:
- OpenSSL 1.0.x β legacy support (1.0.2 and later)
- OpenSSL 1.1.x β full support
- OpenSSL 2.x β (not a thing bestie, keep scrolling)
- OpenSSL 3.x β full support (current stable)
- OpenSSL 4.x β full support (with ASN1 opaque structure compatibility)
- LibreSSL 2.x/3.x β compatible
OpenSSL 4.0.0 introduced opaque ASN1 string types, which requires using accessor functions instead of direct structure member access. This module uses conditional compilation to keep compatibility across all versions while supporting the new OpenSSL 4.x API requirements. Lowkey iconic of her honestly π
π EXPORT π
None by default. She respects your boundaries π«Ά
On request:
FORMAT_UNDEF FORMAT_ASN1 FORMAT_TEXT FORMAT_PEM
FORMAT_PKCS12 FORMAT_SMIME FORMAT_ENGINE FORMAT_IISSGC
π₯ FUNCTIONS π₯
π« X509 CONSTRUCTORS π«
new ( )β creates a brand-new X509 object. Fresh out the box β¨new_from_string ( STRING [ FORMAT ] )new_from_file ( FILENAME [ FORMAT ] )β create a new X509 object from a string or a file.FORMATshould beFORMAT_ASN1orFORMAT_PEM, bestie, don't forget π
β X509 ACCESSORS β
subjectβ subject name as a string.issuerβ issuer name as a string.issuer_hashβ issuer name hash as a string.serialβ serial number as a string.hashβ alias forsubject_hash. Same energy, different name.subject_hashβ subject name hash as a string.notBeforeβnotBeforetime as a string.notAfterβnotAftertime as a string.emailβ email addresses as a string. If it finds multiple addresses, they're separated by a space (' '). She's not messy, she's organized πversionβ certificate version as a string.sig_alg_nameβ signature algorithm name as a string.key_alg_nameβ public key algorithm name as a string.curveβ name of the EC curve used in the public key.
π X509 METHODS π
subject_name ( )issuer_name ( )β return a Name object for the subject or issuer name. Methods for handling Name objects are given below πis_selfsigned ( )β returns a boolean value, true if subject and issuer name are the same. It's giving "I made myself" main character energy πͺas_string ( [ FORMAT ] )β returns the certificate as a string in the specified format.FORMATcan be one ofFORMAT_PEM(the default) orFORMAT_ASN1.modulus ( )β returns the modulus for an RSA public key as a string of hex digits. For DSA and EC it returns the public key instead. Other algorithms are not supported πbit_length ( )β returns the length of the modulus as a number of bits.fingerprint_md5 ( )fingerprint_sha1 ( )fingerprint_sha224 ( )fingerprint_sha256 ( )fingerprint_sha384 ( )fingerprint_sha512 ( )β returns the specified message digest for the certificate. Whole family, all slaying πcheckend( OFFSET )β given an offset in seconds, will the certificate be expired? Returns true if the certificate will be expired, false otherwise. (Yes, the logic is a little feral β read it twice, bestie π)pubkey ( )β returns the RSA, DSA, or EC public key.num_extensions ( )β returns the number of extensions in the certificate. Counting her accessories πextension ( INDEX )β returns the Extension specified by the integerINDEX. Methods for handling Extension objects are given below πextensions_by_oid ( )extensions_by_name ( )extensions_by_long_name ( )β return a hash of Extensions indexed by OID or name. Take your pick, queen πΈhas_extension_oid ( OID )β returns true if the certificate has the extension specified byOID.subjectaltname ( )β usesConvert::ASN1to extract the Subject Alternative Names from the X509 object.subjectaltname ( )returns an array of objects, each object representing a SAN.
These could be of the following types (as defined in the embedded ASN.1 schema):
rfc822Nameβ email address (IA5String)dNSNameβ DNS hostname (IA5String)x400Addressβ X.400 address (ANY)directoryNameβ Distinguished Name (RDNSequence)ediPartyNameβ EDI party name (EDIPartyName)uniformResourceIdentifierβ URI (IA5String)iPAddressβ IP address (OCTET STRING; 4 bytes IPv4, 16 bytes IPv6)registeredIDβ OID (OBJECT IDENTIFIER)
β οΈ Note:otherName(tag[0]in RFC 5280) is not implemented and will never appear in the output. She simply doesn't know her, periodt π
[
{
'rfc822Name' => 'altuser@mpi-sws.org'
},
{
'rfc822Name' => 'user@mpi-sws.org'
},
]
π X509::Extension METHODS π
critical ( )β returns a value indicating if the extension is critical or not. FIXME: the value is an ASN.1 BOOLEAN value. (She's aware, she's working on it π)object ( )β returns the ObjectID of the extension. Methods for handling ObjectID objects are given below πvalue ( )β returns the value of the extension as anasn1parse(1)style hex dump.as_string ( )β returns a human-readable version of the extension as formatted byX509V3_EXT_print. Heads up: this returns an empty string for OIDs with unknown ASN.1 encodings πbasicC ( TYPE )β returns the value of abasicConstraintsfield.TYPEmust beca(returns1if the certificate is a CA,0otherwise) orpathlen(returns the path length constraint, or0if absent).
π¨ This one throws if thebasicConstraintsextension DER cannot be parsed. Callers processing certificates from untrusted sources should wrap this call ineval {}β fr fr, do it:perl my $is_ca = eval { $ext->basicC('ca') } // 0;
ia5string ( )β returns the value of an IA5String extension (e.g.nsComment) as a string. Returns an empty string if the extension DER cannot be parsed.bit_string ( )β returns the bit-string value of a key usage or Netscape certificate type extension as a string of0/1characters. Returns an empty string if the extension DER cannot be parsed.auth_att ( )β returns1if the Authority Key Identifier extension contains akeyIdentifierfield,0otherwise. Returns0if the extension DER cannot be parsed.keyid_data ( )β returns the key identifier octets from asubjectKeyIdentifierorauthorityKeyIdentifierextension as a binary string. Returns an empty string if the extension DER cannot be parsed or if the optionalkeyIdentifierfield is absent.extendedKeyUsage ( )β returns the extended key usage OIDs as a space-separated string of short names (e.g.serverAuth clientAuth). OIDs with no registered short name are silently omitted. Returns an empty string if the extension DER cannot be parsed. She's quiet about the ones she doesn't know π€«
π X509::ObjectID METHODS π
name ( )β returns the long name of the object as a string.oid ( )β returns the numeric dot-separated form of the object identifier as a string.
π¦ X509::Name METHODS π¦
as_string ( )β returns a string representation of the Name.entries ( )β returns an array of Name_Entry objects. Methods for handling Name_Entry objects are given below πhas_entry ( TYPE [ LASTPOS ] )has_long_entry ( TYPE [ LASTPOS ] )has_oid_entry ( TYPE [ LASTPOS ] )β returns true if a name has an entry of the specifiedTYPE. Depending on the function,TYPEmay be in the short form (e.g.CN), long form (commonName) or OID (2.5.4.3). IfLASTPOSis specified, the search starts from that index rather than from the beginning. Skipping ahead, we stan πget_index_by_type ( TYPE [ LASTPOS ] )get_index_by_long_type ( TYPE [ LASTPOS ] )get_index_by_oid_type ( TYPE [ LASTPOS ] )β returns the index of an entry of the specifiedTYPEin a name. Depending on the function,TYPEmay be in the short form (e.g.CN), long form (commonName) or OID (2.5.4.3). IfLASTPOSis specified, the search starts from that index rather than from the beginning.get_entry_by_type ( TYPE [ LASTPOS ] )get_entry_by_long_type ( TYPE [ LASTPOS ] )β these methods work similarly toget_index_by_*but return the Name_Entry rather than the index. Same search, better gift wrap π
π X509::Name_Entry METHODS π
as_string ( [ LONG ] )β returns a string representation of the Name_Entry of the formtypeName=Value. IfLONGis1, the long form of the type is used.type ( [ LONG ] )β returns a string representation of the type of the Name_Entry. IfLONGis1, the long form of the type is used.value ( )β returns a string representation of the value of the Name_Entry.is_printableString ( )is_ia5string ( )is_utf8string ( )is_asn1_type ( [ASN1_TYPE] )β return true if the Name_Entry value is of the specified type. The value ofASN1_TYPEshould be as listed in OpenSSL'sasn1.hπ
π«Ά ISSUE REPORTING π«Ά
Please report any bugs or feature requests using GitHub. She reads her DMs, bestie π
- GitHub Issues β
https://github.com/dsully/perl-crypt-openssl-x509/issues(link split across lines in the original ashttps://github.com/dsully/perl-crypt-openssl-/x509/issuesβ same URL, no cap π¦)
π SEE ALSO π
Okay bestie, if you're in your βI need more loreβ era, these are the links to bookmark:
- OpenSSL website β
https://www.openssl.org/π«Ά - Crypt::OpenSSL::RSA β
https://metacpan.org/pod/Crypt::OpenSSL::RSAπ₯ - Crypt::OpenSSL::Bignum β
https://metacpan.org/pod/Crypt::OpenSSL::Bignumβ¨ - Crypt::OpenSSL::Guess β
https://metacpan.org/pod/Crypt::OpenSSL::Guessπ¦
π AUTHOR π
The people behind the page, no cap:
- Dan Sully β original author π
- Jonas BrΓΈmsΓΈ β current maintainer β¨
- Please see the
"ACKNOWLEDGEMENTS"section for a list of contributors. π«Ά
π ACKNOWLEDGEMENTS π
In alphabetical order, because we stay organized. Shoutout to every single one of these icons:
- @eserte
- @kmx
- @stphnlyd
- Ashley Hindmarsh @bestscarper
- Bernhard M. Wiedemann @bmwiedemann
- Brad Davidson @brandond
- Daniel Kahn Gillmor
- Daniel Risacher
- David O'Callaghan
- David Steinbrunner @dsteinbrunner
- dsteinwand
- Florian Schlichting @fschlich
- IKEDA Soji @ikedas
- James Hunt @jhunt
- James Rouzier @jrouzierinverse
- Johanna @0xxon
- Jonas BrΓΈmsΓΈ @jonasbn
- Louise Doran
- Maxime Besson @maxbes
- Michael McClimon @mmcclimon
- Michal Josef Ε paΔek @michal-josef-spacek
- Neil Bowers @neilb
- Nicholas Harteau
- Otmar Lendl
- Patrick C. @errror
- Patrick Cernko
- Petr Pisar @ppisar
- pi-rho
- Salvador FandiΓ±o @salva
- Sebastian Andrzej Siewior
- Sho Nakatani @laysakura
- Shoichi Kaji @skaji
- Timothy Legge @timlegge
- Todd Rinaldo @toddr
- Uli Scholler
π COPYRIGHT AND LICENSE π
Copyright 2004 by Dan Sully
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π That's the whole page, bestie! It's from perl v5.42.3, dated 2026-08-20, and it's the X509(3pm) page. Byeee! π
β¨
π¦ where this page comes from
- ubuntu stonking: libcrypt-openssl-x509-perl 2.1.3-1build2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms