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 int main( int argc, const char* argv[] ) {
34 if( argc == 2 && std::string( "--once" ) == std::string( argv[1] ) ) {
41 path = "/etc/cacert/cassiopeia/cassiopeia.conf";
46 if( parseConfig( path ) != 0 ) {
50 if( serialPath == "" ) {
51 std::cout << "Error: no serial device is given" << std::endl;
55 std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
56 std::shared_ptr<BIO> b = openSerial( serialPath );
57 std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
58 ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
59 std::shared_ptr<RemoteSigner> sign( new RemoteSigner( slip1, generateSSLContext( false ) ) );
60 // std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
63 std::shared_ptr<Job> job = jp->fetchJob();
66 std::cout << "Nothing to work on" << std::endl;
71 std::ofstream* logP = new std::ofstream( std::string( "logs/" ) + job->id + std::string( "_" ) + job->warning + std::string( ".log" ) );
72 std::shared_ptr<std::ofstream> logPtr(
74 []( std::ofstream * ptr ) {
78 std::ofstream& log = *logP;
80 sign->setLog( logPtr );
81 log << "TASK ID: " << job->id << std::endl;
82 log << "TRY: " << job->warning << std::endl;
83 log << "TARGET: " << job->target << std::endl;
84 log << "TASK: " << job->task << std::endl << std::endl;
86 if( job->task == "sign" ) {
88 std::shared_ptr<TBSCertificate> cert = jp->fetchTBSCert( job );
89 log << "INFO: message digest: " << cert->md << std::endl;
90 log << "INFO: profile id: " << cert->profile << std::endl;
92 for( auto& SAN : cert->SANs ) {
93 log << "INFO: SAN " << SAN->type << ": " << SAN->content;
96 for( auto& AVA : cert->AVAs ) {
97 log << "INFO: AVA " << AVA->name << ": " << AVA->value;
101 std::cout << "wasn't able to load CSR" << std::endl;
106 log << "FINE: Found the CSR at '" << cert->csr << "'" << std::endl;
107 cert->csr_content = readFile( keyDir + "/../" + cert->csr );
108 log << "FINE: CSR is " << std::endl << cert->csr_content << std::endl;
110 std::shared_ptr<SignedCertificate> res = sign->sign( cert );
113 log << "ERROR: The signer failed. There was no certificate." << std::endl;
118 log << "FINE: CERTIFICATE LOG: " << res->log << std::endl;
119 log << "FINE: CERTIFICATE:" << std::endl << res->certificate << std::endl;
120 std::string fn = writeBackFile( job->target.c_str(), res->certificate, keyDir );
122 jp->writeBack( job, res );
123 log << "FINE: signing done." << std::endl;
126 jp->finishJob( job );
130 } catch( const char* c ) {
131 log << "ERROR: " << c << std::endl;
132 } catch( std::string c ) {
133 log << "ERROR: " << c << std::endl;
138 } catch( const char* c ) {
139 log << "ERROR: " << c << std::endl;
140 } catch( std::string c ) {
141 log << "ERROR: " << c << std::endl;
144 log << "Unknown job type" << job->task << std::endl;
147 if( !DAEMON || once ) {