#include "crypto/simpleOpensslSigner.h"
#include "crypto/remoteSigner.h"
#include "crypto/sslUtil.h"
+#include "log/logger.hpp"
#include "util.h"
#include "io/bios.h"
#include "io/slipBio.h"
extern std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
void checkCRLs( std::shared_ptr<Signer> sign ) {
- std::cout << "Signing CRLs" << std::endl;
+
+ logger::note( "Signing CRLs" );
for( auto& x : CAs ) {
- std::cout << "Checking: " << x.first << std::endl;
+ logger::notef( "Checking: %s ...", x.first );
if( !x.second->crlNeedsResign() ) {
- std::cout << "Skipping Resigning CRL: " + x.second->name << std::endl;
+ logger::warnf( "Skipping Resigning CRL: %s ...", x.second->name );
continue;
}
- std::cout << "Resigning CRL: " + x.second->name << std::endl;
+ logger::notef( "Resigning CRL: %s ...", x.second->name );
try {
std::vector<std::string> serials;
std::pair<std::shared_ptr<CRL>, std::string> rev = sign->revoke( x.second, serials );
} catch( const char* c ) {
- std::cout << "Exception: " << c << std::endl;
+ logger::error( "Exception: ", c );
}
}
}
#endif
if( parseConfig( path ) != 0 ) {
+ logger::fatal( "Error: Could not parse the configuration file." );
return -1;
}
if( serialPath == "" ) {
- std::cout << "Error: no serial device is given" << std::endl;
+ logger::fatal( "Error: no serial device is given!" );
return -1;
}
std::shared_ptr<Job> job = jp->fetchJob();
if( !job ) {
- std::cout << "Nothing to work on" << std::endl;
+ logger::debug( "Nothing to work on." );
sleep( 5 );
continue;
}
std::ofstream& log = *( logPtr.get() );
sign->setLog( logPtr );
- log << "TASK ID: " << job->id << std::endl;
- log << "TRY: " << job->warning << std::endl;
- log << "TARGET: " << job->target << std::endl;
- log << "TASK: " << job->task << std::endl << std::endl;
+ logger::note( "TASK ID: ", job->id );
+ logger::note( "TRY: ", job->warning );
+ logger::note( "TARGET: ", job->target );
+ logger::note( "TASK: ", job->task );
if( job->task == "sign" ) {
try {
std::shared_ptr<TBSCertificate> cert = jp->fetchTBSCert( job );
cert->wishFrom = job->from;
cert->wishTo = job->to;
- log << "INFO: message digest: " << cert->md << std::endl;
- log << "INFO: profile id: " << cert->profile << std::endl;
+ logger::note( "INFO: Message Digest: ", cert->md );
+ logger::note( "INFO: Profile ID: ", cert->profile );
for( auto& SAN : cert->SANs ) {
- log << "INFO: SAN " << SAN->type << ": " << SAN->content;
+ logger::notef( "INFO: SAN %s: %s", SAN->type, SAN->content );
}
for( auto& AVA : cert->AVAs ) {
- log << "INFO: AVA " << AVA->name << ": " << AVA->value;
+ logger::notef( "INFO: AVA %s: %s", AVA->name, AVA->value );
}
if( !cert ) {
- std::cout << "wasn't able to load CSR" << std::endl;
+ logger::error( "Unable to load CSR" );
jp->failJob( job );
continue;
}
- log << "FINE: Found the CSR at '" << cert->csr << "'" << std::endl;
+ logger::notef( "FINE: Found the CSR at '%s'", cert->csr );
cert->csr_content = readFile( keyDir + "/../" + cert->csr );
- log << "FINE: CSR is " << std::endl << cert->csr_content << std::endl;
+ logger::note( "FINE: CSR content:\n", cert->csr_content );
std::shared_ptr<SignedCertificate> res = sign->sign( cert );
if( !res ) {
- log << "ERROR: The signer failed. There was no certificate." << std::endl;
+ logger::error( "ERROR: The signer failed. No certificate was returned." );
jp->failJob( job );
continue;
}
- log << "FINE: CERTIFICATE LOG: " << res->log << std::endl;
- log << "FINE: CERTIFICATE:" << std::endl << res->certificate << std::endl;
+ logger::note( "FINE: CERTIFICATE LOG:\n", res->log );
+ logger::note( "FINE: CERTIFICATE:\n", res->certificate );
std::string fn = writeBackFile( job->target.c_str(), res->certificate, keyDir );
if( fn.empty() ) {
- log << "ERROR: Writeback of the certificate failed." << std::endl;
+ logger::error( "ERROR: Writeback of the certificate failed." );
jp->failJob( job );
continue;
}
res->crt_name = fn;
jp->writeBack( job, res ); //! \FIXME: Check return value
- log << "FINE: signing done." << std::endl;
+ logger::note( "FINE: signing done." );
if( DAEMON ) {
jp->finishJob( job );
continue;
} catch( const char* c ) {
- log << "ERROR: " << c << std::endl;
+ logger::error( "ERROR: ", c );
} catch( std::string& c ) {
- log << "ERROR: " << c << std::endl;
+ logger::error( "ERROR: ", c );
}
try {
jp->failJob( job );
} catch( const char* c ) {
- log << "ERROR: " << c << std::endl;
+ logger::error( "ERROR: ", c );
} catch( std::string& c ) {
- log << "ERROR: " << c << std::endl;
+ logger::error( "ERROR: ", c );
}
} else if( job->task == "revoke" ) {
try {
jp->writeBackRevocation( job, timeToString( time ) );
jp->finishJob( job );
} catch( const char* c ) {
- std::cout << "Exception: " << c << std::endl;
+ logger::error( "Exception: ", c );
} catch( const std::string& c ) {
- std::cout << "Exception: " << c << std::endl;
+ logger::error( "Exception: ", c );
}
} else {
- log << "Unknown job type" << job->task << std::endl;
+ logger::errorf( "Unknown job type (\"%s\")", job->task );
jp->failJob( job );
}
#include "io/bios.h"
#include "io/slipBio.h"
#include "io/recordHandler.h"
+#include "log/logger.hpp"
#include "util.h"
#include "config.h"
#endif
if( parseConfig( path ) != 0 ) {
+ logger::fatal("Could not parse configuration file.");
return -1;
}
std::shared_ptr<int> ssl_lib = ssl_lib_ref;
if( serialPath == "" ) {
- std::cout << "Error: no serial device is given" << std::endl;
+ logger::fatal( "Error: No device for the serial connection was given." );
return -1;
}
//} catch( const std::exception &ch ) {
//std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
} catch( const std::string& ch ) {
- std::cout << "Exception: " << ch << std::endl;
+ logger::error( "Exception: ", ch );
} catch( char const* ch ) {
- std::cout << "Exception: " << ch << std::endl;
+ logger::error( "Exception: ", ch );
}
}
return -1;
-} catch(std::exception& e) {
- std::cerr << "Fatal Error: " << e.what() << "!\n";
+} catch( std::exception& e ) {
+ logger::fatalf( "Fatal Error: %s!\n", e.what() );
return -1;
-} catch(...) {
- std::cerr << "Fatal Error: Unknown Exception!\n";
+} catch( ... ) {
+ logger::fatal( "Fatal Error: Unknown Exception!\n" );
return -1;
}
#include "crypto/sslUtil.h"
+#include "log/logger.hpp"
+
std::string keyDir;
std::unordered_map<std::string, Profile> profiles;
std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
config.open( path );
if( !config.is_open() ) {
- std::cout << "Where is " << path << "?" << std::endl;
+ logger::notef( "Where is \"%s\"?", path );
throw "Config missing";
}
int splitter = line1.find( "=" );
if( splitter == -1 ) {
- std::cerr << "Ignoring malformed config line: " << line1 << std::endl;
+ logger::warn( "Ignoring malformed config line: ", line1 );
continue;
}
dp = opendir( "profiles" );
if( dp == NULL ) {
- std::cerr << "Profiles not found " << std::endl;
+ logger::error( "Profiles directory not found" );
return -1;
}
int splitter = profileName.find( "-" );
if( splitter == -1 ) {
- std::cerr << "Ignoring malformed profile: " << profileName << std::endl;
+ logger::warn( "Ignoring malformed profile: ", profileName );
continue;
}
std::string id = profileName.substr( 0, splitter );
if( profileName.substr( profileName.size() - 4 ) != ".cfg" ) {
- std::cerr << "Ignoring malformed profile: " << profileName << std::endl;
+ logger::warn( "Ignoring malformed profile: ", profileName );
continue;
}
std::string cas = map->at( "ca" );
- DIR *dir;
- struct dirent *ent;
- if ((dir = opendir ("ca")) != NULL) {
- while ((ent = readdir (dir)) != NULL) {
- std::string caName = std::string(ent->d_name);
- if( caName.find( cas ) != 0 ){
+ DIR* dir;
+ struct dirent* ent;
+
+ if( ( dir = opendir( "ca" ) ) != NULL ) {
+ while( ( ent = readdir( dir ) ) != NULL ) {
+ std::string caName = std::string( ent->d_name );
+
+ if( caName.find( cas ) != 0 ) {
continue;
}
}
prof.ca.push_back( CAs.at( caName ) );
- std::cout << "Adding CA: " << caName << std::endl;
+ logger::note( "Adding CA: ", caName );
}
- closedir (dir);
+
+ closedir( dir );
} else {
throw "Directory with CAConfigs not found";
}
profiles.emplace( profileName, prof );
- std::cout << "Profile: " << profileName << " up and running." << std::endl;
+ logger::notef( "Profile: \"%s\" up and running.", profileName );
}
( void ) closedir( dp );
-
- std::cout << profiles.size() << " profiles loaded." << std::endl;
+ logger::notef( "%s profiles loaded.", profiles.size() );
return 0;
}
serialPath = masterConf->at( "serialPath" );
if( keyDir == "" ) {
- std::cerr << "Missing config property key.directory" << std::endl;
+ logger::error( "Missing config property key.directory" );
return -1;
}
#include "remoteSigner.h"
+
+#include "log/logger.hpp"
#include "util.h"
#include <iostream>
head.command_count++;
head.totalLength = data.size();
sendCommand( head, data, bio, log );
-
}
std::shared_ptr<SignedCertificate> RemoteSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
} else if( cert->csr_type == "SPKAC" ) {
send( conn, head, RecordHeader::SignerCommand::SET_SPKAC, cert->csr_content );
} else {
- std::cout << "Unknown csr_type: " << cert->csr_type;
+ logger::error( "Unknown csr_type: ", cert->csr_type );
return std::shared_ptr<SignedCertificate>();
}
int length = conn->read( buffer.data(), buffer.size() );
if( length <= 0 ) {
- std::cout << "Error, no response data" << std::endl;
+ logger::error( "Error, no response data" );
result = std::shared_ptr<SignedCertificate>();
break;
}
break;
default:
- std::cout << "Invalid Message" << std::endl;
+ logger::error( "Invalid Message" );
break;
}
} catch( const char* msg ) {
- std::cout << msg << std::endl;
+ logger::error( msg );
return std::shared_ptr<SignedCertificate>();
}
}
}
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) { // need to close the connection twice
- std::cout << "SSL shutdown failed" << std::endl;
+ logger::warn( "SSL shutdown failed" );
}
return result;
bool ok = crl->verify( ca );
if( ok ) {
- ( *log ) << "CRL verificated successfully" << std::endl;
+ logger::note( "CRL verificated successfully" );
writeFile( ca->path + std::string( "/ca.crl" ), crl->toString() );
} else {
- ( *log ) << "CRL is broken" << std::endl;
+ logger::warn( "CRL is broken, trying to recover" );
send( conn, head, RecordHeader::SignerCommand::GET_FULL_CRL, ca->name );
length = conn->read( buffer.data(), buffer.size() );
if( crl->verify( ca ) ) {
writeFile( ca->path + std::string( "/ca.crl" ), crl->toString() );
- ( *log ) << "CRL is now valid" << std::endl;
+ logger::note( "CRL is now valid again" );
} else {
- ( *log ) << "CRL is still broken... Please, help me" << std::endl;
+ logger::warn( "CRL is still broken... Please, help me" );
}
-
}
- ( *log ) << "CRL: " << std::endl << crl->toString() << std::endl;
+ logger::debug( "CRL:\n", crl->toString() );
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) { // need to close the connection twice
- std::cout << "SSL shutdown failed" << std::endl;
+ logger::warn( "SSL shutdown failed" );
}
return std::pair<std::shared_ptr<CRL>, std::string>( crl, date );
#pragma once
+
#include <memory>
#include <openssl/ssl.h>
#include <openssl/engine.h>
#include <openssl/x509v3.h>
+#include "log/logger.hpp"
+
#include "X509.h"
#include "util.h"
#include "sslUtil.h"
std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
std::stringstream signlog;
- signlog << "FINE: profile is " << cert->profile << std::endl;
+ logger::note( "FINE: Profile name is: ", cert->profile );
Profile& prof = profiles.at( cert->profile );
- signlog << "FINE: Profile id is: " << prof.id << std::endl;
+ logger::note( "FINE: Profile ID is: ", prof.id );
std::shared_ptr<CAConfig> ca = prof.getCA();
if( !ca ) {
- signlog << "ERROR: Signing CA specified in profile could not be loaded." << std::endl;
+ logger::error( "ERROR: Signing CA specified in profile could not be loaded." );
throw "CA-key not found";
}
- signlog << "FINE: Key for Signing CA is correctly loaded." << std::endl;
+ logger::note( "FINE: Key for Signing CA is correctly loaded." );
- signlog << "INFO: Baseline Key Usage is: " << prof.ku << std::endl;
- signlog << "INFO: Extended Key Usage is: " << prof.eku << std::endl;
+ logger::note( "INFO: Baseline Key Usage is: ", prof.ku );
+ logger::note( "INFO: Extended Key Usage is: ", prof.eku );
- signlog << "FINE: Signing is wanted by: " << cert->wishFrom << std::endl;
- signlog << "FINE: Signing is wanted for: " << cert->wishTo << std::endl;
+ logger::note( "FINE: Signing is wanted by: ", cert->wishFrom );
+ logger::note( "FINE: Signing is wanted for: ", cert->wishTo );
std::shared_ptr<X509Req> req;
} else if( cert->csr_type == "CSR" ) {
req = X509Req::parseCSR( cert->csr_content );
} else {
- signlog << "ERROR: Unknown type of certification in request: " << cert->csr_type << std::endl;
- throw "Error, unknown REQ rype " + ( cert->csr_type );
+ logger::errorf( "ERROR: Unknown type (\"%s\") of certification in request.", cert->csr_type );
+ throw "Error, unknown REQ rype " + ( cert->csr_type ); //! \fixme: Pointer instead of string, please use proper exception classes
}
int i = req->verify();
} else if( i == 0 ) {
throw "Request contains a Signature that does not match ...";
} else {
- signlog << "FINE: Request contains valid self-signature." << std::endl;
+ logger::note( "FINE: Request contains valid self-signature." );
}
// Construct the Certificate
X509Cert c = X509Cert();
- signlog << "INFO: Populating RDN ..." << std::endl;
+ logger::note( "INFO: Populating RDN ..." );
+
for( std::shared_ptr<AVA> a : cert->AVAs ) {
- signlog << "INFO: Trying to add RDN: " << a->name << ": " << a->value << std::endl;
+ logger::notef( "INFO: Trying to add RDN: %s: %s", a->name, a->value );
if( a->name == "CN" ) {
c.addRDN( NID_commonName, a->value );
} else if( a->name == "OU" ) {
c.addRDN( NID_organizationalUnitName, a->value );
} else {
- signlog << "ERROR: Trying to add illegal RDN/AVA type: " << a->name << std::endl;
+ logger::error( "ERROR: Trying to add illegal RDN/AVA type: ", a->name );
throw "Unhandled/Illegal AVA type";
}
}
- signlog << "INFO: Populating Issuer ..." << std::endl;
+ logger::note( "INFO: Populating Issuer ..." );
c.setIssuerNameFrom( ca->ca );
- signlog << "INFO: Validating Public key for use in certificate" << std::endl;
- signlog << "INFO: - Checking generic key parameters" << std::endl;
- signlog << "FINE: ->Public Key parameters are okay" << std::endl;
+ logger::note( "INFO: Validating Public key for use in certificate" );
+ logger::note( "INFO: - Checking generic key parameters" );
+ logger::note( "FINE: ->Public Key parameters are okay" );
- signlog << "INFO: - Checking blacklists" << std::endl;
- signlog << "FINE: ->Does not appear on any blacklist" << std::endl;
+ logger::note( "INFO: - Checking blacklists" );
+ logger::note( "FINE: ->Does not appear on any blacklist" );
- signlog << "INFO: - Checking trivial factorization" << std::endl;
- signlog << "FINE: ->Trivial factorization not possible" << std::endl;
+ logger::note( "INFO: - Checking trivial factorization" );
+ logger::note( "FINE: ->Trivial factorization not possible" );
- signlog << "INFO: - Checking astrological signs" << std::endl;
- signlog << "FINE: ->The stars look good for this one" << std::endl;
- signlog << "FINE: Public key is fine for use in certificate" << std::endl;
+ logger::note( "INFO: - Checking astrological signs" );
+ logger::note( "FINE: ->The stars look good for this one" );
+ logger::note( "FINE: Public key is fine for use in certificate" );
- signlog << "INFO: Copying Public Key from Request ..." << std::endl;
+ logger::note( "INFO: Copying Public Key from Request ..." );
c.setPubkeyFrom( req );
- signlog << "FINE: Public Key successfully copied from Request." << std::endl;
+ logger::note( "FINE: Public Key successfully copied from Request." );
{
- signlog << "INFO: Determining Validity Period ..." << std::endl;
+ logger::note( "INFO: Determining Validity Period ..." );
std::time_t from, to;
std::time_t now = time( 0 );
std::pair<bool, std::time_t> parsed;
from = now;
}
- if( ((from - now) > /* 2 Weeks */ (2 * 7 * 24 * 60 * 60)) || ((now - from) >= 0) ) {
+ if( ( ( from - now ) > /* 2 Weeks */ ( 2 * 7 * 24 * 60 * 60 ) ) || ( ( now - from ) >= 0 ) ) {
from = now;
}
time_t limit = prof.maxValidity;
- if( (to - from > limit) || (to - from < 0) ) {
+ if( ( to - from > limit ) || ( to - from < 0 ) ) {
to = from + limit;
}
c.setTimes( from, to );
- signlog << "FINE: Setting validity period successful:" << std::endl;
+ logger::note( "FINE: Setting validity period successful:" );
{
struct tm* timeobj;
std::vector<char> timebuf;
- timeobj = gmtime(&from);
- timebuf.resize(128);
- timebuf.resize(std::strftime(const_cast<char *>(timebuf.data()), timebuf.size(), "%F %T %Z", timeobj));
- signlog << "FINE: - Valid not before: " << std::string(timebuf.cbegin(), timebuf.cend()) << std::endl;
+ timeobj = gmtime( &from );
+ timebuf.resize( 128 );
+ timebuf.resize( std::strftime( const_cast<char*>( timebuf.data() ), timebuf.size(), "%F %T %Z", timeobj ) );
+ logger::note( "FINE: - Valid not before: ", std::string( timebuf.cbegin(), timebuf.cend() ) );
- timeobj = gmtime(&to);
- timebuf.resize(128);
- timebuf.resize(std::strftime(const_cast<char *>(timebuf.data()), timebuf.size(), "%F %T %Z", timeobj));
- signlog << "FINE: - Valid not after: " << std::string(timebuf.cbegin(), timebuf.cend()) << std::endl;
+ timeobj = gmtime( &to );
+ timebuf.resize( 128 );
+ timebuf.resize( std::strftime( const_cast<char*>( timebuf.data() ), timebuf.size(), "%F %T %Z", timeobj ) );
+ logger::note( "FINE: - Valid not after: ", std::string( timebuf.cbegin(), timebuf.cend() ) );
}
}
- signlog << "INFO: Setting extensions:" << std::endl;
+ logger::note( "INFO: Setting extensions:" );
c.setExtensions( ca->ca, cert->SANs, prof );
- signlog << "FINE: Setting extensions successful." << std::endl;
+ logger::note( "FINE: Setting extensions successful." );
- signlog << "INFO: Generating next Serial Number ..." << std::endl;
+ logger::note( "INFO: Generating next Serial Number ..." );
std::shared_ptr<BIGNUM> ser;
std::string num;
std::tie( ser, num ) = nextSerial( prof, ca );
c.setSerialNumber( ser.get() );
- signlog << "FINE: Certificate Serial Number set to:" << num << std::endl;
+ logger::note( "FINE: Certificate Serial Number set to: ", num );
{
- signlog << "INFO: Trying to sign Certificate:" << std::endl;
+ logger::note( "INFO: Trying to sign Certificate:" );
std::shared_ptr<SignedCertificate> output = c.sign( ca->caKey, cert->md );
- signlog << "INFO: Writing certificate to local file." << std::endl;
+ logger::note( "INFO: Writing certificate to local file." );
std::string fn = writeBackFile( num, output->certificate, ca->path );
if( fn.empty() ) {
- signlog << "ERROR: failed to get filename for storage of signed certificate." << std::endl;
+ logger::error( "ERROR: failed to get filename for storage of signed certificate." );
throw "Storage location could not be determined";
}
- signlog << "FINE: Certificate signed successfully." << std::endl;
- signlog << "FINE: - Certificate written to: " << fn << std::endl;
+
+ logger::note( "FINE: Certificate signed successfully." );
+ logger::note( "FINE: - Certificate written to: ", fn );
output->ca_name = ca->name;
output->log = signlog.str();
#include <iostream>
#include "crypto/CRL.h"
+#include "log/logger.hpp"
std::shared_ptr<int> ssl_lib_ref(
new int( SSL_library_init() ),
//X509_print_ex(o, cert, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
//BIO_free(o);
- std::cout << "Verification failed: " << preverify_ok << " because " << X509_STORE_CTX_get_error( ctx ) << std::endl;
+ logger::errorf( "Verification failed: %s because %s", preverify_ok, X509_STORE_CTX_get_error( ctx ) );
}
return preverify_ok;
dh_param = std::shared_ptr<DH>( PEM_read_DHparams( paramfile.get(), NULL, NULL, NULL ), DH_free );
} else {
dh_param = std::shared_ptr<DH>( DH_new(), DH_free );
- std::cout << "Generating DH params" << std::endl;
+ logger::note( "Generating DH params" );
BN_GENCB cb;
cb.ver = 2;
cb.arg = 0;
std::shared_ptr<FILE> f( fopen( name.c_str(), "r+" ), fclose );
if( !f ) {
- std::cout << "Opening serial device failed" << std::endl;
+ logger::error( "Opening serial device failed." );
return std::shared_ptr<BIO>();
}
#include <memory>
#include <sstream>
-#include "bios.h"
-#include "opensslBIO.h"
+#include "io/bios.h"
+#include "io/opensslBIO.h"
+#include "log/logger.hpp"
std::string toHexAndChecksum( const std::string& src ) {
char checksum = 0;
std::string res = toHexAndChecksum( s );
if( log ) {
- ( *log.get() ) << "FINE: RECORD output: " << res << std::endl;
+ logger::debug( "FINE: RECORD output: ", res );
}
bio->write( res.data(), res.size() );
std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log ) {
if( log ) {
- ( *log.get() ) << "FINE: RECORD input: " << input << std::endl;
+ logger::debug( "FINE: RECORD input: ", input );
}
int32_t dlen = ( input.size() - 2 ) / 2;
#include "db/database.h"
#include "crypto/remoteSigner.h"
#include "crypto/sslUtil.h"
-
#include "crypto/simpleOpensslSigner.h"
+#include "log/logger.hpp"
+
extern std::vector<Profile> profiles;
extern std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
int res = io->read( buffer.data(), buffer.capacity() );
if( res <= 0 ) {
- ( *log ) << "Stream error, resetting SSL" << std::endl;
+ logger::error( "Stream error, resetting SSL" );
parent->reset();
return;
}
execute( head, payload );
} catch( const char* msg ) {
if( log ) {
- ( *log ) << "ERROR: " << msg << std::endl;
+ logger::error( "ERROR: ", msg );
}
parent->reset();
case RecordHeader::SignerCommand::SET_CSR:
tbs->csr_content = data;
tbs->csr_type = "CSR";
- ( *log ) << "INFO: CSR read: " << tbs->csr_content << std::endl;
+ logger::note( "INFO: CSR read:\n", tbs->csr_content );
break;
case RecordHeader::SignerCommand::SET_SPKAC:
tbs->csr_content = data;
tbs->csr_type = "SPKAC";
- ( *log ) << "INFO: SPKAC read: " << tbs->csr_content << std::endl;
+ logger::note( "INFO: SPKAC read:\n", tbs->csr_content );
break;
case RecordHeader::SignerCommand::SET_SIGNATURE_TYPE:
case RecordHeader::SignerCommand::SIGN:
result = signer->sign( tbs );
- ( *log ) << "INFO: signlog: " << result->log << std::endl;
- ( *log ) << "INFO: res: " << result->certificate << std::endl;
+ logger::note( "INFO: signlog:\n", result->log );
+ logger::note( "INFO: res:\n", result->certificate );
respondCommand( RecordHeader::SignerResult::SAVE_LOG, result->log );
break;
}
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) {
- ( *log ) << "ERROR: SSL close failed" << std::endl;
+ logger::warn( "ERROR: SSL shutdown failed." );
}
+
parent->reset(); // Connection ended
break;
case RecordHeader::SignerCommand::REVOKE: {
std::string ca = data;
auto reqCA = CAs.at( ca );
- ( *log ) << "CA found" << std::endl;
+ logger::note( "CA found" );
std::shared_ptr<CRL> crl;
std::string date;
std::tie<std::shared_ptr<CRL>, std::string>( crl, date ) = signer->revoke( reqCA, serials );
respondCommand( RecordHeader::SignerResult::FULL_CRL, c.toString() );
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) {
- ( *log ) << "ERROR: SSL close failed" << std::endl;
+ logger::error( "ERROR: SSL shutdown failed." );
}
+
parent->reset(); // Connection ended
break;
}
void DefaultRecordHandler::handle() {
if( !currentSession ) {
- std::cout << "session allocated" << std::endl;
+ logger::note( "New session allocated." );
currentSession = std::shared_ptr<RecordHandlerSession>( new RecordHandlerSession( this, signer, ctx, bio ) );
}
#include <iostream>
+#include "log/logger.hpp"
+
#define BUFFER_SIZE 8192
#define SLIP_ESCAPE_CHAR ( (char) 0xDB)
int SlipBIO::write( const char* buf, int num ) {
#ifdef SLIP_IO_DEBUG
- std::cout << "Out: " << toHex( buf, num ) << std::endl;
+ logger::debug( "Out: " << toHex( buf, num ) );
#endif
int badOnes = 0;
}
#ifdef SLIP_IO_DEBUG
- std::cout << "in: " << toHex( buf, len ) << std::endl;
+ logger::debug( "in: " << toHex( buf, len ) );
#endif
return len;
decodePos = 0;
decodeTarget = 0;
rawPos = 0;
- std::cout << "resetting SLIP" << std::endl;
+ logger::note( "Resetting SLIP layer" );
return 0;
}
#include <memory>
#include <vector>
-#include "bios.h"
+#include "io/bios.h"
class SlipBIO : public OpensslBIO {
private:
}
}
-std::shared_ptr<std::ofstream> openLogfile( const std::string name) {
+std::shared_ptr<std::ofstream> openLogfile( const std::string name ) {
struct stat buffer;
std::string tname = name;
int ctr = 2;
- while(stat (tname.c_str(), &buffer) == 0) {
- tname = name + "_" + std::to_string(ctr++);
+
+ while( stat( tname.c_str(), &buffer ) == 0 ) {
+ tname = name + "_" + std::to_string( ctr++ );
}
- auto res = std::shared_ptr<std::ofstream>(new std::ofstream( tname ),
- [](std::ofstream *p){
+
+ auto res = std::shared_ptr<std::ofstream>( new std::ofstream( tname ),
+ []( std::ofstream * p ) {
p->close();
delete p;
- });
- if(! res->good() ){
- throw std::string("Failed to open file for logging: ") + name;
+ } );
+
+ if( ! res->good() ) {
+ throw std::string( "Failed to open file for logging: " ) + name;
}
+
return res;
}
std::pair<bool, std::time_t> parseMonthInterval( std::time_t t, const std::string& date );
std::pair<bool, std::time_t> parseYearInterval( std::time_t t, const std::string& date );
-
-std::shared_ptr<std::ofstream> openLogfile( const std::string name);
+std::shared_ptr<std::ofstream> openLogfile( const std::string name );