From e8f8107bdd0d1149117f06e10b145ef00d5543fb Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 21 Mar 2015 17:16:41 +0100 Subject: [PATCH] fmt: Whitespace --- src/apps/client.cpp | 1 + src/crypto/X509.cpp | 3 +++ src/crypto/simpleOpensslSigner.cpp | 1 + src/crypto/sslUtil.cpp | 1 + src/io/record.h | 4 +-- src/io/recordHandler.cpp | 2 +- src/util.cpp | 4 +++ test/src/sql.cpp | 40 ++++++++++++++++-------------- 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/apps/client.cpp b/src/apps/client.cpp index e30803e..3d4c339 100644 --- a/src/apps/client.cpp +++ b/src/apps/client.cpp @@ -159,6 +159,7 @@ int main( int argc, const char* argv[] ) { log << "FINE: CERTIFICATE LOG: " << res->log << std::endl; log << "FINE: CERTIFICATE:" << std::endl << res->certificate << std::endl; std::string fn = writeBackFile( job->target.c_str(), res->certificate, keyDir ); + if( fn.empty() ) { log << "ERROR: Writeback of the certificate failed." << std::endl; jp->failJob( job ); diff --git a/src/crypto/X509.cpp b/src/crypto/X509.cpp index a068957..a617ac3 100644 --- a/src/crypto/X509.cpp +++ b/src/crypto/X509.cpp @@ -247,9 +247,11 @@ std::shared_ptr X509Cert::sign( std::shared_ptr caK //X509_print_fp( stdout, target.get() ); std::shared_ptr mem = std::shared_ptr( BIO_new( BIO_s_mem() ), BIO_free ); + if( !mem ) { throw "Failed to allocate memory for the signed certificate."; } + PEM_write_bio_X509( mem.get(), target.get() ); BUF_MEM* buf = NULL; @@ -259,6 +261,7 @@ std::shared_ptr X509Cert::sign( std::shared_ptr caK res->certificate = std::string( buf->data, buf->data + buf->length ); std::shared_ptr ser( ASN1_INTEGER_to_BN( target->cert_info->serialNumber, NULL ), BN_free ); + if( !ser ) { throw "Failed to retrieve certificate serial of signed certificate."; } diff --git a/src/crypto/simpleOpensslSigner.cpp b/src/crypto/simpleOpensslSigner.cpp index f7042a2..b6005b7 100644 --- a/src/crypto/simpleOpensslSigner.cpp +++ b/src/crypto/simpleOpensslSigner.cpp @@ -191,6 +191,7 @@ std::shared_ptr SimpleOpensslSigner::sign( std::shared_ptr output = c.sign( ca->caKey, cert->md ); signlog << "FINE: all went well" << std::endl; std::string fn = writeBackFile( num, output->certificate, ca->path ); + if( fn.empty() ) { signlog << "ERROR: failed to get filename for storage of signed certificate." << std::endl; throw "Storage location could not be determined"; diff --git a/src/crypto/sslUtil.cpp b/src/crypto/sslUtil.cpp index cc80916..d0df60c 100644 --- a/src/crypto/sslUtil.cpp +++ b/src/crypto/sslUtil.cpp @@ -96,6 +96,7 @@ std::shared_ptr generateSSLContext( bool server ) { SSL_CTX_set_verify( ctx.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback ); SSL_CTX_use_certificate_file( ctx.get(), server ? "keys/signer_server.crt" : "keys/signer_client.crt", SSL_FILETYPE_PEM ); SSL_CTX_use_PrivateKey_file( ctx.get(), server ? "keys/signer_server.key" : "keys/signer_client.key", SSL_FILETYPE_PEM ); + if( 1 != SSL_CTX_load_verify_locations( ctx.get(), "keys/ca.crt", 0 ) ) { throw "Cannot load CA store for certificate validation."; } diff --git a/src/io/record.h b/src/io/record.h index 8857665..0a13681 100644 --- a/src/io/record.h +++ b/src/io/record.h @@ -59,10 +59,10 @@ public: template static void read( std::string::const_iterator& it, T& val ) { union typeConversion { - char buf[sizeof(T)]; + char buf[sizeof( T )]; T value; - typeConversion(const T& v) : value(v) {} + typeConversion( const T& v ) : value( v ) {} }; typeConversion data( 0 ); diff --git a/src/io/recordHandler.cpp b/src/io/recordHandler.cpp index 6727128..35ad808 100644 --- a/src/io/recordHandler.cpp +++ b/src/io/recordHandler.cpp @@ -40,7 +40,7 @@ public: RecordHandlerSession( DefaultRecordHandler* parent, std::shared_ptr signer, std::shared_ptr ctx, std::shared_ptr output ) : sessid( 0 ), lastCommandCount( 0 ), - tbs( new TBSCertificate() ){ + tbs( new TBSCertificate() ) { this->parent = parent; this->signer = signer; time_t c_time; diff --git a/src/util.cpp b/src/util.cpp index ed7b42e..dc03e9d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -30,6 +30,7 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c errno = 0; std::string filename = keydir; + if( 0 != mkdir( filename.c_str(), 0755 ) ) { if( EEXIST != errno ) { return ""; @@ -39,6 +40,7 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c } filename += "/crt"; + if( 0 != mkdir( filename.c_str(), 0755 ) ) { if( EEXIST != errno ) { return ""; @@ -46,6 +48,7 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c //! \FIXME: Check this is a directory } + std::string first; if( serial.length() < 3 ) { @@ -55,6 +58,7 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c } filename += "/" + first; + if( 0 != mkdir( filename.c_str(), 0755 ) ) { if( EEXIST != errno ) { return ""; diff --git a/test/src/sql.cpp b/test/src/sql.cpp index 8f5107e..cf85629 100644 --- a/test/src/sql.cpp +++ b/test/src/sql.cpp @@ -10,12 +10,14 @@ extern std::string sqlHost, sqlUser, sqlPass, sqlDB; BOOST_AUTO_TEST_SUITE( TestSQL ) BOOST_AUTO_TEST_CASE( testSQL ) { - std::ifstream conf("config.txt"); + std::ifstream conf( "config.txt" ); + if( !conf ) { BOOST_WARN_MESSAGE( 0, "Config file is missing. Exiting." ); - return; + return; } - BOOST_REQUIRE( parseConfig("config.txt") == 0 ); + + BOOST_REQUIRE( parseConfig( "config.txt" ) == 0 ); std::shared_ptr jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) ); BOOST_REQUIRE( jp->query( "TRUNCATE TABLE profiles" ).first == 0 ); BOOST_REQUIRE( jp->query( "TRUNCATE TABLE certs" ).first == 0 ); @@ -27,24 +29,24 @@ BOOST_AUTO_TEST_CASE( testSQL ) { std::shared_ptr job = jp->fetchJob(); BOOST_REQUIRE( job ); - jp->failJob(job); + jp->failJob( job ); BOOST_REQUIRE_EQUAL( job->target, "1" ); BOOST_REQUIRE_EQUAL( job->task, "sign" ); job = jp->fetchJob(); BOOST_REQUIRE( job ); - std::shared_ptr cert = jp->fetchTBSCert(job); + std::shared_ptr cert = jp->fetchTBSCert( job ); BOOST_REQUIRE( !cert ); BOOST_REQUIRE( jp->query( "INSERT INTO certs SET csr_type='CSR', id='1', profile='1'" ).first == 0 ); BOOST_REQUIRE( jp->query( "INSERT INTO subjectAlternativeNames SET certId='1', contents='example.org', type='DNS'" ).first == 0 ); BOOST_REQUIRE( jp->query( "INSERT INTO certAvas SET certid='1', name='CN', value='example.org'" ).first == 0 ); - cert = jp->fetchTBSCert(job); + cert = jp->fetchTBSCert( job ); BOOST_REQUIRE( cert ); std::shared_ptr fcert( new SignedCertificate() ); - fcert->certificate="CERT"; - fcert->serial="1234"; - fcert->crt_name="crt.name.crt"; - fcert->ca_name="assured"; + fcert->certificate = "CERT"; + fcert->serial = "1234"; + fcert->crt_name = "crt.name.crt"; + fcert->ca_name = "assured"; jp->writeBack( job, fcert ); jp->finishJob( job ); BOOST_REQUIRE( !jp->fetchJob() ); @@ -53,27 +55,29 @@ BOOST_AUTO_TEST_CASE( testSQL ) { BOOST_REQUIRE_EQUAL( job->target, "1" ); BOOST_REQUIRE_EQUAL( job->task, "revoke" ); std::pair revocationInfo = jp->getRevocationInfo( job ); - BOOST_REQUIRE_EQUAL( revocationInfo.first, "1234"); - BOOST_REQUIRE_EQUAL( revocationInfo.second, "assured"); + BOOST_REQUIRE_EQUAL( revocationInfo.first, "1234" ); + BOOST_REQUIRE_EQUAL( revocationInfo.second, "assured" ); jp->writeBackRevocation( job, "2000-01-01 01:01:01" ); jp->finishJob( job ); } BOOST_AUTO_TEST_CASE( testSQLDisconnected ) { - std::ifstream conf("config.txt"); + std::ifstream conf( "config.txt" ); + if( !conf ) { BOOST_WARN_MESSAGE( 0, "Config file is missing. Exiting." ); - return; + return; } + //if(1) return; //BOOST_REQUIRE( parseConfig("config.txt") == 0 ); std::shared_ptr jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) ); jp->disconnect(); jp->disconnect(); - BOOST_REQUIRE( jp->query("SELECT 1").first); - BOOST_REQUIRE_THROW( jp->escape_string("uia"), const char * ); - BOOST_REQUIRE_THROW( jp->finishJob(std::shared_ptr()), const char * ); - BOOST_REQUIRE_THROW( jp->failJob(std::shared_ptr()), const char * ); + BOOST_REQUIRE( jp->query( "SELECT 1" ).first ); + BOOST_REQUIRE_THROW( jp->escape_string( "uia" ), const char* ); + BOOST_REQUIRE_THROW( jp->finishJob( std::shared_ptr() ), const char* ); + BOOST_REQUIRE_THROW( jp->failJob( std::shared_ptr() ), const char* ); } BOOST_AUTO_TEST_SUITE_END() -- 2.39.2