From: Krzysztof Jackiewicz Date: Wed, 9 Oct 2019 14:22:54 +0000 (+0200) Subject: Move the logging code to a common directory X-Git-Tag: submit/tizen/20191011.053630^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_5.5;p=platform%2Fcore%2Fsecurity%2Ftrusted%2Fkey-manager-ta.git Move the logging code to a common directory This is to avoid 2-way calls between ta and serialization directories which SAM complains about. Change-Id: Ibac9f6e6bbda7ee37c7bc5591cfa2a480c9c0531 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index eafbd21..46b3b66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ PROJECT("key-manager-ta") SET(KEY_MANAGER_TA_ROOT_PATH ${PROJECT_SOURCE_DIR}) SET(KEY_MANAGER_TA_PATH ${KEY_MANAGER_TA_ROOT_PATH}/ta) SET(KEY_MANAGER_TA_SERIALIZATION_PATH ${KEY_MANAGER_TA_ROOT_PATH}/serialization) +SET(KEY_MANAGER_TA_COMMON_PATH ${KEY_MANAGER_TA_ROOT_PATH}/common) IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG") @@ -34,6 +35,7 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") INCLUDE_DIRECTORIES( ${KEY_MANAGER_TA_PATH}/include ${KEY_MANAGER_TA_SERIALIZATION_PATH}/include + ${KEY_MANAGER_TA_COMMON_PATH}/include ) ADD_DEFINITIONS("-D${CMAKE_BUILD_TYPE}") diff --git a/common/include/log.h b/common/include/log.h new file mode 100644 index 0000000..0c519b7 --- /dev/null +++ b/common/include/log.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/* + * @file log.h + * @author Rafał Tyminski (r.tyminski@partner.samsung.com) + * @version 1.0 + * @brief + */ +#ifndef __LOG_H__ +#define __LOG_H__ + +#include +#include + +void log_msg(const char* type, const char* location, int line, const char* func, + const char* format, ...) +__attribute__((format(printf, 5, 6))); + +#define LOG(...) do { \ + log_msg(" MSG ", __FILE__, __LINE__, __func__, __VA_ARGS__); \ +} while(0) + +#ifdef BUILD_TYPE_DEBUG +#define LOGD(...) do { \ + log_msg("DEBUG", __FILE__, __LINE__, __func__, __VA_ARGS__); \ +} while(0) +#else +#define LOGD(...) do { } while(0) +#endif + +void log_id(const char* prefix, void* id, unsigned int size); + +#ifdef BUILD_TYPE_DEBUG +#define LOGD_ID(prefix, id, size) do {\ + log_id(prefix, id, size);\ +} while(0) +#else +#define LOGD_ID(...) do {} while(0) +#endif + +#endif // __LOG_H__ diff --git a/common/src/log.c b/common/src/log.c new file mode 100644 index 0000000..25ba45d --- /dev/null +++ b/common/src/log.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/* + * @file log.c + * @author Lukasz Kostyra (l.kostyra@samsung.com) + * @version 1.0 + * @brief + */ + +#include "log.h" +#include +#include +#include + +void log_msg(const char* type, const char* location, int line, const char* func, + const char* format, ...) +{ +#ifdef BUILD_TYPE_DEBUG + va_list args; + const size_t logSize = 512; // increase this limit as needed + char logBuffer[logSize]; + + va_start(args, format); + vsnprintf(logBuffer, logSize, format, args); + va_end(args); + + printf("[%s] %s @ %i (%s): %s \n\r", type, location, line, func, logBuffer); + fflush(stdout); +#else +// TODO actually code below is a mitigation for ARM compilation on OpTEE +// TODO this entire ifdef should probably be replaced for TEE-OS specific logging +// TODO but this should be done in separate commit + (void) type; + (void) location; + (void) line; + (void) func; + (void) format; +#endif +} + +void log_id(const char* prefix, void* id, unsigned int size) { +#ifdef BUILD_TYPE_DEBUG + char* out = (char*)malloc(sizeof(char) * (size * 2 + 1)); + for (unsigned int i = 0; i < size; i++) + snprintf(out + i*2, 3, "%02x", ((unsigned char*)id)[i]); + LOGD("%s%s", prefix, out); + free(out); +#else +// TODO actually code below is a mitigation for ARM compilation on OpTEE +// TODO this entire ifdef should probably be replaced for TEE-OS specific logging +// TODO but this should be done in separate commit + (void) prefix; + (void) id; + (void) size; +#endif +} diff --git a/serialization/CMakeLists.txt b/serialization/CMakeLists.txt index 915f412..99640cf 100644 --- a/serialization/CMakeLists.txt +++ b/serialization/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd 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. @@ -21,7 +21,7 @@ SET(TARGET_KEY_MANAGER_TA_SERIALIZATION km_serialization) SET(KEY_MANAGER_TA_SERIALIZATION_SOURCES ${KEY_MANAGER_TA_SERIALIZATION_PATH}/src/km_serialization.c - ${KEY_MANAGER_TA_PATH}/src/log.c + ${KEY_MANAGER_TA_COMMON_PATH}/src/log.c ) SET(KEY_MANAGER_TA_SERIALIZATION_HEADERS diff --git a/ta/CMakeLists.txt b/ta/CMakeLists.txt index 850215b..b473bc3 100644 --- a/ta/CMakeLists.txt +++ b/ta/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd 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. @@ -32,9 +32,9 @@ SET(KEY_MANAGER_TA_SOURCES ${KEY_MANAGER_TA_PATH}/src/crypto_padding.c ${KEY_MANAGER_TA_PATH}/src/crypto_symmetric.c ${KEY_MANAGER_TA_PATH}/src/internal.c - ${KEY_MANAGER_TA_PATH}/src/log.c ${KEY_MANAGER_TA_PATH}/src/km_ta.c ${KEY_MANAGER_TA_PATH}/src/base64.c + ${KEY_MANAGER_TA_COMMON_PATH}/src/log.c ${KEY_MANAGER_TA_SERIALIZATION_PATH}/src/km_serialization.c ) diff --git a/ta/include/log.h b/ta/include/log.h deleted file mode 100644 index 0c519b7..0000000 --- a/ta/include/log.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ -/* - * @file log.h - * @author Rafał Tyminski (r.tyminski@partner.samsung.com) - * @version 1.0 - * @brief - */ -#ifndef __LOG_H__ -#define __LOG_H__ - -#include -#include - -void log_msg(const char* type, const char* location, int line, const char* func, - const char* format, ...) -__attribute__((format(printf, 5, 6))); - -#define LOG(...) do { \ - log_msg(" MSG ", __FILE__, __LINE__, __func__, __VA_ARGS__); \ -} while(0) - -#ifdef BUILD_TYPE_DEBUG -#define LOGD(...) do { \ - log_msg("DEBUG", __FILE__, __LINE__, __func__, __VA_ARGS__); \ -} while(0) -#else -#define LOGD(...) do { } while(0) -#endif - -void log_id(const char* prefix, void* id, unsigned int size); - -#ifdef BUILD_TYPE_DEBUG -#define LOGD_ID(prefix, id, size) do {\ - log_id(prefix, id, size);\ -} while(0) -#else -#define LOGD_ID(...) do {} while(0) -#endif - -#endif // __LOG_H__ diff --git a/ta/src/log.c b/ta/src/log.c deleted file mode 100644 index 25ba45d..0000000 --- a/ta/src/log.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/* - * @file log.c - * @author Lukasz Kostyra (l.kostyra@samsung.com) - * @version 1.0 - * @brief - */ - -#include "log.h" -#include -#include -#include - -void log_msg(const char* type, const char* location, int line, const char* func, - const char* format, ...) -{ -#ifdef BUILD_TYPE_DEBUG - va_list args; - const size_t logSize = 512; // increase this limit as needed - char logBuffer[logSize]; - - va_start(args, format); - vsnprintf(logBuffer, logSize, format, args); - va_end(args); - - printf("[%s] %s @ %i (%s): %s \n\r", type, location, line, func, logBuffer); - fflush(stdout); -#else -// TODO actually code below is a mitigation for ARM compilation on OpTEE -// TODO this entire ifdef should probably be replaced for TEE-OS specific logging -// TODO but this should be done in separate commit - (void) type; - (void) location; - (void) line; - (void) func; - (void) format; -#endif -} - -void log_id(const char* prefix, void* id, unsigned int size) { -#ifdef BUILD_TYPE_DEBUG - char* out = (char*)malloc(sizeof(char) * (size * 2 + 1)); - for (unsigned int i = 0; i < size; i++) - snprintf(out + i*2, 3, "%02x", ((unsigned char*)id)[i]); - LOGD("%s%s", prefix, out); - free(out); -#else -// TODO actually code below is a mitigation for ARM compilation on OpTEE -// TODO this entire ifdef should probably be replaced for TEE-OS specific logging -// TODO but this should be done in separate commit - (void) prefix; - (void) id; - (void) size; -#endif -}