libcamgm
Static Public Member Functions | List of all members
ca_mgm::LocalManagement Class Reference

Functions for local certificate management. More...

#include <LocalManagement.hpp>

Static Public Member Functions

static void importAsLocalCertificate (const std::string &pkcs12File, const std::string &password, const std::string &destinationCAsDir, const std::string &destinationCertFile, const std::string &destinationKeyFile)
 
static void importAsLocalCertificate (const ca_mgm::ByteBuffer &pkcs12Data, const std::string &password, const std::string &destinationCAsDir, const std::string &destinationCertFile, const std::string &destinationKeyFile)
 
static void importCommonServerCertificate (const std::string &pkcs12File, const std::string &password)
 
static void importCommonServerCertificate (const ca_mgm::ByteBuffer &pkcs12Data, const std::string &password)
 
static CertificateData getCertificate (const std::string &file, FormatType type)
 
static CertificateData getCertificate (const ca_mgm::ByteBuffer &data, FormatType type)
 
static RequestData getRequest (const std::string &file, FormatType type)
 
static RequestData getRequest (const ca_mgm::ByteBuffer &data, FormatType type)
 
static CRLData getCRL (const std::string &file, FormatType type)
 
static CRLData getCRL (const ca_mgm::ByteBuffer &data, FormatType type)
 
static ca_mgm::ByteBuffer readFile (const std::string &file)
 
static void writeFile (const ca_mgm::ByteBuffer &data, const std::string &file, bool overwrite=true, mode_t mode=0644)
 
static ca_mgm::ByteBuffer x509Convert (const ca_mgm::ByteBuffer &certificate, FormatType inform, FormatType outform)
 
static ca_mgm::ByteBuffer rsaConvert (const ca_mgm::ByteBuffer &key, FormatType inform, FormatType outform, const std::string &inPassword, const std::string &outPassword, const std::string &algorithm="des3")
 
static ca_mgm::ByteBuffer crlConvert (const ca_mgm::ByteBuffer &crl, FormatType inform, FormatType outform)
 
static ca_mgm::ByteBuffer reqConvert (const ca_mgm::ByteBuffer &req, FormatType inform, FormatType outform)
 
static ca_mgm::ByteBuffer createPKCS12 (const ca_mgm::ByteBuffer &certificate, const ca_mgm::ByteBuffer &key, const std::string &inPassword, const std::string &outPassword, const ca_mgm::ByteBuffer &caCert, const std::string &caPath, bool withChain=false)
 
static ca_mgm::ByteBuffer pkcs12ToPEM (const ca_mgm::ByteBuffer &pkcs12, const std::string &inPassword, const std::string &outPassword, const std::string &algorithm="des3")
 

Detailed Description

Functions for local certificate management.

This class provides functions for local certificate management which are usefull on every host.

Member Function Documentation

static ca_mgm::ByteBuffer ca_mgm::LocalManagement::createPKCS12 ( const ca_mgm::ByteBuffer certificate,
const ca_mgm::ByteBuffer key,
const std::string &  inPassword,
const std::string &  outPassword,
const ca_mgm::ByteBuffer caCert,
const std::string &  caPath,
bool  withChain = false 
)
static

Create a PKCS12 bundle. Certificate and key has to be in PEM format.

Parameters
certificatethe certificate in PEM format
keythe private key in PEM format
inPasswordthe password of key. If key is not encrypted use "".
outPasswordthe password of the pkcs12 file (empty not allowed)
caCertadditional certificates to include in this container
caPathset the path to the CA store
withChaininclude the entire certificate chain of certificate
Returns
the PKCS12 file
static ca_mgm::ByteBuffer ca_mgm::LocalManagement::crlConvert ( const ca_mgm::ByteBuffer crl,
FormatType  inform,
FormatType  outform 
)
static

Convert a CRL from PEM/DER to DER/PEM format

Parameters
crlthe CRL in PEM or DER format
informthe format of crl
outformthe output format
Returns
the converted CRL
static CertificateData ca_mgm::LocalManagement::getCertificate ( const std::string &  file,
FormatType  type 
)
static

Parse a Certificate and return the data

Parameters
filepath to the certificate file in PEM or DER format
typethe format of the certificate
Returns
the parsed certificate data
static CertificateData ca_mgm::LocalManagement::getCertificate ( const ca_mgm::ByteBuffer data,
FormatType  type 
)
static

Parse a Certificate and return the data

Parameters
datathe certificate data in PEM or DER format
typethe format of the certificate
Returns
the parsed certificate data
static CRLData ca_mgm::LocalManagement::getCRL ( const std::string &  file,
FormatType  type 
)
static

Parse a CRL and return the data

Parameters
filepath to the CRL file in PEM or DER format
typethe format of the CRL
Returns
the parsed CRL data
static CRLData ca_mgm::LocalManagement::getCRL ( const ca_mgm::ByteBuffer data,
FormatType  type 
)
static

Parse a CRL and return the data

Parameters
datathe CRL data in PEM or DER format
typethe format of the CRL
Returns
the parsed CRL data
static RequestData ca_mgm::LocalManagement::getRequest ( const std::string &  file,
FormatType  type 
)
static

Parse a Request and return the data

