X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fapps%2Fclient.cpp;h=999b4532cb1cef0741e020ac835b157b3cc126e2;hb=d04ce75bc27a0cdb4482c493bbc63d6af3347121;hp=193626fe906edaa26607fdf260d374061e7b6721;hpb=1df411e55f9af5ae3071442255a78d0e512426a3;p=cassiopeia.git diff --git a/src/apps/client.cpp b/src/apps/client.cpp index 193626f..999b453 100644 --- a/src/apps/client.cpp +++ b/src/apps/client.cpp @@ -11,6 +11,7 @@ #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" @@ -28,33 +29,32 @@ extern std::string serialPath; extern std::unordered_map> CAs; void checkCRLs( std::shared_ptr 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 serials; std::pair, std::string> rev = sign->revoke( x.second, serials ); } catch( const char* c ) { - std::cout << "Exception: " << c << std::endl; + logger::error( "Exception: ", c ); } } } int main( int argc, const char* argv[] ) { - ( void ) argc; - ( void ) argv; bool once = false; - if( argc == 2 && std::string( "--once" ) == std::string( argv[1] ) ) { + if( argc == 2 && std::string( "--once" ) == argv[1] ) { once = true; } @@ -67,11 +67,12 @@ int main( int argc, const char* argv[] ) { #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; } @@ -92,7 +93,7 @@ int main( int argc, const char* argv[] ) { // todo set good log TODO FIXME sign->setLog( std::shared_ptr( &std::cout, - []( std::ostream * o ) { + []( std::ostream* o ) { ( void ) o; } ) ); checkCRLs( sign ); @@ -102,68 +103,66 @@ int main( int argc, const char* argv[] ) { std::shared_ptr job = jp->fetchJob(); if( !job ) { - std::cout << "Nothing to work on" << std::endl; + logger::debug( "Nothing to work on." ); sleep( 5 ); continue; } std::shared_ptr logPtr = openLogfile( std::string( "logs/" ) + job->id + std::string( "_" ) + job->warning + std::string( ".log" ) ); - 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 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 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 ); @@ -171,17 +170,17 @@ int main( int argc, const char* argv[] ) { 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 { @@ -196,12 +195,12 @@ int main( int argc, const char* argv[] ) { 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 ); }