Browse Source

[4633] Decorated library errors

Francis Dupont 8 years ago
parent
commit
fa68968aeb

+ 11 - 6
src/lib/cryptolink/botan_hash.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -74,7 +74,8 @@ public:
                       "Unknown hash algorithm: " <<
                       "Unknown hash algorithm: " <<
                       static_cast<int>(hash_algorithm));
                       static_cast<int>(hash_algorithm));
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
         }
 
 
         hash_.reset(hash);
         hash_.reset(hash);
@@ -110,7 +111,8 @@ public:
         try {
         try {
             hash_->update(static_cast<const Botan::byte*>(data), len);
             hash_->update(static_cast<const Botan::byte*>(data), len);
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -126,7 +128,8 @@ public:
             }
             }
             result.writeData(&b_result[0], len);
             result.writeData(&b_result[0], len);
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -142,7 +145,8 @@ public:
             }
             }
             std::memcpy(result, &b_result[0], output_size);
             std::memcpy(result, &b_result[0], output_size);
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -157,7 +161,8 @@ public:
             }
             }
             return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
             return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
         }
     }
     }
 
 

+ 8 - 8
src/lib/cryptolink/botan_hmac.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -58,7 +58,7 @@ public:
                       "Unknown hash algorithm: " <<
                       "Unknown hash algorithm: " <<
                       static_cast<int>(hash_algorithm));
                       static_cast<int>(hash_algorithm));
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
 
 
         hmac_.reset(new Botan::HMAC(hash));
         hmac_.reset(new Botan::HMAC(hash));
@@ -94,7 +94,7 @@ public:
         } catch (const Botan::Invalid_Key_Length& ikl) {
         } catch (const Botan::Invalid_Key_Length& ikl) {
             isc_throw(BadKey, ikl.what());
             isc_throw(BadKey, ikl.what());
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -129,7 +129,7 @@ public:
         try {
         try {
             hmac_->update(static_cast<const Botan::byte*>(data), len);
             hmac_->update(static_cast<const Botan::byte*>(data), len);
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -145,7 +145,7 @@ public:
             }
             }
             result.writeData(&b_result[0], len);
             result.writeData(&b_result[0], len);
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -161,7 +161,7 @@ public:
             }
             }
             std::memcpy(result, &b_result[0], output_size);
             std::memcpy(result, &b_result[0], output_size);
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -176,7 +176,7 @@ public:
             }
             }
             return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
             return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
     }
     }
 
 
@@ -203,7 +203,7 @@ public:
                                     static_cast<const unsigned char*>(sig),
                                     static_cast<const unsigned char*>(sig),
                                     len));
                                     len));
         } catch (const Botan::Exception& exc) {
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
         }
     }
     }
 
 

+ 2 - 2
src/lib/cryptolink/botan_link.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2015,2017 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -31,7 +31,7 @@ CryptoLink::initialize() {
         try {
         try {
             c.impl_ = new CryptoLinkImpl();
             c.impl_ = new CryptoLinkImpl();
         } catch (const Botan::Exception& ex) {
         } catch (const Botan::Exception& ex) {
-            isc_throw(InitializationError, ex.what());
+            isc_throw(InitializationError, "Botan error: " << ex.what());
         }
         }
     }
     }
 }
 }

+ 3 - 2
src/lib/cryptolink/openssl_hash.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -67,7 +67,8 @@ public:
 
 
         md_ = EVP_MD_CTX_new();
         md_ = EVP_MD_CTX_new();
         if (md_ == 0) {
         if (md_ == 0) {
-            isc_throw(isc::cryptolink::LibraryError, "EVP_MD_CTX_new");
+            isc_throw(isc::cryptolink::LibraryError,
+                      "OpenSSL EVP_MD_CTX_new() failed");
         }
         }
 
 
         EVP_DigestInit_ex(md_, algo, NULL);
         EVP_DigestInit_ex(md_, algo, NULL);

