libdigidocpp
digidoc::X509Cert Class Reference

Wrapper for OpenSSL X509 certificate structure. More...

#include <X509Cert.h>

Public Types

enum  Format { Der, Pem }
 
enum  KeyUsage {
  DigitalSignature = 0, NonRepudiation, KeyEncipherment, DataEncipherment,
  KeyAgreement, KeyCertificateSign, CRLSign, EncipherOnly,
  DecipherOnly
}
 

Public Member Functions

 X509Cert (X509 *cert=0)
 
 X509Cert (const unsigned char *bytes, size_t size, Format format=Der)
 
 X509Cert (const std::vector< unsigned char > &bytes, Format format=Der)
 
 X509Cert (const std::string &path, Format format=Pem)
 
 X509Cert (X509Cert &&other)
 
 X509Cert (const X509Cert &other)
 
 ~X509Cert ()
 
std::string serial () const
 
std::string issuerName (const std::string &obj=std::string()) const
 
std::string subjectName (const std::string &obj=std::string()) const
 
std::vector< KeyUsagekeyUsage () const
 
std::vector< std::string > certificatePolicies () const
 
std::vector< std::string > qcStatements () const
 
bool isCA () const
 
bool isValid (time_t *t=0) const
 
X509 * handle () const
 
 operator std::vector< unsigned char > () const
 
X509Certoperator= (const X509Cert &other)
 
X509Certoperator= (X509Cert &&other)
 
bool operator! () const
 
bool operator== (const X509Cert &other) const
 
bool operator!= (const X509Cert &other) const
 
template<typename Func >
string toString (Func func, const string &obj) const
 

Static Public Attributes

static const std::string QC_COMPLIANT = "0.4.0.1862.1.1"
 
static const std::string QC_SSCD = "0.4.0.1862.1.4"
 
static const std::string QC_QCP = "0.4.0.1862.1.5"
 
static const std::string QC_QCT = "0.4.0.1862.1.6"
 
static const std::string QC_SYNTAX1 = "1.3.6.1.5.5.7.11.1"
 
static const std::string QC_SYNTAX2 = "1.3.6.1.5.5.7.11.2"
 
static const std::string QCS_NATURAL = "0.4.0.194121.1.1"
 
static const std::string QCS_LEGAL = "0.4.0.194121.1.2"
 
static const std::string QCT_ESIGN = "0.4.0.1862.1.6.1"
 
static const std::string QCT_ESEAL = "0.4.0.1862.1.6.2"
 
static const std::string QCT_WEB = "0.4.0.1862.1.6.3"
 
static const std::string QCP_PUBLIC_WITH_SSCD = "0.4.0.1456.1.1"
 
static const std::string QCP_PUBLIC = "0.4.0.1456.1.2"
 
static const std::string QCP_NATURAL = "0.4.0.194112.1.0"
 
static const std::string QCP_LEGAL = "0.4.0.194112.1.1"
 
static const std::string QCP_NATURAL_QSCD = "0.4.0.194112.1.2"
 
static const std::string QCP_LEGAL_QSCD = "0.4.0.194112.1.3"
 
static const std::string QCP_WEB = "0.4.0.194112.1.4"
 

Detailed Description

Wrapper for OpenSSL X509 certificate structure.

Member Enumeration Documentation

Binary encoding format

Enumerator
Der 

ASN.1 syntax

Pem 

Base64 encoded ASN.1 syntax

Key usage bits defined in certificate

Enumerator
DigitalSignature 
NonRepudiation 

Used for signing certificate selection in the current library

KeyEncipherment 
DataEncipherment 
KeyAgreement 
KeyCertificateSign 
CRLSign 
EncipherOnly 
DecipherOnly 

Constructor & Destructor Documentation

X509Cert::X509Cert ( X509 *  cert = 0)
explicit

Creates copy of the OpenSSL X509 certificate.

Parameters
certX509 certificate structure to be wrapped.
X509Cert::X509Cert ( const unsigned char *  bytes,
size_t  size,
Format  format = Der 
)
explicit

Creates X509 certificate from bytes.

Parameters
bytesX509 certificate in bytes.
sizeof X509 certificate in bytes.
formatFormat input bytes format
Exceptions
Exceptionthrows exception if X509 certificate parsing failed.

References Der.

X509Cert::X509Cert ( const std::vector< unsigned char > &  bytes,
Format  format = Der 
)
explicit

Creates X509 certificate from bytes.

Parameters
bytesX509 certificate in bytes.
formatFormat input bytes format
Exceptions
Exceptionthrows exception if X509 certificate parsing failed.
X509Cert::X509Cert ( const std::string &  path,
Format  format = Pem 
)
explicit

Creates X509 certificate from path.

Parameters
pathX509 certificate path.
formatFormat input bytes format
Exceptions
Exceptionthrows exception if X509 certificate parsing failed.

