#include <certificate_db.h>

Collaboration diagram for Ssl::CertificateDb:

Classes

class  Row
 A wrapper for OpenSSL database row of TXT_DB database. More...
 

Public Types

enum  Columns {
  cnlKey = 0 ,
  cnlExp_date ,
  cnlRev_date ,
  cnlSerial ,
  cnlName ,
  cnlNumber
}
 Names of db columns. More...
 

Public Member Functions

 CertificateDb (std::string const &db_path, size_t aMax_db_size, size_t aFs_block_size)
 
bool find (std::string const &key, const Security::CertPointer &expectedOrig, Security::CertPointer &cert, Security::PrivateKeyPointer &pkey)
 finds matching generated certificate and its private key More...
 
bool purgeCert (std::string const &key)
 Delete a certificate from database. More...
 
bool addCertAndPrivateKey (std::string const &useKey, const Security::CertPointer &cert, const Security::PrivateKeyPointer &pkey, const Security::CertPointer &orig)
 Save certificate to disk. More...
 

Static Public Member Functions

static void Create (std::string const &db_path)
 Create and initialize a database under the db_path. More...
 
static void Check (std::string const &db_path, size_t max_db_size, size_t fs_block_size)
 Check the database stored under the db_path. More...
 

Private Member Functions

void load ()
 Load db from disk. More...
 
void save ()
 Save db to disk. More...
 
size_t size ()
 
void addSize (std::string const &filename)
 Increase db size by the given file size and update size_file. More...
 
void subSize (std::string const &filename)
 Decrease db size by the given file size and update size_file. More...
 
size_t readSize ()
 Read size from file size_file. More...
 
void writeSize (size_t db_size)
 Write size to file size_file. More...
 
size_t getFileSize (std::string const &filename)
 get file size on disk. More...
 
size_t rebuildSize ()
 
bool pure_find (std::string const &key, const Security::CertPointer &expectedOrig, Security::CertPointer &cert, Security::PrivateKeyPointer &pkey)
 Only find certificate in current db and return it. More...
 
void deleteRow (const char **row, int rowIndex)
 Delete a row from TXT_DB. More...
 
bool deleteInvalidCertificate ()
 Delete invalid certificate. More...
 
bool deleteOldestCertificate ()
 Delete oldest certificate. More...
 
bool deleteByKey (std::string const &key)
 Delete using key. More...
 
bool hasRows () const
 Whether the TXT_DB has stored items. More...
 

Static Private Member Functions

static bool WriteEntry (const std::string &filename, const Security::CertPointer &cert, const Security::PrivateKeyPointer &pkey, const Security::CertPointer &orig)
 stores the db entry into a file More...
 
static bool ReadEntry (std::string filename, Security::CertPointer &cert, Security::PrivateKeyPointer &pkey, Security::CertPointer &orig)
 loads a db entry from the file More...
 
static void sq_TXT_DB_delete (TXT_DB *db, const char **row)
 Removes the first matching row from TXT_DB. Ignores failures. More...
 
static void sq_TXT_DB_delete_row (TXT_DB *db, int idx)
 Remove the row on position idx from TXT_DB. Ignores failures. More...
 
static unsigned long index_serial_hash (const char **a)
 Callback hash function for serials. Used to create TXT_DB index of serials. More...
 
static int index_serial_cmp (const char **a, const char **b)
 Callback compare function for serials. Used to create TXT_DB index of serials. More...
 
static unsigned long index_name_hash (const char **a)
 Callback hash function for names. Used to create TXT_DB index of names.. More...
 
static int index_name_cmp (const char **a, const char **b)
 Callback compare function for names. Used to create TXT_DB index of names.. More...
 
