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