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;
27 extern std::string serialPath;
29 std::string writeBackFile( uint32_t serial, std::string cert ) {
30 std::string filename = "keys";
31 mkdir( filename.c_str(), 0755 );
33 mkdir( filename.c_str(), 0755 );
34 filename += "/" + std::to_string( serial / 1000 );
35 mkdir( filename.c_str(), 0755 );
36 filename += "/" + std::to_string( serial ) + ".crt";
37 writeFile( filename, cert );
38 std::cout << "wrote to " << filename << std::endl;
42 int main( int argc, const char* argv[] ) {
47 if( argc == 2 && std::string( "--once" ) == std::string( argv[1] ) ) {
54 path = "/etc/cacert/cassiopeia/cassiopeia.conf";
59 if( parseConfig( path ) != 0 ) {
63 if( serialPath == "" ) {
64 std::cout << "Error: no serial device is given" << std::endl;
68 std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
69 std::shared_ptr<BIO> b = openSerial( serialPath );
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 );
100 std::cout << "Error no cert came back." << std::endl;
104 std::cout << "did it!" << res->certificate << std::endl;
105 std::string fn = writeBackFile( atoi( job->target.c_str() ), res->certificate );
107 jp->writeBack( job, res );
108 std::cout << "wrote back" << std::endl;
109 } catch( const char* c ) {
110 std::cerr << "ERROR: " << c << std::endl;
112 } catch( std::string c ) {
113 std::cerr << "ERROR: " << c << std::endl;
117 std::cout << "Unknown job type" << job->task << std::endl;
120 if( DAEMON && !jp->finishJob( job ) ) {
124 if( !DAEMON || once ) {