]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
chg: rename package name and all references to it
[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 "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/wpia/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::exception& e ) {
63             logger::error( "Exception: ", e.what() );
64         }
65     }
66
67     return -1;
68
69 } catch( std::exception& e ) {
70     try {
71         logger::fatalf( "Fatal Error: %s!\n", e.what() );
72     }catch( std::exception &e){
73         printf( "Fatal Error (+logger failed): %s!\n", e.what() );
74     }
75     return -1;
76 } catch( ... ) {
77     try{
78         logger::fatal( "Fatal Error: Unknown Exception!\n" );
79     }catch( std::exception &e){
80         printf( "Fatal Error (+ logger failed): %s!\n", e.what() );
81     }
82     return -1;
83 }