static IMPLEMENT_LHASH_HASH_FN (index_serial_hash, const char **) static IMPLEMENT_LHASH_COMP_FN(index_serial_cmp
 
static const char **static IMPLEMENT_LHASH_HASH_FN (index_name_hash, const char **) static IMPLEMENT_LHASH_COMP_FN(index_name_cmp
 

Private Attributes

const std::string db_path
 The database directory. More...
 
const std::string db_full
 Full path of the database index file. More...
 
const std::string cert_full
 Full path of the directory to store the certs. More...
 
const std::string size_full
 Full path of the file to store the db size. More...
 
TXT_DB_Pointer db
 Database with certificates info. More...
 
const size_t max_db_size
 Max size of db. More...
 
const size_t fs_block_size
 File system block size. More...
 
Lock dbLock
 protects the database file More...
 

Static Private Attributes

static const char **static const char **static const std::string db_file
 Base name of the database index file. More...
 
static const std::string cert_dir
 Base name of the directory to store the certs. More...
 
static const std::string size_file
 
static const size_t min_db_size
 Min size of disk db. If real size < min_db_size the db will be disabled. More...
 

Detailed Description

Database class for storing SSL certificates and their private keys. A database consist by:

  • A disk file to store current serial number
  • A disk file to store the current database size
  • A disk file which is a normal TXT_DB openSSL database
  • A directory under which the certificates and their private keys stored. The database before used must initialized with CertificateDb::create static method.

Definition at line 63 of file certificate_db.h.

Member Enumeration Documentation

◆ Columns

Enumerator
cnlKey 
cnlExp_date 
cnlRev_date 
cnlSerial 
cnlName 
cnlNumber 

Definition at line 67 of file certificate_db.h.

Constructor & Destructor Documentation

◆ CertificateDb()

Ssl::CertificateDb::CertificateDb ( std::string const &  db_path,
size_t  aMax_db_size,
size_t  aFs_block_size 
)

Definition at line 253 of file certificate_db.cc.

Member Function Documentation

◆ addCertAndPrivateKey()

bool Ssl::CertificateDb::addCertAndPrivateKey ( std::string const &  useKey,
const Security::CertPointer cert,
const Security::PrivateKeyPointer &  pkey,
const Security::CertPointer orig 
)

◆ addSize()

void Ssl::CertificateDb::addSize ( std::string const &  filename)
private

Definition at line 452 of file certificate_db.cc.

◆ Check()

void Ssl::CertificateDb::Check ( std::string const &  db_path,
size_t  max_db_size,
size_t  fs_block_size 
)
static

Definition at line 390 of file certificate_db.cc.

References db, and db_path.

Referenced by main().

◆ Create()

void Ssl::CertificateDb::Create ( std::string const &  db_path)
static

Definition at line 366 of file certificate_db.cc.

References db, db_path, Here, size, and ToSBuf().

Referenced by main().

◆ deleteByKey()

bool Ssl::CertificateDb::deleteByKey ( std::string const &  key)
private

Definition at line 591 of file certificate_db.cc.

References db.

◆ deleteInvalidCertificate()

bool Ssl::CertificateDb::deleteInvalidCertificate ( )
private

Definition at line 541 of file certificate_db.cc.

References db, and Ssl::sslDateIsInTheFuture().

◆ deleteOldestCertificate()

bool Ssl::CertificateDb::deleteOldestCertificate ( )
private

Definition at line 570 of file certificate_db.cc.

References db.

◆ deleteRow()

void Ssl::CertificateDb::deleteRow ( const char **  row,
int  rowIndex 
)
private

Definition at line 531 of file certificate_db.cc.

References db, Here, and ToSBuf().

◆ find()

bool Ssl::CertificateDb::find ( std::string const &  key,
const Security::CertPointer expectedOrig,
Security::CertPointer cert,
Security::PrivateKeyPointer &  pkey 
)

Definition at line 264 of file certificate_db.cc.

References Here.

◆ getFileSize()

size_t Ssl::CertificateDb::getFileSize ( std::string const &  filename)
private

Definition at line 482 of file certificate_db.cc.

◆ hasRows()

bool Ssl::CertificateDb::hasRows ( ) const
private

Definition at line 614 of file certificate_db.cc.

References db.

◆ IMPLEMENT_LHASH_HASH_FN() [1/2]

static const char **static Ssl::CertificateDb::IMPLEMENT_LHASH_HASH_FN ( index_name_hash  ,
const char **   
)
staticprivate

◆ IMPLEMENT_LHASH_HASH_FN() [2/2]

static Ssl::CertificateDb::IMPLEMENT_LHASH_HASH_FN ( index_serial_hash  ,
const char **   
)
staticprivate

Definitions required by openSSL, to use the index_* functions defined above with TXT_DB_create_index.

◆ index_name_cmp()

int Ssl::CertificateDb::index_name_cmp ( const char **  a,
const char **  b 
)
staticprivate

Definition at line 245 of file certificate_db.cc.

References cnlKey.

◆ index_name_hash()

unsigned long Ssl::CertificateDb::index_name_hash ( const char **  a)
staticprivate

Definition at line 241 of file certificate_db.cc.

References cnlKey, and OPENSSL_LH_strhash.

◆ index_serial_cmp()

int Ssl::CertificateDb::index_serial_cmp ( const char **  a,
const char **  b 
)
staticprivate

Definition at line 234 of file certificate_db.cc.

References cnlSerial.

◆ index_serial_hash()

unsigned long Ssl::CertificateDb::index_serial_hash ( const char **  a)
staticprivate

Definition at line 227 of file certificate_db.cc.

References cnlSerial, and OPENSSL_LH_strhash.

◆ load()

void Ssl::CertificateDb::load ( )
private

Definition at line 493 of file certificate_db.cc.

References db, db_path, Here, and ToSBuf().

◆ pure_find()

bool Ssl::CertificateDb::pure_find ( std::string const &  key,
const Security::CertPointer expectedOrig,
Security::CertPointer cert,
Security::PrivateKeyPointer &  pkey 
)
private

◆ purgeCert()

bool Ssl::CertificateDb::purgeCert ( std::string const &  key)

Definition at line 271 of file certificate_db.cc.

References db, and Here.

◆ ReadEntry()

bool Ssl::CertificateDb::ReadEntry ( std::string  filename,
Security::CertPointer cert,
Security::PrivateKeyPointer &  pkey,
Security::CertPointer orig 
)
staticprivate

◆ readSize()

size_t Ssl::CertificateDb::readSize ( )
private

Definition at line 467 of file certificate_db.cc.

◆ rebuildSize()

size_t Ssl::CertificateDb::rebuildSize ( )
private

Rebuild size_file

Definition at line 398 of file certificate_db.cc.

References db.

◆ save()

void Ssl::CertificateDb::save ( )
private

Definition at line 517 of file certificate_db.cc.

References db, Here, and ToSBuf().

◆ size()

size_t Ssl::CertificateDb::size ( )
private

Get db size on disk in bytes.

Definition at line 448 of file certificate_db.cc.

◆ sq_TXT_DB_delete()

void Ssl::CertificateDb::sq_TXT_DB_delete ( TXT_DB *  db,
const char **  row 
)
staticprivate

Definition at line 175 of file certificate_db.cc.

References db, and sq_TXT_DB_delete_row().

◆ sq_TXT_DB_delete_row()

void Ssl::CertificateDb::sq_TXT_DB_delete_row ( TXT_DB *  db,
int  idx 
)
staticprivate

Definition at line 199 of file certificate_db.cc.

References assert, cnlKey, cnlNumber, cnlSerial, countof, db, and OPENSSL_LH_delete.

Referenced by sq_TXT_DB_delete().

◆ subSize()

void Ssl::CertificateDb::subSize ( std::string const &  filename)
private

Definition at line 459 of file certificate_db.cc.

◆ WriteEntry()

bool Ssl::CertificateDb::WriteEntry ( const std::string &  filename,
const Security::CertPointer cert,
const Security::PrivateKeyPointer &  pkey,
const Security::CertPointer orig 
)
staticprivate

◆ writeSize()

void Ssl::CertificateDb::writeSize ( size_t  db_size)
private

Definition at line 475 of file certificate_db.cc.

References Here, and ToSBuf().

Member Data Documentation

◆ cert_dir

const std::string Ssl::CertificateDb::cert_dir
staticprivate

Definition at line 170 of file certificate_db.h.

◆ cert_full

const std::string Ssl::CertificateDb::cert_full
private

Definition at line 177 of file certificate_db.h.

◆ db

TXT_DB_Pointer Ssl::CertificateDb::db
private

Definition at line 180 of file certificate_db.h.

Referenced by sq_TXT_DB_delete(), and sq_TXT_DB_delete_row().

◆ db_file

const std::string Ssl::CertificateDb::db_file
staticprivate

Definition at line 169 of file certificate_db.h.

◆ db_full

const std::string Ssl::CertificateDb::db_full
private

Definition at line 176 of file certificate_db.h.

◆ db_path

const std::string Ssl::CertificateDb::db_path
private

Definition at line 175 of file certificate_db.h.

◆ dbLock

Lock Ssl::CertificateDb::dbLock
mutableprivate

Definition at line 183 of file certificate_db.h.

◆ fs_block_size

const size_t Ssl::CertificateDb::fs_block_size
private

Definition at line 182 of file certificate_db.h.

◆ max_db_size

const size_t Ssl::CertificateDb::max_db_size
private

Definition at line 181 of file certificate_db.h.

◆ min_db_size

const size_t Ssl::CertificateDb::min_db_size
staticprivate

Definition at line 173 of file certificate_db.h.

◆ size_file

const std::string Ssl::CertificateDb::size_file
staticprivate

Base name of the file to store db size.

Definition at line 171 of file certificate_db.h.

◆ size_full

const std::string Ssl::CertificateDb::size_full
private

Definition at line 178 of file certificate_db.h.


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors