]> WPIA git - cassiopeia.git/blobdiff - src/apps/signer.cpp
fix: Check return value of writeBackFile for non-empty filename
[cassiopeia.git] / src / apps / signer.cpp
index 551f13f7866ebed0509f73c184cfaab8fa1d5af4..b607b9cd949152b8b13affce75fb96bb0f91614e 100644 (file)
@@ -2,16 +2,16 @@
 #include <fstream>
 #include <streambuf>
 
-#include "database.h"
-#include "mysql.h"
-#include "simpleOpensslSigner.h"
+#include "db/database.h"
+#include "db/mysql.h"
+#include "crypto/simpleOpensslSigner.h"
+#include "crypto/remoteSigner.h"
+#include "crypto/sslUtil.h"
+#include "io/bios.h"
+#include "io/slipBio.h"
+#include "io/recordHandler.h"
 #include "util.h"
-#include "bios.h"
-#include "slipBio.h"
-#include "remoteSigner.h"
-#include "sslUtil.h"
 #include "config.h"
-#include "recordHandler.h"
 
 #ifdef NO_DAEMON
 #define DAEMON false
@@ -19,7 +19,7 @@
 #define DAEMON true
 #endif
 
-int handlermain( int argc, const char* argv[] );
+extern std::string serialPath;
 
 int main( int argc, const char* argv[] ) {
     ( void ) argc;
@@ -27,16 +27,38 @@ int main( int argc, const char* argv[] ) {
 
     std::string path;
 
-    if( DAEMON ) {
-        path = "/etc/cacert/cassiopeia/cassiopeia.conf";
-    } else {
-        path = "config.txt";
+#ifdef NDEBUG
+    path = "/etc/cacert/cassiopeia/cassiopeia.conf";
+#else
+    path = "config.txt";
+#endif
+
+    if( parseConfig( path ) != 0 ) {
+        return -1;
     }
 
+    std::shared_ptr<int> ssl_lib = ssl_lib_ref;
 
-    if( parseConfig( path ) != 0 ) {
+    if( serialPath == "" ) {
+        std::cout << "Error: no serial device is given" << std::endl;
         return -1;
     }
 
-    return handlermain( argc, argv );
+    std::shared_ptr<BIO> conn = openSerial( serialPath );
+    std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
+    static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
+
+    DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
+
+    while( true ) {
+        try {
+            dh->handle();
+            //} catch( const std::exception &ch ) {
+            //std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
+        } catch( char const* ch ) {
+            std::cout << "Exception: " << ch << std::endl;
+        }
+    }
+
+    return -1;
 }