Signed-off-by: woohoa <wanghuan36@huawei.com>

# Conflicts:
#	bundle.json
This commit is contained in:
15950533375
2025-06-17 15:02:07 +08:00
parent 7d7864a014
commit a58388fbb6
17 changed files with 389 additions and 23 deletions
+2 -1
View File
@@ -27,7 +27,8 @@ group("app_domain_verify_packages") {
"interfaces/inner_api/client:app_domain_verify_agent_client",
"interfaces/inner_api/client:app_domain_verify_mgr_client",
"interfaces/inner_api/common:app_domain_verify_common",
"interfaces/kits/js:appdomainverify_napi",
"interfaces/kits/js/ani:appdomainverify_ani",
"interfaces/kits/js/jsi:appdomainverify_napi",
"profile:bundlemanager_app_domain_verify_sa_profiles",
"services:app_domain_verify_agent_service",
"services:app_domain_verify_mgr_service",
+2 -1
View File
@@ -48,7 +48,8 @@
"hiappevent",
"hicollie",
"netmanager_base",
"memmgr"
"memmgr",
"runtime_core"
],
"third_party": [
"openssl"
+118
View File
@@ -0,0 +1,118 @@
# Copyright (C) 2025-2025 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/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//build/ohos/taihe_idl/taihe.gni")
import("../../../../app_domain_verify.gni")
subsystem_name = "bundlemanager"
part_name = "app_domain_verify"
taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name"
copy_taihe_idl("copy_taihe") {
sources = [
"${app_domain_verify_kits_path}/ani/idl/ohos.bundle.appDomainVerify.taihe",
]
}
ohos_taihe("run_taihe") {
taihe_generated_file_path = "$taihe_generated_file_path"
deps = [ ":copy_taihe" ]
outputs = [
"$taihe_generated_file_path/src/ohos.bundle.appDomainVerify.ani.cpp",
"$taihe_generated_file_path/src/ohos.bundle.appDomainVerify.abi.c",
]
}
taihe_shared_library("app_domain_verify_ani") {
taihe_generated_file_path = "$taihe_generated_file_path"
subsystem_name = "$subsystem_name"
part_name = "$part_name"
include_dirs = [
"include",
"${app_domain_verify_client_path}/include",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_common_path}/include/zidl",
"${app_domain_verify_kits_path}/common/include",
]
sources = get_target_outputs(":run_taihe")
sources += [
"${app_domain_verify_kits_path}/ani/src/ani_constructor.cpp",
"${app_domain_verify_kits_path}/ani/src/ohos.bundle.appDomainVerify.impl.cpp",
"${app_domain_verify_kits_path}/common/src/api_event_reporter.cpp",
"${app_domain_verify_kits_path}/common/src/config_parser.cpp",
]
deps = [
":run_taihe",
"${app_domain_verify_client_path}:app_domain_verify_mgr_client",
"${app_domain_verify_common_path}:app_domain_verify_common",
]
if (os_level == "standard") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
}
cflags = [
"-DHILOG_ENABLE",
"-fPIC",
"-g3",
]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiappevent:hiappevent_innerapi",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"runtime_core:ani",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
}
generate_static_abc("app_domain_verify_ets") {
base_url = "$taihe_generated_file_path"
files = [ "$taihe_generated_file_path/@ohos.bundle.appDomainVerify.ets" ]
is_boot_abc = "True"
device_dst_file = "/system/framework/app_domain_verify_ets.abc"
dependencies = [ ":run_taihe" ]
}
generate_static_abc("app_domain_verify_test") {
base_url = "${app_domain_verify_kits_path}/ani/test"
files = [ "${app_domain_verify_kits_path}/ani/test/test_main.ets" ]
is_boot_abc = "True"
device_dst_file = "/system/framework/app_domain_verify_test.abc"
}
ohos_prebuilt_etc("app_domain_verify_etc") {
source = "$target_out_dir/app_domain_verify_ets.abc"
module_install_dir = "framework"
part_name = "$part_name"
subsystem_name = "$subsystem_name"
deps = [
":app_domain_verify_ets",
# ":app_domain_verify_test",
]
}
group("appdomainverify_ani") {
deps = [
":app_domain_verify_ani",
":app_domain_verify_etc",
]
}
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2025-2025 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.
*/
@!namespace("@ohos.bundle.appDomainVerify", "appDomainVerify")
@!typed_array
@!sts_inject("""
static { loadLibrary("app_domain_verify_ani.z"); }
""")
function queryAssociatedDomains(bundleName: String): Array<String>;
function queryAssociatedBundleNames(domain: String): Array<String>;
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2025-2025 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 "ohos.bundle.appDomainVerify.ani.hpp"
ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result)
{
ani_env* env;
if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
return ANI_ERROR;
}
if (ANI_OK != ohos::bundle::appDomainVerify::ANIRegister(env)) {
std::cerr << "ohos::bundle::appDomainVerify" << std::endl;
return ANI_ERROR;
}
*result = ANI_VERSION_1;
return ANI_OK;
}
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2025-2025 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 "ohos.bundle.appDomainVerify.proj.hpp"
#include "ohos.bundle.appDomainVerify.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
#include <map>
#include "app_domain_verify_hilog.h"
#include "app_domain_verify_mgr_client.h"
#include "js_common_defined.h"
#include "api_event_reporter.h"
using namespace taihe;
using namespace OHOS::AppDomainVerify;
namespace {
bool CheckInput(const std::string& input)
{
if (input.empty() || input.size() > MAX_STR_INPUT_SIZE) {
return false;
}
return true;
}
array<string> BuildError(ErrorCode errorCode)
{
taihe::set_business_error(errorCode, ErrCodeMap[errorCode]);
return taihe::array<string>(nullptr, 0);
}
array<string> BuildStringArray(const std::vector<std::string>& data)
{
array<string> resArr(data.size(), "");
for (int i = 0; i < data.size(); i++) {
resArr[i] = data[i];
}
return resArr;
}
array<string> queryAssociatedDomains(string_view bundleName)
{
Dfx::ApiEventReporter reporter("QueryAssociatedDomains");
if (!CheckInput(bundleName.c_str())) {
reporter.WriteEndEvent(Dfx::API_FAIL, ErrorCode::E_PARAM_ERROR);
return BuildError(ErrorCode::E_PARAM_ERROR);
}
std::vector<std::string> domains;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedDomains(bundleName.c_str(), domains);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<ErrorCode>(ret)) != 0) {
reporter.WriteEndEvent(Dfx::API_FAIL, static_cast<ErrorCode>(ret));
return BuildError(static_cast<ErrorCode>(ret));
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
reporter.WriteEndEvent(Dfx::API_FAIL, ret);
return BuildStringArray(domains);
}
}
reporter.WriteEndEvent(Dfx::API_SUCCESS, ret);
return BuildStringArray(domains);
}
array<string> queryAssociatedBundleNames(string_view domain)
{
Dfx::ApiEventReporter reporter("QueryAssociatedBundleNames");
if (!CheckInput(domain.c_str())) {
reporter.WriteEndEvent(Dfx::API_FAIL, ErrorCode::E_PARAM_ERROR);
return BuildError(ErrorCode::E_PARAM_ERROR);
}
std::vector<std::string> bundleNames;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedBundleNames(domain.c_str(), bundleNames);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<ErrorCode>(ret)) != 0) {
reporter.WriteEndEvent(Dfx::API_FAIL, static_cast<ErrorCode>(ret));
return BuildError(static_cast<ErrorCode>(ret));
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
reporter.WriteEndEvent(Dfx::API_FAIL, ret);
return BuildStringArray(bundleNames);
}
}
reporter.WriteEndEvent(Dfx::API_SUCCESS, ret);
return BuildStringArray(bundleNames);
}
} // namespace
TH_EXPORT_CPP_API_queryAssociatedDomains(queryAssociatedDomains);
TH_EXPORT_CPP_API_queryAssociatedBundleNames(queryAssociatedBundleNames);
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"package": "",
"baseUrl": ".",
"outDir": "./dist",
"paths": {
"std": [
"../../../../../../../arkcompiler/runtime_core/static_core/plugins/ets/stdlib/std"
],
"escompat": [
"../../../../../../../arkcompiler/runtime_core/static_core/plugins/ets/stdlib/escompat"
],
"@ohos": [
"../../../../../../../interface/sdk-js/api/@ohos"
]
}
},
"includes": [
"*.ets"
]
}
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2025-2025 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 appDomainVerify from '@ohos.bundle.appDomainVerify';
function testQueryAssociatedBundleNames(){
try{
let domain = 'https://www.openHarmony.cn'
let bundleNames = appDomainVerify.queryAssociatedDomains(domain)
console.log('testQueryAssociatedBundleNames: ' + bundleNames)
}
catch (err) {
console.error('testQueryAssociatedBundleNames failed: ' + err)
}
}
function testQueryAssociatedDomains(){
try{
let bundleName = 'com.openHarmony.test'
let domains = appDomainVerify.queryAssociatedDomains(bundleName)
console.log('testQueryAssociatedDomains: ' + domains)
}
catch (err) {
console.error('testQueryAssociatedDomains failed: ' + err)
}
}
function main() {
testQueryAssociatedBundleNames();
testQueryAssociatedDomains();
}
@@ -17,6 +17,8 @@
#include <string>
namespace OHOS::AppDomainVerify::Dfx {
constexpr int32_t API_SUCCESS = 0;
constexpr int32_t API_FAIL = 1;
class ApiEventReporter {
public:
explicit ApiEventReporter(const std::string& apiName);
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2023 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 APP_DOMAIN_VERIFY_JS_COMMON_DEFINED_H
#define APP_DOMAIN_VERIFY_JS_COMMON_DEFINED_H
#include <map>
#include "app_domain_verify_error.h"
namespace OHOS::AppDomainVerify {
constexpr int32_t MAX_STR_INPUT_SIZE = 256;
constexpr int32_t STRING_BUF_MAX_SIZE = 4096;
static std::map<ErrorCode, const char*> ErrCodeMap = { { ErrorCode::E_PERMISSION_DENIED, "Permission denied." },
{ ErrorCode::E_IS_NOT_SYS_APP, "System API accessed by non-system app." },
{ ErrorCode::E_PARAM_ERROR, "Parameter error." }, { ErrorCode::E_INTERNAL_ERR, "Internal error." } };
}
#endif // APP_DOMAIN_VERIFY_JS_COMMON_DEFINED_H
@@ -29,8 +29,8 @@ bool ConfigParser::load(const std::string& filename)
std::ifstream file(filename, std::ios::ate);
if (!file.is_open()) {
std::cerr << "Unable to open file: " << filename << std::endl;
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_JS_NAPI, "Unable to open file: filename:%{public}s",
filename.c_str());
APP_DOMAIN_VERIFY_HILOGE(
APP_DOMAIN_VERIFY_MODULE_JS_NAPI, "Unable to open file: filename:%{public}s", filename.c_str());
return false;
}
@@ -12,7 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import("../../../app_domain_verify.gni")
import("../../../../app_domain_verify.gni")
config("app_domain_verify_mgr_napi_config") {
visibility = [ ":*" ]
include_dirs = [
@@ -20,6 +20,7 @@ config("app_domain_verify_mgr_napi_config") {
"${app_domain_verify_client_path}/include",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_common_path}/include/zidl",
"${app_domain_verify_kits_path}/common/include",
]
configs = [ "//build/config/compiler:exceptions" ]
ldflags = [ "-Wl,--exclude-libs=ALL" ]
@@ -51,9 +52,9 @@ ohos_shared_library("appdomainverify_napi") {
}
sources = [
"src/api_event_reporter.cpp",
"${app_domain_verify_kits_path}/common/src/api_event_reporter.cpp",
"${app_domain_verify_kits_path}/common/src/config_parser.cpp",
"src/app_domain_verify_manager_napi.cpp",
"src/config_parser.cpp",
"src/native_module.cpp",
]
public_configs = [ ":app_domain_verify_mgr_napi_config" ]
@@ -18,17 +18,11 @@
#include "app_domain_verify_manager_napi.h"
#include "app_domain_verify_hilog.h"
#include "app_domain_verify_mgr_client.h"
#include "app_domain_verify_error.h"
#include "js_common_defined.h"
#include "api_event_reporter.h"
namespace OHOS::AppDomainVerify {
constexpr int32_t API_SUCCESS = 0;
constexpr int32_t API_FAIL = 1;
constexpr int32_t MAX_STR_INPUT_SIZE = 256;
constexpr int32_t STRING_BUF_MAX_SIZE = 4096;
std::map<ErrorCode, const char*> ErrCodeMap = { { ErrorCode::E_PERMISSION_DENIED, "Permission denied." },
{ ErrorCode::E_IS_NOT_SYS_APP, "System API accessed by non-system app." },
{ ErrorCode::E_PARAM_ERROR, "Parameter error." }, { ErrorCode::E_INTERNAL_ERR, "Internal error." } };
static std::string GetString(napi_env env, napi_value value)
{
std::unique_ptr<char[]> valueBuf = std::make_unique<char[]>(STRING_BUF_MAX_SIZE);
@@ -78,22 +72,22 @@ napi_value QueryAssociatedDomains(napi_env env, napi_callback_info info)
NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), nullptr);
std::string bundleName = GetString(env, args[0]);
if (!CheckInput(bundleName)) {
reporter.WriteEndEvent(API_FAIL, ErrorCode::E_PARAM_ERROR);
reporter.WriteEndEvent(Dfx::API_FAIL, ErrorCode::E_PARAM_ERROR);
return BuildError(env, ErrorCode::E_PARAM_ERROR);
}
std::vector<std::string> domains;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedDomains(bundleName, domains);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<ErrorCode>(ret)) != 0) {
reporter.WriteEndEvent(API_FAIL, static_cast<ErrorCode>(ret));
reporter.WriteEndEvent(Dfx::API_FAIL, static_cast<ErrorCode>(ret));
return BuildError(env, static_cast<ErrorCode>(ret));
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
reporter.WriteEndEvent(API_FAIL, ret);
reporter.WriteEndEvent(Dfx::API_FAIL, ret);
return BuildStringArray(env, domains);
}
}
reporter.WriteEndEvent(API_SUCCESS, ret);
reporter.WriteEndEvent(Dfx::API_SUCCESS, ret);
return BuildStringArray(env, domains);
}
napi_value QueryAssociatedBundleNames(napi_env env, napi_callback_info info)
@@ -105,22 +99,22 @@ napi_value QueryAssociatedBundleNames(napi_env env, napi_callback_info info)
NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), nullptr);
std::string domain = GetString(env, args[0]);
if (!CheckInput(domain)) {
reporter.WriteEndEvent(API_FAIL, ErrorCode::E_PARAM_ERROR);
reporter.WriteEndEvent(Dfx::API_FAIL, ErrorCode::E_PARAM_ERROR);
return BuildError(env, ErrorCode::E_PARAM_ERROR);
}
std::vector<std::string> bundleNames;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedBundleNames(domain, bundleNames);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<ErrorCode>(ret)) != 0) {
reporter.WriteEndEvent(API_FAIL, static_cast<ErrorCode>(ret));
reporter.WriteEndEvent(Dfx::API_FAIL, static_cast<ErrorCode>(ret));
return BuildError(env, static_cast<ErrorCode>(ret));
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
reporter.WriteEndEvent(API_FAIL, ret);
reporter.WriteEndEvent(Dfx::API_FAIL, ret);
return BuildStringArray(env, bundleNames);
}
}
reporter.WriteEndEvent(API_SUCCESS, ret);
reporter.WriteEndEvent(Dfx::API_SUCCESS, ret);
return BuildStringArray(env, bundleNames);
}
}