std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
std::shared_ptr<BIO> b = openSerial( serialPath );
std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
- ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
+ static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
std::shared_ptr<RemoteSigner> sign( new RemoteSigner( slip1, generateSSLContext( false ) ) );
// std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
continue;
} catch( const char* c ) {
log << "ERROR: " << c << std::endl;
- } catch( std::string c ) {
+ } catch( std::string& c ) {
log << "ERROR: " << c << std::endl;
}
jp->failJob( job );
} catch( const char* c ) {
log << "ERROR: " << c << std::endl;
- } catch( std::string c ) {
+ } catch( std::string& c ) {
log << "ERROR: " << c << std::endl;
}
} else if( job->task == "revoke" ) {
std::shared_ptr<BIO> conn = openSerial( serialPath );
std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
- ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
+ static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
#include <openssl/bio.h>
#include <openssl/x509v3.h>
-X509Req::X509Req( X509_REQ* csr ) {
- req = std::shared_ptr<X509_REQ>( csr, X509_REQ_free );
+X509Req::X509Req( X509_REQ* csr ) : req( csr, X509_REQ_free ) {
EVP_PKEY* pkt = X509_REQ_get_pubkey( req.get() );
if( !pkt ) {
return X509_REQ_verify( req.get(), pk.get() );
}
-std::shared_ptr<EVP_PKEY> X509Req::getPkey() {
+std::shared_ptr<EVP_PKEY> X509Req::getPkey() const {
return pk;
}
static std::shared_ptr<X509Req> parseCSR( std::string content );
static std::shared_ptr<X509Req> parseSPKAC( std::string content );
int verify();
- std::shared_ptr<EVP_PKEY> getPkey();
+ std::shared_ptr<EVP_PKEY> getPkey() const;
};
class X509Cert {
#include <openssl/ssl.h>
#include <openssl/bn.h>
-RemoteSigner::RemoteSigner( std::shared_ptr<BIO> target, std::shared_ptr<SSL_CTX> ctx ) {
- this->target = target;
- this->ctx = ctx;
+RemoteSigner::RemoteSigner( std::shared_ptr<BIO> target, std::shared_ptr<SSL_CTX> ctx ) : target( target ), ctx( ctx ) {
}
RemoteSigner::~RemoteSigner() {
CRYPTO_cleanup_all_ex_data();
} );
-std::shared_ptr<X509> loadX509FromFile( std::string filename ) {
+std::shared_ptr<X509> loadX509FromFile( const std::string& filename ) {
FILE* f = fopen( filename.c_str(), "r" );
if( !f ) {
} );
}
-std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename ) {
+std::shared_ptr<EVP_PKEY> loadPkeyFromFile( const std::string& filename ) {
FILE* f = fopen( filename.c_str(), "r" );
if( !f ) {
}
}
-std::shared_ptr<BIO> openSerial( const std::string name ) {
+std::shared_ptr<BIO> openSerial( const std::string& name ) {
FILE* f = fopen( name.c_str(), "r+" );
if( !f ) {
return b;
}
-CAConfig::CAConfig( std::string name ) {
- this->name = name;
- this->path = "ca/" + name;
+CAConfig::CAConfig( const std::string& name ) : path( "ca/" + name ), name( name ) {
ca = loadX509FromFile( path + "/ca.crt" );
caKey = loadPkeyFromFile( path + "/ca.key" );
ASN1_TIME* tm = X509_get_notBefore( ca );
std::shared_ptr<X509> ca;
std::shared_ptr<EVP_PKEY> caKey;
std::shared_ptr<ASN1_TIME> notBefore;
- CAConfig( std::string name );
+ CAConfig( const std::string& name );
bool crlNeedsResign();
};
extern std::shared_ptr<int> ssl_lib_ref;
-std::shared_ptr<X509> loadX509FromFile( std::string filename );
-std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename );
+std::shared_ptr<X509> loadX509FromFile( const std::string& filename );
+std::shared_ptr<EVP_PKEY> loadPkeyFromFile( const std::string& filename );
std::shared_ptr<SSL_CTX> generateSSLContext( bool server );
-std::shared_ptr<BIO> openSerial( const std::string name );
+std::shared_ptr<BIO> openSerial( const std::string& name );
std::string timeToString( std::shared_ptr<ASN1_TIME> time );
void extractTimes( std::shared_ptr<X509> source, std::shared_ptr<SignedCertificate> cert );
namespace BIOWrapper {
int write( BIO* b, const char* buf, int num ) {
- return ( ( OpensslBIO* )b->ptr )->write( buf, num );
+ return static_cast<OpensslBIO*>( b->ptr )->write( buf, num );
}
int read( BIO* b, char* buf, int size ) {
- return ( ( OpensslBIO* )b->ptr )->read( buf, size );
+ return static_cast<OpensslBIO*>( b->ptr )->read( buf, size );
}
int puts( BIO* b, const char* str ) {
- return ( ( OpensslBIO* )b->ptr )->puts( str );
+ return static_cast<OpensslBIO*>( b->ptr )->puts( str );
}
int gets( BIO* b, char* str, int size ) {
- return ( ( OpensslBIO* )b->ptr )->gets( str, size );
+ return static_cast<OpensslBIO*>( b->ptr )->gets( str, size );
}
long ctrl( BIO* b, int cmod, long arg1, void* arg2 ) {
- return ( ( OpensslBIO* )b->ptr )->ctrl( cmod, arg1, arg2 );
+ return static_cast<OpensslBIO*>( b->ptr )->ctrl( cmod, arg1, arg2 );
}
int free( BIO* b ) {
- delete( ( OpensslBIO* ) b->ptr );
+ delete static_cast<OpensslBIO*>( b->ptr );
b->ptr = 0;
return 0;
}
#include "opensslBIO.h"
-OpensslBIOWrapper::OpensslBIOWrapper( std::shared_ptr<BIO> b ) {
- this->b = b;
+OpensslBIOWrapper::OpensslBIOWrapper( std::shared_ptr<BIO> b ) : b( b ) {
}
OpensslBIOWrapper::~OpensslBIOWrapper() {
return res;
}
-std::string parseCommand( RecordHeader& head, const std::string input, std::shared_ptr<std::ostream> log ) {
+std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log ) {
if( log ) {
( *log.get() ) << "FINE: RECORD input: " << input << std::endl;
}
}
template <class T>
- void append( std::string& str, T val ) {
+ static void append( std::string& str, T val ) {
str.append( ( char* ) &val, sizeof( T ) );
}
template <class T>
- void read( std::string::iterator& it, T& val ) {
+ static void read( std::string::iterator& it, T& val ) {
char* data = ( char* ) &val;
for( size_t i = 0; i < sizeof( T ); i++ ) {
};
-std::string parseCommand( RecordHeader& head, const std::string input, std::shared_ptr<std::ostream> log );
+std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log );
void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio, std::shared_ptr<std::ostream> log );
}
};
-DefaultRecordHandler::DefaultRecordHandler( std::shared_ptr<Signer> signer, std::shared_ptr<BIO> bio ) :
- currentSession() {
-
- this->signer = signer;
-
- ctx = generateSSLContext( true );
-
- this->bio = bio;
+DefaultRecordHandler::DefaultRecordHandler( std::shared_ptr<Signer> signer, std::shared_ptr<BIO> bio )
+ : bio( bio ), ctx( generateSSLContext( true ) ), signer( signer ), currentSession() {
}
void DefaultRecordHandler::reset() {
return data;
}
-SlipBIO::SlipBIO() {
- this->buffer = std::vector<char>( BUFFER_SIZE );
- this->decodeTarget = 0;
- this->decodePos = 0;
- this->rawPos = 0;
- this->failed = false;
+SlipBIO::SlipBIO() : buffer( std::vector<char>( BUFFER_SIZE ) ), decodeTarget( 0 ), decodePos( 0 ), rawPos( 0 ), failed( false ) {
}
void SlipBIO::setTarget( std::shared_ptr<OpensslBIO> target ) {
this->target = target;
}
-SlipBIO::SlipBIO( std::shared_ptr<OpensslBIO> target ) {
- this->target = target;
-
- this->buffer = std::vector<char>( BUFFER_SIZE );
- this->decodeTarget = 0;
- this->decodePos = 0;
- this->rawPos = 0;
-
- this->failed = false;
+SlipBIO::SlipBIO( std::shared_ptr<OpensslBIO> target ) : target( target ), buffer( std::vector<char>( BUFFER_SIZE ) ), decodeTarget( 0 ), decodePos( 0 ), rawPos( 0 ), failed( false ) {
}
SlipBIO::~SlipBIO() {}