X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fcrypto%2FremoteSigner.cpp;h=c52936b8bc2afe26e78f0341a0fbfd2ce7276819;hb=dc63575cbbef92d3ee7f0f6c22dae7e42f579651;hp=4b1e630ad21e511a1229bce1b78b61c3c8b918a2;hpb=f8d1606423c351f2003ce18258ef047e0d2af326;p=cassiopeia.git diff --git a/src/crypto/remoteSigner.cpp b/src/crypto/remoteSigner.cpp index 4b1e630..c52936b 100644 --- a/src/crypto/remoteSigner.cpp +++ b/src/crypto/remoteSigner.cpp @@ -75,7 +75,7 @@ std::shared_ptr RemoteSigner::sign( std::shared_ptr( head.command )) { + switch( static_cast( head.command ) ) { case RecordHeader::SignerResult::CERTIFICATE: result->certificate = payload; break; @@ -92,8 +92,8 @@ std::shared_ptr RemoteSigner::sign( std::shared_ptr(); } } @@ -107,20 +107,20 @@ std::shared_ptr RemoteSigner::sign( std::shared_ptr pem( PEM_read_bio_X509( bios.get(), NULL, 0, NULL ) ); + std::shared_ptr pem( PEM_read_bio_X509( bios.get(), NULL, 0, NULL ), X509_free ); if( !pem ) { - throw "Pem was not readable"; + throw std::runtime_error( "Pem was not readable" ); } - std::shared_ptr ser( ASN1_INTEGER_to_BN( pem->cert_info->serialNumber, NULL ), BN_free ); + std::shared_ptr ser( ASN1_INTEGER_to_BN( X509_get_serialNumber( pem.get() ), NULL ), BN_free ); std::shared_ptr serStr( BN_bn2hex( ser.get() ), []( char* p ) { @@ -133,9 +133,11 @@ std::shared_ptr RemoteSigner::sign( std::shared_ptr, std::string> RemoteSigner::revoke( std::shared_p std::string date; if( static_cast( head.command ) != RecordHeader::SignerResult::REVOKED ) { - throw "Protocol violation"; + throw std::runtime_error( "Protocol violation" ); } const unsigned char* buffer2 = reinterpret_cast( payload.data() ); @@ -196,7 +198,7 @@ std::pair, std::string> RemoteSigner::revoke( std::shared_p payload = parseCommandChunked( head, conn ); if( static_cast( head.command ) != RecordHeader::SignerResult::FULL_CRL ) { - throw "Protocol violation"; + throw std::runtime_error( "Protocol violation" ); } std::string name_bak = ca->path + std::string( "/ca.crl.bak" ); @@ -204,10 +206,10 @@ std::pair, std::string> RemoteSigner::revoke( std::shared_p crl = std::make_shared( name_bak ); if( crl->verify( ca ) ) { - writeFile( tgtName, crl->toString() ); - if( remove( name_bak.c_str() ) != 0 ){ - logger::warn( "Removing old CRL failed" ); + if( rename( name_bak.c_str(), tgtName.c_str() ) != 0 ) { + logger::warn( "Moving new CRL over old CRL failed" ); } + logger::note( "CRL is now valid again" ); } else { logger::warn( "CRL is still broken... Please, help me" ); @@ -215,9 +217,11 @@ std::pair, std::string> RemoteSigner::revoke( std::shared_p } logger::note( "Closing SSL connection" ); + if( !SSL_shutdown( ssl.get() ) && !SSL_shutdown( ssl.get() ) ) { // need to close the connection twice logger::warn( "SSL shutdown failed" ); } + logger::note( "SSL connection closed" ); return { crl, date };