From: Tomasz Swierczek Date: Tue, 30 Mar 2021 10:16:11 +0000 (+0200) Subject: Add EXT API backend implementation in dummy backend X-Git-Tag: submit/tizen/20210419.104558^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e07c3e16641bd80826b30024e699ca6d6a95050b;p=platform%2Fcore%2Fsecurity%2Fdevice-certificate-manager-backend.git Add EXT API backend implementation in dummy backend 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 --- diff --git a/src/dummy-backend/CMakeLists.txt b/src/dummy-backend/CMakeLists.txt index 57ec8a9..4d74c39 100644 --- a/src/dummy-backend/CMakeLists.txt +++ b/src/dummy-backend/CMakeLists.txt @@ -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 index 0000000..486299f --- /dev/null +++ b/src/dummy-backend/dcm-backend-api-ext-dummy.cpp @@ -0,0 +1,61 @@ +/****************************************************************** + * Copyright 2021 Samsung Electronics All Rights Reserved. + * + * Author: Tomasz Swierczek + * + * 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 +#include +#include + + +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; +}