std::shared_ptr<Job> job = jp->fetchJob();
if( !job ) {
- logger::debug( "Nothing to work on." );
+ logger::note( "Nothing to work on." );
sleep( 5 );
continue;
}
std::shared_ptr<std::ofstream> logPtr = openLogfile( std::string( "logs/" ) + job->id + std::string( "_" ) + job->warning + std::string( ".log" ) );
- sign->setLog( logPtr );
+ logger::logger_set log_set({logger::log_target(*logPtr, logger::level::debug)}, logger::auto_register::on);
+
logger::note( "TASK ID: ", job->id );
logger::note( "TRY: ", job->warning );
logger::note( "TARGET: ", job->target );
DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
+ logger::note( "Entering mainloop" );
while( true ) {
try {
dh->handle();
head.command = ( uint16_t ) cmd;
head.command_count++;
head.totalLength = data.size();
- sendCommand( head, data, bio, log );
+ sendCommand( head, data, bio );
}
std::shared_ptr<SignedCertificate> RemoteSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
}
RecordHeader head;
- std::string payload = parseCommand( head, std::string( buffer.data(), length ), log );
+ std::string payload = parseCommand( head, std::string( buffer.data(), length ) );
switch( ( RecordHeader::SignerResult ) head.command ) {
case RecordHeader::SignerResult::CERTIFICATE:
throw "Error, no response data";
}
- payload = parseCommand( head, std::string( buffer.data(), length ), log );
+ payload = parseCommand( head, std::string( buffer.data(), length ) );
std::shared_ptr<CRL> crl( new CRL( ca->path + std::string( "/ca.crl" ) ) );
std::string date;
throw "Error, no response data";
}
- payload = parseCommand( head, std::string( buffer.data(), length ), log );
+ payload = parseCommand( head, std::string( buffer.data(), length ) );
if( ( RecordHeader::SignerResult ) head.command != RecordHeader::SignerResult::FULL_CRL ) {
throw "Protocol violation";
std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
std::stringstream signlog;
+ logger::logger_set log_set_sign({logger::log_target(signlog, logger::level::debug)}, logger::auto_register::on);
logger::note( "FINE: Profile name is: ", cert->profile );
#include <iostream>
#include <mysql/errmsg.h>
+#include <log/logger.hpp>
//This static variable exists to handle initializing and finalizing the MySQL driver library
std::shared_ptr<int> MySQLJobProvider::lib_ref(
return nullptr;
}
- unsigned int num = mysql_num_fields( res.get() );
-
MYSQL_ROW row = mysql_fetch_row( res.get() );
if( !row ) {
job->to = std::string( row[4], row[4] + l[4] );
job->warning = std::string( row[5], row[5] + l[5] );
- for( unsigned int i = 0; i < num; i++ ) {
- printf( "[%.*s] ", ( int ) l[i], row[i] ? row[i] : "NULL" );
- }
-
- printf( "\n" );
+ logger::note( "Got a job: (id=%s, target=%s, task=%s, from=%s, to=%s, warnings=%s)", job->id, job->target, job->task, job->from, job->to, job->warning );
return job;
}
return ss.str();
}
-void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio, std::shared_ptr<std::ostream> log ) {
+void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio ) {
head.payloadLength = data.size();
std::string s;
s += head.packToString();
std::string res = toHexAndChecksum( s );
- if( log ) {
- logger::debug( "FINE: RECORD output: ", res );
- }
+ logger::debug( "FINE: RECORD output: ", res );
bio->write( res.data(), res.size() );
}
return res;
}
-std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log ) {
- if( log ) {
- logger::debug( "FINE: RECORD input: ", input );
- }
+std::string parseCommand( RecordHeader& head, const std::string& input) {
+ logger::debug( "FINE: RECORD input: ", input );
int32_t dlen = ( input.size() - 2 ) / 2;
char checksum = 0;
};
-std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log );
+std::string parseCommand( RecordHeader& head, const std::string& input );
-void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio, std::shared_ptr<std::ostream> log );
+void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio );
#include "io/recordHandler.h"
#include <iostream>
+#include <sstream>
#include <fstream>
#include <ctime>
#include <unordered_map>
DefaultRecordHandler* parent;
std::shared_ptr<Signer> signer;
- std::shared_ptr<std::ofstream> log;
+ std::shared_ptr<std::ofstream> logFile;
+ //std::stringstream sessionlog;
std::vector<std::string> serials;
+ logger::logger_set logger;
+
RecordHandlerSession( DefaultRecordHandler* parent, std::shared_ptr<Signer> signer, std::shared_ptr<SSL_CTX> ctx, std::shared_ptr<BIO> output ) :
sessid( 0 ),
lastCommandCount( 0 ),
- tbs( new TBSCertificate() ) {
+ tbs( new TBSCertificate() ),
+ logFile(openLogfile( std::string( "logs/log_" ) + std::to_string( [](){
+ time_t c_time;
+ if( time( &c_time ) == -1 ) {
+ throw "Error while fetching time?";
+ }
+ return c_time;
+ }() ) )),
+ logger( {
+ logger::log_target(std::cout, logger::level::note),
+ //logger::log_target(sessionlog, logger::level::note),
+ logger::log_target(*logFile, logger::level::note)
+ }, logger::auto_register::on) {
this->parent = parent;
this->signer = signer;
- time_t c_time;
-
- if( time( &c_time ) == -1 ) {
- throw "Error while fetching time?";
- }
-
- log = openLogfile( std::string( "logs/log_" ) + std::to_string( c_time ) );
ssl = std::shared_ptr<SSL>( SSL_new( ctx.get() ), SSL_free );
std::shared_ptr<BIO> bio(
rh.flags = 0;
rh.command_count = 0; // TODO i++
rh.totalLength = payload.size();
- sendCommand( rh, payload, io, log );
+ sendCommand( rh, payload, io );
}
void work() {
try {
RecordHeader head;
- std::string payload = parseCommand( head, content, log );
+ std::string payload = parseCommand( head, content );
execute( head, payload );
} catch( const char* msg ) {
- if( log ) {
- logger::error( "ERROR: ", msg );
- }
-
+ logger::error( "ERROR: ", msg );
parent->reset();
return;
}
case RecordHeader::SignerCommand::REVOKE:
{
+ logger::note("Revoking: ", data);
std::string ca = data;
auto reqCA = CAs.at( ca );
- logger::note( "CA found" );
+ logger::note( "CA found in recordHandler" );
std::shared_ptr<CRL> crl;
std::string date;
std::tie<std::shared_ptr<CRL>, std::string>( crl, date ) = signer->revoke( reqCA, serials );
case RecordHeader::SignerCommand::GET_FULL_CRL:
{
+ logger::note("Requesting full CRL: ", data);
auto ca = CAs.at( data );
CRL c( ca->path + "/ca.crl" );
respondCommand( RecordHeader::SignerResult::FULL_CRL, c.toString() );