#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...
 
bool IsEnabledDiskStore () const
 Check enabled of dist store. 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...
 
bool enabled_disk_store
 The storage on the disk is enabled. 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 67 of file certificate_db.h.

Member Enumeration Documentation

Enumerator
cnlKey 
cnlExp_date 
cnlRev_date 
cnlSerial 
cnlName 
cnlNumber 

Definition at line 71 of file certificate_db.h.

Constructor & Destructor Documentation

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

Definition at line 252 of file certificate_db.cc.

References db_path, enabled_disk_store, and max_db_size.

Member Function Documentation

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

Definition at line 459 of file certificate_db.cc.

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

Definition at line 397 of file certificate_db.cc.

References db, load(), and readSize().

Referenced by main().

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

Definition at line 373 of file certificate_db.cc.

References db, and size.

Referenced by main().

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

Definition at line 598 of file certificate_db.cc.

References i.

bool Ssl::CertificateDb::deleteInvalidCertificate ( )
private

Definition at line 548 of file certificate_db.cc.

References i, and Ssl::sslDateIsInTheFuture().

bool Ssl::CertificateDb::deleteOldestCertificate ( )
private

Definition at line 577 of file certificate_db.cc.

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

Definition at line 538 of file certificate_db.cc.

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

Definition at line 268 of file certificate_db.cc.

References Here.

Referenced by processNewRequest().

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

Definition at line 489 of file certificate_db.cc.

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

Definition at line 621 of file certificate_db.cc.

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.

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

Definition at line 244 of file certificate_db.cc.

References cnlKey.

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

Definition at line 240 of file certificate_db.cc.

References cnlKey.

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

Definition at line 233 of file certificate_db.cc.

References cnlSerial.

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

Definition at line 226 of file certificate_db.cc.

References cnlSerial.

bool Ssl::CertificateDb::IsEnabledDiskStore ( ) const

Definition at line 635 of file certificate_db.cc.

Referenced by processNewRequest().

void Ssl::CertificateDb::load ( )
private

Definition at line 500 of file certificate_db.cc.

References db_path, and NULL.

Referenced by Check().

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

Definition at line 275 of file certificate_db.cc.

References Here.

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

Definition at line 474 of file certificate_db.cc.

Referenced by Check().

size_t Ssl::CertificateDb::rebuildSize ( )
private

Rebuild size_file

Definition at line 405 of file certificate_db.cc.

References i.

void Ssl::CertificateDb::save ( )
private

Definition at line 524 of file certificate_db.cc.

size_t Ssl::CertificateDb::size ( )
private

Get db size on disk in bytes.

Definition at line 455 of file certificate_db.cc.

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

Definition at line 174 of file certificate_db.cc.

References i, and sq_TXT_DB_delete_row().

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

Definition at line 198 of file certificate_db.cc.

References assert, cnlKey, cnlNumber, cnlSerial, countof, data, i, and NULL.

Referenced by sq_TXT_DB_delete().

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

Definition at line 466 of file certificate_db.cc.

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

Definition at line 482 of file certificate_db.cc.

Member Data Documentation

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

Definition at line 176 of file certificate_db.h.

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

Definition at line 183 of file certificate_db.h.

TXT_DB_Pointer Ssl::CertificateDb::db
private

Definition at line 186 of file certificate_db.h.

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

Definition at line 175 of file certificate_db.h.

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

Definition at line 182 of file certificate_db.h.

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

Definition at line 181 of file certificate_db.h.

Referenced by CertificateDb().

Lock Ssl::CertificateDb::dbLock
mutableprivate

Definition at line 189 of file certificate_db.h.

bool Ssl::CertificateDb::enabled_disk_store
private

Definition at line 191 of file certificate_db.h.

Referenced by CertificateDb().

const size_t Ssl::CertificateDb::fs_block_size
private

Definition at line 188 of file certificate_db.h.

const size_t Ssl::CertificateDb::max_db_size
private

Definition at line 187 of file certificate_db.h.

Referenced by CertificateDb().

const size_t Ssl::CertificateDb::min_db_size
staticprivate

Definition at line 179 of file certificate_db.h.

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

Base name of the file to store db size.

Definition at line 177 of file certificate_db.h.

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

Definition at line 184 of file certificate_db.h.


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors