2 Cassiopeia - CAcert signing module
3 Copyright (C) 2014 CAcert Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "simpleOpensslSigner.h"
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";
38 file.open( filename.c_str() );
44 int main( int argc, const char* argv[] ) {
46 std::cout << argv[0] << " password" << std::endl;
50 std::shared_ptr<JobProvider> jp( new MySQLJobProvider( "localhost", "cacert", argv[1], "cacert" ) );
51 std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
52 std::shared_ptr<Job> job = jp->fetchJob();
55 std::cout << "Nothing to work on" << std::endl;
59 if( job->task == "sign" ) {
61 std::shared_ptr<TBSCertificate> cert = jp->fetchTBSCert( job );
64 std::cout << "wasn't able to load CSR" << std::endl;
68 std::cout << "Found a CSR at '" << cert->csr << "' signing" << std::endl;
69 std::ifstream t( cert->csr );
70 cert->csr_content = std::string( std::istreambuf_iterator<char>( t ), std::istreambuf_iterator<char>() );
72 std::shared_ptr<SignedCertificate> res = sign->sign( cert );
73 std::string fn = writeBackFile( res->serial, res->certificate );
75 jp->writeBack( job, res );
76 } catch( const char* c ) {
77 std::cerr << c << std::endl;
82 if( !jp->finishJob( job ) ) {