}
#define countof(arr) (sizeof(arr)/sizeof(*arr))
-void Ssl::CertificateDb::sq_TXT_DB_delete_row(TXT_DB *db, int idx)
-{
+void Ssl::CertificateDb::sq_TXT_DB_delete_row(TXT_DB *db, int idx) {
char **rrow;
#if SQUID_SSLTXTDB_PSTRINGDATA
rrow = (char **)sk_OPENSSL_PSTRING_delete(db->data, idx);
}
}
-unsigned long Ssl::CertificateDb::index_serial_hash(const char **a)
-{
+unsigned long Ssl::CertificateDb::index_serial_hash(const char **a) {
const char *n = a[Ssl::CertificateDb::cnlSerial];
while (*n == '0')
++n;
return lh_strhash(n);
}
-int Ssl::CertificateDb::index_serial_cmp(const char **a, const char **b)
-{
+int Ssl::CertificateDb::index_serial_cmp(const char **a, const char **b) {
const char *aa, *bb;
for (aa = a[Ssl::CertificateDb::cnlSerial]; *aa == '0'; ++aa);
for (bb = b[Ssl::CertificateDb::cnlSerial]; *bb == '0'; ++bb);
return strcmp(aa, bb);
}
-unsigned long Ssl::CertificateDb::index_name_hash(const char **a)
-{
+unsigned long Ssl::CertificateDb::index_name_hash(const char **a) {
return(lh_strhash(a[Ssl::CertificateDb::cnlName]));
}
-int Ssl::CertificateDb::index_name_cmp(const char **a, const char **b)
-{
+int Ssl::CertificateDb::index_name_cmp(const char **a, const char **b) {
return(strcmp(a[Ssl::CertificateDb::cnlName], b[CertificateDb::cnlName]));
}
max_db_size(aMax_db_size),
fs_block_size(aFs_block_size),
dbLock(db_full),
- enabled_disk_store(true)
-{
+ enabled_disk_store(true) {
if (db_path.empty() && !max_db_size)
enabled_disk_store = false;
else if ((db_path.empty() && max_db_size) || (!db_path.empty() && !max_db_size))
throw std::runtime_error("ssl_crtd is missing the required parameter. There should be -s and -M parameters together.");
}
-bool Ssl::CertificateDb::find(std::string const & host_name, Ssl::X509_Pointer & cert, Ssl::EVP_PKEY_Pointer & pkey)
-{
+bool Ssl::CertificateDb::find(std::string const & host_name, Ssl::X509_Pointer & cert, Ssl::EVP_PKEY_Pointer & pkey) {
const Locker locker(dbLock, Here);
load();
return pure_find(host_name, cert, pkey);
}
-bool Ssl::CertificateDb::purgeCert(std::string const & key)
-{
+bool Ssl::CertificateDb::purgeCert(std::string const & key) {
const Locker locker(dbLock, Here);
load();
if (!db)
return true;
}
-bool Ssl::CertificateDb::addCertAndPrivateKey(Ssl::X509_Pointer & cert, Ssl::EVP_PKEY_Pointer & pkey, std::string const & useName)
-{
+bool Ssl::CertificateDb::addCertAndPrivateKey(Ssl::X509_Pointer & cert, Ssl::EVP_PKEY_Pointer & pkey, std::string const & useName) {
const Locker locker(dbLock, Here);
load();
if (!db || !cert || !pkey)
return true;
}
-void Ssl::CertificateDb::create(std::string const & db_path)
-{
+void Ssl::CertificateDb::create(std::string const & db_path) {
if (db_path == "")
throw std::runtime_error("Path to db is empty");
std::string db_full(db_path + "/" + db_file);
throw std::runtime_error("Cannot open " + db_full + " to open");
}
-void Ssl::CertificateDb::check(std::string const & db_path, size_t max_db_size)
-{
+void Ssl::CertificateDb::check(std::string const & db_path, size_t max_db_size) {
CertificateDb db(db_path, max_db_size, 0);
db.load();
}
-bool Ssl::CertificateDb::pure_find(std::string const & host_name, Ssl::X509_Pointer & cert, Ssl::EVP_PKEY_Pointer & pkey)
-{
+bool Ssl::CertificateDb::pure_find(std::string const & host_name, Ssl::X509_Pointer & cert, Ssl::EVP_PKEY_Pointer & pkey) {
if (!db)
return false;
return true;
}
-size_t Ssl::CertificateDb::size() const
-{
+size_t Ssl::CertificateDb::size() const {
return readSize();
}
-void Ssl::CertificateDb::addSize(std::string const & filename)
-{
+void Ssl::CertificateDb::addSize(std::string const & filename) {
writeSize(readSize() + getFileSize(filename));
}
-void Ssl::CertificateDb::subSize(std::string const & filename)
-{
+void Ssl::CertificateDb::subSize(std::string const & filename) {
writeSize(readSize() - getFileSize(filename));
}
-size_t Ssl::CertificateDb::readSize() const
-{
+size_t Ssl::CertificateDb::readSize() const {
std::ifstream ifstr(size_full.c_str());
if (!ifstr && enabled_disk_store)
throw std::runtime_error("cannot open for reading: " + size_full);
return db_size;
}
-void Ssl::CertificateDb::writeSize(size_t db_size)
-{
+void Ssl::CertificateDb::writeSize(size_t db_size) {
std::ofstream ofstr(size_full.c_str());
if (!ofstr && enabled_disk_store)
throw std::runtime_error("cannot write \"" + size_full + "\" file");
ofstr << db_size;
}
-size_t Ssl::CertificateDb::getFileSize(std::string const & filename)
-{
+size_t Ssl::CertificateDb::getFileSize(std::string const & filename) {
std::ifstream file(filename.c_str(), std::ios::binary);
file.seekg(0, std::ios_base::end);
size_t file_size = file.tellg();
return ((file_size + fs_block_size - 1) / fs_block_size) * fs_block_size;
}
-void Ssl::CertificateDb::load()
-{
+void Ssl::CertificateDb::load() {
// Load db from file.
Ssl::BIO_Pointer in(BIO_new(BIO_s_file()));
if (!in || BIO_read_filename(in.get(), db_full.c_str()) <= 0)
db.reset(temp_db.release());
}
-void Ssl::CertificateDb::save()
-{
+void Ssl::CertificateDb::save() {
if (!db)
throw std::runtime_error("The certificates database is not loaded");;
}
// Normally defined in defines.h file
-void Ssl::CertificateDb::deleteRow(const char **row, int rowIndex)
-{
+void Ssl::CertificateDb::deleteRow(const char **row, int rowIndex) {
const std::string filename(cert_full + "/" + row[cnlSerial] + ".pem");
sq_TXT_DB_delete_row(db.get(), rowIndex);
throw std::runtime_error("Failed to remove certficate file " + filename + " from db");
}
-bool Ssl::CertificateDb::deleteInvalidCertificate()
-{
+bool Ssl::CertificateDb::deleteInvalidCertificate() {
if (!db)
return false;
return true;
}
-bool Ssl::CertificateDb::deleteOldestCertificate()
-{
+bool Ssl::CertificateDb::deleteOldestCertificate() {
if (!db)
return false;
return true;
}
-bool Ssl::CertificateDb::deleteByHostname(std::string const & host)
-{
+bool Ssl::CertificateDb::deleteByHostname(std::string const & host) {
if (!db)
return false;
return false;
}
-bool Ssl::CertificateDb::IsEnabledDiskStore() const
-{
+bool Ssl::CertificateDb::IsEnabledDiskStore() const {
return enabled_disk_store;
}