10 #include "simpleOpensslSigner.h"
14 #include "remoteSigner.h"
24 extern std::string keyDir;
25 extern std::vector<Profile> profiles;
26 extern std::string sqlHost, sqlUser, sqlPass, sqlDB;
28 std::string writeBackFile( uint32_t serial, std::string cert ) {
29 std::string filename = "keys";
30 mkdir( filename.c_str(), 0755 );
32 mkdir( filename.c_str(), 0755 );
33 filename += "/" + std::to_string( serial / 1000 );
34 mkdir( filename.c_str(), 0755 );
35 filename += "/" + std::to_string( serial ) + ".crt";
36 writeFile( filename, cert );
37 std::cout << "wrote to " << filename << std::endl;
41 int handlermain( int argc, const char* argv[] );
43 int main( int argc, const char* argv[] ) {
48 if( argc == 2 && std::string( "--once" ) == std::string( argv[1] ) ) {
55 path = "/etc/cacert/cassiopeia/cassiopeia.conf";
60 if( parseConfig( path ) != 0 ) {
65 return handlermain( argc, argv );
68 std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
69 std::shared_ptr<BIO> b = openSerial( "/dev/ttyUSB0" );
70 std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
71 ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
72 std::shared_ptr<RemoteSigner> sign( new RemoteSigner( slip1, generateSSLContext( false ) ) );
73 // std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
76 std::shared_ptr<Job> job = jp->fetchJob();
79 std::cout << "Nothing to work on" << std::endl;
84 if( job->task == "sign" ) {
86 std::shared_ptr<TBSCertificate> cert = jp->fetchTBSCert( job );
89 std::cout << "wasn't able to load CSR" << std::endl;
93 std::cout << "Found a CSR at '" << cert->csr << "' signing" << std::endl;
94 cert->csr_content = readFile( cert->csr );
95 std::cout << cert->csr_content << " content " << std::endl;
97 std::shared_ptr<SignedCertificate> res = sign->sign( cert );
98 std::cout << "did it!" << res->certificate << std::endl;
99 std::string fn = writeBackFile( atoi( job->target.c_str() ), res->certificate );
101 jp->writeBack( job, res );
102 std::cout << "wrote back" << std::endl;
103 } catch( const char* c ) {
104 std::cerr << "ERROR: " << c << std::endl;
106 } catch( std::string c ) {
107 std::cerr << "ERROR: " << c << std::endl;
111 std::cout << "Unknown job type" << job->task << std::endl;
114 if( DAEMON && !jp->finishJob( job ) ) {
118 if( !DAEMON || once ) {