summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Swierczek <t.swierczek@samsung.com>2019-02-20 10:08:14 +0100
committerTomasz Swierczek <t.swierczek@samsung.com>2019-02-26 13:29:18 +0100
commit6911e20f59b5804eea399017afc678653f0188f2 (patch)
tree41a4b86bc82bf434abab37a07d5c33388c3d33e6
parent2a92e35ca020ca064ff162334efbfbfdadef8900 (diff)
downloadkey-manager-6911e20f59b5804eea399017afc678653f0188f2.tar.gz
key-manager-6911e20f59b5804eea399017afc678653f0188f2.tar.bz2
key-manager-6911e20f59b5804eea399017afc678653f0188f2.zip
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
-rw-r--r--src/include/ckm/ckm-error.h15
-rw-r--r--src/manager/CMakeLists.txt1
-rw-r--r--src/manager/common/ckm-error.cpp66
-rw-r--r--tools/ckm_db_tool/CMakeLists.txt1
-rw-r--r--tools/ckm_db_tool/ckm_db_tool.cpp2
5 files changed, 77 insertions, 8 deletions
diff --git a/src/include/ckm/ckm-error.h b/src/include/ckm/ckm-error.h
index 372bd98..788eaef 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 <ckm/ckm-type.h>
/**
* \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 53c572c..d4f67b6 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 0000000..520bcbe
--- /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 <ckm/ckm-error.h>
+
+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 33fa991..a25e497 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 2435ee3..0de240d 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;
}