diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/.gitignore b/DeviceCertificateKit/CertificateAlgorithmLibrary/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/.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/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/app.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..801e86b73888d0950ee8e5cdb105e063820226a9 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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.certificatealgorithmlibrary", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ad134223d3d57d15e5b21ae6072ab7faabd7981e --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CertificateAlgorithmLibrary" + } + ] +} diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/media/app_icon.png b/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/media/app_icon.png differ diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md b/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f43087ee0f42e0254ceeed7c6b3c09d0f905862c --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md @@ -0,0 +1,84 @@ +# 证书算法库 + +### 介绍 + +证书算法库框架是一个屏蔽了第三方算法库实现差异的证书算法框架,向应用提供证书、证书扩展域段、证书吊销列表的创建、解析及校验能力,此外还提供了证书链的校验能力。 + +本示例主要展示了证书算法库中证书对象的创建、证书扩展信息对象的创建、证书吊销列表对象的创建、证书链校验时从p12文件构造TrustAnchor对象数组、证书链校验器对象的创建和校验、证书集合及证书吊销列表集合对象的创建和获取、证书链对象的创建和校验的场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [证书对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-cert-object.md) +- [证书扩展信息对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-certextension-object.md) +- [证书吊销列表对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-crl-object.md) +- [证书链校验时从p12文件构造TrustAnchor对象数组](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-trustanchor-from-p12.md) +- [证书链校验器对象的创建和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-verify-cerchainvalidator-object.md) +- [证书集合及证书吊销列表集合对象的创建和获取](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-get-cert-crl-object.md) +- [证书链对象的创建和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-verify-certchain-object.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例CertificateAlgorithmLibrary.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 证书算法库示例代码 + │ │ ├── CreateGetCertCrlObject.ets + │ │ ├── CreateParseVerifyCertextensionObject.ets + │ │ ├── CreateParseVerifyCertObject.ets + │ │ ├── CreateParseVerifyCrlObject.ets + │ │ ├── CreateTrustanchorFromP12.ets + │ │ ├── CreateVerifyCerchainvalidatorObject.ets + │ │ ├── CreateVerifyCertchainObject.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── CertificateAlgorithmLibrary.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo DeviceCertificateKit/CertificateAlgorithmLibrary > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 @@ -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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + "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/DeviceCertificateKit/CertificateAlgorithmLibrary/code-linter.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/.gitignore b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/hvigorfile.ts b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/oh-package.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entryability/EntryAbility.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..5cb1c7db979a43744dd339a96ed94e138be2d36b --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets @@ -0,0 +1,135 @@ +/* + * 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. + */ + + + +// [Start certificate_collection_and_certificate_revocation_list_collection_object_creation_and_acquisition] +import { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +async function createX509CRL(): Promise { + let crlData = '-----BEGIN X509 CRL-----\n' + + 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + + 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + + 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + + 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + + '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + + 'eavsH0Q3\n' + + '-----END X509 CRL-----\n'; + + // 证书吊销列表二进制数据,需业务自行赋值 + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(crlData), + // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + let x509CRL: cert.X509CRL = {} as cert.X509CRL; + try { + x509CRL = await cert.createX509CRL(encodingBlob); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`createX509CRL failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + return x509CRL; +} + +async function createX509Cert(): Promise { + let certData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + + 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + + 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + + 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + + 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + + 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + + 'Qw==\n' + + '-----END CERTIFICATE-----\n'; + + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(certData), + // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + let x509Cert: cert.X509Cert = {} as cert.X509Cert; + try { + x509Cert = await cert.createX509Cert(encodingBlob); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`createX509Cert failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + return x509Cert; +} + +async function sample() { + const x509Cert = await createX509Cert(); + const x509CRL = await createX509CRL(); + let collection: cert.CertCRLCollection = {} as cert.CertCRLCollection; + try { + collection = cert.createCertCRLCollection([x509Cert], [x509CRL]); + console.log('createCertCRLCollection success'); + } catch (err) { + console.error('createCertCRLCollection failed'); + } + + const certParam: cert.X509CertMatchParameters = { + validDate: '231128000000Z' + } + try { + let certs: cert.X509Cert[] = await collection.selectCerts(certParam); + } catch (err) { + console.error('selectCerts failed'); + } + + const crlParam: cert.X509CRLMatchParameters = { + x509Cert: x509Cert + } + try { + let crls: cert.X509CRL[] = await collection.selectCRLs(crlParam); + console.error('selectCRLs success'); + } catch (err) { + console.error('selectCRLs failed'); + } +} + + +// [End certificate_collection_and_certificate_revocation_list_collection_object_creation_and_acquisition] +@Entry +@Component +struct Index { + @State message: string = 'CreateGetCertCrlObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateGetCertCrlObject') + .width('70%') + .onClick(() => { + try { + sample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..188021f53c3ee7e3f82cc814ce8de20f358f1c3f --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets @@ -0,0 +1,115 @@ +/* + * 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. + */ + +// [Start certificate_object_creation_resolution_validation] + +import { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +// 此处仅为示例的证书二进制数据,需根据业务的不同对证书数据进行赋值 +let certData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' + + 'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' + + 'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' + + 'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' + + 'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' + + '0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' + + 'BetUokslUfjT6+s/X4ByaxycAA==\n' + + '-----END CERTIFICATE-----\n'; + +// 证书示例 +function certSample(): void { + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + // 将证书数据从string类型转换成Unit8Array + data: textEncoder.encodeInto(certData), + // 证书格式,仅支持PEM和DER。在此示例中,证书为PEM格式 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + // 创建X509Cert实例 + cert.createX509Cert(encodingBlob, (err, x509Cert) => { + if (err != null) { + // 创建X509Cert实例失败 + console.error(`createX509Cert failed, errCode:${err.code}, errMsg:${err.message}`); + return; + } + // X509Cert实例创建成功 + console.log('createX509Cert success'); + + // 获取证书版本 + let version = x509Cert.getVersion(); + let serial = x509Cert.getCertSerialNumber(); + console.log(`X509 version: ${version} , X509 serial:${serial}`); + + // 使用上级证书对象的getPublicKey()方法或本(自签名)证书对象获取公钥对象 + try { + let pubKey = x509Cert.getPublicKey(); + // 验证证书签名 + x509Cert.verify(pubKey, (err, data) => { + if (err == null) { + // 签名验证成功 + console.log('verify success'); + } else { + // 签名验证失败 + console.error(`verify failed, errCode: ${err.code} , errMsg:${err.message}`); + } + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`getPublicKey failed, errCode: ${e.code} , errMsg:${e.message}`); + } + + // 用一个字符串代表时间 + let date = '20230930000001Z'; + + // 验证证书的有效期 + try { + x509Cert.checkValidityWithDate(date); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`checkValidityWithDate failed, errCode: ${e.code}, errMsg:${e.message}`); + } + }); +} + + +// [End certificate_object_creation_resolution_validation] +@Entry +@Component +struct Index { + @State message: string = 'CreateParseVerifyCertObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateParseVerifyCertObject') + .width('70%') + .onClick(()=>{ + try { + certSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..ec59e35bd6d0fe2cd66367574dfff91dcfd78589 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets @@ -0,0 +1,100 @@ +/* + * 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. + */ + + +// [Start create_parse_validate_certificate_extension_info_objects] + +import { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +// 证书扩展数据,以下只是一个示例。需要根据具体业务来赋值 +let extData = new Uint8Array([ + 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, + 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, + 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, + 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, + 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, + 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, + 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, + 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, + 0xD9, 0xE4 +]); + +// 证书扩展示例 +function certExtensionSample(): void { + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + data: extData, + // 证书扩展格式,目前仅支持DER格式 + encodingFormat: cert.EncodingFormat.FORMAT_DER + }; + + // 创建一个证书扩展实例 + cert.createCertExtension(encodingBlob, (err, certExtension) => { + if (err != null) { + // 证书扩展实例创建失败 + console.error(`createCertExtension failed, errCode:${err.code}, errMsg:${err.message} `); + return; + } + // 证书扩展实例创建成功 + console.log('createCertExtension success'); + + try { + // 根据OID获取证书扩展信息 + let oidData = '2.5.29.14'; + let oid: cert.DataBlob = { + data: textEncoder.encodeInto(oidData), + } + let entry = certExtension.getEntry(cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, oid); + + // 检查证书是否为CA证书 + let pathLen = certExtension.checkCA(); + console.log('test cert extension success'); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`operation failed, message:${e.message} ,code:${e.code} `); + } + }); +} + + +// [End create_parse_validate_certificate_extension_info_objects] + +@Entry +@Component +struct Index { + @State message: string = 'CreateParseVerifyCertextensionObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateParseVerifyCertextensionObject') + .width('70%') + .onClick(()=>{ + try { + certExtensionSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..019ef19a2ae2160f73ffedc6b576adf9afabc751 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets @@ -0,0 +1,205 @@ +/* + * 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. + */ + +// [Start create_parse_verify_certificate_revocation_list_objects] + + +import { cert } from '@kit.DeviceCertificateKit'; +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +// CRL数据,以下只是一个示例,需要根据具体业务来赋值 +let crlData = '-----BEGIN X509 CRL-----\n' + + 'MIIByzCBtAIBATANBgkqhkiG9w0BAQsFADBXMQswCQYDVQQGEwJDTjEPMA0GA1UE\n' + + 'CAwG6ZmV6KW/MQ8wDQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMG\n' + + 'A1UEAwwM5Lit5paH5rWL6K+VFw0yNTAyMjAwNjEzMTZaFw0yNTAzMjIwNjEzMTZa\n' + + 'MBkwFwIGAXKnJjrAFw0yNTAyMjAwNjEzMDNaoA4wDDAKBgNVHRQEAwIBADANBgkq\n' + + 'hkiG9w0BAQsFAAOCAQEAt9AZ/B5FQiXnKKBGocKmM5QKeky/3etcI+cAVyD0zfjI\n' + + 'r1UrL1aF+49LdZps3zQRqm4RQmo9CwL+KsMZiIMSeWF5Q6LW7BQa08hx5PtdjoOu\n' + + '1IWVKAwR5IigpaOwMKRTq1xJ372EiUkDD83AsxEkQoQW0bBvFklGrzglSACeKST+\n' + + 'Pn6ywwFyYj34cfRuz3ueqwHRmN/mGzQdet7Ns8JBGWutDzfJsAiPC/TIaafTOocO\n' + + 'CHo81Q2rMcqAJj5uXyc1Gq8KfOEqsxo/oDwReghjwrUedJ+9l/cQBr0F8HPV4H8W\n' + + '49sYMpseywjp9lxjWt/2nrx1z2yMaivGrVhoFasZvQ==\n' + + '-----END X509 CRL-----\n' + +let certData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIDgTCCAmmgAwIBAgIGAXKnJjrAMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + + 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + + '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDYwOTUyWhcN\n' + + 'MzUwMjE4MDYwOTUyWjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + + 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + + '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2DQpPYN7cJjQ\n' + + 'LWLlkP5dD8J/g1xx97t2bFciUOru14IBm9EeX6qkohDSl6kQHwfVSqTfcqdIn9We\n' + + '73FiitfDjHc9xxbvBKbCYicCzS/eNl0W9q14FiEB8M9vz4dpKK00KZBcGc1QK2m+\n' + + '/N6zw4Tw4wXZ97v6/M+bhY5X0b3qEJlgQNyz7dD0wF7SCuzLL9zbr403KktHMG5Y\n' + + 'MzyOBaGOaMuVQFlXMV/E5OWfqbM7n0Pu/cGj+AfkkziWxB+5WFCRP6Pw64LJGo+e\n' + + 'uZHgHp07kk6+a2YNnFMcdTsOIWBSpCvC3I612NjpBirn2bFRWqTD++YAuvJQagmM\n' + + '+VhIjXD48wIDAQABo1MwUTAdBgNVHQ4EFgQUIN7ulBn89L5HXh9m9JM7rpkvlXUw\n' + + 'HwYDVR0jBBgwFoAUIN7ulBn89L5HXh9m9JM7rpkvlXUwDwYDVR0TAQH/BAUwAwEB\n' + + '/zANBgkqhkiG9w0BAQsFAAOCAQEAxWNa3LSOR3QOJ+wE1Y/q5zzEPWmWR5OMrRJK\n' + + 'juBHhYbzsg3r74fBO3Hw8XggEpHr6SOI1rBpZhciA8D9E8RnM1aJLY53rpBDY5OV\n' + + 'wxTFzrjdwIknt13t6ILfGeLye5OAF0S8VPdfDqP9NddNNr/WFKpd3tKoBlG0ObMa\n' + + 'LaQvOqObz0MJrjKsyI680nJjFLjLZ6+lEDSg4rsGU+bxEkONerStAPNcN2x9z7O6\n' + + 'YJOvhiLjWvr8VRjlMZYVmT9gqCImoo+7JaHbu8jz9mjRxD6fo9I1OvCLNFyFw2sV\n' + + 'iYID9UEbT6IWv/kKBdr7Te9+SY6AWxUxO8Hd7HdPKDOCrGrU9A==\n' + + '-----END CERTIFICATE-----\n'; + +let pubKeyData = new Uint8Array([ + 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 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, 0x57, 0x31, 0x5f, 0xc4, 0xe4, 0xe5, 0x9f, 0xa9, 0xb3, 0x3b, 0x9f, + 0x43, 0xee, 0xfd, 0xc1, 0xa3, 0xf8, 0x07, 0xe4, 0x93, 0x38, 0x96, 0xc4, 0x1f, 0xb9, 0x58, 0x50, + 0x91, 0x3f, 0xa3, 0xf0, 0xeb, 0x82, 0xc9, 0x1a, 0x8f, 0x9e, 0xb9, 0x91, 0xe0, 0x1e, 0x9d, 0x3b, + 0x92, 0x4e, 0xbe, 0x6b, 0x66, 0x0d, 0x9c, 0x53, 0x1c, 0x75, 0x3b, 0x0e, 0x21, 0x60, 0x52, 0xa4, + 0x2b, 0xc2, 0xdc, 0x8e, 0xb5, 0xd8, 0xd8, 0xe9, 0x06, 0x2a, 0xe7, 0xd9, 0xb1, 0x51, 0x5a, 0xa4, + 0xc3, 0xfb, 0xe6, 0x00, 0xba, 0xf2, 0x50, 0x6a, 0x09, 0x8c, 0xf9, 0x58, 0x48, 0x8d, 0x70, 0xf8, + 0xf3, 0x02, 0x03, 0x01, 0x00, 0x01 +]); + +// CRL示例 +function crlSample(): void { + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + // 将CRL数据从string转为Unit8Array + data: textEncoder.encodeInto(crlData), + // CRL格式,仅支持PEM和DER格式。在这个例子中,CRL用的是PEM格式 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + // 创建X509CRL实例 + cert.createX509CRL(encodingBlob, (err, x509Crl) => { + if (err != null) { + // 创建X509CRL实例失败 + console.error(`createX509Crl failed, errCode: ${err.code}, errMsg:${err.message} `); + return; + } + // 创建X509CRL实例成功 + console.log('createX509CRL success'); + + // 获取CRL的版本 + let version = x509Crl.getVersion(); + let revokedType = x509Crl.getType(); + console.log(`X509 CRL version: ${version}, type :${revokedType}`); + + // 公钥的二进制数据需要传入@ohos.security.cryptoFramework的convertKey()方法去获取公钥对象 + try { + let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); + console.log('createAsyKeyGenerator success'); + let pubEncodingBlob: cryptoFramework.DataBlob = { + data: pubKeyData, + }; + keyGenerator.convertKey(pubEncodingBlob, null, (e, keyPair) => { + if (e == null) { + console.log('convert key success'); + x509Crl.verify(keyPair.pubKey, (err, data) => { + if (err == null) { + // 签名验证成功 + console.log('verify success'); + } else { + // 签名验证失败 + console.error(`verify failed, errCode: ${err.code}, errMsg: ${err.message}`); + } + }); + } else { + console.error(`convert key failed, message: ${e.message}, code: ${e.code} `); + } + }) + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`get pubKey failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + + // 使用certFramework的createX509Cert()方法创建一个X509Cert实例 + let certBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(certData), + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + let revokedFlag = true; + let serial: bigint = BigInt('0'); + cert.createX509Cert(certBlob, (err, cert) => { + serial = cert.getCertSerialNumber(); + if (err == null) { + try { + // 检查证书是否被吊销 + revokedFlag = x509Crl.isRevoked(cert); + console.log(`revokedFlag is: ${revokedFlag}`); + if (!revokedFlag) { + console.log('the given cert is not revoked.'); + return; + } + // 根据序列号来获取被吊销的证书 + try { + let crlEntry = x509Crl.getRevokedCert(serial); + console.log('get getRevokedCert success'); + let serialNumber = crlEntry.getSerialNumber(); + console.log(`crlEntry serialNumber is: ${serialNumber}`); + + // 获取被吊销证书的吊销日期 + let date = crlEntry.getRevocationDate(); + console.log(`revocation date is: ${date}`); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`getRevokedCert failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`isRevoked failed, errCode: ${e.code}, errMsg:${e.message}`); + } + } else { + console.error(`create x509 cert failed, errCode: ${err.code}, errMsg: ${err.message}`); + } + }) + }); +} + + +// [End create_parse_verify_certificate_revocation_list_objects] + +@Entry +@Component +struct Index { + @State message: string = 'CreateParseVerifyCrlObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateParseVerifyCrlObject') + .width('70%') + .onClick(() => { + try { + crlSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets new file mode 100644 index 0000000000000000000000000000000000000000..3b29ec8d989b0012c1ddcdfb68b18a3d11221b45 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets @@ -0,0 +1,161 @@ +/* + * 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. + */ + + +// [Start trust_array_constructed_from_p12_file_during_validation] +import { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function test() { + let p12Data = + new Uint8Array([0x30, 0x82, 0x07, 0x5C, 0x02, 0x01, 0x03, 0x30, 0x82, 0x07, 0x12, 0x06, 0x09, 0x2A, 0x86, 0x48, + 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x07, 0x03, 0x04, 0x82, 0x06, 0xFF, 0x30, 0x82, 0x06, 0xFB, 0x30, + 0x82, 0x05, 0xB2, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06, 0xA0, 0x82, 0x05, 0xA3, 0x30, + 0x82, 0x05, 0x9F, 0x02, 0x01, 0x00, 0x30, 0x82, 0x05, 0x98, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + 0x07, 0x01, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, + 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, 0x30, 0x1C, 0x04, 0x08, 0xA9, 0x1C, 0x1B, 0x19, + 0x36, 0xDE, 0xD4, 0x20, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, + 0x09, 0x05, 0x00, 0x30, 0x1D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x01, 0x2A, 0x04, 0x10, 0x7D, + 0xE5, 0x23, 0x96, 0x18, 0x8B, 0xF4, 0xBC, 0x9F, 0x4E, 0xE8, 0xE9, 0xAA, 0x52, 0x18, 0x39, 0x80, 0x82, 0x05, 0x30, + 0x02, 0x2D, 0x59, 0xA9, 0x96, 0x5A, 0xFE, 0x20, 0x18, 0xB2, 0x25, 0xEA, 0xFC, 0x86, 0x0F, 0xA8, 0x3C, 0x2B, 0x26, + 0x2F, 0x44, 0x6E, 0xF3, 0x15, 0xB7, 0x94, 0xE4, 0x43, 0xEE, 0xE6, 0xC3, 0xBB, 0x3C, 0x9E, 0x60, 0x08, 0xF8, 0x15, + 0x61, 0x44, 0xD0, 0xEA, 0xD5, 0x6D, 0x1A, 0x3B, 0x9F, 0x4E, 0x2A, 0x1E, 0xBB, 0xB9, 0x4E, 0x15, 0x43, 0xB8, 0x68, + 0xDB, 0x1A, 0x4E, 0x41, 0xBA, 0x29, 0x8E, 0x75, 0xEB, 0x12, 0xC1,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2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x01, 0x32, 0x04, 0x82, + 0x01, 0x2E, 0x30, 0x82, 0x01, 0x2A, 0x30, 0x82, 0x01, 0x26, 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + 0x0C, 0x0A, 0x01, 0x02, 0xA0, 0x81, 0xEF, 0x30, 0x81, 0xEC, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, + 0x30, 0x1C, 0x04, 0x08, 0xED, 0x3E, 0xED, 0x07, 0x5C, 0x1F, 0x71, 0xAD, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, + 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x09, 0x05, 0x00, 0x30, 0x1D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x01, 0x2A, 0x04, 0x10, 0xA7, 0x49, 0xA4, 0x6E, 0x00, 0x19, 0x75, 0x59, 0x75, 0x59, 0xBA, 0x4B, + 0xC7, 0x24, 0x88, 0x34, 0x04, 0x81, 0x90, 0xCA, 0x23, 0x82, 0xAA, 0x16, 0x57, 0x99, 0xFA, 0x94, 0x9F, 0xAE, 0x32, + 0x5C, 0x5B, 0xE7, 0x01, 0xD0, 0xED, 0xA7, 0x58, 0x57, 0x52, 0xBF, 0x57, 0x13, 0xD4, 0x15, 0xB0, 0x06, 0xF5, 0x38, + 0xCC, 0x64, 0x23, 0x09, 0xD5, 0x8C, 0x0D, 0x64, 0x31, 0xFA, 0x74, 0xAA, 0x96, 0x7E, 0x9B, 0x16, 0xCA, 0x21, 0xFD, + 0xC0, 0x54, 0x91, 0x40, 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 0x08, 0xE7, 0x96, + 0x59, 0xCC, 0x42, 0x9F, 0xEF, 0xFC, 0x02, 0x02, 0x08, 0x00]); + + try { + cert.createTrustAnchorsWithKeyStore(p12Data, '123456').then((data) => { + console.log('createTrustAnchorsWithKeyStore sucess, the num of result is :' + JSON.stringify(data.length)); + }).catch((err: BusinessError) => { + console.error('createTrustAnchorsWithKeyStore failed, error :' + JSON.stringify(err)); + }) + } catch (error) { + console.error('createTrustAnchorsWithKeyStore failed, error :' + JSON.stringify(error)); + } +} + + +// [End trust_array_constructed_from_p12_file_during_validation] +@Entry +@Component +struct Index { + @State message: string = 'CreateTrustanchorFromP12'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateTrustanchorFromP12') + .width('70%') + .onClick(() => { + try { + test(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..4dd9b499558c38b71706f428c8fbe3639807e872 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets @@ -0,0 +1,154 @@ +/* + * 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. + */ + + + +// [Start certificate_chain_validator_object_creation_and_validation] +import { cert } from '@kit.DeviceCertificateKit'; +import { util } from '@kit.ArkTS'; + +// CA数据,这只是一个示例,需要根据具体业务来赋值 +let caCertData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIDgTCCAmmgAwIBAgIGAXKnJjrAMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + + 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + + '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDI1NjMxWhcN\n' + + 'MzUwMjE4MDI1NjMxWjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + + 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + + '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyY30ubE33Zmc\n' + + 'BBM4OIpD1UuDVKynC4xNBK4v79vnlc4ElmRZD4RjkS612DtpaUzt/yHMZXmJTdqg\n' + + '2jq7UG4sQc0G3uNGIXdUpRZpnUYGVftuZMxHaNOb+IgDkZzaO3Dk33piOpH/X/Ke\n' + + 'OosCbm7eBL+y+wRhUsLSCEasEsIvW3edHuYLrfz3MzwY/9AmnwqDGdRJ5rPayODD\n' + + 'HH0yw9JuRkdMacN8omVX8jBfJeI8KafcQW8MJz+Y0qyQyiZ6A81AQSVfT+6Sk2U3\n' + + 'UqeSTmtdIL1u29HfYLwYGHey+1Ro2wxqnMsFKIdKu2dDMDQZx61pER/dFtPYFlS7\n' + + '/uh3mi9HUQIDAQABo1MwUTAdBgNVHQ4EFgQUGDykmR825RPNFIEQaFzUqkr+CIow\n' + + 'HwYDVR0jBBgwFoAUGDykmR825RPNFIEQaFzUqkr+CIowDwYDVR0TAQH/BAUwAwEB\n' + + '/zANBgkqhkiG9w0BAQsFAAOCAQEAXjlmYKjBz1ajWywZNlN+LVRXNx7bS4TYtOc2\n' + + 'ME4N1ls6yjWSLtBe4DdkBqZ2HwrVW4dg5xZdAS/T0v/rRiGbX6iUFRV9WCTdtLZB\n' + + 'HKNh7vU39F7mgTaaWXQK/+6NeLKMzwJENRRaESI/sXeKE6irfJgYuq3NH8GGFd+w\n' + + 'HnvVBHRb6WSlY2s5Li7t6lj40UbwOljnqzRQvBeX57rOnzJgVKND3oY9pex/05Oe\n' + + '96x+qc2iqZbu54A6NYCTj/65EEKoj5rYxPXMV4FegV42ouaLJJoS+cEEY7w+ixcl\n' + + '04TjtjEdhTZiJCmI0RK50H2SWC0t9qkFewM3CCWTHY5ygPtMGA==\n' + + '-----END CERTIFICATE-----\n'; + +// 二级CA证书数据,这只是一个示例,需要根据具体业务来赋值 +let secondCaCertData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIDgTCCAmmgAwIBAgIGAXKnJjrBMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + + 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + + '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDI1NjU3WhcN\n' + + 'MzUwMjE4MDI1NjU3WjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + + 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + + '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxSL5L7fwMaRF\n' + + 'RiT1l7kpzaAqZe33/3lgexoMfGiIFarIhYyYJsmOJKes2uLSnPeqEtscrXmFQiIG\n' + + '0srmwrriGgo3oxDp4/5i1FhCf3FqZUwD/RJhtVmkHT0HoYl4cpt/dJSF/e5vxt/J\n' + + '2Z1eRIQOj9DzyqET6+ONQmfVOyzEH6xlpXHZLvykSZ7ytPp25LxULPWjTmpDOPRq\n' + + 'vkSMaH4H3mPw/Z9r0MVKP7DgAZMl2yVudHp785AMTVD0L9zWGHf3sek25ek5nv2r\n' + + 'SlB21MTBpvd8GC/iGns4V3Bvf75WAMgpGghAkRRyADeqt5Hw+x9BIb9FcfE+h6n+\n' + + '6EF6FPa8GQIDAQABo1MwUTAdBgNVHQ4EFgQUjt2Crk/j6W8WCdHWyz4H+Q2/3PYw\n' + + 'HwYDVR0jBBgwFoAUGDykmR825RPNFIEQaFzUqkr+CIowDwYDVR0TAQH/BAUwAwEB\n' + + '/zANBgkqhkiG9w0BAQsFAAOCAQEAksPHMuVF9e2GMVlaSe1Ao9D1KrJvKNaFZPCI\n' + + 'lQe2CDsX+Qu7sQj4SML5vvWFLtcAp6ZovqUyEM0PtZWVSjPCRTMJ3ofBPwnXvQ2N\n' + + '7J7NCDA227MQabXeN3jMhkcAzlpdO5poTnobPF4xRqb39jM7otnNJsujvzdDab2l\n' + + 'LiP4eU5TrEaF2lwidBWJX0VoLrRpqzQhiWXGMpCBBugP5U+bFs20wezJBG19WYyc\n' + + '2xKKfvyIcxrpmvjLZl8HddS7Ot1CKXyc8U9QZBGAlPwOXu8juppcEtjJyl36EnvF\n' + + 'YAcwrXOAtCiNpX3UnLUbG8GtpOOWQWCt+x1gKmA6V0jbqQmqcw==\n' + + '-----END CERTIFICATE-----\n'; + +// 证书链校验器示例。在这个示例中,验证了一个二级证书链 +function certChainValidatorSample(): void { + let textEncoder = new util.TextEncoder(); + // 证书链校验器算法。目前仅支持PKIX + let algorithm = 'PKIX'; + + // 创建一个证书链校验器实例 + let validator = cert.createCertChainValidator(algorithm); + + // CA证书数据 + let uint8ArrayOfCaCertData = textEncoder.encodeInto(caCertData); + + // CA证书数据的长度 + let uint8ArrayOfCaCertDataLen = new Uint8Array(new Uint16Array([uint8ArrayOfCaCertData.byteLength]).buffer); + + // 二级CA证书数据 + let uint8ArrayOf2ndCaCertData = textEncoder.encodeInto(secondCaCertData); + + // 二级CA证书数据的长度 + let uint8ArrayOf2ndCaCertDataLen = new Uint8Array(new Uint16Array([uint8ArrayOf2ndCaCertData.byteLength]).buffer); + + // 证书链二进制数据:二级CA证书数据长度+二级CA证书数据+CA证书数据长度+CA证书数据(L-V格式) + let encodingData = new Uint8Array(uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + + uint8ArrayOfCaCertDataLen.length + uint8ArrayOfCaCertData.length); + for (let i = 0; i < uint8ArrayOf2ndCaCertDataLen.length; i++) { + encodingData[i] = uint8ArrayOf2ndCaCertDataLen[i]; + } + for (let i = 0; i < uint8ArrayOf2ndCaCertData.length; i++) { + encodingData[uint8ArrayOf2ndCaCertDataLen.length + i] = uint8ArrayOf2ndCaCertData[i]; + } + for (let i = 0; i < uint8ArrayOfCaCertDataLen.length; i++) { + encodingData[uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + i] = + uint8ArrayOfCaCertDataLen[i]; + } + for (let i = 0; i < uint8ArrayOfCaCertData.length; i++) { + encodingData[uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + + uint8ArrayOfCaCertDataLen.length + i] = uint8ArrayOfCaCertData[i]; + } + + let certChainData: cert.CertChainData = { + // Uint8Array类型:L-V格式(证书数据长度-证书数据) + data: encodingData, + // 证书的数量。本例中为2 + count: 2, + // 证书格式。仅支持 PEM 和 DER。在此示例中,证书为 PEM 格式 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + // 验证证书链 + validator.validate(certChainData, (err, data) => { + if (err != null) { + // 校验失败 + console.error(`validate failed, errCode: ${err.code}, errMsg: ${err.message}`); + } else { + // 校验成功 + console.log('validate success'); + } + }); +} + + +// [End certificate_chain_validator_object_creation_and_validation] +@Entry +@Component +struct Index { + @State message: string = 'CreateVerifyCerchainvalidatorObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateVerifyCerchainvalidatorObject') + .width('70%') + .onClick(() => { + try { + certChainValidatorSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..6307cb4d1efa77935ddf2ede7636a25ef7377fe9 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets @@ -0,0 +1,149 @@ +/* + * 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. + */ + +// [Start certificate_chain_object_creation_and_validation] + +import { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +let certChainData = '-----BEGIN CERTIFICATE-----\n' + + 'MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n' + + 'BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n' + + 'ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n' + + 'MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n' + + 'Z3N1MRAwDgYDVQQHEwdOYW5qaW5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4G\n' + + 'CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n' + + 'b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n' + + 'uKPWR9dKBA==\n' + + '-----END CERTIFICATE-----\n' + + '-----BEGIN CERTIFICATE-----\n' + + 'MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n' + + 'DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n' + + 'MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n' + + 'MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n' + + 'A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n' + + 'AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n' + + 'klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n' + + 'St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n' + + 'AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n' + + 'KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n' + + 'xjoE\n' + + '-----END CERTIFICATE-----\n'; + +async function sample() { + let textEncoder = new util.TextEncoder(); + // 证书链二进制数据,需业务自行赋值 + const encodingBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(certChainData), + // 根据encodingData的格式进行赋值,支持FORMAT_PEM、FORMAT_DER和FORMAT_PKCS7 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; + try { + x509CertChain = await cert.createX509CertChain(encodingBlob); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`createX509CertChain failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + + try { + let certList = x509CertChain.getCertList(); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`X509CertChain getCertList failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + + // 证书链校验数据,需业务自行赋值 + const param: cert.CertChainValidationParameters = { + date: '20231212080000Z', + trustAnchors: [{ + CAPubKey: new Uint8Array([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, 0xbb, 0x16, + 0x9d, 0x8f, 0x5c, 0x30, 0xd0, 0xba, 0x8f, 0x37, 0x6e, 0x33, 0xaf, 0x6f, 0x23, 0x71, 0x23, 0xa5, 0x49, 0x60, + 0x1e, 0xd1, 0x07, 0x4b, 0xc9, 0x11, 0x7e, 0x66, 0x01, 0xba, 0x92, 0x52]), + CASubject: new Uint8Array([0x30, 0x5a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x45, + 0x4e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x45, 0x6e, 0x67, 0x6c, 0x61, 0x6e, + 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x06, 0x4c, 0x6f, 0x6e, 0x64, 0x6f, 0x6e, + 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, + 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, + 0x03, 0x13, 0x03, 0x74, 0x73, 0x31]), + }] + }; + try { + const validationRes = await x509CertChain.validate(param); + console.log('X509CertChain validate success'); + } catch (err) { + console.error('X509CertChain validate failed'); + } +} + + +// [End certificate_chain_object_creation_and_validation] +@Entry +@Component +struct Index { + @State message: string = 'CreateVerifyCertchainObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateVerifyCertchainObject') + .width('70%') + .onClick(()=>{ + try { + sample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/Index.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..681dc6d72a5fe6082e107cb6fc2ed087d1225f29 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,79 @@ +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'CertificateAlgorithmLibrary'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('CreateParseVerifyCertObject') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateParseVerifyCertObject'); + }) + Button('CreateParseVerifyCertextensionObject') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateParseVerifyCertextensionObject'); + }) + Button('CreateParseVerifyCrlObject') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateParseVerifyCrlObject'); + }) + Button('CreateTrustanchorFromP12') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateTrustanchorFromP12'); + }) + Button('CreateVerifyCerchainvalidatorObject') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateVerifyCerchainvalidatorObject'); + }) + Button('CreateGetCertCrlObject') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateGetCertCrlObject'); + }) + Button('CreateVerifyCertchainObject') + .width('70%') + .onClick(() => { + this.goToSample('pages/CreateVerifyCertchainObject'); + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4bdc71c1d64e827bf919ab4a9fde28908d33746e --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 @@ -0,0 +1,78 @@ +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_CERT_MANAGER", + "reason": "$string:reason", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + }, + ] + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/color.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/string.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8e49920df6c15f02c3c9e07967e0b4d7d0d6aee7 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CertificateAlgorithmLibrary" + }, + { + "name": "reason", + "value": "CertificateAlgorithmLibrary" + } + ] +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/background.png b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/background.png differ diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/foreground.png b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/foreground.png differ diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/layered_image.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/startIcon.png b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/startIcon.png differ diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/main_pages.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..d06e39e2f87b72f08aadb69484de7e8b364155e9 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,12 @@ +{ + "src": [ + "pages/Index", + "pages/CreateParseVerifyCertObject", + "pages/CreateParseVerifyCertextensionObject", + "pages/CreateGetCertCrlObject", + "pages/CreateParseVerifyCrlObject", + "pages/CreateTrustanchorFromP12", + "pages/CreateVerifyCertchainObject", + "pages/CreateVerifyCerchainvalidatorObject" + ] +} diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/dark/element/color.json b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/Ability.test.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a99ab838b79a8fa43323c78b4fd4afd4854955b7 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets @@ -0,0 +1,176 @@ +/* + * 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 certificateAlgorithmLibraryTest() { + describe('certificateAlgorithmLibraryTest', () => { + /** + * 打开应用 + */ + 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'); + }) + + /** + * 点击按钮,创建、解析校验证书对象 + */ + it('testCertificateAlgorithmLibrary001', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateParseVerifyCertObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCertObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary001 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建、解析和校验证书扩展信息对象 + */ + it('testCertificateAlgorithmLibrary002', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateParseVerifyCertextensionObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCertextensionObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary002 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建、解析和校验证书吊销列表对象 + */ + it('testCertificateAlgorithmLibrary003', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateParseVerifyCrlObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCrlObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary003 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,构造TrustAnchor对象数组 + */ + it('testCertificateAlgorithmLibrary004', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateTrustanchorFromP12')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateTrustanchorFromP12')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary004 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建和校验证书链校验器对象 + */ + it('testCertificateAlgorithmLibrary005', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateVerifyCerchainvalidatorObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateVerifyCerchainvalidatorObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary005 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建和获取证书集合及证书吊销列表集合对象 + */ + it('testCertificateAlgorithmLibrary006', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateGetCertCrlObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateGetCertCrlObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary006 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建和校验证书链对象 + */ + it('testCertificateAlgorithmLibrary007', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateVerifyCertchainObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateVerifyCertchainObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary007 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/List.test.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e01634f12a7270c767add1f97d0d32ebe6b102d --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 certificateAlgorithmLibraryTest from './CertificateAlgorithmLibrary.test'; + +export default function testsuite() { + abilityTest(); + certificateAlgorithmLibraryTest(); +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/module.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/List.test.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/LocalUnit.test.ets b/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigor/hvigor-config.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigorfile.ts b/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/oh-package.json5 b/DeviceCertificateKit/CertificateAlgorithmLibrary/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/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/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md b/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..282567f26044325a9eec99dc10a98adbf4a7e459 --- /dev/null +++ b/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md @@ -0,0 +1,14 @@ +# 证书算法库测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,创建、解析校验证书对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建、解析和校验证书扩展信息对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建、解析和校验证书吊销列表对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,构造TrustAnchor对象数组 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建和校验证书链校验器对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建和获取证书集合及证书吊销列表集合对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建和校验证书链对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary1.png b/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary1.png new file mode 100644 index 0000000000000000000000000000000000000000..f22b2a8857783ba1fe0531638eece9227b3fe108 Binary files /dev/null and b/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary1.png differ diff --git a/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary2.png b/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary2.png new file mode 100644 index 0000000000000000000000000000000000000000..26ed0cf623308ee37efcfb2154aff2bef65cd0a2 Binary files /dev/null and b/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary2.png differ diff --git a/DeviceCertificateKit/CertificateManagement/.gitignore b/DeviceCertificateKit/CertificateManagement/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/.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/DeviceCertificateKit/CertificateManagement/AppScope/app.json5 b/DeviceCertificateKit/CertificateManagement/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f6dcb15f5a47f36774ee0587223fffd5f5c464d9 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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.certificatemanagement", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json b/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..939dfafaa7e20bd1f187de1f7f7097929946b194 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CertificateManagement" + } + ] +} diff --git a/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/media/app_icon.png b/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/media/app_icon.png differ diff --git a/DeviceCertificateKit/CertificateManagement/README.md b/DeviceCertificateKit/CertificateManagement/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d039703efbc7450b979cd75f2560273802b644f2 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/README.md @@ -0,0 +1,74 @@ +# 证书管理 + +### 介绍 + +证书管理主要提供系统级的证书管理能力,实现证书全生命周期(安装、存储、使用和销毁)的管理和安全使用。 + +本示例主要展示了证书管理中证书管理与证书管理对话框的使用场景。该工程中展示的代码详细描述可查如下链接中介绍。 + +- [证书管理开发指导](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/certManager-guidelines.md) +- [证书管理对话框开发指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/DeviceCertificateKit/certManagerDialog-guidelines.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例CertificateManagement.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 证书管理示例代码 + │ │ ├── CertManagerGuidelines.ets + │ │ ├── CertManagerDialogGuidelines.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── CertificateManagement.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +[ohos.permission.ACCESS_CERT_MANAGER](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccesscertmanager) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo DeviceCertificateKit/CertificateManagement > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/build-profile.json5 b/DeviceCertificateKit/CertificateManagement/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/build-profile.json5 @@ -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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + "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/DeviceCertificateKit/CertificateManagement/code-linter.json5 b/DeviceCertificateKit/CertificateManagement/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/.gitignore b/DeviceCertificateKit/CertificateManagement/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 b/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/hvigorfile.ts b/DeviceCertificateKit/CertificateManagement/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/oh-package.json5 b/DeviceCertificateKit/CertificateManagement/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entryability/EntryAbility.ets b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6b8c16549bca30eb0bd6434ebeaa115a6d9e1a5 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets @@ -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. + */ +// [Start certificate_management_dialog_box_development_guide] +import { certificateManagerDialog } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; + +async function certificateManagerDialogSample() { + /* context为应用的上下文信息,由调用方自行获取,此处仅为示例 */ + let context: common.Context = getContext(); + /* pageType为页面类型,此处赋值PAGE_MAIN,即拉起证书管理主界面 */ + let pageType: certificateManagerDialog.CertificateDialogPageType = + certificateManagerDialog.CertificateDialogPageType.PAGE_MAIN; + try { + certificateManagerDialog.openCertificateManagerDialog(context, pageType).then(() => { + console.info('Succeeded in opening certificate manager dialog.'); + }).catch((err: BusinessError) => { + console.error(`Failed to open certificate manager dialog. Code: ${err.code}, message: ${err.message}`); + }) + } catch (error) { + console.error(`Failed to open certificate manager dialog. Code: ${error.code}, message: ${error.message}`); + } +} + + +// [End certificate_management_dialog_box_development_guide] +@Entry +@Component +struct Index { + @State message: string = 'CertManagerDialogGuidelines'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Bold) + .fontSize(25) + Button($r('app.string.call_certManagerDialogGuidelines')) + .width('70%') + .onClick(() => { + certificateManagerDialogSample(); + this.message = 'CertManagerDialogGuidelines Success'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets new file mode 100644 index 0000000000000000000000000000000000000000..2114a688246668b0c66f1597cda9ba72321e04f4 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets @@ -0,0 +1,298 @@ +/* + * 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. + */ +// [Start certificate_management_development_guidance] + +import { certificateManager } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +async function certificateManagerSample() { + /* 安装的凭据数据需要业务赋值,本例数据非凭据数据 */ + let keystore: Uint8Array = new Uint8Array([ + 0x30,0x82,0x0c,0x26,0x02,0x01,0x03,0x30,0x82,0x0b,0xe0,0x06,0x09,0x2a,0x86,0x48, + 0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x82,0x0b,0xd1,0x04,0x82,0x0b,0xcd,0x30,0x82, + 0x0b,0xc9,0x30,0x82,0x05,0x6e,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07, + 0x01,0xa0,0x82,0x05,0x5f,0x04,0x82,0x05,0x5b,0x30,0x82,0x05,0x57,0x30,0x82,0x05, + 0x53,0x06,0x0b,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x0a,0x01,0x02,0xa0,0x82, + 0x04,0xfa,0x30,0x82,0x04,0xf6,0x30,0x28,0x06,0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d, + 0x01,0x0c,0x01,0x03,0x30,0x1a,0x04,0x14,0xb6,0x80,0x7d,0xb9,0xc3,0x44,0x84,0x1f, + 0x44,0xe6,0x95,0x6a,0x98,0xa1,0xcb,0x97,0xfb,0x2b,0xcc,0x5a,0x02,0x02,0x04,0x00, + 0x04,0x82,0x04,0xc8,0x78,0xa7,0x16,0x45,0x40,0xf0,0xec,0xac,0x3e,0x34,0x17,0xd7, + 0x8b,0x5c,0xca,0x85,0x29,0x0b,0x08,0xef,0xa2,0xf0,0x6d,0x55,0xd7,0xde,0x96,0xa5, + 0x49,0x6d,0x9d,0xa6,0xe6,0x00,0xd7,0x2c,0x65,0xf6,0xc2,0xd1,0xe8,0x70,0xfb,0xb5, + 0xd9,0xc6,0x7d,0xd4,0x28,0x45,0x17,0x4f,0x4f,0xd9,0x9b,0xab,0xe2,0xdc,0xe7,0x22, + 0x6c,0x1e,0xbc,0xd6,0xf0,0x38,0x0b,0xd7,0xd9,0xfc,0xa7,0xb4,0x87,0x95,0x96,0xc3, + 0x93,0xc0,0xb5,0x37,0xf4,0x64,0xfe,0xe5,0x07,0xac,0x41,0x2d,0xf5,0xeb,0xe3,0x8b, + 0xc2,0x74,0x73,0x13,0x3b,0x5f,0x17,0x54,0x2d,0x31,0x20,0x69,0x1c,0xab,0x66,0xba, + 0x06,0x43,0x03,0xa3,0x69,0x54,0x72,0x70,0x5f,0x78,0xd2,0xec,0xdd,0x50,0xb8,0x25, + 0x03,0xd4,0xec,0x2d,0x92,0x96,0x9f,0xcc,0xa6,0x4a,0x50,0x34,0x1c,0xfc,0xe3,0xc2, + 0x6b,0x65,0xec,0xb3,0x1c,0xc8,0xf2,0xd0,0x79,0xf0,0x28,0x61,0x9a,0xfe,0xea,0x7f, + 0x16,0x38,0xe1,0xf4,0x7f,0x86,0xfe,0x73,0x67,0xc9,0x60,0x73,0xd8,0xef,0x2c,0x6b, + 0xde,0x88,0x37,0xc5,0xd7,0x18,0x60,0x74,0x97,0x07,0x85,0x70,0x74,0x30,0x66,0x8f, + 0x11,0x4a,0xb9,0x18,0xed,0xfc,0xc7,0xdb,0x63,0x58,0x7b,0x57,0x0d,0xfa,0x43,0x81, + 0xbd,0x34,0xfc,0x17,0xd3,0x2a,0xa9,0x74,0xa0,0x2c,0x1b,0xe2,0xaa,0x3d,0xd2,0x84, + 0x18,0xaa,0x2a,0x0e,0xa8,0xcc,0x2a,0xc4,0x39,0x60,0x29,0xb5,0x03,0xaf,0xea,0x96, + 0xcf,0xa5,0x67,0x4c,0xa7,0x59,0x76,0xea,0x8a,0x60,0xd6,0xd8,0xc3,0x9e,0x0e,0xad, + 0xd6,0xa0,0x5a,0x00,0x7c,0xa6,0xe8,0x62,0xa4,0x0a,0x53,0xcc,0x48,0xf0,0x4d,0x6d, + 0xda,0xb3,0xa9,0x82,0x37,0x75,0xff,0x20,0xa9,0xe8,0x6e,0xc8,0x4a,0x8a,0x81,0x84, + 0x7a,0x1d,0x02,0x40,0xd9,0x76,0xee,0x89,0x62,0xd5,0x57,0x19,0xc8,0x9a,0x6a,0x22, + 0x8d,0x01,0x8f,0xc9,0x14,0x72,0xf9,0x90,0xa3,0x0f,0x5f,0x23,0x32,0xc4,0xd5,0x79, + 0x53,0x1f,0xbc,0x3a,0xf4,0x19,0x7f,0x93,0xb7,0x8b,0x0b,0xb9,0xeb,0x1f,0xa2,0x5c, + 0x93,0x0e,0x5f,0x29,0x87,0xea,0x67,0x4d,0x5d,0x2b,0x5e,0x29,0x81,0xbd,0x3d,0xfc, + 0xdf,0x92,0x50,0x19,0xc2,0x50,0x4d,0x07,0x76,0x08,0xfc,0xbe,0xd1,0x73,0x64,0xb7, + 0x22,0x6f,0xb7,0x89,0x93,0xc1,0xb1,0x44,0x42,0x27,0xf5,0x61,0x06,0x32,0xd1,0xc0, + 0xdb,0x92,0x51,0x1b,0xd3,0x5c,0x95,0x85,0x0e,0x66,0xc5,0xe9,0xf5,0x7f,0x44,0x52, + 0x49,0xfb,0x0a,0x83,0x02,0x6e,0x69,0x6c,0xf1,0x6f,0xe5,0xa1,0xa0,0x5d,0x8a,0xd3, + 0x4f,0x9d,0x0a,0x08,0x1b,0x32,0x70,0xe3,0xf3,0xf0,0x63,0xda,0x37,0x90,0x96,0x3f, + 0xac,0xf7,0x3d,0xd5,0xeb,0x08,0xc1,0x51,0x91,0x75,0x2c,0x0f,0xf1,0x5b,0x39,0xce, + 0x05,0x06,0x65,0x1c,0xe8,0x36,0xb0,0x86,0x6e,0xbe,0xb9,0x25,0xd6,0xdf,0x5c,0x50, + 0x56,0x99,0x69,0x8e,0x92,0xbe,0xa1,0x03,0x18,0xd6,0x34,0xa6,0x98,0x53,0x3a,0xb7, + 0x96,0xcb,0xa8,0x1d,0xc9,0x9e,0x92,0x15,0xf4,0x99,0x7e,0x58,0x81,0x99,0x84,0xa0, + 0x67,0xa5,0x77,0x1e,0xa9,0xac,0xc2,0xcf,0xd8,0x7a,0x68,0xef,0x35,0x9e,0xb6,0xb7, + 0x78,0x6b,0x43,0x12,0x53,0x93,0x7b,0x50,0x94,0x37,0x48,0x75,0x98,0x27,0x0f,0x73, + 0x1a,0xb7,0x2f,0x19,0x7e,0x42,0x08,0x02,0x05,0x42,0x71,0xd6,0x26,0x64,0x04,0x25, + 0x87,0xd9,0x02,0x05,0x1f,0x79,0x6b,0x9b,0x0e,0xfa,0x10,0x7b,0xf3,0x96,0x3f,0x53, + 0x02,0x9d,0x80,0x13,0xd7,0x30,0x03,0x24,0x96,0x21,0x05,0xdb,0x2d,0xe9,0xc8,0x51, + 0x30,0x42,0x6d,0xa9,0xe8,0x39,0xb0,0xa9,0x59,0xb9,0x21,0x22,0x98,0x41,0x0e,0x33, + 0x0d,0x7f,0x7a,0x69,0x45,0x0b,0xf1,0xac,0xfd,0xaa,0xaa,0x45,0x7f,0x78,0x24,0xf8, + 0x56,0x85,0x3b,0x4b,0x95,0x78,0x40,0xc7,0x2f,0xfc,0xb6,0xb7,0x5f,0xa2,0xf9,0xe9, + 0x80,0x4c,0x4a,0xbf,0x4f,0xcb,0xb9,0x51,0x7c,0x18,0xb7,0xb7,0x70,0xf1,0x4c,0x96, + 0xd2,0x4a,0x44,0xb9,0xa6,0x22,0xc9,0x95,0xf5,0x99,0xbd,0x8c,0xf2,0x45,0x88,0xfb, + 0x2f,0xe0,0x38,0x42,0xc8,0xe5,0x0d,0x55,0x05,0x0f,0xb9,0x91,0x7d,0xaf,0x27,0x91, + 0xb3,0xc4,0x83,0x46,0x49,0x1a,0xce,0x3a,0xff,0x1b,0x58,0xc9,0xa4,0x22,0x82,0x57, + 0x7f,0xda,0x5f,0xae,0xea,0xae,0x96,0x91,0xef,0xde,0x4e,0x25,0x66,0xbb,0xe9,0xb3, + 0xa7,0xbc,0x12,0xc4,0x5f,0xee,0xc6,0x13,0x9c,0xd9,0xbc,0x14,0xef,0x3d,0x7b,0xa4, + 0x91,0x4a,0x77,0xf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e,0xa0,0x64,0xba, + 0x02,0x21,0x18,0x05,0xd1,0x30,0xdd,0x33,0x32,0x98,0x3d,0x0d,0x22,0xb4,0xda,0x8d, + 0xa0,0x9a,0x3a,0x97,0x0f,0xa5,0xe1,0xf1,0x56,0x17,0xd8,0xbd,0x15,0xd3,0xd6,0xe0, + 0x20,0x95,0x7b,0x6a,0x63,0x59,0x80,0xee,0xcd,0x60,0xb1,0xb0,0xba,0x8d,0x6a,0x4c, + 0x3d,0x5c,0xac,0x1a,0x87,0x1d,0x07,0xfe,0x69,0x81,0x8f,0x5d,0xba,0x64,0x3f,0xea, + 0xdf,0x36,0xb3,0x07,0x6c,0xbc,0x5b,0xe8,0xc0,0x5c,0x9a,0xd1,0x16,0xe3,0x2e,0xa5, + 0x92,0x5b,0xba,0x89,0x55,0x65,0x5d,0x14,0xd2,0x36,0x9e,0xfd,0x6d,0xcf,0x9d,0x68, + 0x10,0x7f,0xb6,0xdf,0x6b,0x9a,0x9b,0xd4,0x6b,0x37,0xfd,0x77,0xde,0x39,0x59,0xed, + 0xe3,0xdb,0x65,0xe8,0xa4,0x15,0x4a,0x6d,0xb4,0xad,0xb8,0x36,0xe1,0x3a,0xf8,0x6a, + 0xfe,0x6e,0x1f,0x02,0x15,0x09,0x36,0x44,0xb7,0x52,0x5b,0x79,0x3c,0x8e,0xfb,0x20, + 0x62,0xdb,0x7b,0xb6,0xb1,0x43,0xea,0x29,0xff,0x10,0xef,0x24,0x9c,0x4d,0xc2,0xa8, + 0x98,0xaa,0x29,0x59,0x85,0x06,0xc3,0xdb,0xcf,0xc2,0x71,0xfa,0xad,0x7b,0xd5,0xf7, + 0x50,0x53,0xc5,0x75,0x97,0x15,0x42,0x90,0x8f,0xf1,0xed,0x6a,0x98,0x83,0x59,0x15, + 0x23,0xa7,0xea,0xe9,0xed,0x22,0xec,0x0a,0x41,0x4c,0xc2,0x35,0x54,0xd9,0xec,0x4b, + 0xb8,0x3f,0xd0,0x68,0xed,0xa7,0x83,0x4e,0x42,0x29,0x5c,0x4d,0xa3,0x79,0x3e,0x59, + 0x86,0x04,0x62,0x24,0x9d,0x7b,0xb3,0x69,0xe9,0x82,0x57,0xdb,0xbf,0xeb,0x98,0x4f, + 0x59,0x7e,0x8d,0x8f,0x69,0x56,0xdc,0x3f,0xeb,0x01,0xcf,0x82,0x05,0x1e,0xe7,0x6d, + 0xff,0xb2,0x67,0xd8,0x34,0x68,0xf7,0xd0,0xee,0x6d,0xc6,0x22,0x4c,0x4d,0x36,0xd1, + 0xf5,0x5a,0xab,0xbb,0x41,0x43,0x4d,0xef,0x2c,0x62,0x64,0x28,0x31,0x46,0x30,0x1f, + 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x14,0x31,0x12,0x1e,0x10,0x00, + 0x6c,0x00,0x64,0x00,0x71,0x00,0x20,0x00,0x74,0x00,0x65,0x00,0x73,0x00,0x74,0x30, + 0x23,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x15,0x31,0x16,0x04,0x14, + 0x44,0x37,0x75,0x8f,0xcd,0x94,0x90,0x07,0x3e,0x38,0x20,0xb7,0x1b,0x3f,0x0d,0x3d, + 0x40,0x85,0x32,0x6a,0x30,0x82,0x06,0x53,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d, + 0x01,0x07,0x06,0xa0,0x82,0x06,0x44,0x30,0x82,0x06,0x40,0x02,0x01,0x00,0x30,0x82, + 0x06,0x39,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0x30,0x28,0x06, + 0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x01,0x06,0x30,0x1a,0x04,0x14,0xc8, + 0xe2,0x48,0x69,0x85,0x06,0xb3,0x34,0x55,0xf1,0xfe,0x9c,0x95,0x92,0xbd,0x73,0xcd, + 0x50,0xf4,0x88,0x02,0x02,0x04,0x00,0x80,0x82,0x06,0x00,0xb6,0x66,0x06,0x1a,0x84, + 0xb1,0xb7,0xf8,0xca,0x74,0xe1,0x7c,0x23,0x94,0x5f,0xb3,0x73,0xda,0x81,0x51,0x0e, + 0x4d,0x07,0xcd,0x8a,0x68,0xd5,0x15,0x98,0x57,0xc1,0xb9,0x94,0x30,0xc7,0x97,0x40, + 0x3b,0xa4,0xc0,0xd5,0xfe,0xd3,0x9f,0x92,0xe9,0x6a,0xeb,0x52,0x1c,0xd8,0x89,0x26, + 0xf4,0x1b,0x49,0xe9,0xef,0x45,0x0b,0x33,0x36,0x73,0x1b,0x91,0x2b,0x75,0xff,0x9b, + 0x12,0x41,0xc7,0x80,0xb1,0x4a,0x12,0xaf,0x02,0x8d,0x4b,0xea,0xcd,0x0e,0xc6,0x03, + 0x14,0x4c,0x79,0xef,0xa6,0xc2,0xf6,0x86,0xd3,0x19,0xfd,0xe6,0x85,0xfa,0x3b,0x0d, + 0x3b,0xb2,0x98,0xd2,0xff,0xa0,0xfe,0x65,0x63,0xc9,0xc2,0xa7,0xf4,0x0d,0x98,0x57, + 0xab,0xd5,0x7b,0x58,0x87,0x62,0x58,0x74,0x40,0x75,0x06,0x8f,0x4a,0x93,0xff,0x76, + 0xbb,0xd3,0x19,0x4d,0xf8,0x04,0x89,0xa4,0xc5,0xe3,0xbe,0xde,0x60,0x04,0x7f,0x52, + 0x58,0x11,0x51,0x6f,0xa9,0xf9,0x06,0x6d,0x03,0x83,0xcd,0xa7,0x01,0xf8,0x2d,0xa0, + 0xe6,0x45,0x63,0x85,0x46,0x7c,0x9b,0x55,0x86,0xfd,0xe9,0xc3,0xd4,0xeb,0xeb,0x3e, + 0x2b,0x0e,0x33,0x8a,0x9f,0x40,0xe3,0x9d,0x52,0xe3,0xf8,0x6f,0x1a,0x4d,0x5f,0xaf, + 0x78,0x12,0x56,0x56,0xab,0x3d,0xbd,0x36,0x8e,0xd9,0xa9,0xc4,0xfc,0xd3,0x21,0x6b, + 0xa7,0xa0,0xa3,0xc6,0x50,0x41,0x43,0xdb,0xd0,0xf7,0x16,0x08,0x06,0x0d,0xed,0x15, + 0x90,0xdc,0x31,0xeb,0x0d,0x4b,0x7b,0x1c,0xa6,0x32,0xca,0x52,0xaa,0x3a,0x71,0xc2, + 0xb7,0xce,0x42,0xd4,0x90,0xbe,0x65,0x0b,0x55,0x54,0x79,0x6b,0xbf,0xbc,0xf7,0x1d, + 0x5f,0x14,0x4a,0x02,0x4c,0x63,0x16,0x6d,0x85,0xad,0xb3,0x1f,0x11,0x43,0x3f,0xd3, + 0x4d,0x3b,0xfc,0x96,0x79,0xca,0xa5,0x9e,0xc1,0xdf,0xbc,0x94,0x2d,0x46,0xe2,0xe7, + 0x1a,0x93,0xfc,0xc5,0x09,0x16,0x8d,0x91,0x41,0xc0,0x59,0x4f,0x9c,0x76,0x94,0x86, + 0xf2,0x59,0x5d,0xca,0xa9,0x20,0x93,0x10,0xd6,0x45,0x3b,0x30,0x55,0xdf,0x96,0x9f, + 0x60,0x06,0x7c,0x9a,0xb9,0x24,0x1e,0xe0,0xae,0x65,0xd5,0x4b,0x4a,0xe2,0x55,0xc7, + 0x09,0xb5,0x51,0x40,0x07,0x7e,0xe1,0xef,0x34,0x63,0x7b,0x3a,0xa9,0x98,0x2f,0x09, + 0xe1,0xfd,0x7a,0xb3,0x29,0x79,0xfc,0xf5,0xbd,0x3c,0x3c,0x05,0x02,0xd5,0xc5,0x86, + 0xaf,0x9a,0xd3,0x10,0x7e,0xc3,0x1b,0xf7,0x73,0x64,0xd6,0x27,0x04,0x08,0xee,0x7b, + 0x49,0x2d,0x21,0x2e,0xd8,0xbc,0x29,0x3a,0x80,0x82,0x2d,0xed,0xf2,0xaf,0x08,0x55, + 0xce,0x80,0x9c,0xf2,0xeb,0x60,0x38,0x12,0x27,0x31,0xa0,0x2f,0x64,0xbf,0x21,0x8c, + 0x63,0x88,0x90,0xee,0x9e,0xc0,0x5f,0xb8,0xea,0xa5,0xf3,0x26,0x01,0x65,0xe3,0x97, + 0xb6,0x17,0x6f,0x6a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a,0x6a,0xb9,0x19, + 0xfa,0x04,0x3e,0xc5,0x0a,0xc6,0x5c,0xc0,0x3f,0xbb,0x3f,0x18,0x9b,0x27,0xdc,0xd5, + 0xf7,0x2b,0x54,0x30,0x68,0x47,0x45,0xae,0x12,0xe4,0xdc,0x71,0xa5,0xbd,0x4b,0x6e, + 0xd6,0xba,0x6e,0x96,0xa6,0x73,0x77,0xc5,0x2b,0x48,0x6d,0x7e,0xbb,0x44,0x6f,0xd5, + 0x5d,0x17,0xcb,0xd6,0x96,0xb8,0xd1,0x06,0xe1,0xea,0x2f,0xa6,0x86,0x1b,0x81,0x97, + 0xbe,0xa0,0xfb,0x9a,0x20,0x6d,0xf5,0x33,0xeb,0x64,0xd3,0x89,0x68,0x8c,0x8b,0xa9, + 0x4f,0x19,0x51,0xb5,0x8d,0x89,0x74,0x51,0x2c,0x90,0x38,0x0e,0x0d,0x18,0x53,0x87, + 0x31,0x62,0x3d,0x54,0x1e,0x74,0xc0,0x9a,0xc3,0x37,0xdd,0x36,0x00,0x5c,0xc9,0xb4, + 0x1d,0x57,0x0b,0xb2,0x43,0x25,0x2b,0xb6,0xee,0x83,0xda,0xfd,0xad,0x41,0x9d,0xf4, + 0xdf,0x60,0xfe,0xa1,0xd0,0x1c,0x78,0x3e,0x36,0x17,0x38,0x4a,0xb2,0x42,0x15,0xac, + 0xa6,0x5e,0x88,0xe3,0x11,0x76,0x48,0xc9,0xcd,0x86,0xbb,0x2b,0x7a,0xab,0xa9,0xfe, + 0x76,0x0f,0xb5,0xb4,0x6e,0x1a,0xfd,0x5f,0xa4,0x20,0x32,0xb2,0xb5,0x4d,0x25,0xa4, + 0x34,0xd3,0x06,0xf4,0xc6,0x6e,0x83,0xcb,0x5e,0x87,0xe0,0x25,0xee,0x17,0x58,0x2e, + 0xaa,0x3c,0x54,0xf1,0xb5,0x33,0xcd,0xa7,0x37,0x78,0x10,0x25,0x23,0x90,0x8a,0x80, + 0x3f,0xbb,0x4b,0xdf,0x89,0xc2,0xee,0x5c,0x78,0x33,0x1a,0x76,0x3e,0xf9,0x46,0x49, + 0x50,0x0c,0x39,0x38,0x33,0x6b,0xbe,0xae,0xec,0xec,0xf9,0xf5,0x1c,0x40,0xa1,0xa7, + 0x29,0x0e,0x02,0x7a,0xd7,0xb9,0x0b,0x2e,0x6f,0x9f,0x33,0x97,0x63,0x87,0xe0,0xb7, + 0xf6,0x9e,0xa0,0x43,0xa6,0xbe,0x04,0x3f,0x3f,0x8a,0xcc,0x8d,0xd3,0xbc,0x15,0x0e, + 0x9b,0xb7,0x99,0xc1,0x3f,0xfa,0xaf,0x8a,0xc4,0x67,0x0d,0x36,0xda,0xab,0xf5,0xe9, + 0x77,0xa9,0x84,0x0b,0xf9,0x22,0x49,0x15,0x9d,0x72,0x62,0x73,0x21,0x90,0x14,0x6e, + 0x4b,0x2d,0x50,0x80,0x02,0x5e,0x79,0x66,0x7d,0x8c,0x5b,0xf8,0x2a,0x0c,0x2e,0x62, + 0x15,0x85,0x78,0xce,0xa7,0xb6,0x33,0x8f,0xba,0xe4,0xb1,0xa5,0x9e,0xea,0x66,0x9e, + 0x9c,0x98,0x7d,0x90,0x75,0x6f,0xd4,0xc0,0xd5,0x42,0x5d,0x5e,0xd4,0xab,0xed,0x1e, + 0xe0,0x77,0x48,0xaf,0x13,0xac,0x89,0x8c,0x2a,0x2a,0x6b,0xb1,0x45,0xca,0xae,0x86, + 0xfc,0xd8,0x15,0x4e,0xae,0xce,0x00,0x63,0x71,0xa6,0xef,0x43,0xdd,0x1c,0x77,0x21, + 0x85,0xa8,0xd2,0x46,0x61,0xf0,0xfd,0xcb,0x43,0x31,0x41,0x35,0xda,0x2f,0xa9,0xc8, + 0xb0,0x5f,0xd6,0xc9,0x7b,0x43,0x97,0x28,0xfa,0x2e,0xe7,0x07,0x8e,0x32,0xd5,0xf5, + 0x30,0x2f,0x76,0x51,0x4b,0x21,0xcf,0xbd,0xc2,0x3a,0x5e,0x85,0x60,0x2b,0x42,0xc5, + 0x56,0x70,0xf1,0xfb,0xce,0xd5,0xee,0x4f,0x30,0x33,0x08,0xea,0x3b,0xa7,0x31,0x54, + 0x67,0xc2,0x07,0x2d,0x7c,0x2f,0x43,0xbe,0x34,0x34,0xd4,0x11,0x5c,0x8f,0x94,0x6a, + 0x77,0xcb,0x03,0x77,0x48,0x33,0xac,0x77,0x78,0x42,0x6c,0x6f,0x08,0x93,0x23,0x5c, + 0xb8,0x6e,0xae,0xac,0xd0,0x33,0x85,0x1a,0x55,0xd5,0x85,0xa7,0x00,0xf0,0xf9,0x01, + 0x58,0xac,0x39,0x10,0x05,0x45,0x3e,0xb0,0xa9,0x86,0x12,0x78,0xe7,0xad,0xb0,0xee, + 0x4f,0xc7,0x34,0xf4,0x09,0x9c,0x70,0x77,0xa7,0x41,0xb3,0x54,0xc3,0xc4,0xa0,0xf2, + 0x72,0x50,0x74,0x9c,0xed,0x16,0x45,0x92,0x15,0xa8,0x42,0x86,0x93,0x4e,0x28,0x79, + 0x1e,0x80,0x7a,0x13,0xae,0x4d,0x37,0x55,0xeb,0xbd,0x83,0x35,0xec,0x20,0xa1,0x83, + 0x19,0x50,0x30,0x02,0x6c,0x48,0x78,0x3b,0xa9,0x6f,0x18,0x57,0x69,0x3a,0x5b,0xdb, + 0xd6,0x77,0x7f,0x5c,0x0d,0xe3,0xd1,0xd0,0x27,0x1f,0x3f,0xd2,0xfb,0x6b,0xab,0x36, + 0x44,0x58,0x6f,0xf4,0xa2,0x45,0x32,0xc9,0x05,0x67,0xd9,0x1a,0x9c,0x9b,0x63,0x31, + 0x7a,0x54,0xbd,0xa0,0x63,0x7a,0x01,0x73,0xbc,0xcc,0xd2,0xe2,0x44,0x17,0xd2,0xd7, + 0xb8,0x76,0x7e,0xb7,0x5a,0x04,0xfc,0xb9,0xd9,0xed,0xd2,0x76,0x38,0x21,0x71,0xfc, + 0x83,0x55,0x89,0x30,0x6e,0xf8,0x0d,0xc0,0xe7,0xb6,0x8e,0x1a,0x44,0xf6,0x8d,0xd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xf4,0x26,0x7f,0x46,0x30,0x3d,0x30,0x21,0x30, + 0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14,0x33,0x7b,0x5c,0xd1, + 0x1b,0xad,0x79,0x93,0x10,0xa3,0x79,0x2e,0xae,0x8b,0x10,0x87,0xba,0x28,0xf7,0xa6, + 0x04,0x14,0x84,0x78,0x82,0x85,0xc4,0x9e,0xa2,0x14,0x4f,0xad,0x59,0x15,0x3d,0x23, + 0xe6,0x62,0xbf,0x6d,0x8c,0x06,0x02,0x02,0x04,0x00 + ]); + + /* 安装凭据对应的密码,业务赋值 */ + let keystorePwd: string = 'huawei'; + let appKeyUri: string = ''; + try { + /* 安装私有凭据 */ + const res: certificateManager.CMResult = await certificateManager.installPrivateCertificate(keystore, keystorePwd, 'testPriCredential'); + appKeyUri = (res.uri != undefined) ? res.uri : ''; + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`Failed to install private certificate. Code: ${e.code}, message: ${e.message}`); + } + + try { + /* srcData为待签名、验签的数据,业务自行赋值 */ + let srcData: Uint8Array = new Uint8Array([ + 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, + ]); + + /* 构造签名的属性参数 */ + const signSpec: certificateManager.CMSignatureSpec = { + purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_SIGN, + padding: certificateManager.CmKeyPadding.CM_PADDING_PSS, + digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256 + }; + + /* 签名 */ + const signHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, signSpec); + await certificateManager.update(signHandle.handle, srcData); + const signResult: certificateManager.CMResult = await certificateManager.finish(signHandle.handle); + + /* 构造验签的的属性参数 */ + const verifySpec: certificateManager.CMSignatureSpec = { + purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_VERIFY, + padding: certificateManager.CmKeyPadding.CM_PADDING_PSS, + digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256 + }; + + /* 验签 */ + const verifyHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, verifySpec); + await certificateManager.update(verifyHandle.handle, srcData); + const verifyResult = await certificateManager.finish(verifyHandle.handle, signResult.outData); + console.info('Succeeded in signing and verifying.'); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`Failed to sign or verify. Code: ${e.code}, message: ${e.message}`); + } + + try { + /* 卸载私有凭据 */ + await certificateManager.uninstallPrivateCertificate(appKeyUri); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`Failed to uninstall private certificate. Code: ${e.code}, message: ${e.message}`); + } +} + +// [End certificate_management_development_guidance] + +@Entry +@Component +struct Index { + @State message: string = 'CertManagerGuidelines'; + + build() { + Column({space: 5}) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_certManagerGuidelines')) + .width('70%') + .onClick(()=>{ + certificateManagerSample(); + this.message = 'CertManagerGuidelines Success'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/Index.ets b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5e7821beed19e6feedb012d59c87d73dcad2a9b --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,53 @@ +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'CertificateManagement'; + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.certManagerGuidelines')) + .width('70%') + .onClick(() => { + this.goToSample('pages/CertManagerGuidelines') + }) + Button($r('app.string.certManagerDialogGuidelines')) + .width('70%') + .onClick(() => { + this.goToSample('pages/CertManagerDialogGuidelines') + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 b/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6ec5c351a433017454fe6df8e3be97f56e279472 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 @@ -0,0 +1,78 @@ +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_CERT_MANAGER", + "reason": "$string:reason", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/color.json b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/string.json b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..490aab6c21dbdbc4bd45084b4b812721038db304 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CertificateManagement" + }, + { + "name": "reason", + "value": "CertificateManagement" + }, + { + "name": "dialog", + "value": "证书与凭据" + }, + { + "name": "certManagerGuidelines", + "value": "CertManagerGuidelines" + }, + { + "name": "certManagerDialogGuidelines", + "value": "CertManagerDialogGuidelines" + }, + { + "name": "call_certManagerGuidelines", + "value": "Call CertManagerGuidelines" + }, + { + "name": "call_certManagerDialogGuidelines", + "value": "Call CertManagerDialogGuidelines" + } + ] +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/background.png b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/background.png differ diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/foreground.png b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/foreground.png differ diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/layered_image.json b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/startIcon.png b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/startIcon.png differ diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/main_pages.json b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..15b79b33c8571c871d72e67eff5223f7275920f7 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/CertManagerDialogGuidelines", + "pages/CertManagerGuidelines" + ] +} diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/dark/element/color.json b/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/Ability.test.ets b/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets b/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5d4e5875911ce81256d315ebf7570417ab90726 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets @@ -0,0 +1,85 @@ +/* + * 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; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +export default function certificateManagementTest() { + describe('certificateManagementTest', () => { + /** + * 打开应用 + */ + 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'); + }) + + /** + * 点击按钮,安装、获取、使用、卸载证书 + */ + it('testCertificateManagement001', 0, async (done: Function) => { + console.info('uitest: testCertificateManagement001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CertManagerGuidelines')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CertManagerGuidelines')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('CertManagerGuidelines Success')); + console.info('uitest: testCertificateManagement001 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,拉起证书管理界面 + */ + it('testCertificateManagement002', 0, async (done: Function) => { + console.info('uitest: testCertificateManagement002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CertManagerDialogGuidelines')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CertManagerDialogGuidelines')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text(resourceToString($r('app.string.dialog')))); + console.info('uitest: testCertificateManagement002 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/List.test.ets b/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b643b53bb9b815023cf4b5aa1ccd55c8936d15dc --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 certificateManagementTest from './CertificateManagement.test'; + +export default function testsuite() { + abilityTest(); + certificateManagementTest(); +} \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/module.json5 b/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/test/List.test.ets b/DeviceCertificateKit/CertificateManagement/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/entry/src/test/LocalUnit.test.ets b/DeviceCertificateKit/CertificateManagement/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/hvigor/hvigor-config.json5 b/DeviceCertificateKit/CertificateManagement/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/hvigorfile.ts b/DeviceCertificateKit/CertificateManagement/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/oh-package.json5 b/DeviceCertificateKit/CertificateManagement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/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/DeviceCertificateKit/CertificateManagement/ohosTest.md b/DeviceCertificateKit/CertificateManagement/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..6301852ad71ebe1413bf61d336122af484a2e4c0 --- /dev/null +++ b/DeviceCertificateKit/CertificateManagement/ohosTest.md @@ -0,0 +1,9 @@ +# **证书管理**测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮安装,获取,应用私有凭据进行签名、验签,删除 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮拉起证书管理界面 | 成功拉起应用 | | 成功拉起弹窗并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement1.png b/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement1.png new file mode 100644 index 0000000000000000000000000000000000000000..2b44666b90a7f4cb6b308e49080d9461b434cbb1 Binary files /dev/null and b/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement1.png differ diff --git a/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement2.png b/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement2.png new file mode 100644 index 0000000000000000000000000000000000000000..48c54cfa91b9837069b7aaf035d24e5e0d983ea6 Binary files /dev/null and b/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement2.png differ