summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2024-03-28 04:45:20 +0300
committerEd Tanous <ed@tanous.net>2024-03-29 19:57:53 +0300
commitc160ae72068a19b852861f6d2b542a5929c3eb9b (patch)
tree5d5409442cf6e17c5049ee059dad88ec4605167b /include
parent1847f2a0c517df6a7439b9bd491afbf6b2302a92 (diff)
downloadbmcweb-c160ae72068a19b852861f6d2b542a5929c3eb9b.tar.xz
Remove old uses of cout/cerr
Most of this code was written before bmcweb had a logger, and therefore used cout/cerr. This commit greps the codebase and finds all places where we still use cout/cerr, and moves them to logging. Tested: Inspection only. No functional changes. Change-Id: I5ce1883c9941e80203ec29decb3a0206fd118506 Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'include')
-rw-r--r--include/ossl_random.hpp4
-rw-r--r--include/ssl_key_handler.hpp36
2 files changed, 21 insertions, 19 deletions
diff --git a/include/ossl_random.hpp b/include/ossl_random.hpp
index 2cbec849a9..b392410986 100644
--- a/include/ossl_random.hpp
+++ b/include/ossl_random.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "logging.hpp"
+
#include <openssl/rand.h>
#include <iostream>
@@ -17,7 +19,7 @@ struct OpenSSLGenerator
int rc = RAND_bytes(&index, sizeof(index));
if (rc != opensslSuccess)
{
- std::cerr << "Cannot get random number\n";
+ BMCWEB_LOG_ERROR("Cannot get random number");
err = true;
}
diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp
index 5ce7cc7a41..d12fcabdc2 100644
--- a/include/ssl_key_handler.hpp
+++ b/include/ssl_key_handler.hpp
@@ -106,7 +106,7 @@ inline bool verifyOpensslKeyCert(const std::string& filepath)
bool privateKeyValid = false;
bool certValid = false;
- std::cout << "Checking certs in file " << filepath << "\n";
+ BMCWEB_LOG_INFO("Checking certs in file {}", filepath);
FILE* file = fopen(filepath.c_str(), "r");
if (file != nullptr)
@@ -118,15 +118,15 @@ inline bool verifyOpensslKeyCert(const std::string& filepath)
RSA* rsa = EVP_PKEY_get1_RSA(pkey);
if (rsa != nullptr)
{
- std::cout << "Found an RSA key\n";
+ BMCWEB_LOG_INFO("Found an RSA key");
if (RSA_check_key(rsa) == 1)
{
privateKeyValid = true;
}
else
{
- std::cerr << "Key not valid error number "
- << ERR_get_error() << "\n";
+ BMCWEB_LOG_ERROR("Key not valid error number {}",
+ ERR_get_error());
}
RSA_free(rsa);
}
@@ -135,15 +135,15 @@ inline bool verifyOpensslKeyCert(const std::string& filepath)
EC_KEY* ec = EVP_PKEY_get1_EC_KEY(pkey);
if (ec != nullptr)
{
- std::cout << "Found an EC key\n";
+ BMCWEB_LOG_INFO("Found an EC key");
if (EC_KEY_check_key(ec) == 1)
{
privateKeyValid = true;
}
else
{
- std::cerr << "Key not valid error number "
- << ERR_get_error() << "\n";
+ BMCWEB_LOG_ERROR("Key not valid error number {}",
+ ERR_get_error());
}
EC_KEY_free(ec);
}
@@ -154,8 +154,8 @@ inline bool verifyOpensslKeyCert(const std::string& filepath)
if (pkeyCtx == nullptr)
{
- std::cerr << "Unable to allocate pkeyCtx " << ERR_get_error()
- << "\n";
+ BMCWEB_LOG_ERROR("Unable to allocate pkeyCtx {}",
+ ERR_get_error());
}
else if (EVP_PKEY_check(pkeyCtx) == 1)
{
@@ -163,8 +163,8 @@ inline bool verifyOpensslKeyCert(const std::string& filepath)
}
else
{
- std::cerr << "Key not valid error number " << ERR_get_error()
- << "\n";
+ BMCWEB_LOG_ERROR("Key not valid error number {}",
+ ERR_get_error());
}
#endif
@@ -179,8 +179,8 @@ inline bool verifyOpensslKeyCert(const std::string& filepath)
X509* x509 = PEM_read_X509(file, nullptr, nullptr, nullptr);
if (x509 == nullptr)
{
- std::cout << "error getting x509 cert " << ERR_get_error()
- << "\n";
+ BMCWEB_LOG_ERROR("error getting x509 cert {}",
+ ERR_get_error());
}
else
{
@@ -253,14 +253,14 @@ inline void generateSslCertificate(const std::string& filepath,
const std::string& cn)
{
FILE* pFile = nullptr;
- std::cout << "Generating new keys\n";
+ BMCWEB_LOG_INFO("Generating new keys");
initOpenssl();
- std::cerr << "Generating EC key\n";
+ BMCWEB_LOG_INFO("Generating EC key");
EVP_PKEY* pPrivKey = createEcKey();
if (pPrivKey != nullptr)
{
- std::cerr << "Generating x509 Certificate\n";
+ BMCWEB_LOG_INFO("Generating x509 Certificates");
// Use this code to directly generate a certificate
X509* x509 = X509_new();
if (x509 != nullptr)
@@ -359,7 +359,7 @@ EVP_PKEY* createEcKey()
/* pKey owns myecc from now */
if (EC_KEY_check_key(myecc) <= 0)
{
- std::cerr << "EC_check_key failed.\n";
+ BMCWEB_LOG_ERROR("EC_check_key failed.");
}
}
}
@@ -423,7 +423,7 @@ inline void ensureOpensslKeyPresentAndValid(const std::string& filepath)
if (!pemFileValid)
{
- std::cerr << "Error in verifying signature, regenerating\n";
+ BMCWEB_LOG_WARNING("Error in verifying signature, regenerating");
generateSslCertificate(filepath, "testhost");
}
}