]> WPIA git - cassiopeia.git/commitdiff
upd: only throwing exceptions now
authorFelix Dörre <felix@dogcraft.de>
Tue, 26 Jan 2016 22:58:56 +0000 (23:58 +0100)
committerFelix Dörre <felix@dogcraft.de>
Tue, 26 Jan 2016 22:58:56 +0000 (23:58 +0100)
17 files changed:
src/apps/client.cpp
src/apps/signer.cpp
src/config.cpp
src/crypto/CRL.cpp
src/crypto/X509.cpp
src/crypto/remoteSigner.cpp
src/crypto/simpleOpensslSigner.cpp
src/crypto/sslUtil.cpp
src/db/mysql.cpp
src/db/psql.cpp
src/io/opensslBIO.cpp
src/io/opensslBIO.h
src/io/record.cpp
src/io/record.h
src/io/recordHandler.cpp
src/io/slipBio.cpp
src/util.cpp

index 9dea0a88b5f06ebf438377f86003f454db54f904..bfb7fb1688148e104ccfaaea1cb69fd9472f155f 100644 (file)
@@ -45,8 +45,8 @@ void checkCRLs( std::shared_ptr<Signer> sign ) {
         try {
             std::vector<std::string> serials;
             std::pair<std::shared_ptr<CRL>, std::string> rev = sign->revoke( x.second, serials );
-        } catch( const char* c ) {
-            logger::error( "Exception: ", c );
+        } catch( const std::exception &e ) {
+            logger::error( "Exception: ", e.what() );
         }
     }
 }
@@ -185,18 +185,14 @@ int main( int argc, const char* argv[] ) {
                     }
 
                     continue;
