Add definitions of the new DCM ext API 59/254559/11
authorTomasz Swierczek <t.swierczek@samsung.com>
Thu, 4 Mar 2021 10:19:46 +0000 (11:19 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 1 Apr 2021 11:39:50 +0000 (13:39 +0200)
New API is supposed to give DCM backends possibility
to define any custom method guarded with a Cynara privilege.

New API is not mandatory for plugins - plugins can implement
old, new, or both APIs of DCM.

This commit makes header files available for both: client
and the backend.

The DCM EXT error codes are defined in separate header
for easier management of errors returned from the daemon
to client.

Change-Id: Ia3478d1352f6eabfa913a975f7ee09c02b976939

packaging/device-certificate-manager.spec
src/dcm-client/CMakeLists.txt
src/dcm-client/device_certificate_manager_ext.h [new file with mode: 0644]
src/dcm-client/device_certificate_manager_ext_types.h [new file with mode: 0644]
src/dcm-daemon/CMakeLists.txt
src/dcm-daemon/dcm-ext-backend-api.h [new file with mode: 0644]

index 5a83d8e..1bacc49 100644 (file)
@@ -40,6 +40,14 @@ Requires:    device-certificate-manager = %{version}-%{release}
 %description -n device-certificate-manager-devel
 Device Certificate Manager development headers and libraries
 
+%package -n device-certificate-manager-ext-devel
+Summary:       Device Certificate Manager (development/extension API)
+Group:         Security/Development
+Requires:      device-certificate-manager = %{version}-%{release}
+
+%description -n device-certificate-manager-ext-devel
+Device Certificate Manager development headers and libraries only for extension of the API
+
 %package -n device-certificate-manager-backend-devel
 Summary:       Device Certificate Manager backend (development)
 Group:         Security/Development
@@ -133,10 +141,17 @@ fi
 %{_includedir}/device-certificate-manager/device_certificate_manager.h
 %{_libdir}/pkgconfig/device-certificate-manager.pc
 
+%files ext-devel
+%manifest %{name}.manifest
+%license LICENSE
+%{_includedir}/device-certificate-manager/device_certificate_manager_ext.h
+%{_includedir}/device-certificate-manager/device_certificate_manager_ext_types.h
+
 %files backend-devel
 %manifest %{name}.manifest
 %license LICENSE
 %{_includedir}/device-certificate-manager-backend/dcm-backend-api.h
+%{_includedir}/device-certificate-manager-backend/dcm-ext-backend-api.h
 %{_includedir}/device-certificate-manager-backend/dcm_support.pb.h
 %{_libdir}/pkgconfig/device-certificate-manager-backend.pc
 %{_sysconfdir}/rpm/macros.dcm-backend-api
index b15d8b8..daea88a 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2017 - 2021 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.
@@ -61,6 +61,8 @@ INSTALL(TARGETS ${TARGET_CLIENT}
 
 INSTALL(FILES
        device_certificate_manager.h
+       device_certificate_manager_ext.h
+       device_certificate_manager_ext_types.h
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/device-certificate-manager)
 
 INSTALL(FILES
diff --git a/src/dcm-client/device_certificate_manager_ext.h b/src/dcm-client/device_certificate_manager_ext.h
new file mode 100644 (file)
index 0000000..94f8528
--- /dev/null
@@ -0,0 +1,64 @@
+/******************************************************************
+ *
+ * Copyright 2021 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.
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef __DEVICE_CERTIFICATE_MANAGER_EXT_H__
+#define __DEVICE_CERTIFICATE_MANAGER_EXT_H__
+
+#include <stddef.h>
+
+#include "device_certificate_manager_ext_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @platform
+ * @brief Calls dcm_ext_backend_call_api in the DCM backend with specified method name & arguments.
+ * @since_tizen 6.5
+ * @privlevel platform
+ * @privilege custom one, defined by the backend for given method call
+ *
+ * @remarks To know which privilege is checked on the API call, please consult implementation of given method in DCM backend.
+ * @remarks Both: input and output buffers can be passed as NULLs, if the method doesn't expect or return any data.
+ *
+ * @param[in] method_name  Name of method to be called within DCM backend
+ * @param[in] input_data  Serialized input data for the method call - client should know data format expected by DCM backend
+ * @param[in] input_len  Length of the input data in bytes
+ * @param[out] output_data Output from the DCM backend method call, will be allocated by the library, to be released with free() by client
+ * @param[out] output_len Lenght of the output data in bytes
+ * @return #DCM_EXT_ERROR_NONE on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DCM_EXT_ERROR_NONE Successful
+ * @retval #DCM_EXT_ERROR_INVALID_PARAMETER Input parameter is invalid
+ * @retval #DCM_EXT_ERROR_OUT_OF_MEMORY Out of memory during processing
+ * @retval #DCM_EXT_ERROR_PERMISSION_DENIED Failed to access device certificate manager
+ * @retval #DCM_EXT_ERROR_NOT_SUPPORTED DCM backend supporting the API call requested is not loaded on daemon side
+ * @retval #DCM_EXT_ERROR_SOCKET Socket error between client and server
+ * @retval #DCM_EXT_ERROR_UNKNOWN Unknown error
+ */
+int dcm_ext_call_api(const char* method_name, const char* input_data, size_t input_len,
+                     char** output_data, size_t* output_len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DEVICE_CERTIFICATE_MANAGER_EXT_H__ */
diff --git a/src/dcm-client/device_certificate_manager_ext_types.h b/src/dcm-client/device_certificate_manager_ext_types.h
new file mode 100644 (file)
index 0000000..38a178a
--- /dev/null
@@ -0,0 +1,46 @@
+/******************************************************************
+ *
+ * Copyright 2021 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.
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef __DEVICE_CERTIFICATE_MANAGER_EXT_TYPES_H__
+#define __DEVICE_CERTIFICATE_MANAGER_EXT_TYPES_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for DCM EXT error values.
+ * @since_tizen 6.5
+ */
+typedef enum {
+    DCM_EXT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+    DCM_EXT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */
+    DCM_EXT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+    DCM_EXT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+    DCM_EXT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< DCM backend supporting the API call requested is not loaded on daemon side */
+    DCM_EXT_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown error */
+    DCM_EXT_ERROR_SOCKET = TIZEN_ERROR_DEVICE_CERTIFICATE_MANAGER | 0x01, /**< Socket error between client and server */
+} dcm_ext_error_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DEVICE_CERTIFICATE_MANAGER_EXT_TYPES_H__ */
index aadb2be..856d699 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2017 - 2021 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.
@@ -60,4 +60,5 @@ INSTALL(TARGETS ${TARGET_DAEMON}
 
 INSTALL(FILES
        dcm-backend-api.h
+       dcm-ext-backend-api.h
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/device-certificate-manager-backend)
diff --git a/src/dcm-daemon/dcm-ext-backend-api.h b/src/dcm-daemon/dcm-ext-backend-api.h
new file mode 100644 (file)
index 0000000..3a9038a
--- /dev/null
@@ -0,0 +1,62 @@
+/******************************************************************
+ *
+ * Copyright 2021 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.
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef DCM_EXT_BACKEND_API_H_
+#define DCM_EXT_BACKEND_API_H_
+
+#ifndef API_DCM_EXT_BACKEND_EXPORT
+#define API_DCM_EXT_BACKEND_EXPORT __attribute__((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Calls relevant method/functionality in the backend.
+ * Returns 0 in case of success or other code in case of error.
+ *
+ * If the backend developers wish to return backend-specific
+ * error code to the caller that uses the DCM EXT client libary,
+ * it should be implemented by returning 0 from function below
+ * and returning custom information/data in output_data.
+ *
+ * This function should not throw exceptions.
+ */
+API_DCM_EXT_BACKEND_EXPORT
+int dcm_ext_backend_call_api(const std::string& method_name,
+                             const std::string& input_data,
+                             std::string& output_data);
+
+/*
+ * Returns the privilege that should be checked by Cynara in order for
+ * DCM daemon to allow a client call to the method_name method/functionality.
+ * Can return emtpy string in case no privilege guards access to the method.
+ * Returns 0 in case of success or other code in case of error.
+ *
+ * This function should not throw exceptions.
+ */
+API_DCM_EXT_BACKEND_EXPORT
+int dcm_ext_backend_get_api_privilege(const std::string& method_name,
+                                      std::string& privilege);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DCM_EXT_BACKEND_API_H_ */