]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
fix: add catch-all block around main in signer
[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 "util.h"
15 #include "config.h"
16
17 #ifdef NO_DAEMON
18 #define DAEMON false
19 #else
20 #define DAEMON true
21 #endif
22
23 extern std::string serialPath;
24
25 int main( int argc, const char* argv[] ) try {
26     ( void ) argc;
27     ( void ) argv;
28
29     std::string path;
30
31 #ifdef NDEBUG
32     path = "/etc/cacert/cassiopeia/cassiopeia.conf";
33 #else
34     path = "config.txt";
35 #endif
36
37     if( parseConfig( path ) != 0 ) {
38         return -1;
39     }
40
41     std::shared_ptr<int> ssl_lib = ssl_lib_ref;
42
43     if( serialPath == "" ) {
44         std::cout << "Error: no serial device is given" << std::endl;
45         return -1;
46     }
47
48     std::shared_ptr<BIO> conn = openSerial( serialPath );
49     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
50     static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
51
52     DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
53
54     while( true ) {
55         try {
56             dh->handle();
57             //} catch( const std::exception &ch ) {
58             //std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
59         } catch( const std::string& ch ) {
60             std::cout << "Exception: " << ch << std::endl;
61         } catch( char const* ch ) {
62             std::cout << "Exception: " << ch << std::endl;
63         }
64     }
65
66     return -1;
67
68 } catch(std::exception& e) {
69     std::cerr << "Fatal Error: " << e.what() << "!\n";
70     return -1;
71 } catch(...) {
72     std::cerr << "Fatal Error: Unknown Exception!\n";
73     return -1;
74 }