From 6911e20f59b5804eea399017afc678653f0188f2 Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Wed, 20 Feb 2019 10:08:14 +0100 Subject: Add API for CKM return code descriptions In rare case when DB tool was used for db inspection, and db could not be opened, the commandline interface returned raw error code, without any explanation. Change-Id: If7a29842ae5a7fc2e99a2d991545539704647f3c --- src/include/ckm/ckm-error.h | 15 ++++----- src/manager/CMakeLists.txt | 1 + src/manager/common/ckm-error.cpp | 66 +++++++++++++++++++++++++++++++++++++++ tools/ckm_db_tool/CMakeLists.txt | 1 + tools/ckm_db_tool/ckm_db_tool.cpp | 2 +- 5 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 src/manager/common/ckm-error.cpp diff --git a/src/include/ckm/ckm-error.h b/src/include/ckm/ckm-error.h index 372bd984..788eaef5 100644 --- a/src/include/ckm/ckm-error.h +++ b/src/include/ckm/ckm-error.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 - 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. @@ -20,9 +20,7 @@ #ifndef _CKM_ERROR_H_ #define _CKM_ERROR_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include /** * \name Return Codes @@ -110,8 +108,11 @@ extern "C" { #define CKM_API_ERROR_UNKNOWN -255 /** @}*/ -#ifdef __cplusplus -} -#endif +namespace CKM { + +/*! \brief returns stringified name of return code/status constant */ +KEY_MANAGER_API const char * APICodeToString(int error); + +} // namespace CKM #endif diff --git a/src/manager/CMakeLists.txt b/src/manager/CMakeLists.txt index 53c572c1..d4f67b69 100644 --- a/src/manager/CMakeLists.txt +++ b/src/manager/CMakeLists.txt @@ -26,6 +26,7 @@ SET(COMMON_SOURCES ${COMMON_PATH}/common/pkcs12-impl.cpp ${COMMON_PATH}/common/log-setup.cpp ${COMMON_PATH}/common/ckm-zero-memory.cpp + ${COMMON_PATH}/common/ckm-error.cpp ${COMMON_PATH}/dpl/log/src/abstract_log_provider.cpp ${COMMON_PATH}/dpl/log/src/dlog_log_provider.cpp ${COMMON_PATH}/dpl/log/src/log.cpp diff --git a/src/manager/common/ckm-error.cpp b/src/manager/common/ckm-error.cpp new file mode 100644 index 00000000..520bcbed --- /dev/null +++ b/src/manager/common/ckm-error.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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 ckm-zero-memory.cpp + * @author Tomasz Swierczek (t.swierczek@samsung.com) + * @version 1.0 + */ + +#include + +namespace CKM { + +#define CKM_CODE_DESCRIBE(name) case name: return #name +const char * APICodeToString(int error) { + switch (error) { + CKM_CODE_DESCRIBE(CKM_API_SUCCESS); + CKM_CODE_DESCRIBE(CKM_API_ERROR_SOCKET); + CKM_CODE_DESCRIBE(CKM_API_ERROR_BAD_REQUEST); + CKM_CODE_DESCRIBE(CKM_API_ERROR_BAD_RESPONSE); + CKM_CODE_DESCRIBE(CKM_API_ERROR_SEND_FAILED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_RECV_FAILED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_AUTHENTICATION_FAILED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_INPUT_PARAM); + CKM_CODE_DESCRIBE(CKM_API_ERROR_BUFFER_TOO_SMALL); + CKM_CODE_DESCRIBE(CKM_API_ERROR_OUT_OF_MEMORY); + CKM_CODE_DESCRIBE(CKM_API_ERROR_ACCESS_DENIED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_SERVER_ERROR); + CKM_CODE_DESCRIBE(CKM_API_ERROR_DB_LOCKED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_DB_ERROR); + CKM_CODE_DESCRIBE(CKM_API_ERROR_DB_ALIAS_EXISTS); + CKM_CODE_DESCRIBE(CKM_API_ERROR_DB_ALIAS_UNKNOWN); + CKM_CODE_DESCRIBE(CKM_API_ERROR_VERIFICATION_FAILED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_INVALID_FORMAT); + CKM_CODE_DESCRIBE(CKM_API_ERROR_FILE_ACCESS_DENIED); + CKM_CODE_DESCRIBE(CKM_API_ERROR_NOT_EXPORTABLE); + CKM_CODE_DESCRIBE(CKM_API_ERROR_FILE_SYSTEM); + CKM_CODE_DESCRIBE(CKM_API_ERROR_NOT_SUPPORTED); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_GOOD); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_UNSUPPORTED); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_UNKNOWN); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_REVOKED); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_NET_ERROR); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_INVALID_URL); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_INVALID_RESPONSE); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_REMOTE_ERROR); + CKM_CODE_DESCRIBE(CKM_API_OCSP_STATUS_INTERNAL_ERROR); + CKM_CODE_DESCRIBE(CKM_API_ERROR_UNKNOWN); + default: return "Code not defined"; + } +} +#undef CKM_CODE_DESCRIBE + +} // namespace CKM diff --git a/tools/ckm_db_tool/CMakeLists.txt b/tools/ckm_db_tool/CMakeLists.txt index 33fa991b..a25e4973 100644 --- a/tools/ckm_db_tool/CMakeLists.txt +++ b/tools/ckm_db_tool/CMakeLists.txt @@ -41,6 +41,7 @@ SET(CKM_DB_TOOLS_SOURCES ${PROJECT_SOURCE_DIR}/tools/ckm_db_tool/db-crypto-ext.cpp ${PROJECT_SOURCE_DIR}/tools/ckm_db_tool/ckm-logic-ext.cpp ${PROJECT_SOURCE_DIR}/tools/ckm_db_tool/db-wrapper.cpp + ${KEY_MANAGER_PATH}/common/ckm-error.cpp ${KEY_MANAGER_PATH}/crypto/platform/decider.cpp ${KEY_MANAGER_PATH}/crypto/sw-backend/internals.cpp ${KEY_MANAGER_PATH}/crypto/sw-backend/obj.cpp diff --git a/tools/ckm_db_tool/ckm_db_tool.cpp b/tools/ckm_db_tool/ckm_db_tool.cpp index 2435ee33..0de240d0 100644 --- a/tools/ckm_db_tool/ckm_db_tool.cpp +++ b/tools/ckm_db_tool/ckm_db_tool.cpp @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) int retCode; if (CKM_API_SUCCESS != (retCode = dbw.unlock())) { - cerr << "Unlocking database failed: " << retCode << endl; + cerr << "Unlocking database failed: " << APICodeToString(retCode) << endl; return -1; } -- cgit v1.2.3