X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fapps%2Fclient.cpp;h=71ef1790cd70cbb65d56b22c586614ffb195b4e6;hb=4c5720f760282df8936e55064560373b6c9def0d;hp=5258b9abad9b887e48b966cf1a46e35c3b2a895e;hpb=b9a325b540fd50bc5381877513ba2e632502ea7b;p=cassiopeia.git diff --git a/src/apps/client.cpp b/src/apps/client.cpp index 5258b9a..71ef179 100644 --- a/src/apps/client.cpp +++ b/src/apps/client.cpp @@ -27,12 +27,32 @@ extern std::string sqlHost, sqlUser, sqlPass, sqlDB; extern std::string serialPath; extern std::unordered_map> CAs; +void checkCRLs( std::shared_ptr sign ) { + std::cout << "Signing CRLs" << std::endl; + + for( auto& x : CAs ) { + std::cout << "Checking: " << x.first << std::endl; + + if( !x.second->crlNeedsResign() ) { + std::cout << "Skipping Resigning CRL: " + x.second->name << std::endl; + continue; + } + + std::cout << "Resigning CRL: " + x.second->name << std::endl; + + try { + std::vector serials; + std::pair, std::string> rev = sign->revoke( x.second, serials ); + } catch( const char* c ) { + std::cout << "Exception: " << c << std::endl; + } + } +} + 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; } @@ -56,11 +76,27 @@ int main( int argc, const char* argv[] ) { std::shared_ptr jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) ); std::shared_ptr b = openSerial( serialPath ); std::shared_ptr slip1( BIO_new( toBio() ), BIO_free ); - ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr( new OpensslBIOWrapper( b ) ) ); + static_cast( slip1->ptr )->setTarget( std::shared_ptr( new OpensslBIOWrapper( b ) ) ); std::shared_ptr sign( new RemoteSigner( slip1, generateSSLContext( false ) ) ); // std::shared_ptr sign( new SimpleOpensslSigner() ); + time_t lastCRLCheck = 0; + while( true ) { + time_t current; + time( ¤t ); + + if( lastCRLCheck + 30 * 60 < current ) { + // todo set good log TODO FIXME + sign->setLog( std::shared_ptr( + &std::cout, + []( std::ostream * o ) { + ( void ) o; + } ) ); + checkCRLs( sign ); + lastCRLCheck = current; + } + std::shared_ptr job = jp->fetchJob(); if( !job ) { @@ -69,14 +105,9 @@ int main( int argc, const char* argv[] ) { continue; } - std::ofstream* logP = new std::ofstream( std::string( "logs/" ) + job->id + std::string( "_" ) + job->warning + std::string( ".log" ) ); - std::shared_ptr logPtr( - logP, - []( std::ofstream * ptr ) { - ( *ptr ).close(); - delete ptr; - } ); - std::ofstream& log = *logP; + 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; @@ -87,6 +118,8 @@ int main( int argc, const char* argv[] ) { 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; @@ -119,8 +152,15 @@ int main( int argc, const char* argv[] ) { log << "FINE: CERTIFICATE LOG: " << res->log << std::endl; log << "FINE: CERTIFICATE:" << std::endl << res->certificate << std::endl; std::string fn = writeBackFile( job->target.c_str(), res->certificate, keyDir ); + + if( fn.empty() ) { + log << "ERROR: Writeback of the certificate failed." << std::endl; + jp->failJob( job ); + continue; + } + res->crt_name = fn; - jp->writeBack( job, res ); + jp->writeBack( job, res ); //! \FIXME: Check return value log << "FINE: signing done." << std::endl; if( DAEMON ) { @@ -130,7 +170,7 @@ int main( int argc, const char* argv[] ) { continue; } catch( const char* c ) { log << "ERROR: " << c << std::endl; - } catch( std::string c ) { + } catch( std::string& c ) { log << "ERROR: " << c << std::endl; } @@ -138,7 +178,7 @@ int main( int argc, const char* argv[] ) { jp->failJob( job ); } catch( const char* c ) { log << "ERROR: " << c << std::endl; - } catch( std::string c ) { + } catch( std::string& c ) { log << "ERROR: " << c << std::endl; } } else if( job->task == "revoke" ) { @@ -155,6 +195,8 @@ int main( int argc, const char* argv[] ) { jp->finishJob( job ); } catch( const char* c ) { std::cout << "Exception: " << c << std::endl; + } catch( const std::string& c ) { + std::cout << "Exception: " << c << std::endl; } } else { log << "Unknown job type" << job->task << std::endl;