]> WPIA git - cassiopeia.git/commitdiff
add: Include configuration for the database access
authorBenny Baumann <BenBE@geshi.org>
Wed, 5 Nov 2014 22:52:20 +0000 (23:52 +0100)
committerBenny Baumann <BenBE@geshi.org>
Fri, 7 Nov 2014 22:53:04 +0000 (23:53 +0100)
src/main.cpp
src/mysql.cpp
src/simpleOpensslSigner.cpp
src/simpleOpensslSigner.h

index dc3e9bbd3f9833aadb0980de9195097cb3c08949..eb93eec38c1ed1e0163cf1a6e89f6e45b8412510 100644 (file)
@@ -35,6 +35,7 @@
 
 std::string keyDir;
 std::vector<Profile> profiles;
+std::string sqlHost, sqlUser, sqlPass, sqlDB;
 
 std::string writeBackFile( uint32_t serial, std::string cert ) {
     std::string filename = "keys";
@@ -52,11 +53,8 @@ std::string writeBackFile( uint32_t serial, std::string cert ) {
 }
 
 int main( int argc, const char* argv[] ) {
-    if( argc < 2 ) {
-        std::cout << argv[0] << " password" << std::endl;
-        return 1;
-    }
-
+    ( void ) argc;
+    ( void ) argv;
     std::ifstream config;
     config.open( "config.txt" );
 
@@ -85,6 +83,14 @@ int main( int argc, const char* argv[] ) {
         if( key == "key.directory" ) {
             keyDir = value;
             continue;
+        } else if( key == "sql.host" ) {
+            sqlHost = value;
+        } else if( key == "sql.user" ) {
+            sqlUser = value;
+        } else if( key == "sql.password" ) {
+            sqlPass = value;
+        } else if( key == "sql.database" ) {
+            sqlDB = value;
         }
 
         if( key.compare( 0, 8, "profile." ) == 0 ) {
@@ -103,9 +109,9 @@ int main( int argc, const char* argv[] ) {
             }
 
             if( rest == "key" ) {
-                profiles[i].cert = value;
-            } else if( rest == "cert" ) {
                 profiles[i].key = value;
+            } else if( rest == "cert" ) {
+                profiles[i].cert = value;
             } else {
                 std::cout << "invalid line: " << line1 << std::endl;
                 continue;
@@ -122,7 +128,7 @@ int main( int argc, const char* argv[] ) {
 
     config.close();
 
-    std::shared_ptr<JobProvider> jp( new MySQLJobProvider( "localhost", "cacert", argv[1], "cacert" ) );
+    std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
     std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
 
     while( true ) {
@@ -148,7 +154,7 @@ int main( int argc, const char* argv[] ) {
                 cert->csr_content = std::string( std::istreambuf_iterator<char>( t ), std::istreambuf_iterator<char>() );
 
                 std::shared_ptr<SignedCertificate> res = sign->sign( cert );
-                std::string fn = writeBackFile( res->serial, res->certificate );
+                std::string fn = writeBackFile( atoi( job->target.c_str() ), res->certificate );
                 res->crt_name = fn;
                 jp->writeBack( job, res );
             } catch( const char* c ) {
index 67fc49ecc65bae1122a196242c41a2380e194ac8..3c2cb960ca7563e6ad537cd7c4549ebb542167c9 100644 (file)
@@ -249,7 +249,7 @@ void MySQLJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<Sign
         throw "Error while writing back";
     }
 
-    std::string q = "UPDATE certs SET crt_name='" + this->escape_string( res->crt_name ) + "', serial='" + this->escape_string( std::to_string( res->serial ) ) + "' WHERE id='" + this->escape_string( job->id ) + "' LIMIT 1";
+    std::string q = "UPDATE certs SET crt_name='" + this->escape_string( res->crt_name ) + "', serial='" + this->escape_string( std::to_string( res->serial ) ) + "', created=NOW() WHERE id='" + this->escape_string( job->id ) + "' LIMIT 1";
 
     // TODO write more thingies back
 
index 01189958fd70986c6dc8e49f6a4ea785c38ecaa3..d10a23e6986f75e2b8ff21399061830f0139d6fa 100644 (file)
@@ -9,7 +9,7 @@
 #include <openssl/engine.h>
 #include <openssl/x509v3.h>
 
-#include "X509.h"
+extern std::vector<Profile> profiles;
 
 std::shared_ptr<int> SimpleOpensslSigner::lib_ref(
     new int( SSL_library_init() ),
@@ -62,9 +62,12 @@ std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename ) {
         } );
 }
 
-std::shared_ptr<X509> SimpleOpensslSigner::caCert = loadX509FromFile( "assured.crt" );
+SimpleOpensslSigner::SimpleOpensslSigner() {
+    caCert = loadX509FromFile( profiles[0].cert );
+    caKey = loadPkeyFromFile( profiles[0].key );
+}
 
-std::shared_ptr<EVP_PKEY> SimpleOpensslSigner::caKey = loadPkeyFromFile( "assured.key" );
+int serial = 10;
 
 std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TBSCertificate> cert ) {
     if( !caKey ) {
@@ -94,12 +97,10 @@ std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TB
 
     c.setIssuerNameFrom( caCert );
     c.setPubkeyFrom( req );
-    c.setSerialNumber( 4711 );
+    c.setSerialNumber( serial++ );
     c.setTimes( 0, 60 * 60 * 24 * 10 );
     c.setExtensions( caCert, cert->SANs );
 
-    std::string output = c.sign( caKey );
-
     std::shared_ptr<SignedCertificate> output = c.sign( caKey );
 
     return output;
index b2f245fd0a00221b648f4fcd0551f09704a1fd83..1dae5ed2c11071f6d2b3dff2e9c64fef06fce3f7 100644 (file)
@@ -7,8 +7,9 @@
 class SimpleOpensslSigner : public Signer {
 private:
     static std::shared_ptr<int> lib_ref;
-    static std::shared_ptr<EVP_PKEY> caKey;
-    static std::shared_ptr<X509> caCert;
+    std::shared_ptr<EVP_PKEY> caKey;
+    std::shared_ptr<X509> caCert;
 public:
+    SimpleOpensslSigner();
     std::shared_ptr<SignedCertificate> sign( std::shared_ptr<TBSCertificate> cert );
 };