From: Dariusz Michaluk Date: Tue, 26 May 2020 07:13:00 +0000 (+0200) Subject: Dlog logging framework is always available X-Git-Tag: submit/tizen/20200728.071123~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F234410%2F9;p=platform%2Fcore%2Fsecurity%2Fdevice-certificate-manager.git Dlog logging framework is always available DCM is not used outside Tizen, we can use Tizen dlog framework. In the future commits, all BOOST_LOG_* macros should be replaced with unified logging mechanism. Change-Id: Ibc4c9287925268c99c62c386a8ebbc9688b941a5 --- diff --git a/cmake/CheckFrameworks.cmake b/cmake/CheckFrameworks.cmake index 87851a5..9fbea2e 100644 --- a/cmake/CheckFrameworks.cmake +++ b/cmake/CheckFrameworks.cmake @@ -15,7 +15,7 @@ FIND_PACKAGE(Boost REQUIRED FIND_PACKAGE(PkgConfig REQUIRED) -PKG_CHECK_MODULES(DLOG dlog) +PKG_CHECK_MODULES(DLOG REQUIRED dlog) find_package(Protobuf REQUIRED) diff --git a/dcm-client/CMakeLists.txt b/dcm-client/CMakeLists.txt index 8bf27c7..cca4874 100644 --- a/dcm-client/CMakeLists.txt +++ b/dcm-client/CMakeLists.txt @@ -20,11 +20,8 @@ include(GenerateExportHeader) ###### Include and library directories ###### -IF(DLOG_FOUND) - include_directories(${DLOG_INCLUDE_DIRS}) - link_directories(${DLOG_LIBRARY_DIRS}) - add_definitions(-DUSE_DLOG_LOGGING=1) -ENDIF() +INCLUDE_DIRECTORIES(${DLOG_INCLUDE_DIRS}) +LINK_DIRECTORIES(${DLOG_LIBRARY_DIRS}) include_directories(${PROTOBUF_INCLUDE_DIRS}) link_directories(${PROTOBUF_LIBRARY_DIRS}) @@ -62,14 +59,11 @@ target_link_libraries(device-certificate-manager ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIBRARIES} ${MBEDTLS_LIB} - ${MBEDCRYPTO_LIB}) + ${MBEDCRYPTO_LIB} + ${DLOG_LIBRARIES}) set_property(TARGET device-certificate-manager APPEND PROPERTY LINK_FLAGS "-Wl,--no-undefined -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/version_script.lds") -IF(DLOG_FOUND) - target_link_libraries(device-certificate-manager ${DLOG_LIBRARIES}) -ENDIF() - ###### Properties of library ###### set_property(TARGET device-certificate-manager PROPERTY DEFINE_SYMBOL DEVICE_CERTIFICATE_MANAGER_EXPORT) diff --git a/dcm-client/dcmclient.cpp b/dcm-client/dcmclient.cpp index a2e15ec..7a6d4e0 100644 --- a/dcm-client/dcmclient.cpp +++ b/dcm-client/dcmclient.cpp @@ -1,6 +1,6 @@ /****************************************************************** * - * Copyright 2017 - 2018 Samsung Electronics All Rights Reserved. + * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,8 @@ #include #include -#ifdef USE_DLOG_LOGGING #define LOG_TAG "DCM_CLIENT" #include -#endif static_assert(MD_NONE == (unsigned int)MBEDTLS_MD_NONE, "MBEDTLS_MD_NONE mismatch"); static_assert(MD_MD2 == (unsigned int)MBEDTLS_MD_MD2, "MBEDTLS_MD_MD2 mismatch"); @@ -80,9 +78,7 @@ bool dcm_client_connection_impl::create_context(const std::string& serviceName, std::lock_guard locker(fLock); if(fCookie) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Cookie has already been requested for session %p", __FUNCTION__, this); -#endif // Already created return false; } @@ -91,14 +87,10 @@ bool dcm_client_connection_impl::create_context(const std::string& serviceName, try { ensureSocketConnected(); } catch(std::exception& ex) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Caught exception \"%s\" when connecting socket for session %p", __FUNCTION__, ex.what(), this); -#endif return false; } catch(...) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Caught unknown exception when connecting socket for session %p", __FUNCTION__, this); -#endif return false; } } @@ -116,18 +108,14 @@ bool dcm_client_connection_impl::create_context(const std::string& serviceName, sendReceive(request, response); if(!response.has_associate_context()) { -#ifdef USE_DLOG_LOGGING LOGE("%s: received response is not context association message in context %p", __FUNCTION__, this); -#endif return false; } auto& assoc_message(response.associate_context()); if(assoc_message.result() != 0) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Received context association message with error %d in %p", __FUNCTION__, assoc_message.result(), this); -#endif return false; } @@ -135,15 +123,11 @@ bool dcm_client_connection_impl::create_context(const std::string& serviceName, fKeyType = assoc_message.key_type(); fKeyLength = assoc_message.key_length(); } catch(std::exception& ex) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Caught exception \"%s\" when establishing cookie for session %p", __FUNCTION__, ex.what(), this); -#endif fSocket.reset(); return false; } catch(...) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Caught unknown exception when establishing cookie for session %p", __FUNCTION__, this); -#endif fSocket.reset(); return false; } @@ -163,9 +147,7 @@ int dcm_client_connection_impl::get_certificate_chain(std::vector& chai std::lock_guard locker(fLock); if(!fCookie) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Trying to request certificate in session %p without connection", __FUNCTION__, this); -#endif return DCM_ERROR_INVALID_PARAMETER; } @@ -180,26 +162,20 @@ int dcm_client_connection_impl::get_certificate_chain(std::vector& chai sendReceive(request, response); if(!response.has_request_chain()) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Response from server is not certificate chain response on session %p", __FUNCTION__, this); -#endif return DCM_ERROR_NO_DATA; } auto& cert_resp(response.request_chain()); if(cert_resp.result() != 0) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Server can't respond with certificate chain: error %d in session %p", __FUNCTION__, cert_resp.result(), this); -#endif return DCM_ERROR_NO_DATA; } if(cert_resp.cert_chain().size() == 0) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Server can't respond with certificate chain: certificate empty", __FUNCTION__); -#endif return DCM_ERROR_NO_DATA; } @@ -214,24 +190,16 @@ int dcm_client_connection_impl::get_certificate_chain(std::vector& chai chain.push_back(0); } } catch(std::bad_alloc&) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Out of memory when requesting certificate for session %p", __FUNCTION__, this); -#endif return DCM_ERROR_OUT_OF_MEMORY; } catch(std::invalid_argument&) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Invalid argument passed for certificate request for session %p", __FUNCTION__, this); -#endif return DCM_ERROR_INVALID_PARAMETER; } catch(std::exception& ex) { -#ifdef USE_DLOG_LOGGING LOGE("%s: When requesting certificate for session %p received exception : %s", __FUNCTION__, this, ex.what()); -#endif return DCM_ERROR_UNKNOWN; } catch(...) { -#ifdef USE_DLOG_LOGGING LOGE("%s: When requesting certificate for session %p received exception : %s", __FUNCTION__, this, "Unknown error"); -#endif return DCM_ERROR_UNKNOWN; } @@ -252,9 +220,7 @@ int dcm_client_connection_impl::sign_data(mbedtls_md_type_t digestType, const vo std::lock_guard locker(fLock); if(!fCookie) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Trying to request data signing in object %p but there is no connection", __FUNCTION__, this); -#endif return DCM_ERROR_SOCKET; } @@ -263,18 +229,14 @@ int dcm_client_connection_impl::sign_data(mbedtls_md_type_t digestType, const vo */ if(hash_size == 0) { if(digestType == MBEDTLS_MD_NONE) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Digest type is NONE and hash size is 0", __FUNCTION__); -#endif return DCM_ERROR_INVALID_PARAMETER; } const mbedtls_md_info_t * md_info = mbedtls_md_info_from_type(digestType); if(!md_info) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Can't find hash data for digest type %d", __FUNCTION__, digestType); -#endif return DCM_ERROR_INVALID_PARAMETER; } @@ -286,16 +248,12 @@ int dcm_client_connection_impl::sign_data(mbedtls_md_type_t digestType, const vo const mbedtls_md_info_t * md_info = mbedtls_md_info_from_type(digestType); if(!md_info) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Can't find hash data for digest type %d", __FUNCTION__, digestType); -#endif return DCM_ERROR_INVALID_PARAMETER; } if(hash_size != mbedtls_md_get_size(md_info)) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Hash size mismatch. Expected %zd but got %zd", __FUNCTION__, hash_size, (size_t)mbedtls_md_get_size(md_info)); -#endif return DCM_ERROR_INVALID_PARAMETER; } } @@ -313,41 +271,31 @@ int dcm_client_connection_impl::sign_data(mbedtls_md_type_t digestType, const vo sendReceive(request, response); if(!response.has_sign_data()) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Response for hash signature has no signature data", __FUNCTION__); -#endif return DCM_ERROR_INVALID_PARAMETER; } auto& sign_resp(response.sign_data()); if(sign_resp.result() != 0) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Signature request for session %p received error %d", __FUNCTION__, this, sign_resp.result()); -#endif return DCM_ERROR_INVALID_PARAMETER; } const auto& signature = sign_resp.signature(); if(signature.empty()) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Received signature object is empty for session %p", __FUNCTION__, this); -#endif return DCM_ERROR_INVALID_PARAMETER; } digest.resize(signature.size()); memcpy(&digest[0], signature.c_str(), signature.size()); } catch(std::bad_alloc&) { -#ifdef USE_DLOG_LOGGING LOGE("%s: Out of memory when processing sign request for session %p", __FUNCTION__, this); -#endif return DCM_ERROR_OUT_OF_MEMORY; } catch(...) { -#ifdef USE_DLOG_LOGGING LOGE("%s: When processing signature for session %p got exception : %s", __FUNCTION__, this, "Unknown error"); -#endif return DCM_ERROR_UNKNOWN; } diff --git a/dcm-client/device_certificate_manager.cpp b/dcm-client/device_certificate_manager.cpp index e268c3e..dc3ff83 100644 --- a/dcm-client/device_certificate_manager.cpp +++ b/dcm-client/device_certificate_manager.cpp @@ -1,6 +1,6 @@ /****************************************************************** * - * Copyright 2017 - 2018 Samsung Electronics All Rights Reserved. + * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,8 @@ #include #include -#ifdef USE_DLOG_LOGGING #define LOG_TAG "DCM_CLIENT" #include -#endif static mbedtls_md_type_t to_mbedtls_md_type(dcm_digest_algorithm_e md) { @@ -79,23 +77,17 @@ int dcm_create_key_context(const char *service, const char *usage, const char *k context->connection = dcm_client_connection::create(); if(!context->connection->create_context(service_string, usage_string, keytype_string)) { -#ifdef USE_DLOG_LOGGING LOGE("Can't create connection context"); -#endif return DCM_ERROR_SOCKET; } *key_ctx = context.release(); return DCM_ERROR_NONE; } catch(std::exception& ex) { -#ifdef USE_DLOG_LOGGING LOGE("Context creation failure: %s", ex.what()); -#endif return DCM_ERROR_UNKNOWN; } catch(...) { -#ifdef USE_DLOG_LOGGING LOGE("Context creation failure"); -#endif return DCM_ERROR_UNKNOWN; } } diff --git a/dcm-daemon/CMakeLists.txt b/dcm-daemon/CMakeLists.txt index 931b7e6..9ebfe2b 100644 --- a/dcm-daemon/CMakeLists.txt +++ b/dcm-daemon/CMakeLists.txt @@ -27,12 +27,9 @@ add_custom_target(protobuf_generated ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK) -IF(DLOG_FOUND) - include_directories(${DLOG_INCLUDE_DIRS}) - link_directories(${DLOG_LIBRARY_DIRS}) - add_definitions(${DLOG_CFLAGS_OTHER}) - add_definitions(-DUSE_DLOG_LOGGING=1) -ENDIF(DLOG_FOUND) +INCLUDE_DIRECTORIES(${DLOG_INCLUDE_DIRS}) +LINK_DIRECTORIES(${DLOG_LIBRARY_DIRS}) +ADD_DEFINITIONS(${DLOG_CFLAGS_OTHER}) IF(ENABLE_SYSTEMD_SUPPORT) include_directories(${SYSTEMD_INCLUDE_DIRS}) @@ -76,13 +73,10 @@ target_link_libraries(device-certificate-managerd ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} + ${DLOG_LIBRARIES} device-certificate-manager dl) -IF(DLOG_FOUND) - target_link_libraries(device-certificate-managerd ${DLOG_LIBRARIES}) -ENDIF(DLOG_FOUND) - IF(ENABLE_SYSTEMD_SUPPORT) target_link_libraries(device-certificate-managerd ${SYSTEMD_LIBRARIES}) ENDIF(ENABLE_SYSTEMD_SUPPORT) diff --git a/dcm-daemon/boost_log_dlog_sink.h b/dcm-daemon/boost_log_dlog_sink.h index 625c8c0..89f50f3 100644 --- a/dcm-daemon/boost_log_dlog_sink.h +++ b/dcm-daemon/boost_log_dlog_sink.h @@ -1,6 +1,6 @@ /****************************************************************** * - * Copyright 2017 - 2019 Samsung Electronics All Rights Reserved. + * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved. * * Author: Jaroslaw Pelczar * @@ -24,22 +24,7 @@ #include #include -#ifdef USE_DLOG_LOGGING #include -#else -typedef enum { - DLOG_UNKNOWN = 0, /**< Keep this always at the start */ - DLOG_DEFAULT, /**< Default */ - DLOG_VERBOSE, /**< Verbose */ - DLOG_DEBUG, /**< Debug */ - DLOG_INFO, /**< Info */ - DLOG_WARN, /**< Warning */ - DLOG_ERROR, /**< Error */ - DLOG_FATAL, /**< Fatal */ - DLOG_SILENT, /**< Silent */ - DLOG_PRIO_MAX /**< Keep this always at the end. */ -} log_priority; -#endif template class dlog_direct_severity_mapping : public boost::log::sinks::basic_direct_mapping @@ -74,11 +59,7 @@ private: severity_mapper_type level_mapper_; inline void send(log_priority level, string_type const& formatted_message) { -#ifdef USE_DLOG_LOGGING dlog_print(level, log_domain_.c_str(), "%s", formatted_message.c_str()); -#else - fprintf(stderr, "%d/(%s): %s\n", level, log_domain_.c_str(), formatted_message.c_str()); -#endif } public: diff --git a/dcm-daemon/logging.h b/dcm-daemon/logging.h index aaaf23b..bae7977 100644 --- a/dcm-daemon/logging.h +++ b/dcm-daemon/logging.h @@ -1,6 +1,6 @@ /****************************************************************** * - * Copyright 2017 Samsung Electronics All Rights Reserved. + * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved. * * Author: Jaroslaw Pelczar * @@ -32,10 +32,8 @@ #include #include -#ifdef USE_DLOG_LOGGING #define LOG_TAG "DCM_SERVER" #include -#endif enum class log_severity { debug,