References Der.

X509Cert::X509Cert ( X509Cert &&  other)

Move constructor.

X509Cert::X509Cert ( const X509Cert other)
default

Copy constructor.

X509Cert::~X509Cert ( )
default

Clean up underlying X509 data.

Member Function Documentation

vector< string > X509Cert::certificatePolicies ( ) const

Returns current certificate policies

X509 * X509Cert::handle ( ) const

Returns certificate internal handle (OpenSSL X509 struct)

bool X509Cert::isCA ( ) const

Rerturns true if certificate is CA

string X509Cert::issuerName ( const std::string &  obj = std::string()) const

Returns issuer name as string.

Parameters
objif set to empty string then returns whole issuer name. Otherwise, for example, if set to CN then returns Common name part from issuer name.
Exceptions
Exceptionexception is throws if the conversion failed.
bool X509Cert::isValid ( time_t *  t = 0) const

Validates if certificate is in valid time slot

Parameters
tIf param is 0 then current time is used, else defined time
vector< X509Cert::KeyUsage > X509Cert::keyUsage ( ) const

Returns current certificate key usage bits

digidoc::X509Cert::operator std::vector< unsigned char > ( ) const
bool X509Cert::operator! ( ) const

Negative operator to check if object is valid

bool X509Cert::operator!= ( const X509Cert other) const

Not equal operator to compare two objects

References operator==().

X509Cert & X509Cert::operator= ( const X509Cert other)
default

Assign operator to make copy of object

X509Cert & X509Cert::operator= ( X509Cert &&  other)

Assign operator to make copy of object

bool X509Cert::operator== ( const X509Cert other) const

Equal operator to compare two objects

Referenced by operator!=().

vector< string > X509Cert::qcStatements ( ) const

Return QCStatements info https://www.ietf.org/rfc/rfc3739.txt

References QC_QCT, and QC_SYNTAX2.

string X509Cert::serial ( ) const

Returns X.509 certificate serial number.

Exceptions
Exceptionexception is thrown if the serial is incorrect.
string X509Cert::subjectName ( const std::string &  obj = std::string()) const

Return subject name as string.

Parameters
objempty string then returns whole issuer name. Otherwise, for example, if set to CN then returns Common name part from issuer name.
Exceptions
Exceptionexception is throws if the conversion failed.
template<typename Func >
string digidoc::X509Cert::toString ( Func  func,
const string &  obj 
) const

Converts X509_NAME struct to string.

Parameters
funcX509_NAME struct that is converted to string.
objOptional parameter to get from X509_NAME (default CN).
Returns
converted value of X509_NAME.
Exceptions
Exceptionthrows exception if conversion failed.

Member Data Documentation

const string X509Cert::QC_COMPLIANT = "0.4.0.1862.1.1"
static

https://www.ietf.org/rfc/rfc3739.txt - id-etsi-qcs-QcCompliance

const string X509Cert::QC_QCP = "0.4.0.1862.1.5"
static
const string X509Cert::QC_QCT = "0.4.0.1862.1.6"
static

https://www.ietf.org/rfc/rfc3739.txt - id-etsi-qcs-QcType

Referenced by qcStatements().

const string X509Cert::QC_SSCD = "0.4.0.1862.1.4"
static
const string X509Cert::QC_SYNTAX1 = "1.3.6.1.5.5.7.11.1"
static

https://www.ietf.org/rfc/rfc3739.txt - id-qcs-pkixQCSyntax-v1

const string X509Cert::QC_SYNTAX2 = "1.3.6.1.5.5.7.11.2"
static

https://www.ietf.org/rfc/rfc3739.txt - id-qcs-pkixQCSyntax-v2

Referenced by qcStatements().

const string X509Cert::QCP_LEGAL = "0.4.0.194112.1.1"
static
const string X509Cert::QCP_LEGAL_QSCD = "0.4.0.194112.1.3"
static
const string X509Cert::QCP_NATURAL = "0.4.0.194112.1.0"
static
const string X509Cert::QCP_NATURAL_QSCD = "0.4.0.194112.1.2"
static
const string X509Cert::QCP_PUBLIC = "0.4.0.1456.1.2"
static
const string X509Cert::QCP_PUBLIC_WITH_SSCD = "0.4.0.1456.1.1"
static
const string X509Cert::QCS_LEGAL = "0.4.0.194121.1.2"
static
const string X509Cert::QCS_NATURAL = "0.4.0.194121.1.1"
static
const string X509Cert::QCT_ESEAL = "0.4.0.1862.1.6.2"
static
const string X509Cert::QCT_ESIGN = "0.4.0.1862.1.6.1"
static
const string X509Cert::QCT_WEB = "0.4.0.1862.1.6.3"
static

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