Parameters
filepath to the request file in PEM or DER format
typethe format of the request
Returns
the parsed request data
static RequestData ca_mgm::LocalManagement::getRequest ( const ca_mgm::ByteBuffer data,
FormatType  type 
)
static

Parse a Request and return the data

Parameters
datathe request data in PEM or DER format
typethe format of the request
Returns
the parsed request data
static void ca_mgm::LocalManagement::importAsLocalCertificate ( const std::string &  pkcs12File,
const std::string &  password,
const std::string &  destinationCAsDir,
const std::string &  destinationCertFile,
const std::string &  destinationKeyFile 
)
static

Import a certificate to a specific destination

Parameters
pkcs12Filefull path to a PKCS12 file with the certificates
passwordthe password for the PKCS12 file
destinationCAsDirpath to the directory where the CAs are stored
destinationCertFilethe path where the certificate should be stored
destinationKeyFilethe path where the private key should be stored
static void ca_mgm::LocalManagement::importAsLocalCertificate ( const ca_mgm::ByteBuffer pkcs12Data,
const std::string &  password,
const std::string &  destinationCAsDir,
const std::string &  destinationCertFile,
const std::string &  destinationKeyFile 
)
static

Import a certificate to a specific destination

Parameters
pkcs12DataPKCS12 certificate data
passwordthe password for the PKCS12 file
destinationCAsDirpath to the directory where the CAs are stored
destinationCertFilethe path where the certificate should be stored
destinationKeyFilethe path where the private key should be stored
static void ca_mgm::LocalManagement::importCommonServerCertificate ( const std::string &  pkcs12File,
const std::string &  password 
)
static

Import a certificate as common server certificate. This function store the CAs to '/etc/ssl/certs', the certificate to '/etc/ssl/servercerts/servercert.pem' and the private key to '/etc/ssl/servercerts/serverkey.pem'.

Parameters
pkcs12Filefull path to a PKCS12 file with the certificates
passwordthe password for the PKCS12 file
static void ca_mgm::LocalManagement::importCommonServerCertificate ( const ca_mgm::ByteBuffer pkcs12Data,
const std::string &  password 
)
static

Import a certificate as common server certificate. This function store the CAs to '/etc/ssl/certs', the certificate to '/etc/ssl/servercerts/servercert.pem' and the private key to '/etc/ssl/servercerts/serverkey.pem'.

Parameters
pkcs12DataPKCS12 certificate data
passwordthe password for the PKCS12 file
static ca_mgm::ByteBuffer ca_mgm::LocalManagement::pkcs12ToPEM ( const ca_mgm::ByteBuffer pkcs12,
const std::string &  inPassword,
const std::string &  outPassword,
const std::string &  algorithm = "des3" 
)
static

Extract PKCS12 to PEM

Parameters
pkcs12the PKCS12 file
inPasswordthe password of pkcs12
outPasswordthe new password for the private key. If outPasswort is "", the private key will not be encrypted.
algorithmthe encryption algorithm for the key valid values are: des, des3, aes128, aes192, aes256
Returns
the certificates and private key
static ca_mgm::ByteBuffer ca_mgm::LocalManagement::readFile ( const std::string &  file)
static

Read a file from the harddisk and return the content as ByteBuffer Object

Parameters
filethe path to the file to read
Returns
the file content
static ca_mgm::ByteBuffer ca_mgm::LocalManagement::reqConvert ( const ca_mgm::ByteBuffer req,
FormatType  inform,
FormatType  outform 
)
static

Convert a Request from PEM/DER to DER/PEM format

Parameters
reqthe Request in PEm or DER format
informthe format of req
outformthe output format
Returns
the converted Request
static ca_mgm::ByteBuffer ca_mgm::LocalManagement::rsaConvert ( const ca_mgm::ByteBuffer key,
FormatType  inform,
FormatType  outform,
const std::string &  inPassword,
const std::string &  outPassword,
const std::string &  algorithm = "des3" 
)
static

Convert a rsa key from PEM/DER to DER/PEM. This function can also be used to set a new password or remove the encryption from the key. An encrypted key is only available if the format is PEM.

Parameters
keythe key data
informthe format of the key data
outformthe output format of the key
inPasswordthe password for the key data. "" == no password set.
outPasswordthe new password for the key. "" == no password for the new key.
algorithmthe encryption algorithm for the key valid values are: des, des3, aes128, aes192, aes256
Returns
the converted key
static void ca_mgm::LocalManagement::writeFile ( const ca_mgm::ByteBuffer data,
const std::string &  file,
bool  overwrite = true,
mode_t  mode = 0644 
)
static

Write data into a file

Parameters
datathe data to write
filethe path to the file
overwriteif this is true and the file exists it will be overwritten with the new data, if false it throws an exception
modethe file permissions for the file (only if it is new created)
static ca_mgm::ByteBuffer ca_mgm::LocalManagement::x509Convert ( const ca_mgm::ByteBuffer certificate,
FormatType  inform,
FormatType  outform 
)
static

Convert a certificate from PEM/DER to DER/PEM format

Parameters
certificatethe certificate in PEM or DER str::form
informformat of certificate
outformthe output format
Returns
the converted certificate in the new format

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