+ 11 - 11
src/lib/cryptolink/openssl_hmac.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -46,13 +46,13 @@ public:
 
 
         md_ = HMAC_CTX_new();
         md_ = HMAC_CTX_new();
         if (md_ == 0) {
         if (md_ == 0) {
-            isc_throw(LibraryError, "HMAC_CTX_new");
+            isc_throw(LibraryError, "OpenSSL HMAC_CTX_new() failed");
         }
         }
 
 
         if (!HMAC_Init_ex(md_, secret,
         if (!HMAC_Init_ex(md_, secret,
                           static_cast<int>(secret_len),
                           static_cast<int>(secret_len),
                           algo, NULL)) {
                           algo, NULL)) {
-            isc_throw(LibraryError, "HMAC_Init_ex");
+            isc_throw(LibraryError, "OpenSSL HMAC_Init_ex() failed");
         }
         }
     }
     }
 
 
@@ -75,7 +75,7 @@ public:
     size_t getOutputLength() const {
     size_t getOutputLength() const {
         int size = HMAC_size(md_);
         int size = HMAC_size(md_);
         if (size < 0) {
         if (size < 0) {
-            isc_throw(LibraryError, "HMAC_size");
+            isc_throw(LibraryError, "OpenSSL HMAC_size() failed");
         }
         }
         return (static_cast<size_t>(size));
         return (static_cast<size_t>(size));
     }
     }
@@ -87,7 +87,7 @@ public:
         if (!HMAC_Update(md_,
         if (!HMAC_Update(md_,
                          static_cast<const unsigned char*>(data),
                          static_cast<const unsigned char*>(data),
                          len)) {
                          len)) {
-            isc_throw(LibraryError, "HMAC_Update");
+            isc_throw(LibraryError, "OpenSSLHMAC_Update() failed");
         }
         }
     }
     }
 
 
@@ -98,7 +98,7 @@ public:
         size_t size = getOutputLength();
         size_t size = getOutputLength();
         ossl::SecBuf<unsigned char> digest(size);
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(md_, &digest[0], NULL)) {
         if (!HMAC_Final(md_, &digest[0], NULL)) {
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         }
         if (len > size) {
         if (len > size) {
             len = size;
             len = size;
@@ -113,7 +113,7 @@ public:
         size_t size = getOutputLength();
         size_t size = getOutputLength();
         ossl::SecBuf<unsigned char> digest(size);
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(md_, &digest[0], NULL)) {
         if (!HMAC_Final(md_, &digest[0], NULL)) {
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         }
         if (len > size) {
         if (len > size) {
             len = size;
             len = size;
@@ -128,7 +128,7 @@ public:
         size_t size = getOutputLength();
         size_t size = getOutputLength();
         ossl::SecBuf<unsigned char> digest(size);
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(md_, &digest[0], NULL)) {
         if (!HMAC_Final(md_, &digest[0], NULL)) {
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         }
         if (len < size) {
         if (len < size) {
             digest.resize(len);
             digest.resize(len);
@@ -148,16 +148,16 @@ public:
         // Get the digest from a copy of the context
         // Get the digest from a copy of the context
         HMAC_CTX* tmp = HMAC_CTX_new();
         HMAC_CTX* tmp = HMAC_CTX_new();
         if (tmp == 0) {
         if (tmp == 0) {
-            isc_throw(LibraryError, "HMAC_CTX_new");
+            isc_throw(LibraryError, "OpenSSL HMAC_CTX_new() failed");
         }
         }
         if (!HMAC_CTX_copy(tmp, md_)) {
         if (!HMAC_CTX_copy(tmp, md_)) {
             HMAC_CTX_free(tmp);
             HMAC_CTX_free(tmp);
-            isc_throw(LibraryError, "HMAC_CTX_copy");
+            isc_throw(LibraryError, "OpenSSL HMAC_CTX_copy() failed");
         }
         }
         ossl::SecBuf<unsigned char> digest(size);
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(tmp, &digest[0], NULL)) {
         if (!HMAC_Final(tmp, &digest[0], NULL)) {
             HMAC_CTX_free(tmp);
             HMAC_CTX_free(tmp);
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         }
         HMAC_CTX_free(tmp);
         HMAC_CTX_free(tmp);
         if (len > size) {
         if (len > size) {