#include <openssl/ssl.h>
+#include "util.h"
#include "io/record.h"
#include "io/opensslBIO.h"
#include "io/slipBio.h"
#include "db/database.h"
#include "crypto/remoteSigner.h"
#include "crypto/sslUtil.h"
-
#include "crypto/simpleOpensslSigner.h"
+#include "log/logger.hpp"
+
extern std::vector<Profile> profiles;
extern std::unordered_map<std::string, std::shared_ptr<CAConfig>> CAs;
RecordHandlerSession( DefaultRecordHandler* parent, std::shared_ptr<Signer> signer, std::shared_ptr<SSL_CTX> ctx, std::shared_ptr<BIO> output ) :
sessid( 0 ),
lastCommandCount( 0 ),
- tbs( new TBSCertificate() ){
+ tbs( new TBSCertificate() ) {
this->parent = parent;
this->signer = signer;
time_t c_time;
throw "Error while fetching time?";
}
- log = std::shared_ptr<std::ofstream>(
- new std::ofstream( std::string( "logs/log_" ) + std::to_string( c_time ) ),
- []( std::ofstream * ptr ) {
- ptr->close();
- delete ptr;
- } );
+ log = openLogfile( std::string( "logs/log_" ) + std::to_string( c_time ) );
ssl = std::shared_ptr<SSL>( SSL_new( ctx.get() ), SSL_free );
std::shared_ptr<BIO> bio(
int res = io->read( buffer.data(), buffer.capacity() );
if( res <= 0 ) {
- ( *log ) << "Stream error, resetting SSL" << std::endl;
+ logger::error( "Stream error, resetting SSL" );
parent->reset();
return;
}
execute( head, payload );
} catch( const char* msg ) {
if( log ) {
- ( *log ) << "ERROR: " << msg << std::endl;
+ logger::error( "ERROR: ", msg );
}
parent->reset();
case RecordHeader::SignerCommand::SET_CSR:
tbs->csr_content = data;
tbs->csr_type = "CSR";
- ( *log ) << "INFO: CSR read: " << tbs->csr_content << std::endl;
+ logger::note( "INFO: CSR read:\n", tbs->csr_content );
break;
case RecordHeader::SignerCommand::SET_SPKAC:
tbs->csr_content = data;
tbs->csr_type = "SPKAC";
- ( *log ) << "INFO: SPKAC read: " << tbs->csr_content << std::endl;
+ logger::note( "INFO: SPKAC read:\n", tbs->csr_content );
break;
case RecordHeader::SignerCommand::SET_SIGNATURE_TYPE:
case RecordHeader::SignerCommand::SIGN:
result = signer->sign( tbs );
- ( *log ) << "INFO: signlog: " << result->log << std::endl;
- ( *log ) << "INFO: res: " << result->certificate << std::endl;
+ logger::note( "INFO: signlog:\n", result->log );
+ logger::note( "INFO: res:\n", result->certificate );
respondCommand( RecordHeader::SignerResult::SAVE_LOG, result->log );
break;
}
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) {
- ( *log ) << "ERROR: SSL close failed" << std::endl;
+ logger::warn( "ERROR: SSL shutdown failed." );
}
+ parent->reset(); // Connection ended
+
break;
case RecordHeader::SignerCommand::ADD_SERIAL:
case RecordHeader::SignerCommand::REVOKE: {
std::string ca = data;
auto reqCA = CAs.at( ca );
- ( *log ) << "CA found" << std::endl;
+ logger::note( "CA found" );
std::shared_ptr<CRL> crl;
std::string date;
std::tie<std::shared_ptr<CRL>, std::string>( crl, date ) = signer->revoke( reqCA, serials );
respondCommand( RecordHeader::SignerResult::FULL_CRL, c.toString() );
if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) {
- ( *log ) << "ERROR: SSL close failed" << std::endl;
+ logger::error( "ERROR: SSL shutdown failed." );
}
+ parent->reset(); // Connection ended
break;
}
void DefaultRecordHandler::handle() {
if( !currentSession ) {
- std::cout << "session allocated" << std::endl;
+ logger::note( "New session allocated." );
currentSession = std::shared_ptr<RecordHandlerSession>( new RecordHandlerSession( this, signer, ctx, bio ) );
}