]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
change to postgres with libpqxx
[cassiopeia.git] / src / apps / signer.cpp
1 #include <iostream>
2 #include <fstream>
3 #include <streambuf>
4 #include <stdexcept>
5
6 #include "db/database.h"
7 #include "db/mysql.h"
8 #include "crypto/simpleOpensslSigner.h"
9 #include "crypto/remoteSigner.h"
10 #include "crypto/sslUtil.h"
11 #include "io/bios.h"
12 #include "io/slipBio.h"
13 #include "io/recordHandler.h"
14 #include "log/logger.hpp"
15 #include "util.h"
16 #include "config.h"
17
18 #ifdef NO_DAEMON
19 #define DAEMON false
20 #else
21 #define DAEMON true
22 #endif
23
24 extern std::string serialPath;
25
26 int main( int argc, const char* argv[] ) try {
27     ( void ) argc;
28     ( void ) argv;
29
30     std::string path;
31
32 #ifdef NDEBUG
33     path = "/etc/cacert/cassiopeia/cassiopeia.conf";
34 #else
35     path = "config.txt";
36 #endif
37
38     if( parseConfig( path ) != 0 ) {
39         logger::fatal( "Could not parse configuration file." );
40         return -1;
41     }
42
43     std::shared_ptr<int> ssl_lib = ssl_lib_ref;
44
45     if( serialPath == "" ) {
46         logger::fatal( "Error: No device for the serial connection was given." );
47         return -1;
48     }
49
50     std::shared_ptr<BIO> conn = openSerial( serialPath );
51     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
52     static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ), true );
53
54     DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
55
56     logger::note( "Entering mainloop" );
57     while( true ) {
58         try {
59             dh->handle();
60             //} catch( const std::exception &ch ) {
61             //std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
62         } catch( const std::string& ch ) {
63             logger::error( "Exception: ", ch );
64         } catch( char const* ch ) {
65             logger::error( "Exception: ", ch );
66         }
67     }
68
69     return -1;
70
71 } catch( std::exception& e ) {
72     logger::fatalf( "Fatal Error: %s!\n", e.what() );
73     return -1;
74 } catch( ... ) {
75     logger::fatal( "Fatal Error: Unknown Exception!\n" );
76     return -1;
77 }