Add EXT API backend implementation in dummy backend 81/256181/6 submit/tizen/20210419.104558 submit/tizen/20210510.071600
authorTomasz Swierczek <t.swierczek@samsung.com>
Tue, 30 Mar 2021 10:16:11 +0000 (12:16 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 1 Apr 2021 12:21:44 +0000 (14:21 +0200)
This change is needed to make all DCM API tests pass.
It also serves as an example of EXT API implementation in the backend.

Change-Id: I8dfc135068914f9dda01b6b1004480cf3caf4fc5

src/dummy-backend/CMakeLists.txt
src/dummy-backend/dcm-backend-api-ext-dummy.cpp [new file with mode: 0644]

index 57ec8a9..4d74c39 100644 (file)
@@ -69,6 +69,7 @@ INCLUDE_DIRECTORIES(../shared)
 ADD_LIBRARY(${DCM_BACKEND_API}
        SHARED
        dcm-backend-api-dummy.cpp
+       dcm-backend-api-ext-dummy.cpp
        dummy_backend.cpp
        ../shared/log.cpp
        ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c
diff --git a/src/dummy-backend/dcm-backend-api-ext-dummy.cpp b/src/dummy-backend/dcm-backend-api-ext-dummy.cpp
new file mode 100644 (file)
index 0000000..486299f
--- /dev/null
@@ -0,0 +1,61 @@
+/******************************************************************
+ * Copyright 2021 Samsung Electronics All Rights Reserved.
+ *
+ * Author: Tomasz Swierczek <t.swierczek@samsung.com>
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include <string>
+#include <cstring>
+#include <device-certificate-manager-backend/dcm-ext-backend-api.h>
+
+
+int dcm_ext_backend_call_api(const std::string& method_name,
+                                                        const std::string& input_data,
+                                                        std::string& output_data)
+{
+       if(method_name == "square-int-method") {
+               // method expects one int 'x' and returns one int as 'x*x'
+               int x = *((int*) input_data.c_str());
+               x = x * x;
+               output_data.resize(sizeof(int));
+               memcpy(&output_data[0], &x, sizeof(int));
+               return 0;
+       }
+       if(method_name == "method-with-a-privilege-not-granted") {
+               // no-op, implemented just formally
+               return 0;
+       }
+       // no other methods
+       return -1;
+}
+
+int dcm_ext_backend_get_api_privilege(const std::string& method_name,
+                                                                         std::string& privilege)
+{
+       if(method_name == "method-with-a-privilege-not-granted") {
+               // this privilege is not granted to any label like User System::Privileged etc.
+               // so API test binary will NOT have it when executed from shell
+               privilege = "http://tizen.org/privilege/internal/sysadmin";
+               return 0;
+       }
+       if(method_name == "square-int-method") {
+               // no privileges here as an example for DCM API that does not require any privilege check
+               privilege = "";
+               return 0;
+       }
+       // no other methods
+       return -1;
+}