]> WPIA git - cassiopeia.git/blob - src/apps/signer.cpp
1e1a5894fc59e6da66384ab1c714c7a3196100dd
[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     if( DAEMON ) {
34         path = "/etc/cacert/cassiopeia/cassiopeia.conf";
35     } else {
36         path = "config.txt";
37     }
38
39
40     if( parseConfig( path ) != 0 ) {
41         return -1;
42     }
43
44     std::shared_ptr<int> ssl_lib = ssl_lib_ref;
45
46     if( serialPath == "" ) {
47         std::cout << "Error: no serial device is given" << std::endl;
48         return -1;
49     }
50
51     std::shared_ptr<BIO> conn = openSerial( serialPath );
52     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
53     ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
54
55     try {
56         DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( profiles[5] ) ), slip1 );
57
58         while( true ) {
59             dh->handle();
60         }
61     } catch( char const* ch ) {
62         std::cout << "Exception: " << ch << std::endl;
63     }
64
65     return -1;
66 }