]> WPIA git - cassiopeia.git/blobdiff - src/apps/client.cpp
fix: Make CppCheck happy by fixing the code
[cassiopeia.git] / src / apps / client.cpp
index 5258b9abad9b887e48b966cf1a46e35c3b2a895e..7c5bf0888b5a9bb3ac6996e7e02cd1ec19ca2aa7 100644 (file)
@@ -27,6 +27,28 @@ extern std::string sqlHost, sqlUser, sqlPass, sqlDB;
 extern std::string serialPath;
 extern std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
 
+void checkCRLs( std::shared_ptr<Signer> 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<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;
+        }
+    }
+}
+
 int main( int argc, const char* argv[] ) {
     ( void ) argc;
     ( void ) argv;
@@ -56,11 +78,27 @@ int main( int argc, const char* argv[] ) {
     std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
     std::shared_ptr<BIO> b = openSerial( serialPath );
     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
-    ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
+    static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
     std::shared_ptr<RemoteSigner> sign( new RemoteSigner( slip1, generateSSLContext( false ) ) );
     // std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
 
+    time_t lastCRLCheck = 0;
+
     while( true ) {
+        time_t current;
+        time( &current );
+
+        if( lastCRLCheck + 30 * 60 < current ) {
+            // todo set good log TODO FIXME
+            sign->setLog( std::shared_ptr<std::ostream>(
+                &std::cout,
+                []( std::ostream * o ) {
+                    ( void ) o;
+                } ) );
+            checkCRLs( sign );
+            lastCRLCheck = current;
+        }
+
         std::shared_ptr<Job> job = jp->fetchJob();
 
         if( !job ) {
@@ -87,6 +125,8 @@ int main( int argc, const char* argv[] ) {
         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;
 
@@ -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" ) {