Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Crypto::X509Certificate Class Reference

This class represents a X509 Certificate. More...

#include <X509Certificate.h>

+ Inheritance diagram for Poco::Crypto::X509Certificate:
+ Collaboration diagram for Poco::Crypto::X509Certificate:

Public Types

enum  NID {
  NID_COMMON_NAME = 13 , NID_COUNTRY = 14 , NID_LOCALITY_NAME = 15 , NID_STATE_OR_PROVINCE = 16 ,
  NID_ORGANIZATION_NAME = 17 , NID_ORGANIZATION_UNIT_NAME = 18 , NID_PKCS9_EMAIL_ADDRESS = 48 , NID_SERIAL_NUMBER = 105
}
 
using List = std::vector<X509Certificate>
 

Public Member Functions

 X509Certificate (std::istream &istr)
 
 X509Certificate (const std::string &path)
 
 X509Certificate (X509 *pCert)
 
 X509Certificate (X509 *pCert, bool shared)
 
 X509Certificate (const X509Certificate &cert)
 
 X509Certificate (X509Certificate &&cert) noexcept
 Creates the certificate by copying another one.
 
X509Certificateoperator= (const X509Certificate &cert)
 Creates the certificate by moving another one.
 
X509Certificateoperator= (X509Certificate &&cert) noexcept
 Assigns a certificate.
 
void swap (X509Certificate &cert)
 Move assignment.
 
 ~X509Certificate ()
 Exchanges the certificate with another one.
 
long version () const
 Destroys the X509Certificate.
 
const std::string & serialNumber () const
 Returns the version of the certificate.
 
const std::string & issuerName () const
 
std::string issuerName (NID nid) const
 Returns the certificate issuer's distinguished name.
 
const std::string & subjectName () const
 
std::string subjectName (NID nid) const
 Returns the certificate subject's distinguished name.
 
std::string commonName () const
 
void extractNames (std::string &commonName, std::set< std::string > &domainNames) const
 
Poco::DateTime validFrom () const
 
Poco::DateTime expiresOn () const
 Returns the date and time the certificate is valid from.
 
Poco::DigestEngine::Digest fingerprint (const std::string &algorithm="SHA1") const
 Returns the date and time the certificate expires.
 
void save (std::ostream &stream) const
 
void save (const std::string &path) const
 
bool issuedBy (const X509Certificate &issuerCertificate) const
 
bool equals (const X509Certificate &otherCertificate) const
 
const X509certificate () const
 
X509dup () const
 Returns the underlying OpenSSL certificate.
 
std::string signatureAlgorithm () const
 
void print (std::ostream &out) const
 Returns the certificate signature algorithm long name.
 

Static Public Member Functions

static List readPEM (const std::string &pemFileName)
 Prints the certificate information to ostream.
 
static void writePEM (const std::string &pemFileName, const List &list)
 

Protected Member Functions

void load (std::istream &stream)
 Writes the list of certificates to the specified PEM file.
 
void load (const std::string &path)
 
void init ()
 

Private Types

enum  { NAME_BUFFER_SIZE = 256 }
 Extracts issuer and subject name from the certificate. More...
 

Private Attributes

std::string _issuerName
 
std::string _subjectName
 
std::string _serialNumber
 
X509_pCert
 
OpenSSLInitializer _openSSLInitializer
 

Detailed Description

This class represents a X509 Certificate.

Definition at line 36 of file X509Certificate.h.

Member Typedef Documentation

◆ List

Definition at line 40 of file X509Certificate.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Extracts issuer and subject name from the certificate.

Enumerator
NAME_BUFFER_SIZE 

Definition at line 197 of file X509Certificate.h.

◆ NID

Name identifier for extracting information from a certificate subject's or issuer's distinguished name.

Enumerator
NID_COMMON_NAME 
NID_COUNTRY 
NID_LOCALITY_NAME 
NID_STATE_OR_PROVINCE 
NID_ORGANIZATION_NAME 
NID_ORGANIZATION_UNIT_NAME 
NID_PKCS9_EMAIL_ADDRESS 
NID_SERIAL_NUMBER 

Definition at line 42 of file X509Certificate.h.

Constructor & Destructor Documentation

◆ X509Certificate() [1/6]

Poco::Crypto::X509Certificate::X509Certificate ( std::istream & istr)
explicit

◆ X509Certificate() [2/6]

Poco::Crypto::X509Certificate::X509Certificate ( const std::string & path)
explicit

Creates the X509Certificate object by reading a certificate in PEM format from a stream.

◆ X509Certificate() [3/6]

Poco::Crypto::X509Certificate::X509Certificate ( X509 * pCert)
explicit

Creates the X509Certificate object by reading a certificate in PEM format from a file.

◆ X509Certificate() [4/6]

Poco::Crypto::X509Certificate::X509Certificate ( X509 * pCert,
bool shared )

Creates the X509Certificate from an existing OpenSSL certificate. Ownership is taken of the certificate.

◆ X509Certificate() [5/6]

Poco::Crypto::X509Certificate::X509Certificate ( const X509Certificate & cert)

Creates the X509Certificate from an existing OpenSSL certificate. Ownership is taken of the certificate. If shared is true, the certificate's reference count is incremented.

◆ X509Certificate() [6/6]

Poco::Crypto::X509Certificate::X509Certificate ( X509Certificate && cert)
noexcept

Creates the certificate by copying another one.

◆ ~X509Certificate()

Poco::Crypto::X509Certificate::~X509Certificate ( )

Exchanges the certificate with another one.

Member Function Documentation

◆ certificate()

const X509 * Poco::Crypto::X509Certificate::certificate ( ) const
inline

Checks whether the certificate is equal to the other certificate, by comparing the hashes of both certificates.

Returns true if both certificates are identical, otherwise false.

