Remove boost-log dependency
[platform/core/security/device-certificate-manager-backend.git] / src / kse-backend / ksebackendcontext.cpp
index d95fe7f..1e538d6 100644 (file)
@@ -19,7 +19,7 @@
  ******************************************************************/
 
 #include "ksebackendcontext.h"
-#include "logging.h"
+#include "log.h"
 #include "konaise.h"
 #include "cert_utils.h"
 
@@ -39,9 +39,7 @@ static int kse_get_ecdsa_signature_key = 1;
 kse_backend_context::kse_backend_context(std::shared_ptr<kse_backend> backend, const std::string& keyType) :
        fBackendPtr(backend)
 {
-       BOOST_LOG_FUNCTION();
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Created new KSE with key " << keyType;
+       LOGD("Created new KSE with key " << keyType);
 
        if(keyType.empty() || keyType == "ECDSA") {
                fKeyType = CRYPTO_KEY_TYPE_ECDSA;
@@ -49,14 +47,12 @@ kse_backend_context::kse_backend_context(std::shared_ptr<kse_backend> backend, c
                throw std::invalid_argument("Unsupported key type");
        }
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Created new KSE context at " << this;
+       LOGD("Created new KSE context at " << this);
 }
 
 kse_backend_context::~kse_backend_context()
 {
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Deleting KSE context " << this;
+       LOGD("Deleting KSE context " << this);
 }
 
 int kse_backend_context::get_certificate(unsigned int index, std::string& outcert)
@@ -66,8 +62,7 @@ int kse_backend_context::get_certificate(unsigned int index, std::string& outcer
 
        auto backend = fBackendPtr.lock();
        if(!backend) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "Unable to acquire backend pointer";
+               LOGE("Unable to acquire backend pointer");
                return -EINVAL;
        }
 
@@ -77,27 +72,20 @@ int kse_backend_context::get_certificate(unsigned int index, std::string& outcer
                error = resolver.invoke<int, unsigned int, hal_data *>(&kse_get_certificate_key,
                                        method_name, index, &cert);
        } catch(...) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "KSE: Got exception when calling resolver.invoke";
+               LOGE("KSE: Got exception when calling resolver.invoke");
                throw;
        }
 
        if(error != 0) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "Failed to get certificate. error=" << error;
+               LOGE("Failed to get certificate. error=" << error);
                return -EINVAL;
        }
 
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "KSE: Got certificate with " << cert.data_len
-                                       << " bytes and index " << index;
-#endif
+       LOGD("KSE: Got certificate with " << cert.data_len << " bytes and index " << index);
        try {
                outcert.assign((const char *)cert.data, cert.data_len);
        } catch(...) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "KSE: Got exception when assigning data";
+               LOGE("KSE: Got exception when assigning data");
                free(cert.data);
                throw;
        }
@@ -108,11 +96,7 @@ int kse_backend_context::get_certificate(unsigned int index, std::string& outcer
 
 int kse_backend_context::request_certificate_chain(std::string& mutable_chain)
 {
-       BOOST_LOG_FUNCTION();
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "KSE : Request certificate chain";
-#endif
+       LOGD("KSE : Request certificate chain");
 
        std::string leaf_cert;
        std::string subca_cert;
@@ -137,10 +121,7 @@ int kse_backend_context::request_certificate_chain(std::string& mutable_chain)
 
        mutable_chain.append(cert_writer.emit_pem());
 
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Requested certificate in " << this;
-#endif
+       LOGD("Requested certificate in " << this);
 
        return 0;
 }
@@ -164,34 +145,31 @@ hal_hash_type _get_hal_hash_type(MessageDigestType digestType) {
 int kse_backend_context::sign_crypto_data(MessageDigestType digestType, const std::string& dataToSign,
                std::string& digestResult)
 {
-       BOOST_LOG_FUNCTION();
        hal_data hashed_data = {NULL, 0, NULL};
        hal_data signed_data = {NULL, 0, NULL};
 
        hashed_data.data = (void *)dataToSign.c_str();
        hashed_data.data_len = dataToSign.size();
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "KSE: Sign " << hashed_data.data_len << " bytes";
+       LOGD("KSE: Sign " << hashed_data.data_len << " bytes");
 
        auto backend = fBackendPtr.lock();
 
        if(!backend) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Unable to acquire backend pointer";
+               LOGE("Unable to acquire backend pointer");
                return -EINVAL;
        }
 
        auto& resolver(backend->get_so_resolver());
 
-#ifdef ENABLE_DEBUG_LOGGING
        try {
                std::string hex;
                boost::algorithm::hex((const unsigned char *)hashed_data.data,
                                (const unsigned char *)hashed_data.data + hashed_data.data_len,
                                std::back_inserter(hex));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Hashed data is " << hex;
+               LOGD("Hashed data is " << hex);
        } catch(...) {
        }
-#endif
 
        const char *method_name = "hal_ecdsa_sign_md";
        hal_ecdsa_mode mode = {HAL_ECDSA_SEC_P256R1, _get_hal_hash_type(digestType)};
@@ -203,28 +181,22 @@ int kse_backend_context::sign_crypto_data(MessageDigestType digestType, const st
        if(error != 0) {
                char buffer[256];
                mbedtls_strerror(error, buffer, sizeof(buffer));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) <<
-                               "Unable to generate ECDSA signature in " <<
-                               this <<
-                               " (" << error << ") : " <<
-                               std::string(buffer);
+               LOGE("Unable to generate ECDSA signature in " << this << " (" << error << ") : " << std::string(buffer));
 
                return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
        }
 
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Signature length is " << signed_data.data_len;
+       LOGD("Signature length is " << signed_data.data_len);
 
        try {
                std::string hex;
                boost::algorithm::hex((const unsigned char *)signed_data.data,
                                (const unsigned char *)signed_data.data + signed_data.data_len,
                                std::back_inserter(hex));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Hex signature is " << hex;
+               LOGD("Hex signature is " << hex);
        } catch(...) {
        }
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "KSE: Generated ECDSA signature";
-#endif
+       LOGD("KSE: Generated ECDSA signature");
 
        digestResult.assign((const char *)signed_data.data, signed_data.data_len);