]> WPIA git - cassiopeia.git/commitdiff
fetch the TBSCertificate
authorFelix Dörre <felix@dogcraft.de>
Sat, 1 Nov 2014 23:28:36 +0000 (00:28 +0100)
committerBenny Baumann <BenBE@geshi.org>
Fri, 7 Nov 2014 22:52:18 +0000 (23:52 +0100)
src/database.h
src/main.cpp
src/mysql.cpp
src/mysql.h

index b189807107c64df830378821c8927bb4d80fe988..e719df63628ba2923b6a7b3b0088eff0b56390e3 100644 (file)
@@ -5,13 +5,23 @@
 
 struct Job {
     std::string id;
+    std::string target;
     std::string task;
     std::string from;
     std::string to;
 };
+struct TBSCertificate {
+    std::string CN;
+    std::string subj;
+    std::string md;
+    std::string profile;
+    std::string csr;
+    std::string csr_type;
+};
 
 class JobProvider {
 public:
     virtual std::shared_ptr<Job> fetchJob() = 0;
     virtual bool finishJob( std::shared_ptr<Job> job ) = 0;
+    virtual std::shared_ptr<TBSCertificate> fetchTBSCert( std::shared_ptr<Job> job ) = 0;
 };
index bf4df813209d7d384769989ab0e9782a770d8419..e0a6c10190276444bde61cfadb35e2766dd123d1 100644 (file)
@@ -35,6 +35,15 @@ int main( int argc, const char* argv[] ) {
         return 2;
     }
 
+    if( job->task == "sign" ) {
+        std::cout << "signing" << std::endl;
+        std::shared_ptr<TBSCertificate> cert = jp->fetchTBSCert( job );
+        std::cout << cert->CN << std::endl;
+        std::cout << cert->md << std::endl;
+        std::cout << cert->csr << std::endl;
+        std::cout << cert->csr_type << std::endl;
+    }
+
     if( !jp->finishJob( job ) ) {
         return 1;
     }
index 38cb606658511fff675051ac028c1bce0902006c..ab37553ce1899f1fd00c776264398b24209559c8 100644 (file)
@@ -139,6 +139,10 @@ std::shared_ptr<Job> MySQLJobProvider::fetchJob() {
     }
 
     job->id = std::string( row[0], row[0] + l[0] );
+    job->target = std::string( row[1], row[1] + l[1] );
+    job->task = std::string( row[2], row[2] + l[2] );
+    job->from = std::string( row[3], row[3] + l[3] );
+    job->to = std::string( row[4], row[4] + l[4] );
 
     for( unsigned int i = 0; i < num; i++ ) {
         printf( "[%.*s] ", ( int ) l[i], row[i] ? row[i] : "NULL" );
@@ -178,3 +182,38 @@ bool MySQLJobProvider::finishJob( std::shared_ptr<Job> job ) {
 
     return true;
 }
+
+std::shared_ptr<TBSCertificate> MySQLJobProvider::fetchTBSCert( std::shared_ptr<Job> job ) {
+    std::shared_ptr<TBSCertificate> cert = std::shared_ptr<TBSCertificate>( new TBSCertificate() );
+    std::string q = "SELECT CN, subject, md, profile, csr_name, csr_type FROM certs WHERE id='" + this->escape_string( job->id ) + "'";
+
+    int err = 0;
+    std::shared_ptr<MYSQL_RES> res;
+
+    std::tie( err, res ) = query( q );
+
+    if( err ) {
+        return std::shared_ptr<TBSCertificate>();
+    }
+
+    MYSQL_ROW row = mysql_fetch_row( res.get() );
+
+    if( !row ) {
+        return std::shared_ptr<TBSCertificate>();
+    }
+
+    unsigned long* l = mysql_fetch_lengths( res.get() );
+
+    if( !l ) {
+        return std::shared_ptr<TBSCertificate>();
+    }
+
+    cert->CN = std::string( row[0], row[0] + l[0] );
+    cert->subj = std::string( row[1], row[1] + l[1] );
+    cert->md = std::string( row[2], row[2] + l[2] );
+    cert->profile = std::string( row[3], row[3] + l[3] );
+    cert->csr = std::string( row[4], row[4] + l[4] );
+    cert->csr_type = std::string( row[5], row[5] + l[5] );
+
+    return cert;
+}
index f27d0d899ed10445c71b364667f0ade78029e573..827a10a85f7d9230ae5ca6309bdc731ebf3ae99e 100644 (file)
@@ -32,4 +32,5 @@ public:
 public:
     std::shared_ptr<Job> fetchJob();
     bool finishJob( std::shared_ptr<Job> job );
+    std::shared_ptr<TBSCertificate> fetchTBSCert( std::shared_ptr<Job> job );
 };