]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
0d027c0a8070a44823aec9f70adf3399fed96211
[cassiopeia.git] / src / apps / signer.cpp
1 #include <iostream>
2 #include <fstream>
3 #include <streambuf>
4
5 #include "db/database.h"
6 #include "db/mysql.h"
7 #include "crypto/simpleOpensslSigner.h"
8 #include "crypto/remoteSigner.h"
9 #include "crypto/sslUtil.h"
10 #include "io/bios.h"
11 #include "io/slipBio.h"
12 #include "io/recordHandler.h"
13 #include "util.h"
14 #include "config.h"
15
16 #ifdef NO_DAEMON
17 #define DAEMON false
18 #else
19 #define DAEMON true
20 #endif
21
22 extern std::string serialPath;
23
24 int main( int argc, const char* argv[] ) {
25     ( void ) argc;
26     ( void ) argv;
27
28     std::string path;
29
30 #ifdef NDEBUG
31     path = "/etc/cacert/cassiopeia/cassiopeia.conf";
32 #else
33     path = "config.txt";
34 #endif
35
36     if( parseConfig( path ) != 0 ) {
37         return -1;
38     }
39
40     std::shared_ptr<int> ssl_lib = ssl_lib_ref;
41
42     if( serialPath == "" ) {
43         std::cout << "Error: no serial device is given" << std::endl;
44         return -1;
45     }
46
47     std::shared_ptr<BIO> conn = openSerial( serialPath );
48     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
49     static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
50
51     DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
52
53     while( true ) {
54         try {
55             dh->handle();
56             //} catch( const std::exception &ch ) {
57             //std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
58         } catch( const std::string& ch ) {
59             std::cout << "Exception: " << ch << std::endl;
60         } catch( char const* ch ) {
61             std::cout << "Exception: " << ch << std::endl;
62         }
63     }
64
65     return -1;
66 }