Definition at line 242 of file X509Certificate.h.

◆ commonName()

std::string Poco::Crypto::X509Certificate::commonName ( ) const

Extracts the information specified by the given NID (name identifier) from the certificate subject's distinguished name.

◆ dup()

X509 * Poco::Crypto::X509Certificate::dup ( ) const
inline

Returns the underlying OpenSSL certificate.

Definition at line 248 of file X509Certificate.h.

◆ equals()

bool Poco::Crypto::X509Certificate::equals ( const X509Certificate & otherCertificate) const

Checks whether the certificate has been issued by the issuer given by issuerCertificate. This can be used to validate a certificate chain.

Verifies if the certificate has been signed with the issuer's private key, using the public key from the issuer certificate.

Returns true if verification against the issuer certificate was successful, false otherwise.

◆ expiresOn()

Poco::DateTime Poco::Crypto::X509Certificate::expiresOn ( ) const

Returns the date and time the certificate is valid from.

◆ extractNames()

void Poco::Crypto::X509Certificate::extractNames ( std::string & commonName,
std::set< std::string > & domainNames ) const

Returns the common name stored in the certificate subject's distinguished name.

◆ fingerprint()

Poco::DigestEngine::Digest Poco::Crypto::X509Certificate::fingerprint ( const std::string & algorithm = "SHA1") const

Returns the date and time the certificate expires.

◆ init()

void Poco::Crypto::X509Certificate::init ( )
protected

Loads the certificate from the given file. The certificate must be in PEM format.

◆ issuedBy()

bool Poco::Crypto::X509Certificate::issuedBy ( const X509Certificate & issuerCertificate) const

Writes the certificate to the file given by path. The certificate is written in PEM format.

◆ issuerName() [1/2]

const std::string & Poco::Crypto::X509Certificate::issuerName ( ) const
inline

Returns the certificate serial number as a string in decimal encoding.

Definition at line 230 of file X509Certificate.h.

◆ issuerName() [2/2]

std::string Poco::Crypto::X509Certificate::issuerName ( NID nid) const

Returns the certificate issuer's distinguished name.

◆ load() [1/2]

void Poco::Crypto::X509Certificate::load ( const std::string & path)
protected

Loads the certificate from the given stream. The certificate must be in PEM format.

◆ load() [2/2]

void Poco::Crypto::X509Certificate::load ( std::istream & stream)
protected

Writes the list of certificates to the specified PEM file.

◆ operator=() [1/2]

X509Certificate & Poco::Crypto::X509Certificate::operator= ( const X509Certificate & cert)

Creates the certificate by moving another one.

◆ operator=() [2/2]

X509Certificate & Poco::Crypto::X509Certificate::operator= ( X509Certificate && cert)
noexcept

Assigns a certificate.

◆ print()

void Poco::Crypto::X509Certificate::print ( std::ostream & out) const

Returns the certificate signature algorithm long name.

◆ readPEM()

static List Poco::Crypto::X509Certificate::readPEM ( const std::string & pemFileName)
static

Prints the certificate information to ostream.

◆ save() [1/2]

void Poco::Crypto::X509Certificate::save ( const std::string & path) const

Writes the certificate to the given stream. The certificate is written in PEM format.

◆ save() [2/2]

void Poco::Crypto::X509Certificate::save ( std::ostream & stream) const

Computes and returns the fingerprint of the certificate, using the given algorithm. The algorithm must be supported by OpenSSL, e.g., "SHA1" or "SHA256".

◆ serialNumber()

const std::string & Poco::Crypto::X509Certificate::serialNumber ( ) const
inline

Returns the version of the certificate.

Definition at line 224 of file X509Certificate.h.

◆ signatureAlgorithm()

std::string Poco::Crypto::X509Certificate::signatureAlgorithm ( ) const

Duplicates and returns the underlying OpenSSL certificate. Note that the caller assumes responsibility for the lifecycle of the created certificate.

◆ subjectName() [1/2]

const std::string & Poco::Crypto::X509Certificate::subjectName ( ) const
inline

Extracts the information specified by the given NID (name identifier) from the certificate issuer's distinguished name.

Definition at line 236 of file X509Certificate.h.

◆ subjectName() [2/2]

std::string Poco::Crypto::X509Certificate::subjectName ( NID nid) const

Returns the certificate subject's distinguished name.

◆ swap()

void Poco::Crypto::X509Certificate::swap ( X509Certificate & cert)

Move assignment.

◆ validFrom()

Poco::DateTime Poco::Crypto::X509Certificate::validFrom ( ) const

Extracts the common name and the alias domain names from the certificate.

◆ version()

long Poco::Crypto::X509Certificate::version ( ) const
inline

Destroys the X509Certificate.

Definition at line 215 of file X509Certificate.h.

◆ writePEM()

static void Poco::Crypto::X509Certificate::writePEM ( const std::string & pemFileName,
const List & list )
static

Reads and returns a list of certificates from the specified PEM file.

Member Data Documentation

◆ _issuerName

std::string Poco::Crypto::X509Certificate::_issuerName
private

Definition at line 202 of file X509Certificate.h.

◆ _openSSLInitializer

OpenSSLInitializer Poco::Crypto::X509Certificate::_openSSLInitializer
private

Definition at line 206 of file X509Certificate.h.

◆ _pCert

X509* Poco::Crypto::X509Certificate::_pCert
private

Definition at line 205 of file X509Certificate.h.

◆ _serialNumber

std::string Poco::Crypto::X509Certificate::_serialNumber
private

Definition at line 204 of file X509Certificate.h.

◆ _subjectName

std::string Poco::Crypto::X509Certificate::_subjectName
private

Definition at line 203 of file X509Certificate.h.


The documentation for this class was generated from the following file: