MySQL 8.4.2
Source Code Documentation
CertificateGenerator Class Reference

#include <certificate_generator.h>

Classes

struct  EvpPkeyDeleter
 
struct  X509Deleter
 

Public Types

using EvpPkey = std::unique_ptr< EVP_PKEY, EvpPkeyDeleter >
 
using X509Cert = std::unique_ptr< X509, X509Deleter >
 

Public Member Functions

stdx::expected< X509Cert, std::error_code > generate_x509 (EVP_PKEY *pkey, const std::string &common_name, const uint32_t serial, X509 *ca_cert, EVP_PKEY *ca_pkey, uint32_t notbefore=0, uint32_t notafter=10 *k_year) const
 Generate X.509 cerificate. More...
 

Static Public Member Functions

static stdx::expected< EvpPkey, std::error_code > generate_evp_pkey ()
 Generate EVP_PKEY containing public and private keys. More...
 
static std::string pkey_to_string (EVP_PKEY *pkey)
 Get string representation of a private key. More...
 
static std::string cert_to_string (X509 *cert)
 Get string representation of a X.509 certificate. More...
 

Static Private Attributes

constexpr static uint32_t k_year = 365 * 24 * 60 * 60
 
constexpr static uint32_t k_max_cn_name_length = 64
 

Member Typedef Documentation

◆ EvpPkey

using CertificateGenerator::EvpPkey = std::unique_ptr<EVP_PKEY, EvpPkeyDeleter>

◆ X509Cert

using CertificateGenerator::X509Cert = std::unique_ptr<X509, X509Deleter>

Member Function Documentation

◆ cert_to_string()

std::string CertificateGenerator::cert_to_string ( X509 *  cert)
static

Get string representation of a X.509 certificate.

Parameters
[in]certX.509 certificate
Returns
X.509 certificate string representation.

◆ generate_evp_pkey()

stdx::expected< EvpPkey, std::error_code > CertificateGenerator::generate_evp_pkey ( )
static

Generate EVP_PKEY containing public and private keys.

Returns
Unique pointer to EVP_PKEY object on success or std::error_code if key generation failed.

◆ generate_x509()

stdx::expected< X509Cert, std::error_code > CertificateGenerator::generate_x509 ( EVP_PKEY *  pkey,
const std::string &  common_name,
const uint32_t  serial,
X509 *  ca_cert,
EVP_PKEY *  ca_pkey,
uint32_t  notbefore = 0,
uint32_t  notafter = 10 * k_year 
) const

Generate X.509 cerificate.

Generate X.509 cerificate that could be either self-signed or signed by some provided CA certificate. Certificate will be by default valid for 10 years.

Parameters
[in]pkeyEVP_PKEY object containing public/private key pair.
[in]common_nameCommon name that will be used in certificate Subject name section.
[in]serialSerial number that will be encoded into the certificate.
[in]ca_certCertificate that will be used to sign certificate returned by this method. If ca_cert is nullptr then returned certificate will be self-signed.
[in]ca_pkeyCA private key that will be used to sign the certificate, for a self signed certificate 'pkey' argument will be used.
[in]notbeforeCertificate validity period start.
[in]notafterCertificate validity period end.
Returns
X.509 certificate on success or std::error_code if certificate generation failed.

◆ pkey_to_string()

std::string CertificateGenerator::pkey_to_string ( EVP_PKEY *  pkey)
static

Get string representation of a private key.

Parameters
[in]pkeyPrivate key.
Returns
Private key string representation.

Member Data Documentation

◆ k_max_cn_name_length

constexpr static uint32_t CertificateGenerator::k_max_cn_name_length = 64
staticconstexprprivate

◆ k_year

constexpr static uint32_t CertificateGenerator::k_year = 365 * 24 * 60 * 60
staticconstexprprivate

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