]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
add: Add more verbose logging
[cassiopeia.git] / src / apps / signer.cpp
1 #include <iostream>
2 #include <fstream>
3 #include <streambuf>
4
5 #include "database.h"
6 #include "mysql.h"
7 #include "simpleOpensslSigner.h"
8 #include "util.h"
9 #include "bios.h"
10 #include "slipBio.h"
11 #include "remoteSigner.h"
12 #include "sslUtil.h"
13 #include "config.h"
14 #include "recordHandler.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 extern std::vector<Profile> profiles;
24
25 int main( int argc, const char* argv[] ) {
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     ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
51
52     try {
53         DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( profiles[5] ) ), slip1 );
54
55         while( true ) {
56             dh->handle();
57         }
58     } catch( char const* ch ) {
59         std::cout << "Exception: " << ch << std::endl;
60     }
61
62     return -1;
63 }