-                } catch( const char* c ) {
-                    logger::error( "ERROR: ", c );
-                } catch( std::string& c ) {
-                    logger::error( "ERROR: ", c );
+                } catch( std::exception& c ) {
+                    logger::error( "ERROR: ", c.what() );
                 }
 
                 try {
                     jp->failJob( job );
-                } catch( const char* c ) {
-                    logger::error( "ERROR: ", c );
-                } catch( std::string& c ) {
-                    logger::error( "ERROR: ", c );
+                } catch( std::exception& c ) {
+                    logger::error( "ERROR: ", c.what() );
                 }
             } else if( job->task == "revoke" ) {
                 try {
@@ -212,10 +208,8 @@ int main( int argc, const char* argv[] ) {
 
                     jp->writeBackRevocation( job, timeToString( time ) );
                     jp->finishJob( job );
-                } catch( const char* c ) {
-                    logger::error( "Exception: ", c );
-                } catch( const std::string& c ) {
-                    logger::error( "Exception: ", c );
+                } catch( const std::exception& c ) {
+                    logger::error( "Exception: ", c.what() );
                 }
             } else {
                 logger::errorf( "Unknown job type (\"%s\")", job->task );
@@ -225,10 +219,6 @@ int main( int argc, const char* argv[] ) {
             if( !DAEMON || once ) {
                 return 0;
             }
-       } catch( const char* c ) {
-            logger::error( "Exception: ", c );
-        } catch( const std::string& c ) {
-            logger::error( "Exception: ", c );
         } catch ( std::exception &e ){
             logger::errorf ( "std::exception in mainloop: %s", e.what() );
         }
index 2b6798c935aa2f15893c5c059ed5135d640797e3..530c76ced00862f7c6264446ffae229e4d836e4c 100644 (file)
@@ -59,10 +59,8 @@ int main( int argc, const char* argv[] ) try {
             dh->handle();
             //} catch( const std::exception &ch ) {
             //std::cout << "Real exception: " << typeid(ch).name() << ", " << ch.what() << std::endl;
-        } catch( const std::string& ch ) {
-            logger::error( "Exception: ", ch );
-        } catch( char const* ch ) {
-            logger::error( "Exception: ", ch );
+        } catch( const std::exception& e ) {
+            logger::error( "Exception: ", e.what() );
         }
     }
 
@@ -71,7 +69,4 @@ int main( int argc, const char* argv[] ) try {
 } catch( std::exception& e ) {
     logger::fatalf( "Fatal Error: %s!\n", e.what() );
     return -1;
-} catch( ... ) {
-    logger::fatal( "Fatal Error: Unknown Exception!\n" );
-    return -1;
 }
index 4440d09f267e4fc81cf2cfc67f506aac5b21dd6b..164e0bbadef6e43eb989ddfad665833bfc4594a9 100644 (file)
@@ -23,7 +23,7 @@ std::shared_ptr<std::unordered_map<std::string, std::string>> parseConf( std::st
 
     if( !config.is_open() ) {
         logger::notef( "Where is \"%s\"?", path );
-        throw "Config missing";
+        throw std::runtime_error("Config missing");
     }
 
     std::string line1;
@@ -117,7 +117,7 @@ int parseProfiles() {
 
             closedir( dir );
         } else {
-            throw "Directory with CAConfigs not found";
+            throw std::runtime_error("Directory with CAConfigs not found");
         }
 
         profiles.emplace( profileName, prof );
index 902cb6dfb409b1b3e72d618aa29428dbfc80cc5f..41fbe8b6472464af1dbcfab4ed5aec66b7cf44bd 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <openssl/ssl.h>
 #include <log/logger.hpp>
+#include <exception>
 
 CRL::CRL( std::string path ) {
     std::shared_ptr<BIO> bio( BIO_new_file( path.c_str(), "r" ), BIO_free );
@@ -17,21 +18,21 @@ std::string CRL::revoke( std::string serial, std::string time ) {
 
     logger::note("parsing serial");
     if( ! BN_hex2bn( &serBN, serial.c_str() ) ) {
-        throw "hex2bn malloc fail";
+        throw std::runtime_error("hex2bn malloc fail");
     }
 
     std::shared_ptr<BIGNUM> serBNP( serBN, BN_free );
     std::shared_ptr<ASN1_INTEGER> ser( BN_to_ASN1_INTEGER( serBN, NULL ), ASN1_INTEGER_free );
 
     if( !ser ) {
-        throw "BN Malloc fail";
+        throw std::runtime_error("BN Malloc fail");
     }
 
     logger::note("building current time");
     std::shared_ptr<ASN1_TIME> tmptm( ASN1_TIME_new(), ASN1_TIME_free );
 
     if( !tmptm ) {
-        throw "ASN1-Time Malloc fail";
+        throw std::runtime_error("ASN1-Time Malloc fail");
     }
 
     X509_gmtime_adj( tmptm.get(), 0 );
@@ -63,21 +64,21 @@ void CRL::sign( std::shared_ptr<CAConfig> ca ) {
     std::shared_ptr<ASN1_TIME> tmptm( ASN1_TIME_new(), ASN1_TIME_free );
 
     if( !tmptm ) {
-        throw "ASN1-Time Malloc fail";
+        throw std::runtime_error("ASN1-Time Malloc fail");
     }
 
     X509_gmtime_adj( tmptm.get(), 0 );
 
     logger::note("setting issuer");
     if( !X509_CRL_set_issuer_name( crl.get(), X509_get_subject_name( ca->ca.get() ) ) ) {
-        throw "Setting issuer failed";
+        throw std::runtime_error("Setting issuer failed");
     }
 
     logger::note("setting update");
     X509_CRL_set_lastUpdate( crl.get(), tmptm.get() );
 
     if( !X509_time_adj_ex( tmptm.get(), 1, 10, NULL ) ) {
-        throw "Updating time failed";
+        throw std::runtime_error("Updating time failed");
     }
 
     logger::note("setting next update");
index caa2a9dfe0ff52435570faee628d9a7c8b88f1b0..7a4314deab9d830a79dfff527afeec82802206d8 100644 (file)
@@ -11,7 +11,7 @@ X509Req::X509Req( X509_REQ* csr ) : req( csr, X509_REQ_free ) {
     EVP_PKEY* pkt = X509_REQ_get_pubkey( req.get() );
 
     if( !pkt ) {
-        throw "Error extracting public key";
+        throw std::runtime_error("Error extracting public key");
     }
 
     pk = std::shared_ptr<EVP_PKEY>( pkt, EVP_PKEY_free );
@@ -19,21 +19,21 @@ X509Req::X509Req( X509_REQ* csr ) : req( csr, X509_REQ_free ) {
 
 X509Req::X509Req( std::string spkac ) {
     if( spkac.compare( 0, 6, "SPKAC=" ) != 0 ) {
-        throw "Error: not a SPKAC";
+        throw std::runtime_error("Error: not a SPKAC");
     }
 
     spkac = spkac.substr( 6 );
     NETSCAPE_SPKI* spki_p = NETSCAPE_SPKI_b64_decode( spkac.c_str(), spkac.size() );
 
     if( !spki_p ) {
-        throw "Error: decode failed";
+        throw std::runtime_error("Error: decode failed");
     }
 
     spki = std::shared_ptr<NETSCAPE_SPKI>( spki_p, NETSCAPE_SPKI_free );
     EVP_PKEY* pkt_p = NETSCAPE_SPKI_get_pubkey( spki.get() );
 
     if( !pkt_p ) {
-        throw "Error: reading SPKAC Pubkey failed";
+        throw std::runtime_error("Error: reading SPKAC Pubkey failed");
     }
 
     pk = std::shared_ptr<EVP_PKEY>( pkt_p, EVP_PKEY_free );
@@ -56,7 +56,7 @@ std::shared_ptr<X509Req> X509Req::parseCSR( std::string content ) {
     X509_REQ* req = PEM_read_bio_X509_REQ( in.get(), NULL, NULL, NULL );
 
     if( !req ) {
-        throw "Error parsing CSR";
+        throw std::runtime_error("Error parsing CSR");
     }
 
     return std::shared_ptr<X509Req>( new X509Req( req )); // TODO ask
@@ -94,19 +94,19 @@ X509Cert::X509Cert() {
     X509* c = X509_new();
 
     if( !c ) {
-        throw "malloc failed";
+        throw std::runtime_error("malloc failed");
     }
 
     target = std::shared_ptr<X509>( c, X509_free );
 
     if( !X509_set_version( c, 2 ) ) {
-        throw "Setting X509-version to 3 failed";
+        throw std::runtime_error("Setting X509-version to 3 failed");
     }
 
     X509_NAME* subjectP = X509_NAME_new();
 
     if( !subjectP ) {
-        throw "malloc failure in construct.";
+        throw std::runtime_error("malloc failure in construct.");
     }
 
     subject = std::shared_ptr<X509_NAME>( subjectP, X509_NAME_free );
@@ -114,13 +114,13 @@ X509Cert::X509Cert() {
 
 void X509Cert::addRDN( int nid, std::string data ) {
     if( ! X509_NAME_add_entry_by_NID( subject.get(), nid, MBSTRING_UTF8, ( unsigned char* )const_cast<char*>( data.data() ), data.size(), -1, 0 ) ) {
-        throw "malloc failure in RDN";
+        throw std::runtime_error("malloc failure in RDN");
     }
 }
 
 void X509Cert::setIssuerNameFrom( std::shared_ptr<X509> caCert ) {
     if( !X509_set_issuer_name( target.get(), X509_get_subject_name( caCert.get() ) ) ) {
-        throw "Error setting Issuer name";
+        throw std::runtime_error("Error setting Issuer name");
     }
 }
 
@@ -128,7 +128,7 @@ void X509Cert::setPubkeyFrom( std::shared_ptr<X509Req> req ) {
     std::shared_ptr<EVP_PKEY> pktmp = req->getPkey();
 
     if( !X509_set_pubkey( target.get(), pktmp.get() ) ) {
-        throw "Setting public key failed.";
+        throw std::runtime_error("Setting public key failed.");
     }
 }
 
@@ -171,7 +171,7 @@ static X509_EXTENSION* do_ext_i2d( int ext_nid, int crit, ASN1_VALUE* ext_struc
     return ext;
 
 merr:
-    throw "memerr";
+    throw std::runtime_error("memerr");
 }
 
 void X509Cert::setExtensions( std::shared_ptr<X509> caCert, std::vector<std::shared_ptr<SAN>>& sans, Profile& prof, std::string crlURL, std::string crtURL ) {
@@ -200,7 +200,7 @@ void X509Cert::setExtensions( std::shared_ptr<X509> caCert, std::vector<std::sha
         GENERAL_NAME* gen = GENERAL_NAME_new();
 
         if( !gen ) {
-            throw "Malloc failure.";
+            throw std::runtime_error("Malloc failure.");
         }
 
         gen->type = name->type == "DNS" ? GEN_DNS : name->type == "email" ? GEN_EMAIL : 0; // GEN_EMAIL;
@@ -209,7 +209,7 @@ void X509Cert::setExtensions( std::shared_ptr<X509> caCert, std::vector<std::sha
                 || !( gen->d.ia5 = M_ASN1_IA5STRING_new() )
                 || !ASN1_STRING_set( gen->d.ia5, name->content.data(), name->content.size() ) ) {
             GENERAL_NAME_free( gen );
-            throw "initing iasting5 failed";
+            throw std::runtime_error("initing iasting5 failed");
         }
 
         sk_GENERAL_NAME_push( gens.get(), gen );
@@ -223,7 +223,7 @@ void X509Cert::setExtensions( std::shared_ptr<X509> caCert, std::vector<std::sha
 
 std::shared_ptr<SignedCertificate> X509Cert::sign( std::shared_ptr<EVP_PKEY> caKey, std::string signAlg ) {
     if( !X509_set_subject_name( target.get(), subject.get() ) ) {
-        throw "error setting subject";
+        throw std::runtime_error("error setting subject");
     }
 
     const EVP_MD* md;
@@ -237,11 +237,11 @@ std::shared_ptr<SignedCertificate> X509Cert::sign( std::shared_ptr<EVP_PKEY> caK
     } else if( signAlg == "sha1" ) {
         md = EVP_sha1();
     } else {
-        throw "Unknown md-type";
+        throw std::runtime_error("Unknown md-type");
     }
 
     if( !X509_sign( target.get(), caKey.get(), md ) ) {
-        throw "Signing failed.";
+        throw std::runtime_error("Signing failed.");
     }
 
     //X509_print_fp( stdout, target.get() );
@@ -249,7 +249,7 @@ std::shared_ptr<SignedCertificate> X509Cert::sign( std::shared_ptr<EVP_PKEY> caK
     std::shared_ptr<BIO> mem = std::shared_ptr<BIO>( BIO_new( BIO_s_mem() ), BIO_free );
 
     if( !mem ) {
-        throw "Failed to allocate memory for the signed certificate.";
+        throw std::runtime_error("Failed to allocate memory for the signed certificate.");
     }
 
     PEM_write_bio_X509( mem.get(), target.get() );
@@ -263,7 +263,7 @@ std::shared_ptr<SignedCertificate> X509Cert::sign( std::shared_ptr<EVP_PKEY> caK
     std::shared_ptr<BIGNUM> ser( ASN1_INTEGER_to_BN( target->cert_info->serialNumber, NULL ), BN_free );
 
     if( !ser ) {
-        throw "Failed to retrieve certificate serial of signed certificate.";
+        throw std::runtime_error("Failed to retrieve certificate serial of signed certificate.");
     }
 
     std::shared_ptr<char> serStr(
index a8907115dd89b475d222103e0357aa9f757e666b..1c32ba0ed513f877f13811557865cb7989da49f7 100644 (file)
@@ -92,8 +92,8 @@ std::shared_ptr<SignedCertificate> RemoteSigner::sign( std::shared_ptr<TBSCertif
                 logger::error( "Invalid Message" );
                 break;
             }
-        } catch( const char* msg ) {
-            logger::error( msg );
+        } catch( const std::exception& msg ) {
+            logger::error( msg.what() );
             return std::shared_ptr<SignedCertificate>();
         }
     }
@@ -107,7 +107,7 @@ std::shared_ptr<SignedCertificate> RemoteSigner::sign( std::shared_ptr<TBSCertif
             int dlen = BIO_write( bios.get(), buf, len );
 
             if( dlen <= 0 ) {
-                throw "Memory error.";
+                throw std::runtime_error("Memory error.");
             }
 
             len -= dlen;
@@ -117,7 +117,7 @@ std::shared_ptr<SignedCertificate> RemoteSigner::sign( std::shared_ptr<TBSCertif
         std::shared_ptr<X509> pem( PEM_read_bio_X509( bios.get(), NULL, 0, NULL ) );
 
         if( !pem ) {
-            throw "Pem was not readable";
+            throw std::runtime_error("Pem was not readable");
         }
 
         std::shared_ptr<BIGNUM> ser( ASN1_INTEGER_to_BN( pem->cert_info->serialNumber, NULL ), BN_free );
@@ -169,7 +169,7 @@ std::pair<std::shared_ptr<CRL>, std::string> RemoteSigner::revoke( std::shared_p
     std::string date;
 
     if( static_cast<RecordHeader::SignerResult>( head.command ) != RecordHeader::SignerResult::REVOKED ) {
-        throw "Protocol violation";
+        throw std::runtime_error("Protocol violation");
     }
 
     const unsigned char* buffer2 = reinterpret_cast<const unsigned char*>( payload.data() );
@@ -196,7 +196,7 @@ std::pair<std::shared_ptr<CRL>, std::string> RemoteSigner::revoke( std::shared_p
         payload = parseCommandChunked( head, conn );
 
         if( static_cast<RecordHeader::SignerResult>( 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" );
index f0d415eb03de11d858106c3ec690e6f174eb9404..cad772c4e102b9007c33e80cc921ee0af77c86d2 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <sstream>
 #include <unordered_map>
+#include <exception>
 
 #include <openssl/ssl.h>
 #include <openssl/err.h>
@@ -36,11 +37,11 @@ std::pair<std::shared_ptr<BIGNUM>, std::string> SimpleOpensslSigner::nextSerial(
         bn = BN_new();
 
         if( !bn || !BN_hex2bn( &bn, "1" )) {
-            throw "Initing serial failed";
+            throw std::runtime_error("Initing serial failed");
         }
     } else {
         if( !BN_hex2bn( &bn, res.c_str() ) ) {
-            throw "Parsing serial failed.";
+            throw std::runtime_error("Parsing serial failed.");
         }
     }
 
@@ -56,7 +57,7 @@ std::pair<std::shared_ptr<BIGNUM>, std::string> SimpleOpensslSigner::nextSerial(
     data.get()[len + 3] = profile & 0xFF; // profile id
 
     if( !RAND_bytes( data.get() + len + 4, 16 ) || !BN_add_word( serial.get(), 1 ) ) {
-        throw "Big number math failed while fetching random data for serial number.";
+        throw std::runtime_error("Big number math failed while fetching random data for serial number.");
     }
 
     std::shared_ptr<char> serStr = std::shared_ptr<char>(
@@ -83,7 +84,7 @@ std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TB
 
     if( !ca ) {
         logger::error( "ERROR: Signing CA specified in profile could not be loaded." );
-        throw "CA-key not found";
+        throw std::runtime_error("CA-key not found");
     }
 
     logger::note( "FINE: Key for Signing CA is correctly loaded." );
@@ -102,15 +103,15 @@ std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TB
         req = X509Req::parseCSR( cert->csr_content );
     } else {
         logger::errorf( "ERROR: Unknown type (\"%s\") of certification in request.", cert->csr_type );
-        throw "Error, unknown REQ rype " + ( cert->csr_type ); //! \fixme: Pointer instead of string, please use proper exception classes
+        throw std::runtime_error("Error, unknown REQ rype " + cert->csr_type ); //! \fixme: Pointer instead of string, please use proper exception classe)s
     }
 
     int i = req->verify();
 
     if( i < 0 ) {
-        throw "Request contains a Signature with problems ... ";
+        throw std::runtime_error("Request contains a Signature with problems ... ");
     } else if( i == 0 ) {
-        throw "Request contains a Signature that does not match ...";
+        throw std::runtime_error("Request contains a Signature that does not match ...");
     } else {
         logger::note( "FINE: Request contains valid self-signature." );
     }
@@ -142,7 +143,7 @@ std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TB
             c.addRDN( NID_organizationalUnitName, a->value );
         } else {
             logger::error( "ERROR: Trying to add illegal RDN/AVA type: ", a->name );
-            throw "Unhandled/Illegal AVA type";
+            throw std::runtime_error("Unhandled/Illegal AVA type");
         }
     }
 
@@ -244,7 +245,7 @@ std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TB
 
         if( fn.empty() ) {
             logger::error( "ERROR: failed to get filename for storage of signed certificate." );
-            throw "Storage location could not be determined";
+            throw std::runtime_error("Storage location could not be determined");
         }
 
         logger::note( "FINE: Certificate signed successfully." );
index 687387c1573c7d9c615fdcfcff78cb3ab838b9d6..39df1ffc6a8695ee15162551335a16be0fa7fdb1 100644 (file)
@@ -97,7 +97,7 @@ std::shared_ptr<SSL_CTX> generateSSLContext( bool server ) {
         } );
 
     if( !SSL_CTX_set_cipher_list( ctx.get(), "HIGH:+CAMELLIA256:!eNull:!aNULL:!ADH:!MD5:-RSA+AES+SHA1:!RC4:!DES:!3DES:!SEED:!EXP:!AES128:!CAMELLIA128" ) ) {
-        throw "Cannot set cipher list. Your source is broken.";
+        throw std::runtime_error("Cannot set cipher list. Your source is broken.");
     }
 
     SSL_CTX_set_verify( ctx.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback );
@@ -105,7 +105,7 @@ std::shared_ptr<SSL_CTX> generateSSLContext( bool server ) {
     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.";
+        throw std::runtime_error("Cannot load CA store for certificate validation.");
     }
 
     if( server ) {
@@ -131,7 +131,7 @@ std::shared_ptr<SSL_CTX> generateSSLContext( bool server ) {
                 cb.cb.cb_2 = gencb;
 
                 if( !DH_generate_parameters_ex( dh_param.get(), 2048, 5, &cb ) ) {
-                    throw "DH generation failed";
+                    throw std::runtime_error("DH generation failed");
                 }
 
                 std::cout << std::endl;
@@ -144,7 +144,7 @@ std::shared_ptr<SSL_CTX> generateSSLContext( bool server ) {
         }
 
         if( !SSL_CTX_set_tmp_dh( ctx.get(), dh_param.get() ) ) {
-            throw "Cannot set tmp dh.";
+            throw std::runtime_error("Cannot set tmp dh.");
         }
     }
 
@@ -155,7 +155,7 @@ void setupSerial( std::shared_ptr<FILE> f ) {
     struct termios attr;
 
     if( tcgetattr( fileno( f.get() ), &attr ) ) {
-        throw "failed to get attrs";
+        throw std::runtime_error("failed to get attrs");
     }
 
     attr.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON );
@@ -168,7 +168,7 @@ void setupSerial( std::shared_ptr<FILE> f ) {
     cfsetospeed( &attr, B115200 );
 
     if( tcsetattr( fileno( f.get() ), TCSANOW, &attr ) ) {
-        throw "failed to get attrs";
+        throw std::runtime_error("failed to get attrs");
     }
 }
 
@@ -214,7 +214,7 @@ std::string timeToString( std::shared_ptr<ASN1_TIME> time ) {
 
     logger::notef("openssl formatted me a date: %s", strdate);
     if( strdate[strdate.size() - 1] != 'Z' ) {
-        throw "Got invalid date?";
+        throw std::runtime_error("Got invalid date?");
     }
 
     return strdate.substr( 0, strdate.size() - 1 );
index ecb6fe08e09be1e209f1fb88fc505c4ab68faea9..e8f1d4dd44a01cdc33358d53b19d63d6dc93e732 100644 (file)
@@ -32,7 +32,7 @@ std::shared_ptr<int> MySQLJobProvider::lib_ref(
 
 MySQLJobProvider::MySQLJobProvider( const std::string& server, const std::string& user, const std::string& password, const std::string& database ) {
     if( !lib_ref || *lib_ref ) {
-        throw "MySQL library not initialized!";
+        throw std::runtime_error("MySQL library not initialized!");
     }
 
     connect( server, user, password, database );
@@ -86,7 +86,7 @@ std::pair< int, std::shared_ptr<MYSQL_RES> > MySQLJobProvider::query( const std:
     int err = mysql_real_query( this->conn.get(), query.c_str(), query.size() );
 
     if( err ) {
-        throw std::string( "MySQL error: " ) + mysql_error( this->conn.get() );
+        throw std::runtime_error(std::string( "MySQL error: " ) + mysql_error( this->conn.get() ));
     }
 
     auto c = conn;
@@ -143,7 +143,7 @@ std::shared_ptr<Job> MySQLJobProvider::fetchJob() {
 
 std::string MySQLJobProvider::escape_string( const std::string& target ) {
     if( !conn ) {
-        throw "Not connected!";
+        throw std::runtime_error("Not connected!");
     }
 
     std::string result;
@@ -159,25 +159,25 @@ std::string MySQLJobProvider::escape_string( const std::string& target ) {
 
 void MySQLJobProvider::finishJob( std::shared_ptr<Job> job ) {
     if( !conn ) {
-        throw "Not connected!";
+        throw std::runtime_error("Not connected!");
     }
 
     std::string q = "UPDATE jobs SET state='done' WHERE id='" + this->escape_string( job->id ) + "' LIMIT 1";
 
     if( query( q ).first ) {
-        throw "No database entry found.";
+        throw std::runtime_error("No database entry found.");
     }
 }
 
 void MySQLJobProvider::failJob( std::shared_ptr<Job> job ) {
     if( !conn ) {
-        throw "Not connected!";
+        throw std::runtime_error("Not connected!");
     }
 
     std::string q = "UPDATE jobs SET warning = warning + 1 WHERE id='" + this->escape_string( job->id ) + "' LIMIT 1";
 
     if( query( q ).first ) {
-        throw "No database entry found.";
+        throw std::runtime_error("No database entry found.");
     }
 }
 
@@ -273,7 +273,7 @@ std::shared_ptr<TBSCertificate> MySQLJobProvider::fetchTBSCert( std::shared_ptr<
 
 void MySQLJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<SignedCertificate> res ) {
     if( !conn ) {
-        throw "Error while writing back";
+        throw std::runtime_error("Error while writing back");
     }
 
     std::string id = "SELECT id FROM cacerts WHERE keyname='" + this->escape_string( res->ca_name ) + "'";
@@ -283,7 +283,7 @@ void MySQLJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<Sign
     std::tie( err, resu ) = query( id );
 
     if( err ) {
-        throw "Error while looking ca cert id";
+        throw std::runtime_error("Error while looking ca cert id");
     }
 
     MYSQL_ROW row = mysql_fetch_row( resu.get() );
@@ -292,7 +292,7 @@ void MySQLJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<Sign
     std::string read_id;
 
     if( !row || !l ) {
-        throw "Error while inserting new ca cert not found";
+        throw std::runtime_error("Error while inserting new ca cert not found");
     } else {
         read_id = std::string( row[0], row[0] + l[0] );
     }
@@ -301,7 +301,7 @@ void MySQLJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<Sign
     // TODO write more thingies back
 
     if( query( q ).first ) {
-        throw "Error while writing back";
+        throw std::runtime_error("Error while writing back");
     }
 }
 
@@ -312,14 +312,14 @@ std::pair<std::string, std::string> MySQLJobProvider::getRevocationInfo( std::sh
     std::tie( err, resu ) = query( q );
 
     if( err ) {
-        throw "Error while looking ca cert id";
+        throw std::runtime_error("Error while looking ca cert id");
     }
 
     MYSQL_ROW row = mysql_fetch_row( resu.get() );
     unsigned long* l = mysql_fetch_lengths( resu.get() );
 
     if( !row || !l ) {
-        throw "Error while inserting new ca cert";
+        throw std::runtime_error("Error while inserting new ca cert");
     }
 
     return std::pair<std::string, std::string>( std::string( row[0], row[0] + l[0] ), std::string( row[1], row[1] + l[1] ) );
@@ -327,6 +327,6 @@ std::pair<std::string, std::string> MySQLJobProvider::getRevocationInfo( std::sh
 
 void MySQLJobProvider::writeBackRevocation( std::shared_ptr<Job> job, std::string date ) {
     if( query( "UPDATE certs SET revoked = '" + this->escape_string( date ) + "' WHERE id = '" + this->escape_string( job->target ) + "'" ).first ) {
-        throw "Error while writing back revocation";
+        throw std::runtime_error("Error while writing back revocation");
     }
 }
index c2a282e4adf8347abe3c30c6cef3091dc495b37c..7187b9e6ef820068afafa869e9450d59d41f55e3 100644 (file)
@@ -5,6 +5,7 @@
 #include <iostream>
 
 #include <log/logger.hpp>
+#include <exception>
 
 PostgresJobProvider::PostgresJobProvider( const std::string& server, const std::string& user, const std::string& password, const std::string& database ):
     c("dbname="+database+" host="+server+" user="+user+" password=" + password + " client_encoding=UTF-8 application_name=cassiopeia-client"){
@@ -43,7 +44,7 @@ void PostgresJobProvider::finishJob( std::shared_ptr<Job> job ) {
     pqxx::result r = txn.exec(q);
 
     if( r.affected_rows() != 1 ) {
-        throw "No database entry found.";
+        throw std::runtime_error("No database entry found.");
     }
     txn.commit();
 }
@@ -55,7 +56,7 @@ void PostgresJobProvider::failJob( std::shared_ptr<Job> job ) {
     pqxx::result r = txn.exec(q);
 
     if( r.affected_rows() != 1 ) {
-        throw "No database entry found.";
+        throw std::runtime_error("No database entry found.");
     }
     txn.commit();
 }
@@ -67,7 +68,7 @@ std::shared_ptr<TBSCertificate> PostgresJobProvider::fetchTBSCert( std::shared_p
     pqxx::result r = txn.exec(q);
 
     if( r.size() != 1 ) {
-        throw "Error, no or multiple certs found";
+        throw std::runtime_error("Error, no or multiple certs found");
      }
     auto ro = r[0];
 
@@ -124,7 +125,7 @@ void PostgresJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<S
     std::string read_id;
 
     if( r.size() != 1) {
-        throw "Error while inserting new ca cert not found";
+        throw std::runtime_error("Error while inserting new ca cert not found");
     } else {
         read_id = r[0]["id"].as<std::string>();
     }
@@ -135,7 +136,7 @@ void PostgresJobProvider::writeBack( std::shared_ptr<Job> job, std::shared_ptr<S
 
     r = txn.exec( q );
     if( r.affected_rows() != 1 ){
-        throw "Only one row should be updated.";
+        throw std::runtime_error("Only one row should be updated.");
     }
     txn.commit();
 }
@@ -146,7 +147,7 @@ std::pair<std::string, std::string> PostgresJobProvider::getRevocationInfo( std:
 
     pqxx::result r = txn.exec( q );
     if( r.size() != 1) {
-        throw "Only one row expected but multiple found.";
+        throw std::runtime_error("Only one row expected but multiple found.");
     }
 
     
@@ -159,7 +160,7 @@ void PostgresJobProvider::writeBackRevocation( std::shared_ptr<Job> job, std::st
     logger::errorf( "executing" );
     pqxx::result r = txn.exec( "UPDATE certs SET revoked = " + txn.quote( pgTime( date ) ) + " WHERE id = " + txn.quote( job->target ) );
     if( r.affected_rows() != 1 ){
-        throw "Only one row should be updated.";
+        throw std::runtime_error("Only one row should be updated.");
     }
     logger::errorf( "committing" );
     txn.commit();
index 056c2911f657085a844fe557ddc211029f525187..02fd4728a10f2396d8f9d00ee162b1c09181f801 100644 (file)
@@ -1,4 +1,5 @@
 #include "opensslBIO.h"
+#include <log/logger.hpp>
 
 OpensslBIOWrapper::OpensslBIOWrapper( std::shared_ptr<BIO> _b ) : b( _b ), buffer( 2*0xFFFF+20, 0 ), pos(0) {
 }
@@ -29,33 +30,31 @@ int OpensslBIOWrapper::gets( char* str, int size ) {
 const char* OpensslBIOWrapper::getName() {
     return "OpenSSLWrapper";
 }
-#include <log/logger.hpp>
 std::string OpensslBIOWrapper::readLine(){
     int target = 0;
     while(1){
-        logger::warn("doing data");
+        logger::debug("doing data");
         while(target < pos){
             if(buffer[target] == '\n'){
                 target++;
                 std::string res(buffer.data(), 0, target);
                 std::copy(buffer.data() + target, buffer.data() + pos, buffer.data() );
                 pos -= target;
-                logger::warn("emit");
+                logger::debug("emit");
                 return res;
             }
             target++;
         }
         std::stringstream ss;
         ss << "target: " << target << ", pos:" << pos;
-        logger::warn(ss.str());
+        logger::debug(ss.str());
         int dlen = read(buffer.data() + pos, buffer.size() - pos);
         if ( dlen <= 0 ){
-            logger::warn(" error! ");
-            throw EOFException();
+            throw eof_exception();
         }
         std::stringstream ss2;
         ss2 << "done: " << dlen;
-        logger::warn(ss2.str());
+        logger::debug(ss2.str());
         pos += dlen;
     }
 }
index 092fa9cf3a9ff36205b4b15c0d996e1097baab5f..994b7bcafb383e0e11a6c5c277f50d73c69b4ca8 100644 (file)
@@ -26,5 +26,5 @@ public:
     std::string readLine();
 };
 
-class EOFException : public std::exception{
+class eof_exception : public std::exception{
 };
index c3a2270c9174fbb775389ebabe4cd2b37d4e563d..4cc5b898bab50e377d71df9b8017cd2932a3dc91 100644 (file)
@@ -96,10 +96,10 @@ std::string parseCommand( RecordHeader& head, const std::string& input) {
         std::stringstream ss;
         ss << "Expected: " << expectedTotalLength << ", Got: " << input.size();
         logger::error( ss.str() );
-        throw "Error, invalid length";
+        throw std::length_error("Error, invalid length");
     }
     if( checksum != -1 || error || dlen < RECORD_HEADER_SIZE ) {
-        throw "Error, invalid checksum";
+        throw std::runtime_error("Error, invalid checksum");
     }
 
     data.pop_back();
index c06e6ad17114e1e5eb4e2862a950f80e8aef663e..48dd8afee59fe37e8551f527c16172ef2722c8b8 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <memory>
 #include <string>
-
+#include <exception>
 #include "bios.h"
 #include "io/opensslBIO.h"
 
@@ -90,7 +90,7 @@ public:
 
     void unpackFromString( const std::string& str ) {
         if( str.size() != RECORD_HEADER_SIZE ) {
-            throw "Invalid string length";
+            throw std::runtime_error("Invalid string length");
         }
 
         auto it =  str.cbegin();
index 551b2c495144e04c4660bc95c45dacaef885bbb3..f8c2185f395bdcba617e32d5e5410af74947549f 100644 (file)
@@ -75,8 +75,8 @@ public:
             RecordHeader head;
             std::string all = parseCommandChunked( head, io );
             execute( static_cast<RecordHeader::SignerCommand>( head.command ), all );
-        } catch( const char* msg ) {
-            logger::error( "ERROR: ", msg );
+        } catch( const std::exception& msg ) {
+            logger::error( "ERROR: ", msg.what() );
             parent->reset();
             return;
         }
@@ -207,7 +207,7 @@ public:
             break;
 
         default:
-            throw "Unimplemented";
+            throw std::runtime_error("Unimplemented");
         }
     }
 };
@@ -228,7 +228,7 @@ void DefaultRecordHandler::handle() {
     }
     try {
         currentSession->work();
-    } catch( EOFException e ){
+    } catch( eof_exception e ){
         reset();
     }
 }
index a9100b31c88a5e9e44a119ec4f1bf3bb30f2f45f..29bc41e328d663179e7b19c02fde4dafc9bddfec 100644 (file)
@@ -1,7 +1,7 @@
 #include "slipBio.h"
 
 #include <unistd.h>
-
+#include <exception>
 #include <iostream>
 
 #include "log/logger.hpp"
@@ -111,7 +111,7 @@ int SlipBIO::write( const char* buf, int num ) {
 #endif
 
         if( dlen < 0 ) {
-            throw "Error, target write failed";
+            throw std::runtime_error("Error, target write failed");
         } else if( dlen == 0 ) {
             // sleep
             logger::note( "waiting for write ability" );
index 40fcf25ac0dc2f5c9c6cbb3a6ab839404c20921d..3197b68eedcaf2a907a3b493e43cb5adbb8ce28d 100644 (file)
@@ -190,7 +190,7 @@ std::unique_ptr<std::ofstream> openLogfile( const std::string &name ) {
     auto res = std::make_unique<std::ofstream>( tname );
 
     if( ! res->good() ) {
-        throw std::string( "Failed to open file for logging: " ) + name;
+        throw std::runtime_error( std::string("Failed to open file for logging: " ) + name );
     }
 
     return res;