From 4da03ef3abe8a3448e892def3bac899644c4abe4 Mon Sep 17 00:00:00 2001 From: libing23 Date: Thu, 22 Feb 2024 15:37:57 +0800 Subject: [PATCH] hiden symbol Signed-off-by: libing23 --- BUILD.gn | 4 +- bundle.json | 29 --- frameworks/BUILD.gn | 26 +-- .../include/sec_comp_enhance_adapter.h | 8 +- .../src/sec_comp_enhance_adapter.cpp | 8 +- frameworks/enhance_adapter/test/BUILD.gn | 50 +++++ .../src/sec_comp_enhance_adapter_test.cpp | 103 +++++++++++ .../src/sec_comp_enhance_adapter_test.h | 37 ++++ interfaces/inner_api/enhance_kits/BUILD.gn | 14 +- .../include/sec_comp_enhance_kit.h | 4 +- .../include/sec_comp_enhance_kit_c.h | 4 +- .../enhance_kits/src/sec_comp_enhance_kit.cpp | 4 +- .../inner_api/enhance_kits/test/BUILD.gn | 7 +- .../unittest/src/sec_comp_enhance_test.cpp | 119 +----------- .../inner_api/security_component/BUILD.gn | 39 ++-- .../include/location_button.h | 4 +- .../security_component/include/paste_button.h | 4 +- .../security_component/include/save_button.h | 4 +- .../include/sec_comp_base.h | 6 +- .../security_component/include/sec_comp_kit.h | 4 +- .../include/sec_comp_ui_register.h | 4 +- .../security_component/test/BUILD.gn | 21 ++- .../src/sec_comp_register_callback_test.cpp | 173 +++++++++--------- .../security_component_service/sa/BUILD.gn | 33 +++- .../sa/sa_main/delay_exit_task.cpp | 2 +- .../sa/sa_main/delay_exit_task.h | 4 +- .../sa/sa_main/sec_comp_info_helper.h | 4 +- .../sa/sa_main/sec_comp_service.h | 4 +- .../sa/test/BUILD.gn | 8 +- .../unittest/src/sec_comp_entity_test.cpp | 6 +- .../unittest/src/sec_comp_manager_test.cpp | 13 +- .../unittest/src/sec_comp_service_test.cpp | 16 +- .../BUILD.gn | 4 +- .../BUILD.gn | 4 +- .../BUILD.gn | 4 +- .../BUILD.gn | 4 +- .../setenhancecfg_fuzzer/BUILD.gn | 4 +- .../BUILD.gn | 4 +- .../BUILD.gn | 4 +- .../verifysavepermissionInner_fuzzer/BUILD.gn | 4 +- 40 files changed, 429 insertions(+), 369 deletions(-) create mode 100644 frameworks/enhance_adapter/test/BUILD.gn create mode 100644 frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.cpp create mode 100644 frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.h diff --git a/BUILD.gn b/BUILD.gn index 1f7cd3c..11bad1b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -16,7 +16,6 @@ import("//build/ohos.gni") group("security_component_build_module") { if (is_standard_system) { deps = [ - "interfaces/inner_api/enhance_kits:libsecurity_component_enhance_sdk", "interfaces/inner_api/security_component:libsecurity_component_sdk", "services/security_component_service/sa:security_component_service", "services/security_component_service/sa/sa_profile:security_component_sa_profile_standard", @@ -29,6 +28,7 @@ group("security_component_build_module_test") { deps = [] if (is_standard_system) { deps += [ + "frameworks/enhance_adapter/test:unittest", "interfaces/inner_api/enhance_kits/test:unittest", "interfaces/inner_api/security_component/test:unittest", "services/security_component_service/sa/test:unittest", diff --git a/bundle.json b/bundle.json index 17bb881..c3244e1 100644 --- a/bundle.json +++ b/bundle.json @@ -57,35 +57,6 @@ "header_base": "//base/security/security_component_manager/interfaces/inner_api/security_component/include" } }, - { - "name": "//base/security/security_component_manager/interfaces/inner_api/enhance_kits:libsecurity_component_enhance_sdk", - "header": { - "header_files": [ - "sec_comp_enhance_kit.h" - ], - "header_base": "//base/security/security_component_manager/interfaces/inner_api/enhance_kits/include" - } - }, - { - "name": "//base/security/security_component_manager/frameworks:libsecurity_component_framework", - "header": { - "header_files": [ - "location_button.h", - "paste_button.h", - "save_button.h" - ], - "header_base": "//base/security/security_component_manager/interfaces/inner_api/security_component/include" - } - }, - { - "name": "//base/security/security_component_manager/frameworks:libsecurity_component_enhance_adapter", - "header": { - "header_files": [ - "sec_comp_enhance_adapter.h" - ], - "header_base": "//base/security/security_component_manager/frameworks/enhance_adapter/include" - } - }, { "name": "//base/security/security_component_manager/services/security_component_service/sa:security_component_service", "header": { diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index e60bc1b..94f7ec0 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -15,17 +15,16 @@ import("//build/ohos.gni") sec_comp_root_dir = ".." -config("libsecurity_component_framework_config") { +config("security_component_framework_src_set_config") { include_dirs = [ "common/include", "${sec_comp_root_dir}/interfaces/inner_api/security_component/include", ] } -ohos_shared_library("libsecurity_component_framework") { +ohos_source_set("security_component_framework_src_set") { subsystem_name = "security" part_name = "security_component_manager" - output_name = "libsecurity_component_framework" sanitize = { cfi = true cfi_cross_dso = true @@ -49,17 +48,20 @@ ohos_shared_library("libsecurity_component_framework") { ] configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] - public_configs = [ ":libsecurity_component_framework_config" ] + public_configs = [ ":security_component_framework_src_set_config" ] external_deps = [ "c_utils:utils", "hilog:libhilog", ] - cflags_cc = [ "-DHILOG_ENABLE" ] + cflags_cc = [ + "-DHILOG_ENABLE", + "-fvisibility=hidden", + ] } -config("libsecurity_component_enhance_adapter_config") { +config("security_component_enhance_adapter_src_set_config") { include_dirs = [ "common/include", "enhance_adapter/include", @@ -68,10 +70,9 @@ config("libsecurity_component_enhance_adapter_config") { ] } -ohos_shared_library("libsecurity_component_enhance_adapter") { +ohos_source_set("security_component_enhance_adapter_src_set") { subsystem_name = "security" part_name = "security_component_manager" - output_name = "libsecurity_component_enhance_adapter" sanitize = { cfi = true cfi_cross_dso = true @@ -88,7 +89,7 @@ ohos_shared_library("libsecurity_component_enhance_adapter") { sources = [ "enhance_adapter/src/sec_comp_enhance_adapter.cpp" ] configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] - public_configs = [ ":libsecurity_component_enhance_adapter_config" ] + public_configs = [ ":security_component_enhance_adapter_src_set_config" ] external_deps = [ "c_utils:utils", @@ -96,7 +97,10 @@ ohos_shared_library("libsecurity_component_enhance_adapter") { "ipc:ipc_single", ] - cflags_cc = [ "-DHILOG_ENABLE" ] + cflags_cc = [ + "-DHILOG_ENABLE", + "-fvisibility=hidden", + ] if (current_cpu == "arm64") { defines = [ "_ARM64_" ] diff --git a/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h b/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h index 81c3e08..2e96372 100644 --- a/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h +++ b/frameworks/enhance_adapter/include/sec_comp_enhance_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -110,13 +110,13 @@ public: static void AddSecurityComponentProcess(int32_t pid); - static SecCompInputEnhanceInterface* inputHandler; + static __attribute__((visibility("default"))) SecCompInputEnhanceInterface* inputHandler; static bool isEnhanceInputHandlerInit; - static SecCompSrvEnhanceInterface* srvHandler; + static __attribute__((visibility("default"))) SecCompSrvEnhanceInterface* srvHandler; static bool isEnhanceSrvHandlerInit; - static SecCompClientEnhanceInterface* clientHandler; + static __attribute__((visibility("default"))) SecCompClientEnhanceInterface* clientHandler; static bool isEnhanceClientHandlerInit; static std::mutex initMtx; diff --git a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp index 5dfa2e9..2e4c321 100644 --- a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp +++ b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -30,9 +30,9 @@ static const std::string LIB_PATH = "/system/lib64/"; #else static const std::string LIB_PATH = "/system/lib/"; #endif -static const std::string ENHANCE_INPUT_INTERFACE_LIB = LIB_PATH + "libsec_comp_input_enhance.z.so"; -static const std::string ENHANCE_SRV_INTERFACE_LIB = LIB_PATH + "libsec_comp_service_enhance.z.so"; -static const std::string ENHANCE_CLIENT_INTERFACE_LIB = LIB_PATH + "libsec_comp_client_enhance.z.so"; +static const std::string ENHANCE_INPUT_INTERFACE_LIB = LIB_PATH + "libsecurity_component_client_enhance.z.so"; +static const std::string ENHANCE_SRV_INTERFACE_LIB = LIB_PATH + "libsecurity_component_service_enhance.z.so"; +static const std::string ENHANCE_CLIENT_INTERFACE_LIB = LIB_PATH + "libsecurity_component_client_enhance.z.so"; } SecCompInputEnhanceInterface* SecCompEnhanceAdapter::inputHandler = nullptr; diff --git a/frameworks/enhance_adapter/test/BUILD.gn b/frameworks/enhance_adapter/test/BUILD.gn new file mode 100644 index 0000000..375300c --- /dev/null +++ b/frameworks/enhance_adapter/test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# 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. + +import("//build/test.gni") + +sec_comp_root_dir = "../../.." + +ohos_unittest("sec_comp_enhance_adapter_test") { + subsystem_name = "security" + part_name = "security_component_manager" + module_out_path = part_name + "/" + part_name + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + include_dirs = [ "unittest/src" ] + + sources = [ "unittest/src/sec_comp_enhance_adapter_test.cpp" ] + + configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] + cflags_cc = [ "-DHILOG_ENABLE" ] + + deps = [ "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + ] + if (current_cpu == "arm64") { + defines = [ "_ARM64_" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":sec_comp_enhance_adapter_test" ] +} diff --git a/frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.cpp b/frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.cpp new file mode 100644 index 0000000..73b957e --- /dev/null +++ b/frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 "sec_comp_enhance_adapter_test.h" +#include +#include "sec_comp_err.h" +#include "sec_comp_log.h" +#include "sec_comp_info.h" + +using namespace testing::ext; +using namespace OHOS::Security::SecurityComponent; + +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompEnhanceAdapterTest"}; +static constexpr uint32_t SEC_COMP_ENHANCE_CFG_SIZE = 76; +static constexpr uint32_t MAX_HMAC_SIZE = 64; +} // namespace + +void SecCompEnhanceAdapterTest::SetUpTestCase() +{ + SC_LOG_INFO(LABEL, "SetUpTestCase."); +} + +void SecCompEnhanceAdapterTest::TearDownTestCase() +{ + SC_LOG_INFO(LABEL, "TearDownTestCase."); +} + +void SecCompEnhanceAdapterTest::SetUp() +{ + SC_LOG_INFO(LABEL, "SetUp ok."); +} + +void SecCompEnhanceAdapterTest::TearDown() +{ + SC_LOG_INFO(LABEL, "TearDown."); +} + +/** + * @tc.name: EnhanceAdapter001 + * @tc.desc: test enhance adapter fail + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SecCompEnhanceAdapterTest, EnhanceAdapter001, TestSize.Level1) +{ + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + EXPECT_EQ(SecCompEnhanceAdapter::EnableInputEnhance(), SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE); + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + EXPECT_EQ(SecCompEnhanceAdapter::DisableInputEnhance(), SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE); + + SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; + uint8_t cfgData[SEC_COMP_ENHANCE_CFG_SIZE] = { 0 }; + EXPECT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, + SecCompEnhanceAdapter::SetEnhanceCfg(cfgData, SEC_COMP_ENHANCE_CFG_SIZE)); + + SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; + uint8_t originData[MAX_HMAC_SIZE] = { 0 }; + uint32_t enHancedataLen = MAX_HMAC_SIZE; + EXPECT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, + SecCompEnhanceAdapter::GetPointerEventEnhanceData(originData, MAX_HMAC_SIZE, nullptr, enHancedataLen)); + + SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; + SecCompClickEvent touchInfo; + ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, SecCompEnhanceAdapter::CheckExtraInfo(touchInfo)); + + SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false; + std::string componentInfo; + SecCompEnhanceAdapter::EnhanceDataPreprocess(1, componentInfo); + + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + ASSERT_EQ(nullptr, SecCompEnhanceAdapter::GetEnhanceRemoteObject()); + + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + SecCompEnhanceAdapter::StartEnhanceService(); + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + SecCompEnhanceAdapter::ExistEnhanceService(); + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + SecCompEnhanceAdapter::NotifyProcessDied(0); + SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false; + SecCompEnhanceAdapter::RegisterScIdEnhance(0); + SecCompEnhanceAdapter::isEnhanceClientHandlerInit = false; + SecCompEnhanceAdapter::UnregisterScIdEnhance(0); + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + SecCompEnhanceAdapter::AddSecurityComponentProcess(0); + SecCompEnhanceAdapter::isEnhanceSrvHandlerInit = false; + std::shared_ptr compInfo; + const nlohmann::json jsonComponent; + ASSERT_EQ(SC_OK, SecCompEnhanceAdapter::CheckComponentInfoEnhnace(0, compInfo, jsonComponent)); +} diff --git a/frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.h b/frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.h new file mode 100644 index 0000000..34a3362 --- /dev/null +++ b/frameworks/enhance_adapter/test/unittest/src/sec_comp_enhance_adapter_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 SECURITY_COMPONENT_ENHANCE_ADAPTER_TEST +#define SECURITY_COMPONENT_ENHANCE_ADAPTER_TEST + +#include +#include "sec_comp_enhance_adapter.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +class SecCompEnhanceAdapterTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS +#endif // SECURITY_COMPONENT_ENHANCE_ADAPTER_TEST diff --git a/interfaces/inner_api/enhance_kits/BUILD.gn b/interfaces/inner_api/enhance_kits/BUILD.gn index 70ae3f3..4c4d7e4 100644 --- a/interfaces/inner_api/enhance_kits/BUILD.gn +++ b/interfaces/inner_api/enhance_kits/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -24,10 +24,9 @@ config("sec_comp_enhance_config") { ] } -ohos_shared_library("libsecurity_component_enhance_sdk") { +ohos_source_set("security_component_enhance_sdk_src_set") { subsystem_name = "security" part_name = "security_component_manager" - output_name = "libsecurity_component_enhance_sdk" sanitize = { cfi = true cfi_cross_dso = true @@ -44,9 +43,7 @@ ohos_shared_library("libsecurity_component_enhance_sdk") { sources = [ "src/sec_comp_enhance_kit.cpp" ] - deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", - ] + deps = [ "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set" ] configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] @@ -56,5 +53,8 @@ ohos_shared_library("libsecurity_component_enhance_sdk") { "ipc:ipc_single", ] - cflags_cc = [ "-DHILOG_ENABLE" ] + cflags_cc = [ + "-DHILOG_ENABLE", + "-fvisibility=hidden", + ] } diff --git a/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit.h b/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit.h index 11f46ee..9e6b300 100644 --- a/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit.h +++ b/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -20,7 +20,7 @@ namespace OHOS { namespace Security { namespace SecurityComponent { -struct SecCompEnhanceKit { +struct __attribute__((visibility("default"))) SecCompEnhanceKit { static void InitClientEnhance(); static int32_t SetEnhanceCfg(uint8_t* cfg, uint32_t cfgLen); static int32_t GetPointerEventEnhanceData(void* data, uint32_t dataLen, diff --git a/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit_c.h b/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit_c.h index c7e0c6f..08b0164 100644 --- a/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit_c.h +++ b/interfaces/inner_api/enhance_kits/include/sec_comp_enhance_kit_c.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -15,7 +15,7 @@ #ifndef SECURITY_COMPONENT_ENHANCE_KIT_C_H #define SECURITY_COMPONENT_ENHANCE_KIT_C_H -void InitSecCompClientEnhance(void); +__attribute__((visibility("default"))) void InitSecCompClientEnhance(void); #endif // SECURITY_COMPONENT_ENHANCE_KIT_C_H diff --git a/interfaces/inner_api/enhance_kits/src/sec_comp_enhance_kit.cpp b/interfaces/inner_api/enhance_kits/src/sec_comp_enhance_kit.cpp index 4b16511..3e099f4 100644 --- a/interfaces/inner_api/enhance_kits/src/sec_comp_enhance_kit.cpp +++ b/interfaces/inner_api/enhance_kits/src/sec_comp_enhance_kit.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -17,7 +17,7 @@ #include "sec_comp_enhance_adapter.h" -extern "C" void InitSecCompClientEnhance() +extern "C" __attribute__((visibility("default"))) void InitSecCompClientEnhance() { OHOS::Security::SecurityComponent::SecCompEnhanceKit::InitClientEnhance(); } diff --git a/interfaces/inner_api/enhance_kits/test/BUILD.gn b/interfaces/inner_api/enhance_kits/test/BUILD.gn index 4f849a5..a82de68 100644 --- a/interfaces/inner_api/enhance_kits/test/BUILD.gn +++ b/interfaces/inner_api/enhance_kits/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -32,10 +32,7 @@ ohos_unittest("sec_comp_enhance_sdk_test") { configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] cflags_cc = [ "-DHILOG_ENABLE" ] - deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", - "${sec_comp_root_dir}/interfaces/inner_api/enhance_kits:libsecurity_component_enhance_sdk", - ] + deps = [ "${sec_comp_root_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk" ] external_deps = [ "c_utils:utils", diff --git a/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp b/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp index 9ac2300..d17f3e0 100644 --- a/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp +++ b/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -32,8 +32,8 @@ static const std::string LIB_PATH = "/system/lib64/"; #else static const std::string LIB_PATH = "/system/lib/"; #endif -static const std::string ENHANCE_INPUT_INTERFACE_LIB = LIB_PATH + "libsec_comp_input_enhance.z.so"; -static const std::string ENHANCE_SRV_INTERFACE_LIB = LIB_PATH + "libsec_comp_service_enhance.z.so"; +static const std::string ENHANCE_INPUT_INTERFACE_LIB = LIB_PATH + "libsecurity_component_client_enhance.z.so"; +static const std::string ENHANCE_SRV_INTERFACE_LIB = LIB_PATH + "libsecurity_component_service_enhance.z.so"; static constexpr uint32_t MAX_HMAC_SIZE = 64; } // namespace @@ -102,116 +102,3 @@ HWTEST_F(SecCompEnhanceTest, GetPoniterEventEnhanceData001, TestSize.Level1) EXPECT_EQ(result, SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE); } } - -/** - * @tc.name: EnableInputEnhance001 - * @tc.desc: test UnmarshallEnhanceCfg - * @tc.type: FUNC - * @tc.require: AR000HO9IN - */ -HWTEST_F(SecCompEnhanceTest, EnableInputEnhance001, TestSize.Level1) -{ - int32_t result = SecCompEnhanceAdapter::EnableInputEnhance(); - if (g_srvEnhanceExist) { - EXPECT_EQ(result, SC_OK); - } else { - EXPECT_EQ(result, SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE); - } -} - -/** - * @tc.name: DisableInputEnhance001 - * @tc.desc: test DisableInputEnhance - * @tc.type: FUNC - * @tc.require: AR000HO9IN - */ -HWTEST_F(SecCompEnhanceTest, DisableInputEnhance001, TestSize.Level1) -{ - int32_t result = SecCompEnhanceAdapter::DisableInputEnhance(); - if (g_srvEnhanceExist) { - EXPECT_EQ(result, SC_OK); - } else { - EXPECT_EQ(result, SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE); - } -} - -/** - * @tc.name: InitEnhanceHandler001 - * @tc.desc: test InitEnhanceHandler - * @tc.type: FUNC - * @tc.require: AR000HO9IN - */ -HWTEST_F(SecCompEnhanceTest, InitEnhanceHandler001, TestSize.Level1) -{ - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - uint8_t originData[16] = { 0 }; - uint32_t dataLen = 16; - uint8_t* enhanceData = nullptr; - uint32_t enHancedataLen = MAX_HMAC_SIZE; - ASSERT_NE(SC_OK, - SecCompEnhanceAdapter::GetPointerEventEnhanceData(originData, dataLen, enhanceData, enHancedataLen)); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompClickEvent touchInfo; - ASSERT_NE(SC_OK, SecCompEnhanceAdapter::CheckExtraInfo(touchInfo)); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - - std::string componentInfo; - int32_t scId = 1; - SecCompEnhanceAdapter::EnhanceDataPreprocess(scId, componentInfo); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompEnhanceAdapter::RegisterScIdEnhance(scId); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompEnhanceAdapter::DisableInputEnhance(); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompEnhanceAdapter::StartEnhanceService(); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompEnhanceAdapter::ExistEnhanceService(); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompEnhanceAdapter::NotifyProcessDied(scId); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - std::shared_ptr compInfo; - const nlohmann::json jsonComponent; - SecCompEnhanceAdapter::CheckComponentInfoEnhnace(scId, compInfo, jsonComponent); - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = false; - SecCompEnhanceAdapter::GetEnhanceRemoteObject(); -} - -/** - * @tc.name: InitEnhanceHandler002 - * @tc.desc: test InitEnhanceHandler - * @tc.type: FUNC - * @tc.require: AR000HO9IN - */ -HWTEST_F(SecCompEnhanceTest, InitEnhanceHandler002, TestSize.Level1) -{ - SecCompEnhanceAdapter::isEnhanceInputHandlerInit = true; - uint8_t cfgData[SEC_COMP_ENHANCE_CFG_SIZE] = { 0 }; - SecCompEnhanceAdapter::inputHandler = nullptr; - ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, - SecCompEnhanceAdapter::SetEnhanceCfg(cfgData, SEC_COMP_ENHANCE_CFG_SIZE)); - uint8_t originData[16] = { 0 }; - uint32_t dataLen = 16; - uint8_t* enhanceData = nullptr; - uint32_t enHancedataLen = MAX_HMAC_SIZE; - ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, - SecCompEnhanceAdapter::GetPointerEventEnhanceData(originData, dataLen, enhanceData, enHancedataLen)); - SecCompClickEvent touchInfo; - SecCompEnhanceAdapter::srvHandler = nullptr; - ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, SecCompEnhanceAdapter::CheckExtraInfo(touchInfo)); - std::string componentInfo; - int32_t scId = 1; - SecCompEnhanceAdapter::clientHandler = nullptr; - ASSERT_TRUE(SecCompEnhanceAdapter::EnhanceDataPreprocess(componentInfo)); - ASSERT_TRUE(SecCompEnhanceAdapter::EnhanceDataPreprocess(scId, componentInfo)); - SecCompEnhanceAdapter::RegisterScIdEnhance(scId); - ASSERT_EQ(SecCompEnhanceAdapter::srvHandler, nullptr); - ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, SecCompEnhanceAdapter::EnableInputEnhance()); - ASSERT_EQ(SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE, SecCompEnhanceAdapter::DisableInputEnhance()); - SecCompEnhanceAdapter::StartEnhanceService(); - SecCompEnhanceAdapter::ExistEnhanceService(); - SecCompEnhanceAdapter::NotifyProcessDied(scId); - std::shared_ptr compInfo; - const nlohmann::json jsonComponent; - ASSERT_EQ(SC_OK, SecCompEnhanceAdapter::CheckComponentInfoEnhnace(scId, compInfo, jsonComponent)); - ASSERT_EQ(nullptr, SecCompEnhanceAdapter::GetEnhanceRemoteObject()); -} diff --git a/interfaces/inner_api/security_component/BUILD.gn b/interfaces/inner_api/security_component/BUILD.gn index 41cef61..952e11c 100644 --- a/interfaces/inner_api/security_component/BUILD.gn +++ b/interfaces/inner_api/security_component/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -20,21 +20,23 @@ config("sec_comp_config") { include_dirs = [ "include", "${sec_comp_root_dir}/frameworks/common/include", + "${sec_comp_root_dir}/frameworks/enhance_adapter/include/", + "${sec_comp_root_dir}/interfaces/inner_api/enhance_kits/include", "//third_party/json/include", ] } -ohos_shared_library("libsecurity_component_sdk") { +ohos_source_set("security_component_sdk_src_set") { subsystem_name = "security" part_name = "security_component_manager" - output_name = "libsecurity_component_sdk" - - public_configs = [ ":sec_comp_config" ] include_dirs = [ "include", "${sec_comp_root_dir}/frameworks/common/include", + "${sec_comp_root_dir}/frameworks/enhance_adapter/include/", + "${sec_comp_root_dir}/interfaces/inner_api/enhance_kits/include", "${sec_comp_root_dir}/frameworks/security_component/include", + "//third_party/json/include", ] sources = [ @@ -47,11 +49,6 @@ ohos_shared_library("libsecurity_component_sdk") { "src/sec_comp_ui_register.cpp", ] - deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", - "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", - ] - configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] external_deps = [ @@ -63,5 +60,25 @@ ohos_shared_library("libsecurity_component_sdk") { "samgr:samgr_proxy", ] - cflags_cc = [ "-DHILOG_ENABLE" ] + cflags_cc = [ + "-DHILOG_ENABLE", + "-fvisibility=hidden", + ] +} + +ohos_shared_library("libsecurity_component_sdk") { + subsystem_name = "security" + part_name = "security_component_manager" + output_name = "libsecurity_component_sdk" + + public_configs = [ ":sec_comp_config" ] + + deps = [ + ":security_component_sdk_src_set", + "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set", + "${sec_comp_root_dir}/frameworks:security_component_framework_src_set", + "${sec_comp_root_dir}/interfaces/inner_api/enhance_kits:security_component_enhance_sdk_src_set", + ] + + configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] } diff --git a/interfaces/inner_api/security_component/include/location_button.h b/interfaces/inner_api/security_component/include/location_button.h index a98772f..9788b0c 100644 --- a/interfaces/inner_api/security_component/include/location_button.h +++ b/interfaces/inner_api/security_component/include/location_button.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -44,7 +44,7 @@ enum class LocationIcon : int32_t { MAX_ICON_TYPE }; -class LocationButton : public SecCompBase { +class __attribute__((visibility("default"))) LocationButton : public SecCompBase { public: virtual bool IsTextIconTypeValid() override; virtual bool IsCorrespondenceType() override; diff --git a/interfaces/inner_api/security_component/include/paste_button.h b/interfaces/inner_api/security_component/include/paste_button.h index 11b243f..0e43c8f 100644 --- a/interfaces/inner_api/security_component/include/paste_button.h +++ b/interfaces/inner_api/security_component/include/paste_button.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -33,7 +33,7 @@ enum class PasteIcon : int32_t { MAX_ICON_TYPE }; -class PasteButton : public SecCompBase { +class __attribute__((visibility("default"))) PasteButton : public SecCompBase { public: virtual bool IsTextIconTypeValid() override; virtual bool IsCorrespondenceType() override; diff --git a/interfaces/inner_api/security_component/include/save_button.h b/interfaces/inner_api/security_component/include/save_button.h index 126b690..e1f45e6 100644 --- a/interfaces/inner_api/security_component/include/save_button.h +++ b/interfaces/inner_api/security_component/include/save_button.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -41,7 +41,7 @@ enum class SaveIcon : int32_t { MAX_ICON_TYPE }; -class SaveButton : public SecCompBase { +class __attribute__((visibility("default"))) SaveButton : public SecCompBase { public: virtual bool IsTextIconTypeValid() override; virtual bool IsCorrespondenceType() override; diff --git a/interfaces/inner_api/security_component/include/sec_comp_base.h b/interfaces/inner_api/security_component/include/sec_comp_base.h index db539bd..30d15fe 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -35,7 +35,7 @@ enum class SecCompBackground { MAX_BG_TYPE }; -class JsonTagConstants final { +class __attribute__((visibility("default"))) JsonTagConstants final { public: static const std::string JSON_RECT; static const std::string JSON_SC_TYPE; @@ -74,7 +74,7 @@ public: static const std::string JSON_WINDOW_ID; }; -class SecCompBase { +class __attribute__((visibility("default"))) SecCompBase { public: SecCompBase() = default; virtual ~SecCompBase() = default; diff --git a/interfaces/inner_api/security_component/include/sec_comp_kit.h b/interfaces/inner_api/security_component/include/sec_comp_kit.h index 93c7e53..d5fd276 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -24,7 +24,7 @@ namespace OHOS { namespace Security { namespace SecurityComponent { -class SecCompKit { +class __attribute__((visibility("default"))) SecCompKit { public: static int32_t RegisterSecurityComponent(SecCompType type, std::string& componentInfo, int32_t& scId); static int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo); diff --git a/interfaces/inner_api/security_component/include/sec_comp_ui_register.h b/interfaces/inner_api/security_component/include/sec_comp_ui_register.h index b415bb1..27660f8 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_ui_register.h +++ b/interfaces/inner_api/security_component/include/sec_comp_ui_register.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -20,7 +20,7 @@ namespace OHOS { namespace Security { namespace SecurityComponent { -class SecCompUiRegister { +class __attribute__((visibility("default"))) SecCompUiRegister { public: SecCompUiRegister(std::vector& callerList, ISecCompProbe* probe); virtual ~SecCompUiRegister() = default; diff --git a/interfaces/inner_api/security_component/test/BUILD.gn b/interfaces/inner_api/security_component/test/BUILD.gn index c7363f6..bd7abaa 100644 --- a/interfaces/inner_api/security_component/test/BUILD.gn +++ b/interfaces/inner_api/security_component/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -42,8 +42,10 @@ ohos_unittest("sec_comp_sdk_test") { } deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", - "${sec_comp_root_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk", + "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set", + "${sec_comp_root_dir}/frameworks:security_component_framework_src_set", + "${sec_comp_root_dir}/interfaces/inner_api/enhance_kits:security_component_enhance_sdk_src_set", + "${sec_comp_root_dir}/interfaces/inner_api/security_component:security_component_sdk_src_set", ] external_deps = [ @@ -52,6 +54,7 @@ ohos_unittest("sec_comp_sdk_test") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "samgr:samgr_proxy", ] } @@ -71,17 +74,16 @@ ohos_unittest("sec_comp_register_callback_test") { "unittest/src/test_common.cpp", ] configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] - cflags_cc = [ "-DHILOG_ENABLE" ] + cflags_cc = [ + "-DHILOG_ENABLE", + "-O0", + ] if (security_component_enhance_enable) { cflags_cc += [ "-DSECURITY_COMPONENT_ENHANCE_ENABLE" ] } - deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", - "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", - "${sec_comp_root_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk", - ] + deps = [ "${sec_comp_root_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -90,6 +92,7 @@ ohos_unittest("sec_comp_register_callback_test") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "samgr:samgr_proxy", ] } diff --git a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp index 5cbf7b7..aff7413 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -15,23 +15,22 @@ #include #include "i_sec_comp_probe.h" #include "location_button.h" -#define private public -#include "sec_comp_caller_authorization.h" -#include "sec_comp_client.h" -#undef private #include "sec_comp_enhance_adapter.h" +#include "sec_comp_enhance_kit.h" #include "sec_comp_err.h" #include "sec_comp_info.h" #include "sec_comp_kit.h" #include "sec_comp_log.h" #include "sec_comp_tool.h" #include "sec_comp_ui_register.h" +#include "system_ability_load_callback_stub.h" #include "test_common.h" #include "token_setproc.h" using namespace testing::ext; using namespace OHOS::Security::SecurityComponent; using namespace OHOS::Security::AccessToken; +using namespace OHOS; namespace { static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { @@ -51,12 +50,36 @@ public: }; static MockUiSecCompProbe g_probe; + +static __attribute__((noinline)) int32_t RegisterSecurityComponent( + SecCompType type, std::string& componentInfo, int32_t& scId) +{ + SC_LOG_INFO(LABEL, "RegisterSecurityComponent enter"); + return SecCompKit::RegisterSecurityComponent(type, componentInfo, scId); +} + +static __attribute__((noinline)) int32_t ReportSecurityComponentClickEvent( + int32_t scId, std::string& componentInfo, + const SecCompClickEvent& clickInfo, sptr callerToken) +{ + SC_LOG_INFO(LABEL, "ReportSecurityComponentClickEvent enter"); + return SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken); +} + +static __attribute__((noinline)) int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo) +{ + SC_LOG_INFO(LABEL, "UpdateSecurityComponent enter"); + return SecCompKit::UpdateSecurityComponent(scId, componentInfo); +} + static void InitUiRegister() { - std::vector callerList; + std::vector callerList = { + reinterpret_cast(RegisterSecurityComponent), + reinterpret_cast(ReportSecurityComponentClickEvent), + reinterpret_cast(UpdateSecurityComponent) + }; SecCompUiRegister registerCallback(callerList, &g_probe); - SecCompCallerAuthorization::GetInstance().kitCallerList_.clear(); - SecCompCallerAuthorization::GetInstance().isInit_ = false; } } // namespace @@ -96,32 +119,6 @@ void SecCompRegisterCallbackTest::TearDown() SC_LOG_INFO(LABEL, "TearDown."); } -/** - * @tc.name: RegisterWithoutPreprocess001 - * @tc.desc: test register without preprocess - * @tc.type: FUNC - * @tc.require: AR000HO9JM - */ -HWTEST_F(SecCompRegisterCallbackTest, RegisterWithoutPreprocess001, TestSize.Level1) -{ - nlohmann::json jsonRes; - TestCommon::BuildLocationComponentInfo(jsonRes); - std::string locationInfo = jsonRes.dump(); - - SecCompEnhanceAdapter::InitEnhanceHandler(SEC_COMP_ENHANCE_CLIENT_INTERFACE); - int32_t scId; -#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - ASSERT_EQ(SC_ENHANCE_ERROR_CHALLENGE_CHECK_FAIL, - SecCompClient::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); - ASSERT_EQ(-1, scId); -#else - ASSERT_EQ(SC_OK, - SecCompClient::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); - ASSERT_NE(-1, scId); - EXPECT_EQ(SC_OK, SecCompClient::GetInstance().UnregisterSecurityComponent(scId)); -#endif -} - /** * @tc.name: RegisterSecurityComponent001 * @tc.desc: test register security component success. @@ -137,7 +134,7 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent001, TestSize.Lev g_probe.mockRes = 0; int32_t scId; - ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_NE(-1, scId); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -160,11 +157,11 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent002, TestSize.Lev int32_t scId; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_ENHANCE_ERROR_CALLBACK_OPER_FAIL, - SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_EQ(-1, scId); #else ASSERT_EQ(SC_OK, - SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_NE(-1, scId); ASSERT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); #endif @@ -185,7 +182,7 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent003, TestSize.Lev g_probe.mockRes = 0; int32_t scId; - ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -203,7 +200,7 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev std::string saveInfo = jsonRes.dump(); int32_t scId; - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -215,11 +212,11 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -238,7 +235,7 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev std::string saveInfo = jsonRes.dump(); int32_t scId; - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -249,11 +246,11 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev }; clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -271,7 +268,7 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent006, TestSize.Lev std::string saveInfo = jsonRes.dump(); int32_t scId; setuid(100); - EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); } /** @@ -288,7 +285,7 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test std::string saveInfo = jsonRes.dump(); int32_t scId; - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -300,11 +297,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); uint32_t selfTokenId = GetSelfTokenID(); ASSERT_FALSE(SecCompKit::VerifySavePermission(selfTokenId)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -326,7 +323,7 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test int32_t scId; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -339,11 +336,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test clickInfo.extraInfo.data = data; setuid(100); - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); setuid(g_selfUid); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); @@ -363,7 +360,7 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test int32_t scId; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -372,11 +369,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test .point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT }; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -396,7 +393,7 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 g_probe.mockRes = 0; int32_t scId; - ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_NE(-1, scId); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { @@ -408,11 +405,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 }; clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -432,7 +429,7 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) int32_t scId; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -443,11 +440,11 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) }; clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); setuid(100); ASSERT_FALSE(SecCompKit::VerifySavePermission(TestCommon::HAP_TOKEN_ID)); // mediaLibraryTokenId_ != 0 @@ -471,7 +468,7 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) std::string saveInfo = jsonRes.dump(); int32_t scId; - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -482,11 +479,11 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) }; clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); ASSERT_FALSE(SecCompKit::VerifySavePermission(0)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); @@ -506,7 +503,7 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L std::string saveInfo = jsonRes.dump(); int32_t scId; - EXPECT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -517,11 +514,11 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L }; clickInfo.extraInfo.dataSize = TestCommon::MAX_HMAC_SIZE; clickInfo.extraInfo.data = data; - auto proxy = SecCompClient::GetInstance().GetProxy(true); - ASSERT_NE(proxy, nullptr); - auto token = proxy->AsObject(); + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - SecCompKit::ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -538,9 +535,9 @@ HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent001, TestSize.Level TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; - ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); ASSERT_NE(-1, scId); - ASSERT_EQ(SC_OK, SecCompKit::UpdateSecurityComponent(scId, saveInfo)); + ASSERT_EQ(SC_OK, UpdateSecurityComponent(scId, saveInfo)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -558,10 +555,10 @@ HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent002, TestSize.Level int32_t scId; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); - ASSERT_EQ(SC_OK, SecCompKit::RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); ASSERT_NE(-1, scId); setuid(100); - ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, SecCompKit::UpdateSecurityComponent(scId, saveInfo)); + ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, UpdateSecurityComponent(scId, saveInfo)); setuid(g_selfUid); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } diff --git a/services/security_component_service/sa/BUILD.gn b/services/security_component_service/sa/BUILD.gn index a906600..7ea81ab 100644 --- a/services/security_component_service/sa/BUILD.gn +++ b/services/security_component_service/sa/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -32,7 +32,7 @@ ohos_prebuilt_etc("security_component_service.rc") { part_name = "security_component_manager" } -ohos_shared_library("security_component_service") { +ohos_source_set("security_component_service_src_set") { subsystem_name = "security" part_name = "security_component_manager" sanitize = { @@ -65,13 +65,16 @@ ohos_shared_library("security_component_service") { "sa_main/window_info_helper.cpp", ] - cflags_cc = [ "-DHILOG_ENABLE" ] + cflags_cc = [ + "-DHILOG_ENABLE", + "-fvisibility=hidden", + ] cflags = [ "-DHILOG_ENABLE" ] deps = [ ":security_component_service.rc", - "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", - "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", + "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set", + "${sec_comp_root_dir}/frameworks:security_component_framework_src_set", ] configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] @@ -97,3 +100,23 @@ ohos_shared_library("security_component_service") { "window_manager:libwm", ] } + +ohos_shared_library("security_component_service") { + subsystem_name = "security" + part_name = "security_component_manager" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + deps = [ + ":security_component_service.rc", + ":security_component_service_src_set", + "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set", + "${sec_comp_root_dir}/frameworks:security_component_framework_src_set", + ] + + public_configs = [ ":security_component_service_config" ] +} diff --git a/services/security_component_service/sa/sa_main/delay_exit_task.cpp b/services/security_component_service/sa/sa_main/delay_exit_task.cpp index 6a4ce6f..109281b 100644 --- a/services/security_component_service/sa/sa_main/delay_exit_task.cpp +++ b/services/security_component_service/sa/sa_main/delay_exit_task.cpp @@ -23,7 +23,7 @@ namespace SecurityComponent { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "DelayExitTask"}; static const std::string DELAY_EXIT_TASK = "DelayExitTask"; -static const int32_t DELAY_EXIT_MILLISECONDS = 10 * 60 * 1000; // 10m +static const int32_t DELAY_EXIT_MILLISECONDS = 120 * 1000; // 2m } DelayExitTask::DelayExitTask() diff --git a/services/security_component_service/sa/sa_main/delay_exit_task.h b/services/security_component_service/sa/sa_main/delay_exit_task.h index d4315df..cdc3bda 100644 --- a/services/security_component_service/sa/sa_main/delay_exit_task.h +++ b/services/security_component_service/sa/sa_main/delay_exit_task.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -23,7 +23,7 @@ namespace OHOS { namespace Security { namespace SecurityComponent { -class DelayExitTask { +class __attribute__((visibility("default"))) DelayExitTask { public: static DelayExitTask& GetInstance(); virtual ~DelayExitTask() = default; diff --git a/services/security_component_service/sa/sa_main/sec_comp_info_helper.h b/services/security_component_service/sa/sa_main/sec_comp_info_helper.h index ba8006b..7949f4e 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_info_helper.h +++ b/services/security_component_service/sa/sa_main/sec_comp_info_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -35,7 +35,7 @@ T* ConstructComponent(const nlohmann::json& jsonComponent) return componentPtr; } -class SecCompInfoHelper { +class __attribute__((visibility("default"))) SecCompInfoHelper { public: static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent); static int32_t GrantTempPermission(AccessToken::AccessTokenID tokenId, diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.h b/services/security_component_service/sa/sa_main/sec_comp_service.h index 0ac59c7..c7c548e 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.h +++ b/services/security_component_service/sa/sa_main/sec_comp_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -30,7 +30,7 @@ namespace OHOS { namespace Security { namespace SecurityComponent { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; -class SecCompService final : public SystemAbility, public SecCompStub { +class __attribute__((visibility("default"))) SecCompService final : public SystemAbility, public SecCompStub { DECLARE_DELAYED_SINGLETON(SecCompService); DECLEAR_SYSTEM_ABILITY(SecCompService); diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index d4cf894..09bc579 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -66,8 +66,8 @@ ohos_unittest("sec_comp_service_test") { } deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", - "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", + "${sec_comp_root_dir}/frameworks:security_component_enhance_adapter_src_set", + "${sec_comp_root_dir}/frameworks:security_component_framework_src_set", "//third_party/googletest:gmock_main", ] @@ -135,7 +135,7 @@ ohos_unittest("sec_comp_service_mock_test") { cflags_cc = [ "-DHILOG_ENABLE" ] deps = [ - "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", + "${sec_comp_root_dir}/frameworks:security_component_framework_src_set", "//third_party/googletest:gmock_main", ] diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp index 7e50288..0a20e63 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -134,11 +134,7 @@ HWTEST_F(SecCompEntityTest, CheckClickInfo001, TestSize.Level1) entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; touch.point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; -#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - ASSERT_NE(entity_->CheckClickInfo(touch), SC_OK); -#else ASSERT_EQ(entity_->CheckClickInfo(touch), SC_OK); -#endif } /** diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp index 73a38c3..25f5d7f 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -324,14 +324,8 @@ HWTEST_F(SecCompManagerTest, RegisterSecurityComponent001, TestSize.Level1) LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonValid); -#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - // callback check failed - EXPECT_EQ(SC_ENHANCE_ERROR_CALLBACK_NOT_EXIST, - SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonValid, caller, scId)); -#else EXPECT_EQ(SC_OK, SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonValid, caller, scId)); -#endif SecCompManager::GetInstance().malicious_.maliciousAppList_.clear(); } @@ -370,13 +364,8 @@ HWTEST_F(SecCompManagerTest, UpdateSecurityComponent001, TestSize.Level1) SecCompManager::GetInstance().UpdateSecurityComponent(ServiceTestCommon::TEST_SC_ID_1, jsonInvalid, caller)); // no enhance data -#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - EXPECT_NE(SC_OK, - SecCompManager::GetInstance().UpdateSecurityComponent(ServiceTestCommon::TEST_SC_ID_1, jsonValid, caller)); -#else EXPECT_EQ(SC_OK, SecCompManager::GetInstance().UpdateSecurityComponent(ServiceTestCommon::TEST_SC_ID_1, jsonValid, caller)); -#endif SecCompManager::GetInstance().malicious_.maliciousAppList_.clear(); } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp index 9fef594..08978d1 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -260,13 +260,8 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); -#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - EXPECT_EQ(SC_ENHANCE_ERROR_CALLBACK_NOT_EXIST, - secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); -#else EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); -#endif uint8_t data[16] = { 0 }; struct SecCompClickEvent touch = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -278,18 +273,9 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve .extraInfo.data = data, .extraInfo.dataSize = 16, }; -#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - EXPECT_EQ(SC_ENHANCE_ERROR_IN_MALICIOUS_LIST, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr)); - // already in malicious list - EXPECT_EQ(SC_ENHANCE_ERROR_IN_MALICIOUS_LIST, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr)); - EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_NOT_EXIST, secCompService_->UnregisterSecurityComponent(scId)); -#else EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); -#endif setuid(uid); } diff --git a/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/BUILD.gn b/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/BUILD.gn index f0faf30..fa31e3c 100644 --- a/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("GetEnhanceRemoteObjectInnerFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "getenhanceremoteobjectInner_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service" ] + deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service_src_set" ] external_deps = [ "ability_runtime:app_manager", diff --git a/test/fuzztest/security_component/getpointereventenhancedata_fuzzer/BUILD.gn b/test/fuzztest/security_component/getpointereventenhancedata_fuzzer/BUILD.gn index 1c66f3d..4a01750 100644 --- a/test/fuzztest/security_component/getpointereventenhancedata_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/getpointereventenhancedata_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("GetPointerEventEnhanceDataFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "getpointereventenhancedata_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/interfaces/inner_api/enhance_kits:libsecurity_component_enhance_sdk" ] + deps = [ "${sec_comp_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk" ] external_deps = [ "ability_base:want", diff --git a/test/fuzztest/security_component/registersecuritycomponentInner_fuzzer/BUILD.gn b/test/fuzztest/security_component/registersecuritycomponentInner_fuzzer/BUILD.gn index 6b04097..1174766 100644 --- a/test/fuzztest/security_component/registersecuritycomponentInner_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/registersecuritycomponentInner_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("RegisterSecurityComponentInnerFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "registersecuritycomponentInner_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service" ] + deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service_src_set" ] external_deps = [ "ability_runtime:app_manager", diff --git a/test/fuzztest/security_component/reportsecuritycomponentclickeventInner_fuzzer/BUILD.gn b/test/fuzztest/security_component/reportsecuritycomponentclickeventInner_fuzzer/BUILD.gn index 78280ea..8adc654 100644 --- a/test/fuzztest/security_component/reportsecuritycomponentclickeventInner_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/reportsecuritycomponentclickeventInner_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("ReportSecurityComponentClickEventInnerFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "reportsecuritycomponentclickeventInner_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service" ] + deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service_src_set" ] external_deps = [ "ability_runtime:app_manager", diff --git a/test/fuzztest/security_component/setenhancecfg_fuzzer/BUILD.gn b/test/fuzztest/security_component/setenhancecfg_fuzzer/BUILD.gn index dac76f2..860c721 100644 --- a/test/fuzztest/security_component/setenhancecfg_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/setenhancecfg_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -37,7 +37,7 @@ ohos_fuzztest("SetEnhanceCfgFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "setenhancecfg_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/interfaces/inner_api/enhance_kits:libsecurity_component_enhance_sdk" ] + deps = [ "${sec_comp_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk" ] external_deps = [ "ability_base:want", diff --git a/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/BUILD.gn b/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/BUILD.gn index 191e5b6..bfafdf2 100644 --- a/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("UnregisterSecurityComponentInnerFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "unregistersecuritycomponentInner_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service" ] + deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service_src_set" ] external_deps = [ "ability_runtime:app_manager", diff --git a/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/BUILD.gn b/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/BUILD.gn index 804a739..a46e82b 100644 --- a/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("UpdateSecurityComponentInnerFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "updatesecuritycomponentInner_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service" ] + deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service_src_set" ] external_deps = [ "ability_runtime:app_manager", diff --git a/test/fuzztest/security_component/verifysavepermissionInner_fuzzer/BUILD.gn b/test/fuzztest/security_component/verifysavepermissionInner_fuzzer/BUILD.gn index ce74c09..3eaaaf9 100644 --- a/test/fuzztest/security_component/verifysavepermissionInner_fuzzer/BUILD.gn +++ b/test/fuzztest/security_component/verifysavepermissionInner_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # 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 @@ -36,7 +36,7 @@ ohos_fuzztest("VerifySavePermissionInnerFuzzTest") { cflags_cc = [ "-DHILOG_ENABLE" ] sources = [ "verifysavepermissionInner_fuzzer.cpp" ] - deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service" ] + deps = [ "${sec_comp_dir}/services/security_component_service/sa:security_component_service_src_set" ] external_deps = [ "ability_runtime:app_manager", -- Gitee