]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
fix: clean SSL shutdown, reset, allowing deamon operation
[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 int handlermain( int argc, const char* argv[] );
23
24 extern std::string serialPath;
25 extern std::vector<Profile> profiles;
26
27 int main( int argc, const char* argv[] ) {
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         return -1;
41     }
42
43     std::shared_ptr<int> ssl_lib = ssl_lib_ref;
44
45     if( serialPath == "" ) {
46         std::cout << "Error: no serial device is given" << std::endl;
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     ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
53
54     try {
55         DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( profiles[5] ) ), slip1 );
56
57         while( true ) {
58             dh->handle();
59         }
60     } catch( char const* ch ) {
61         std::cout << "Exception: " << ch << std::endl;
62     }
63
64     return -1;
65 }