diff --git a/OAT.xml b/OAT.xml index a859db12f89c5a9c27affe4176ee471b5ac41b19..2117a5d0e5b6ef7e7b876b8f6bebc2046e3037bb 100644 --- a/OAT.xml +++ b/OAT.xml @@ -122,6 +122,10 @@ Note:If the text contains special characters, please escape them according to th + + + + diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9b61f8dafabb98c7e492afe800d47e5044b1c6e5 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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. + */ + +{ + "app": { + "bundleName": "com.samples.generatekey", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..db98e9ec5c89dc27f022a2cab91c60611af68fa8 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "GenerateKey" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/README.md new file mode 100755 index 0000000000000000000000000000000000000000..3b21ebeb46b949175261dd8d1384271c3f2d1110 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/README.md @@ -0,0 +1,87 @@ +## 生成密钥(ArkTS) + +### 介绍 + +1. 本工程实现了对以下 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/UniversalKeystoreKit/huks-key-generation-arkts.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### Call ArkTS + +##### 介绍 + +1. 本示例主要介绍生成密钥,以生成DH密钥为例生成随机密钥,指定待生成的密钥别名keyAlias。 + +##### 效果预览 + +| 主页 | | +| ---------------------------------------------------- | ---------------------------------------------------- | +| | | + +使用说明 + +1. 点击Call ArkTS按钮调用huks.generateKeyItem,传入密钥别名和密钥属性集,生成密钥。 + +## 生成密钥(C/C++) + +### 介绍 + +1. 本工程实现了对以下 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/UniversalKeystoreKit/huks-key-generation-ndk.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### Call C/C++ + +##### 介绍 + +1. 本示例主要介绍生成密钥,以生成ECC密钥为例,生成随机密钥。 + +##### 效果预览 + +| 主页 | | +| -------------------------------------------------- | -------------------------------------------------- | +| | | + +使用说明 + +1. 点击Call C/C++按钮调用OH_Huks_GenerateKeyItem,传入密钥别名和密钥属性集,生成密钥。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---cpp +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---GenerateKey.test.ets // 自动化测试用例 +``` + + +## 相关权限 + +无。 + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 +3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..df8b8004f9207069a86cc1b12716cdcdb73f9072 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5612a9a1db33c953c5d474210a9a9576d1afd4d4 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..5d993e5251fd56950970aa593aefef1b8d71e976 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..a6ed6d775f5a9dc638a522b9433f0010b81c140f --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(GenerateKey) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp new file mode 100755 index 0000000000000000000000000000000000000000..fd8f89141bdd2bef7e30921d66a9e32c6fb16761 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 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. + */ + +/* 以下以生成ECC密钥为例 */ +#include "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static napi_value GenerateKey(napi_env env, napi_callback_info info) +{ + /* 1.确定密钥别名 */ + const char *alias = "test_generate"; + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + /* 2.初始化密钥属性集 */ + ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, + sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 3.生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); + } while (0); + OH_Huks_FreeParamSet(&testGenerateKeyParamSet); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"generateKey", nullptr, GenerateKey, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..9f09a140e54fb4cf4f112355ad0cb466494234f7 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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. + */ + +export const generateKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..846e4c7e13ead48abe6019bd40f3a13bf8f9c083 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..a36ca588fe1aa322e8fca13744debe6f29d41d44 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1504a74f09dfdcfae408be979f99369a2c5affab --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 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 { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..35e3b1e8828f10f796875e0743cf7459f6198178 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,107 @@ +/* + * Copyright (c) 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 { huks } from '@kit.UniversalKeystoreKit'; +import testNapi from 'libentry.so'; + +/* 1.确定密钥别名 */ +let keyAlias = 'dh_key'; +/* 2.初始化密钥属性集 */ +let properties1: Array = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 + } +]; + +let huksOptions: huks.HuksOptions = { + properties: properties1, + inData: new Uint8Array(new Array()) +} + +/* 3.生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise generateKeyItem`); + try { + await generateKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + }); + return 'Success'; + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); + return 'Failed'; + } +} + +async function testGenKey(): Promise { + let ret = await publicGenKeyFunc(keyAlias, huksOptions); + return ret; +} + +@Entry +@Component +struct Index { + @State message: string = 'GenerateKey'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call C/C++') + .width('70%') + .onClick(() => { + let ret: number = testNapi.generateKey(); + this.message = 'C/C++ Call Result: ' + ret.toString(); + }) + Button('Call ArkTS') + .width('70%') + .onClick(async () => { + let ret = await testGenKey(); + this.message = 'ArkTS Call Result: ' + ret; + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..776ce01475229d674487a2830790c4c87b777379 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..b5c4c4673d412bb851a669efcee0213782e10544 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "GenerateKey" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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 { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..19c39f7844060631782b93e709dd0bcc89191f7b --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 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 { describe, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function generateKeyTest() { + describe('generateKeyTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,生成密钥(C/C++) + */ + it('testGenerateKey001', 0, async () => { + console.info('uitest: testGenerateKey001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('C/C++ Call Result: 0')); + console.info('uitest: testGenerateKey001 end'); + }) + + /** + * 点击按钮,生成密钥(ArkTS) + */ + it('testGenerateKey002', 0, async () => { + console.info('uitest: testGenerateKey002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call ArkTS')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ArkTS Call Result: Success')); + console.info('uitest: testGenerateKey002 end'); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..05d18c925aa8b24b806c439268fe009f5a599146 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 abilityTest from './Ability.test'; +import generateKeyTest from './GenerateKey.test'; + +export default function testsuite() { + generateKeyTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9983b2ba4e55e31a172f0328c82c9a75bfa00ded --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..cef74543b1f97c82275e4bf3434b162395bff2eb --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 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. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..eaef52736f22c14e04fca386ba01611ab32a7e4a --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..3f92d43bf35706b0921ce23c8f159c091822dde5 --- /dev/null +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md @@ -0,0 +1,9 @@ +# 密钥删除测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,密钥删除(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +| 点击按钮,密钥删除(C/C++) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_1.png new file mode 100755 index 0000000000000000000000000000000000000000..ebf2fff466956807e0dfdb33b9a8d6085002d478 Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_1.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_2.png new file mode 100755 index 0000000000000000000000000000000000000000..4e59387a46803748114487b126874b5f02a1933d Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_2.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_1.png new file mode 100755 index 0000000000000000000000000000000000000000..ebf2fff466956807e0dfdb33b9a8d6085002d478 Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_1.png differ diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_2.png new file mode 100755 index 0000000000000000000000000000000000000000..5d3e091010ae078e3af728e345fdff2f3fbedd77 Binary files /dev/null and b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_2.png differ