diff --git a/security/BUILD.gn b/security/BUILD.gn index 5e0601340393a54412fb30cc674c45e4b6ebcd61..c8ea4ed86339af50e77c523768d8ff813157bbaf 100644 --- a/security/BUILD.gn +++ b/security/BUILD.gn @@ -20,6 +20,7 @@ group("security") { if (is_standard_system) { deps = [ "access_token/AccessTokenTest_Normal_js:ActsAccessTokenApiJSNormalTest", + "certificate_framework/js_api_test_oh40:ActsCertFrameworkTwoJSNormalTest", "certificate_framework/js_api_test_one:ActsCertificateFrameworkJSNormalTest", "cipher/datacipher:datacipher", "cryptoFramework/js_api_test_oh40:ActsCryptoFrameworkTwoJSNormalTest", diff --git a/security/certificate_framework/js_api_test_oh40/BUILD.gn b/security/certificate_framework/js_api_test_oh40/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..460e4d40d0576b19f320714fef3bddbeb01e98a2 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +base_root = "../../../../../../" +import("$base_root/test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsCertFrameworkTwoJSNormalTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsCertFrameworkTwoJSNormalTest" + subsystem_name = "security" + part_name = "certificate_framework" +} +ohos_js_assets("hjs_demo_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("hjs_demo_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/security/certificate_framework/js_api_test_oh40/Test.json b/security/certificate_framework/js_api_test_oh40/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..729bcf3196b3d697d0578bba23dbe5f4c9e04c8d --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/Test.json @@ -0,0 +1,32 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "1800000", + "shell-timeout": "1800000", + "testcase-timeout": "900000", + "bundle-name": "com.openharmony.certificateframework2", + "package-name": "com.openharmony.certificateframework2" + }, + "kits": [ + { + "test-file-name": ["ActsCertFrameworkTwoJSNormalTest.hap"], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir -p /data/local/tmp/xts-test", + "chmod 777 -R /data/local/tmp/xts-test" + ] + }, + { + "type": "PushKit", + "push": [ + "ActsCertFrameworkTwoJSNormalTest.hap -> /data/local/tmp/xts-test/ActsCertFrameworkTwoJSNormalTest.hap" + ] + } + ] +} diff --git a/security/certificate_framework/js_api_test_oh40/signature/openharmony_sx.p7b b/security/certificate_framework/js_api_test_oh40/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..42a75c325fa1a659682715ac6c6c3359d5c3380f Binary files /dev/null and b/security/certificate_framework/js_api_test_oh40/signature/openharmony_sx.p7b differ diff --git a/security/certificate_framework/js_api_test_oh40/src/main/config.json b/security/certificate_framework/js_api_test_oh40/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..3cf704f7015b5443a18513dd0ed767be8cc16061 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/config.json @@ -0,0 +1,85 @@ +{ + "app": { + "bundleName": "com.openharmony.certificateframework2", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 9, + "target": 10, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.openharmony.certificateframework2", + "name": ".entry", + "mainAbility": ".MainAbility", + "srcPath": "", + "deviceType": ["default", "tablet", "tv", "wearable", "phone"], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": ["entity.system.home"], + "actions": ["action.system.home"] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": ["pages/index/index"], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": ["pages/index/index"], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + } + } +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/app.js b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..9a8580a07af12ad00df4b7ee6423af361dcb614c --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/app.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from "@ohos.hilog"; + +export default { + onCreate() { + hilog.info(0x0000, "testTag", "%{public}s", "Application onCreate"); + }, + onDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "Application onDestroy"); + }, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/i18n/en-US.json b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..d15e42418e8a38ce9f6e5fcb0d59405b8824f282 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,7 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": {} +} \ No newline at end of file diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/i18n/zh-CN.json b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..1782d228dc0e9d336934a509377d8aa9202714df --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,7 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": {} +} \ No newline at end of file diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.css b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..0f1786c36ea9e572a261660f34040d7bcb54411d --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.hml b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.js b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..4e0306559cfe4879ff45721be15ee495d09c09b9 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export default { + data: { + title: "", + }, + onInit() { + this.title = this.$t("strings.world"); + }, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/app.js b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..e0320e9930914b93d67d5fc893d3ab9d3ce3db95 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from "@ohos.hilog"; +import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry"; +import { Hypium } from "@ohos/hypium"; +import testsuite from "../test/List.test"; + +export default { + onCreate() { + hilog.info(0x0000, "testTag", "%{public}s", "TestApplication onCreate"); + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!"); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + }, + onDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestApplication onDestroy"); + }, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/i18n/en-US.json b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3f895b4334b2864f17d0581ac9f46200a421fab3 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,7 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": {} +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/i18n/zh-CN.json b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..764604f3f82f5adb285234f320132066e20e3b58 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,7 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": {} +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.css b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..0f1786c36ea9e572a261660f34040d7bcb54411d --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.hml b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.js b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..dee852571aa7fc079dccc139a91f391763c6772f --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + data: { + title: "", + }, + onInit() { + this.title = this.$t("strings.world"); + }, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/security/certificate_framework/js_api_test_oh40/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..4b29514070f851325e1f550332712b24f82332d4 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from "@ohos.hilog"; +import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry"; + +export default { + onPrepare() { + hilog.info( + 0x0000, + "testTag", + "%{public}s", + "OpenHarmonyTestRunner OnPrepare" + ); + }, + onRun() { + hilog.info( + 0x0000, + "testTag", + "%{public}s", + "OpenHarmonyTestRunner onRun run" + ); + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + + var testAbilityName = + abilityDelegatorArguments.parameters["-p"] + ".TestAbility"; + var cmd = + "aa start -d 0 -a " + + testAbilityName + + " -b " + + abilityDelegatorArguments.bundleName; + var debug = abilityDelegatorArguments.parameters["-D"]; + if (debug == "true") { + cmd += " -D"; + } + hilog.info(0x0000, "testTag", "cmd : %{public}s", cmd); + abilityDelegator.executeShellCommand(cmd, (err, data) => { + hilog.info( + 0x0000, + "testTag", + "executeShellCommand : err : %{public}s", + JSON.stringify(err) ?? "" + ); + hilog.info( + 0x0000, + "testTag", + "executeShellCommand : data : %{public}s", + data.stdResult ?? "" + ); + hilog.info( + 0x0000, + "testTag", + "executeShellCommand : data : %{public}s", + data.exitCode ?? "" + ); + }); + }, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/CertificateFunc.test.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/CertificateFunc.test.js new file mode 100644 index 0000000000000000000000000000000000000000..c5c4dca47b611fbbf09e71b295607817f5cf5423 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/CertificateFunc.test.js @@ -0,0 +1,992 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect, +} from "@ohos/hypium"; +import * as certPromise from "./utils/certificate/publicCertificatePromise"; +import * as certCallback from "./utils/certificate/publicCertificateCallback"; +import * as certCommon from "./utils/certificate/publicCertificateCommon"; +import cert from "@ohos.security.cert"; +import { + uInt8ArrayToString, + uInt8ArrayToShowStr, +} from "./utils/common/publicDoString"; + +export default function CertFrameworkFuncTestJSUnit() { + describe("CertFrameworkFuncTestJSUnit", function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // 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(function () { + // 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(function () { + // 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(function () { + // 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. + }); + + /** + * @tc.number Security_CertificateFramework_Enum_Func_0100 + * @tc.name X509 Cert Enum Type Test + * @tc.desc X509 Cert Enum Type Test + */ + it("Security_CertificateFramework_Enum_Func_0100", 0, function (done) { + certCommon.certificateEnumTypeTest(); + done(); + }); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0100 + * @tc.name X509 getItem for CERT_ITEM_TYPE_TBS Test + * @tc.desc Create Der Cert with Promise Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0100", + 0, + async function (done) { + await certPromise + .createX509CertInstancePromise("der") + .then((certObject) => { + try { + expect( + certObject != null && certObject != undefined + ).assertTrue(); + let TBS = certCommon.getX509CertItem( + certObject, + cert.CertItemType.CERT_ITEM_TYPE_TBS + ); + expect(TBS != null && TBS != undefined).assertTrue(); + console.warn( + "getX509CertItem TBS: " + uInt8ArrayToShowStr(TBS.data) + ); + } catch (err) { + console.error( + "getX509CertItem TBS error, error code is: " + err.code + ); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertInstancePromise error, error code is: " + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0200 + * @tc.name X509 getItem for CERT_ITEM_TYPE_PUBLIC_KEY Test + * @tc.desc Create Der Cert with Callback Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0200", + 0, + async function (done) { + await certCallback + .createX509CertInstanceCallback("der") + .then((certObject) => { + try { + expect( + certObject != null && certObject != undefined + ).assertTrue(); + let pubKey = certCommon.getX509CertItem( + certObject, + cert.CertItemType.CERT_ITEM_TYPE_PUBLIC_KEY + ); + expect(pubKey != null && pubKey != undefined).assertTrue(); + console.log( + "getX509CertItem pubKey: " + uInt8ArrayToShowStr(pubKey.data) + ); + } catch (err) { + console.error( + "getX509CertItem pubKey error, error code is: " + err.code + ); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertInstanceCallback error, error code is: " + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0300 + * @tc.name X509 getItem for CERT_ITEM_TYPE_ISSUER_UNIQUE_ID Test + * @tc.desc Create Der Cert with Promise Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0300", + 0, + async function (done) { + await certPromise + .createX509CertInstancePromise("der") + .then((certObject) => { + try { + expect( + certObject != null && certObject != undefined + ).assertTrue(); + let issuerUniqueID = certCommon.getX509CertItem( + certObject, + cert.CertItemType.CERT_ITEM_TYPE_ISSUER_UNIQUE_ID + ); + expect( + issuerUniqueID != null && issuerUniqueID != undefined + ).assertTrue(); + console.warn( + "getX509CertItem issuerUniqueID: " + + uInt8ArrayToShowStr(issuerUniqueID.data) + ); + } catch (err) { + console.error( + "getX509CertItem issuerUniqueID error, error code is: " + + err.code + ); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertInstancePromise error, error code is: " + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0400 + * @tc.name X509 getItem for CERT_ITEM_TYPE_SUBJECT_UNIQUE_ID Test + * @tc.desc Create Der Cert with Callback Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0400", + 0, + async function (done) { + await certCallback + .createX509CertInstanceCallback("der") + .then((certObject) => { + try { + expect( + certObject != null && certObject != undefined + ).assertTrue(); + let subjectUniqueID = certCommon.getX509CertItem( + certObject, + cert.CertItemType.CERT_ITEM_TYPE_SUBJECT_UNIQUE_ID + ); + expect( + subjectUniqueID != null && subjectUniqueID != undefined + ).assertTrue(); + console.warn( + "getX509CertItem subjectUniqueID: " + + uInt8ArrayToShowStr(subjectUniqueID.data) + ); + } catch (err) { + console.error( + "getX509CertItem subjectUniqueID error, error code is: " + + err.code + ); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertInstanceCallback error, error code is: " + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0500 + * @tc.name X509 getItem for CERT_ITEM_TYPE_EXTENSIONS Test + * @tc.desc Create Der Cert with Promise Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0500", + 0, + async function (done) { + await certPromise + .createX509CertInstancePromise("der") + .then((certObject) => { + try { + expect( + certObject != null && certObject != undefined + ).assertTrue(); + let extensions = certCommon.getX509CertItem( + certObject, + cert.CertItemType.CERT_ITEM_TYPE_EXTENSIONS + ); + expect( + extensions != null && extensions != undefined + ).assertTrue(); + console.warn( + "getX509CertItem extensions: " + + uInt8ArrayToShowStr(extensions.data) + ); + } catch (err) { + console.error( + "getX509CertItem extensions error, error code is: " + err.code + ); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertInstancePromise error, error code is: " + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0600 + * @tc.name X509 getItem invalid param Test 1 + * @tc.desc Create Der Cert with Promise Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0600", + 0, + async function (done) { + try { + let certObject = await certPromise.createX509CertInstancePromise( + "der" + ); + expect(certObject != null && certObject != undefined).assertTrue(); + let extensions = certObject.getItem(-1); + expect(extensions != null && extensions != undefined).assertTrue(); + console.warn( + "getX509CertItem extensions: " + + uInt8ArrayToShowStr(extensions.data) + ); + } catch (err) { + console.error("getX509CertItem err code is:" + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0700 + * @tc.name X509 getItem invalid param Test 2 + * @tc.desc Create Der Cert with Promise Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0700", + 0, + async function (done) { + try { + let certObject = await certPromise.createX509CertInstancePromise( + "der" + ); + expect(certObject != null && certObject != undefined).assertTrue(); + let extensions = certObject.getItem(); + expect(extensions != null && extensions != undefined).assertTrue(); + console.warn( + "getX509CertItem extensions: " + + uInt8ArrayToShowStr(extensions.data) + ); + } catch (err) { + console.error("getX509CertItem err code is:" + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertTest_Func_0800 + * @tc.name X509 getItem invalid param Test 3 + * @tc.desc Create Der Cert with Promise Style + */ + it( + "Security_CertificateFramework_CertTest_Func_0800", + 0, + async function (done) { + try { + let certObject = await certPromise.createX509CertInstancePromise( + "der" + ); + expect(certObject != null && certObject != undefined).assertTrue(); + let extensions = certObject.getItem( + cert.CertItemType.CERT_ITEM_TYPE_EXTENSIONS, + "" + ); + expect(extensions != null && extensions != undefined).assertTrue(); + console.warn( + "getX509CertItem extensions: " + + uInt8ArrayToShowStr(extensions.data) + ); + } catch (err) { + console.error("getX509CertItem err code is:" + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0100 + * @tc.name X509 CertExtension getEncoded Test + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0100", + 0, + async function (done) { + await certPromise + .createX509CertExtensionNormalPromise("certExtensionNormal01") + .then((extensionObj) => { + try { + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let encodedObj = extensionObj.getEncoded(); + expect( + encodedObj != null && encodedObj != undefined + ).assertTrue(); + console.warn( + "encodedObj data is: " + uInt8ArrayToShowStr(encodedObj.data) + ); + console.warn( + "encodedObj encodingFormat is: " + encodedObj.encodingFormat + ); + } catch (err) { + console.error("getEncoded error, error code is: " + err.code); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertExtensionNormalPromise error, error code is: " + + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0200 + * @tc.name X509 CertExtension getOidList and getEntry Test 1 + * @tc.desc Create Der CertExtension with Callback Style + * @tc.desc ExtensionOidType is EXTENSION_OID_TYPE_ALL + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0200", + 0, + async function (done) { + await certCallback + .createX509CertExtensionNormalCallback("certExtensionNormal02") + .then((extensionObj) => { + try { + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList( + cert.ExtensionOidType.EXTENSION_OID_TYPE_ALL + ); + expect( + oidListObj != null && oidListObj != undefined + ).assertTrue(); + console.warn("oidListObj data is: " + oidListObj.data); + let oid = oidListObj.data[0]; + let oid1 = oidListObj.data[1]; + let oidDataBlob = { + data: oid, + }; + let oidDataBlob1 = { + data: oid1, + }; + let entryObj = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, + oidDataBlob + ); + expect(entryObj != null && entryObj != undefined).assertTrue(); + console.warn("entryObj data is: " + entryObj.data); + let entryObj1 = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY_CRITICAL, + oidDataBlob1 + ); + expect(entryObj1 != null && entryObj1 != undefined).assertTrue(); + console.warn("entryObj1 data is: " + entryObj1.data); + } catch (err) { + console.error("getEntry error, error code is: " + err.code); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertExtensionNormalCallback error, error code is: " + + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0300 + * @tc.name X509 CertExtension getOidList and getEntry Test 2 + * @tc.desc Create Der CertExtension with Promise Style + * @tc.desc ExtensionOidType is EXTENSION_OID_TYPE_CRITICAL + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0300", + 0, + async function (done) { + await certPromise + .createX509CertExtensionNormalPromise("certExtensionNormal02") + .then((extensionObj) => { + try { + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList( + cert.ExtensionOidType.EXTENSION_OID_TYPE_CRITICAL + ); + expect( + oidListObj != null && oidListObj != undefined + ).assertTrue(); + console.warn("oidListObj data is: " + oidListObj.data); + let oid = oidListObj.data[0]; + let oid2 = oidListObj.data[oidListObj.data.length - 1]; + let oidDataBlob = { + data: oid, + }; + let oidDataBlob2 = { + data: oid2, + }; + let entryObj = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY_CRITICAL, + oidDataBlob + ); + expect(entryObj != null && entryObj != undefined).assertTrue(); + console.warn( + "entryObj data is: " + uInt8ArrayToShowStr(entryObj.data) + ); + let entryObj2 = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY_VALUE, + oidDataBlob2 + ); + expect(entryObj2 != null && entryObj2 != undefined).assertTrue(); + console.warn("entryObj2 data is: " + entryObj2.data); + } catch (err) { + console.error("getEntry error, error code is: " + err.code); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertExtensionNormalPromise error, error code is: " + + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0400 + * @tc.name X509 CertExtension getOidList and getEntry Test 3 + * @tc.desc Create Der CertExtension with Callback Style + * @tc.desc ExtensionOidType is EXTENSION_OID_TYPE_UNCRITICAL + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0400", + 0, + async function (done) { + await certCallback + .createX509CertExtensionNormalCallback("certExtensionNormal02") + .then((extensionObj) => { + try { + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList( + cert.ExtensionOidType.EXTENSION_OID_TYPE_UNCRITICAL + ); + expect( + oidListObj != null && oidListObj != undefined + ).assertTrue(); + console.warn("oidListObj data is: " + oidListObj.data); + let oid1 = oidListObj.data[1]; + let oid2 = oidListObj.data[oidListObj.data.length - 1]; + let oidDataBlob1 = { + data: oid1, + }; + let oidDataBlob2 = { + data: oid2, + }; + let entryObj1 = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, + oidDataBlob1 + ); + expect(entryObj1 != null && entryObj1 != undefined).assertTrue(); + console.warn( + "entryObj1 data is: " + uInt8ArrayToShowStr(entryObj1.data) + ); + let entryObj2 = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY_VALUE, + oidDataBlob2 + ); + expect(entryObj2 != null && entryObj2 != undefined).assertTrue(); + console.warn( + "entryObj2 data is: " + uInt8ArrayToShowStr(entryObj2.data) + ); + } catch (err) { + console.error("getEntry error, error code is: " + err.code); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertExtensionNormalCallback error, error code is: " + + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0500 + * @tc.name X509 CertExtension checkCA Test 1 + * @tc.desc Use callback style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0500", + 0, + async function (done) { + await certCallback + .createX509CertExtensionNormalCallback("certExtensionNormal02") + .then((extensionObj) => { + try { + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let caStatus = extensionObj.checkCA(); + console.warn("caStatus is: " + caStatus); + expect(caStatus > 0).assertTrue(); + } catch (err) { + console.error("checkCA error, error code is: " + err.code); + expect(null).assertFail(); + } + }) + .catch((err) => { + console.error( + "createX509CertExtensionNormalCallback error, error code is: " + + err.code + ); + expect(null).assertFail(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0600 + * @tc.name X509 CertExtension Test With Invalid Parm + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0600", + 0, + async function (done) { + await certPromise + .createX509CertExtensionNormalPromise("certExtensioninvalid01") + .then((extensionObj) => { + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + }) + .catch((err) => { + console.error( + "createX509CertExtensionNormalPromise error, error code is: " + + err.code + ); + expect(err.code == 401).assertTrue(); + }); + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0700 + * @tc.name X509 CertExtension getOidList Test With Invalid Param 1 + * @tc.desc Create Der CertExtension with Callback Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0700", + 0, + async function (done) { + try { + let extensionObj = + await certCallback.createX509CertExtensionNormalCallback( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList(3); + expect(oidListObj != null && oidListObj != undefined).assertTrue(); + } catch (err) { + console.error("getOidList error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0800 + * @tc.name X509 CertExtension getOidList Test With Invalid Param 2 + * @tc.desc Create Der CertExtension with Callback Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0800", + 0, + async function (done) { + try { + let extensionObj = + await certCallback.createX509CertExtensionNormalCallback( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList(); + expect(oidListObj != null && oidListObj != undefined).assertTrue(); + } catch (err) { + console.error("getOidList error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_0900 + * @tc.name X509 CertExtension getOidList Test With Invalid Param 3 + * @tc.desc Create Der CertExtension with Callback Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_0900", + 0, + async function (done) { + try { + let extensionObj = + await certCallback.createX509CertExtensionNormalCallback( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList( + cert.ExtensionOidType.EXTENSION_OID_TYPE_UNCRITICAL, + "" + ); + expect(oidListObj != null && oidListObj != undefined).assertTrue(); + } catch (err) { + console.error("getOidList error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1000 + * @tc.name X509 CertExtension getEntry Test With Invalid Param 1 + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1000", + 0, + async function (done) { + try { + let extensionObj = + await certPromise.createX509CertExtensionNormalPromise( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oid = new Uint8Array([50, 60, 70]); + let oidDataBlob = { + data: oid, + }; + let entryObj = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, + oidDataBlob + ); + expect(entryObj != null && entryObj != undefined).assertTrue(); + } catch (err) { + console.error("getEntry error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1100 + * @tc.name X509 CertExtension getEntry Test With Invalid Param 2 + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1100", + 0, + async function (done) { + try { + let extensionObj = + await certPromise.createX509CertExtensionNormalPromise( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList( + cert.ExtensionOidType.EXTENSION_OID_TYPE_UNCRITICAL + ); + expect(oidListObj != null && oidListObj != undefined).assertTrue(); + let oid = oidListObj.data[1]; + let oidDataBlob = { + data: oid, + }; + let entryObj = extensionObj.getEntry(3, oidDataBlob); + expect(entryObj != null && entryObj != undefined).assertTrue(); + } catch (err) { + console.error("getEntry error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1200 + * @tc.name X509 CertExtension getEntry Test With Invalid Param 3 + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1200", + 0, + async function (done) { + try { + let extensionObj = + await certPromise.createX509CertExtensionNormalPromise( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oidListObj = extensionObj.getOidList( + cert.ExtensionOidType.EXTENSION_OID_TYPE_UNCRITICAL + ); + expect(oidListObj != null && oidListObj != undefined).assertTrue(); + let oid = oidListObj.data[1]; + let oidDataBlob = { + data: oid, + }; + let entryObj = extensionObj.getEntry(oidDataBlob); + expect(entryObj != null && entryObj != undefined).assertTrue(); + } catch (err) { + console.error("getEntry error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1300 + * @tc.name X509 CertExtension getEntry Test With Invalid Param 4 + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1300", + 0, + async function (done) { + try { + let extensionObj = + await certPromise.createX509CertExtensionNormalPromise( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let entryObj = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY + ); + expect(entryObj != null && entryObj != undefined).assertTrue(); + } catch (err) { + console.error("getEntry error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1400 + * @tc.name X509 CertExtension getEntry Test With Invalid Param 5 + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1400", + 0, + async function (done) { + try { + let extensionObj = + await certPromise.createX509CertExtensionNormalPromise( + "certExtensionNormal02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let oid1 = new Uint8Array([0, 50, 46, 53, 46, 50, 57, 46, 49, 57]); + console.warn("oid1 source string is: " + uInt8ArrayToString(oid1)); + let oidDataBlob1 = { + data: oid1, + }; + let entryObj = extensionObj.getEntry( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, + oidDataBlob1 + ); + expect(entryObj != null && entryObj != undefined).assertTrue(); + } catch (err) { + console.error("getEntry error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1500 + * @tc.name X509 CertExtension getEncoded Test With Invalid Params + * @tc.desc Create Der CertExtension with Promise Style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1500", + 0, + async function (done) { + try { + let extensionObj = + await certPromise.createX509CertExtensionNormalPromise( + "certExtensionNormal01" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let encodedObj = extensionObj.getEncoded(""); + expect(encodedObj != null && encodedObj != undefined).assertTrue(); + } catch (err) { + console.error("getEncoded error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1600 + * @tc.name X509 CertExtension checkCA Test With Invalid Param 1 + * @tc.desc Use callback style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1600", + 0, + async function (done) { + try { + let extensionObj = + await certCallback.createX509CertExtensionNormalCallback( + "certExtensionNormal01" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let encodedObj = extensionObj.checkCA(""); + expect(encodedObj != null && encodedObj != undefined).assertTrue(); + } catch (err) { + console.error("checkCA error , error code is: " + err.code); + expect(err.code == 401).assertTrue(); + } + done(); + } + ); + + /** + * @tc.number Security_CertificateFramework_CertExtensionTest_Func_1700 + * @tc.name X509 CertExtension checkCA Test With Invalid Param 2 + * @tc.desc Use callback style + */ + it( + "Security_CertificateFramework_CertExtensionTest_Func_1700", + 0, + async function (done) { + try { + let extensionObj = + await certCallback.createX509CertExtensionNormalCallback( + "certExtensionInvalid02" + ); + expect( + extensionObj != null && extensionObj != undefined + ).assertTrue(); + let encodedObj = extensionObj.checkCA(); + expect(encodedObj != null && encodedObj != undefined).assertTrue(); + } catch (err) { + console.error("checkCA error , error code is: " + err.code); + expect(err.code == 19030001).assertTrue(); + } + done(); + } + ); + }); +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/List.test.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..85221e81653092568c48a92b0caea2f603bf6d7e --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/List.test.js @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import CertFrameworkFuncTestJSUnit from "./CertificateFunc.test"; + +export default function testsuite() { + CertFrameworkFuncTestJSUnit(); +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificateCallback.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificateCallback.js new file mode 100644 index 0000000000000000000000000000000000000000..fc907803f12b8cdfa8fa985e737fa0919dd86b89 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificateCallback.js @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import cert from "@ohos.security.cert"; +import { stringTouInt8Array } from "../common/publicDoString"; +import * as param from "../common/publicParam"; + +async function createX509CertInstanceCallback(certType) { + var certFormat; + var encodingData; + + if (certType == "der") { + certFormat = cert.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(param.certDataDER01); + } else { + certFormat = cert.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(param.certDataPEM01); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certFormat, + }; + + return new Promise((resolve, reject) => { + cert.createX509Cert(encodingBlob, (err, data) => { + if (data == null) { + console.error( + "[callback] create X509 Cert failed! err code: " + err.code + ); + reject(err); + } else { + console.warn( + "[callback] create X509 Cert success! format is: " + certFormat + ); + resolve(data); + } + }); + }); +} + +async function createX509CertExtensionNormalCallback(flag) { + let encodingData = ""; + let certFormat = cert.EncodingFormat.FORMAT_DER; + + switch (flag) { + case "certExtensionNormal01": + encodingData = new Uint8Array(param.certExtensionNormal01); + break; + case "certExtensionNormal02": + encodingData = new Uint8Array(param.certExtensionNormal02); + break; + case "certExtensionInvalid01": + encodingData = new Uint8Array(param.certExtensionInvalid01); + break; + case "certExtensionInvalid02": + encodingData = new Uint8Array(param.certExtensionInvalid02); + break; + default: + break; + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certFormat, + }; + + return new Promise((resolve, reject) => { + cert.createCertExtension(encodingBlob, (err, extensionObj) => { + if (err) { + console.error( + "[callback] create X509 CertExtension failed! err code: " + err.code + ); + reject(err); + } else { + console.warn( + "[callback] create X509 CertExtension success! format is: " + + certFormat + ); + resolve(extensionObj); + } + }); + }); +} + +export { + createX509CertInstanceCallback, + createX509CertExtensionNormalCallback, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificateCommon.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificateCommon.js new file mode 100644 index 0000000000000000000000000000000000000000..e9168a90c4839d743f6d05c917ae4d20c1bf6557 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificateCommon.js @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from "@ohos/hypium"; +import cert from "@ohos.security.cert"; + +function certificateEnumTypeTest() { + expect(cert.CertResult.INVALID_PARAMS).assertEqual(401); + expect(cert.CertResult.NOT_SUPPORT).assertEqual(801); + expect(cert.CertResult.ERR_OUT_OF_MEMORY).assertEqual(19020001); + expect(cert.CertResult.ERR_RUNTIME_ERROR).assertEqual(19020002); + expect(cert.CertResult.ERR_CRYPTO_OPERATION).assertEqual(19030001); + expect(cert.CertResult.ERR_CERT_SIGNATURE_FAILURE).assertEqual(19030002); + expect(cert.CertResult.ERR_CERT_NOT_YET_VALID).assertEqual(19030003); + expect(cert.CertResult.ERR_CERT_HAS_EXPIRED).assertEqual(19030004); + expect(cert.CertResult.ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY).assertEqual( + 19030005 + ); + expect(cert.CertResult.ERR_KEYUSAGE_NO_CERTSIGN).assertEqual(19030006); + expect(cert.CertResult.ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE).assertEqual( + 19030007 + ); + + expect(cert.EncodingFormat.FORMAT_DER).assertEqual(0); + expect(cert.EncodingFormat.FORMAT_PEM).assertEqual(1); + + expect(cert.CertItemType.CERT_ITEM_TYPE_TBS).assertEqual(0); + expect(cert.CertItemType.CERT_ITEM_TYPE_PUBLIC_KEY).assertEqual(1); + expect(cert.CertItemType.CERT_ITEM_TYPE_ISSUER_UNIQUE_ID).assertEqual(2); + expect(cert.CertItemType.CERT_ITEM_TYPE_SUBJECT_UNIQUE_ID).assertEqual(3); + expect(cert.CertItemType.CERT_ITEM_TYPE_EXTENSIONS).assertEqual(4); + + expect(cert.ExtensionOidType.EXTENSION_OID_TYPE_ALL).assertEqual(0); + expect(cert.ExtensionOidType.EXTENSION_OID_TYPE_CRITICAL).assertEqual(1); + expect(cert.ExtensionOidType.EXTENSION_OID_TYPE_UNCRITICAL).assertEqual(2); + + expect(cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY).assertEqual(0); + expect( + cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY_CRITICAL + ).assertEqual(1); + expect(cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY_VALUE).assertEqual( + 2 + ); +} + +function getX509CertItem(certObject, itemType) { + let uint8Data = certObject.getItem(itemType); + return uint8Data; +} + +export { certificateEnumTypeTest, getX509CertItem }; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificatePromise.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificatePromise.js new file mode 100644 index 0000000000000000000000000000000000000000..6b4ad85702ab47839f49f78a84d43a24d5ab6334 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/certificate/publicCertificatePromise.js @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import cert from "@ohos.security.cert"; +import { stringTouInt8Array } from "../common/publicDoString"; +import * as param from "../common/publicParam"; + +async function createX509CertInstancePromise(certType) { + var certformat; + var encodingData; + + if (certType == "der") { + certformat = cert.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(param.certDataDER01); + } else { + certformat = cert.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(param.certDataPEM01); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat, + }; + + return new Promise((resolve, reject) => { + cert + .createX509Cert(encodingBlob) + .then((data) => { + console.warn( + "[promise] create X509 Cert success! format is: " + certformat + ); + resolve(data); + }) + .catch((err) => { + console.error( + "[promise] create X509 Cert failed! error code is: " + err.code + ); + reject(err); + }); + }); +} + +async function createX509CertExtensionNormalPromise(flag) { + let encodingData = ""; + let certFormat = cert.EncodingFormat.FORMAT_DER; + + switch (flag) { + case "certExtensionNormal01": + encodingData = new Uint8Array(param.certExtensionNormal01); + break; + case "certExtensionNormal02": + encodingData = new Uint8Array(param.certExtensionNormal02); + break; + case "certExtensionInvalid01": + encodingData = new Uint8Array(param.certExtensionInvalid01); + break; + case "certExtensionInvalid02": + encodingData = new Uint8Array(param.certExtensionInvalid02); + break; + default: + break; + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certFormat, + }; + + return new Promise((resolve, reject) => { + cert + .createCertExtension(encodingBlob) + .then((extensionObj) => { + console.warn( + "[promise] create X509 CertExtension success! format is: " + + certFormat + ); + resolve(extensionObj); + }) + .catch((err) => { + console.error( + "[promise] create X509 CertExtension failed! error code is: " + + err.code + ); + reject(err); + }); + }); +} + +export { createX509CertInstancePromise, createX509CertExtensionNormalPromise }; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/common/publicDoString.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/common/publicDoString.js new file mode 100644 index 0000000000000000000000000000000000000000..ab04e2e028a7af4d819a08df85d44ef1fc50d05d --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/common/publicDoString.js @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function stringToArray(str) { + var arr = []; + for (var i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return arr; +} + +//字节流转成可理解的字符串 +function uInt8ArrayToString(fileData) { + var dataString = ""; + for (var i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +//可理解的字符串转成自字节流 +function stringTouInt8Array(str) { + if (str.length == 0) { + console.error("stringTouInt8Array length is 0"); + } + var arr = []; + for (var i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + var tmpUint8Array = new Uint8Array(arr); + return tmpUint8Array; +} + +//字节流以16进制形式输出 +function uInt8ArrayToShowStr(uInt8Array) { + if (uInt8Array.length == 0) { + console.error("uInt8ArrayToShowStr length is 0"); + } + return Array.prototype.map + .call(uInt8Array, (x) => ("00" + x.toString(16)).slice(-2)) + .join(""); +} + +export { + stringToArray, + uInt8ArrayToString, + stringTouInt8Array, + uInt8ArrayToShowStr, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/common/publicParam.js b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/common/publicParam.js new file mode 100644 index 0000000000000000000000000000000000000000..a86ec31e400224da65a1708223957180c058ae02 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/js/test/utils/common/publicParam.js @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var certDataDER01 = [ + 0x30, 0x82, 0x03, 0x4c, 0x30, 0x82, 0x02, 0x34, 0xa0, 0x03, 0x02, 0x01, 0x02, + 0x02, 0x06, 0x20, 0x06, 0x05, 0x16, 0x70, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, + 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x52, 0x4f, 0x31, + 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x63, 0x65, 0x72, + 0x74, 0x53, 0x49, 0x47, 0x4e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, + 0x0b, 0x13, 0x10, 0x63, 0x65, 0x72, 0x74, 0x53, 0x49, 0x47, 0x4e, 0x20, 0x52, + 0x4f, 0x4f, 0x54, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x36, 0x30, + 0x37, 0x30, 0x34, 0x31, 0x37, 0x32, 0x30, 0x30, 0x34, 0x5a, 0x17, 0x0d, 0x33, + 0x31, 0x30, 0x37, 0x30, 0x34, 0x31, 0x37, 0x32, 0x30, 0x30, 0x34, 0x5a, 0x30, + 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x52, + 0x4f, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x63, + 0x65, 0x72, 0x74, 0x53, 0x49, 0x47, 0x4e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, + 0x55, 0x04, 0x0b, 0x13, 0x10, 0x63, 0x65, 0x72, 0x74, 0x53, 0x49, 0x47, 0x4e, + 0x20, 0x52, 0x4f, 0x4f, 0x54, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, + 0x01, 0x00, 0xb7, 0x33, 0xb9, 0x7e, 0xc8, 0x25, 0x4a, 0x8e, 0xb5, 0xdb, 0xb4, + 0x28, 0x1b, 0xaa, 0x57, 0x90, 0xe8, 0xd1, 0x22, 0xd3, 0x64, 0xba, 0xd3, 0x93, + 0xe8, 0xd4, 0xac, 0x86, 0x61, 0x40, 0x6a, 0x60, 0x57, 0x68, 0x54, 0x84, 0x4d, + 0xbc, 0x6a, 0x54, 0x02, 0x05, 0xff, 0xdf, 0x9b, 0x9a, 0x2a, 0xae, 0x5d, 0x07, + 0x8f, 0x4a, 0xc3, 0x28, 0x7f, 0xef, 0xfb, 0x2b, 0xfa, 0x79, 0xf1, 0xc7, 0xad, + 0xf0, 0x10, 0x53, 0x24, 0x90, 0x8b, 0x66, 0xc9, 0xa8, 0x88, 0xab, 0xaf, 0x5a, + 0xa3, 0x00, 0xe9, 0xbe, 0xba, 0x46, 0xee, 0x5b, 0x73, 0x7b, 0x2c, 0x17, 0x82, + 0x81, 0x5e, 0x62, 0x2c, 0xa1, 0x02, 0x65, 0xb3, 0xbd, 0xc5, 0x2b, 0x00, 0x7e, + 0xc4, 0xfc, 0x03, 0x33, 0x57, 0x0d, 0xed, 0xe2, 0xfa, 0xce, 0x5d, 0x45, 0xd6, + 0x38, 0xcd, 0x35, 0xb6, 0xb2, 0xc1, 0xd0, 0x9c, 0x81, 0x4a, 0xaa, 0xe4, 0xb2, + 0x01, 0x5c, 0x1d, 0x8f, 0x5f, 0x99, 0xc4, 0xb1, 0xad, 0xdb, 0x88, 0x21, 0xeb, + 0x90, 0x08, 0x82, 0x80, 0xf3, 0x30, 0xa3, 0x43, 0xe6, 0x90, 0x82, 0xae, 0x55, + 0x28, 0x49, 0xed, 0x5b, 0xd7, 0xa9, 0x10, 0x38, 0x0e, 0xfe, 0x8f, 0x4c, 0x5b, + 0x9b, 0x46, 0xea, 0x41, 0xf5, 0xb0, 0x08, 0x74, 0xc3, 0xd0, 0x88, 0x33, 0xb6, + 0x7c, 0xd7, 0x74, 0xdf, 0xdc, 0x84, 0xd1, 0x43, 0x0e, 0x75, 0x39, 0xa1, 0x25, + 0x40, 0x28, 0xea, 0x78, 0xcb, 0x0e, 0x2c, 0x2e, 0x39, 0x9d, 0x8c, 0x8b, 0x6e, + 0x16, 0x1c, 0x2f, 0x26, 0x82, 0x10, 0xe2, 0xe3, 0x65, 0x94, 0x0a, 0x04, 0xc0, + 0x5e, 0xf7, 0x5d, 0x5b, 0xf8, 0x10, 0xe2, 0xd0, 0xba, 0x7a, 0x4b, 0xfb, 0xde, + 0x37, 0x00, 0x00, 0x1a, 0x5b, 0x28, 0xe3, 0xd2, 0x9c, 0x73, 0x3e, 0x32, 0x87, + 0x98, 0xa1, 0xc9, 0x51, 0x2f, 0xd7, 0xde, 0xac, 0x33, 0xb3, 0x4f, 0x02, 0x03, + 0x01, 0x00, 0x01, 0xa1, 0x08, 0x03, 0x06, 0x01, 0x01, 0x00, 0x4d, 0x57, 0x12, + 0xa2, 0x08, 0x03, 0x06, 0x01, 0x02, 0x03, 0x4d, 0x57, 0x12, 0xa3, 0x42, 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, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, + 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x3e, 0xd2, 0x1c, 0x89, 0x2e, 0x35, + 0xfc, 0xf8, 0x75, 0xdd, 0xe6, 0x7f, 0x65, 0x88, 0xf4, 0x72, 0x4c, 0xc9, 0x2c, + 0xd7, 0x32, 0x4e, 0xf3, 0xdd, 0x19, 0x79, 0x47, 0xbd, 0x8e, 0x3b, 0x5b, 0x93, + 0x0f, 0x50, 0x49, 0x24, 0x13, 0x6b, 0x14, 0x06, 0x72, 0xef, 0x09, 0xd3, 0xa1, + 0xa1, 0xe3, 0x40, 0x84, 0xc9, 0xe7, 0x18, 0x32, 0x74, 0x3c, 0x48, 0x6e, 0x0f, + 0x9f, 0x4b, 0xd4, 0xf7, 0x1e, 0xd3, 0x93, 0x86, 0x64, 0x54, 0x97, 0x63, 0x72, + 0x50, 0xd5, 0x55, 0xcf, 0xfa, 0x20, 0x93, 0x02, 0xa2, 0x9b, 0xc3, 0x23, 0x93, + 0x4e, 0x16, 0x55, 0x76, 0xa0, 0x70, 0x79, 0x6d, 0xcd, 0x21, 0x1f, 0xcf, 0x2f, + 0x2d, 0xbc, 0x19, 0xe3, 0x88, 0x31, 0xf8, 0x59, 0x1a, 0x81, 0x09, 0xc8, 0x97, + 0xa6, 0x74, 0xc7, 0x60, 0xc4, 0x5b, 0xcc, 0x57, 0x8e, 0xb2, 0x75, 0xfd, 0x1b, + 0x02, 0x09, 0xdb, 0x59, 0x6f, 0x72, 0x93, 0x69, 0xf7, 0x31, 0x41, 0xd6, 0x88, + 0x38, 0xbf, 0x87, 0xb2, 0xbd, 0x16, 0x79, 0xf9, 0xaa, 0xe4, 0xbe, 0x88, 0x25, + 0xdd, 0x61, 0x27, 0x23, 0x1c, 0xb5, 0x31, 0x07, 0x04, 0x36, 0xb4, 0x1a, 0x90, + 0xbd, 0xa0, 0x74, 0x71, 0x50, 0x89, 0x6d, 0xbc, 0x14, 0xe3, 0x0f, 0x86, 0xae, + 0xf1, 0xab, 0x3e, 0xc7, 0xa0, 0x09, 0xcc, 0xa3, 0x48, 0xd1, 0xe0, 0xdb, 0x64, + 0xe7, 0x92, 0xb5, 0xcf, 0xaf, 0x72, 0x43, 0x70, 0x8b, 0xf9, 0xc3, 0x84, 0x3c, + 0x13, 0xaa, 0x7e, 0x92, 0x9b, 0x57, 0x53, 0x93, 0xfa, 0x70, 0xc2, 0x91, 0x0e, + 0x31, 0xf9, 0x9b, 0x67, 0x5d, 0xe9, 0x96, 0x38, 0x5e, 0x5f, 0xb3, 0x73, 0x4e, + 0x88, 0x15, 0x67, 0xde, 0x9e, 0x76, 0x10, 0x62, 0x20, 0xbe, 0x55, 0x69, 0x95, + 0x43, 0x00, 0x39, 0x4d, 0xf6, 0xee, 0xb0, 0x5a, 0x4e, 0x49, 0x44, 0x54, 0x58, + 0x5f, 0x42, 0x83, +]; + +var certDataPEM01 = + "-----BEGIN CERTIFICATE-----\n" + + "MIID/jCCAuagAwIBAgIBATANBgkqhkiG9w0BAQsFADCBjDELMAkGA1UEBhMCQ04x\n" + + "ETAPBgNVBAgMCHNoYW5naGFpMQ8wDQYDVQQHDAZodWF3ZWkxFTATBgNVBAoMDHd3\n" + + "dy50ZXN0LmNvbTENMAsGA1UECwwEdGVzdDEVMBMGA1UEAwwMd3d3LnRlc3QuY29t\n" + + "MRwwGgYJKoZIhvcNAQkBFg10ZXN0QHRlc3QuY29tMB4XDTIyMDgyOTA2NTUwM1oX\n" + + "DTIzMDgyOTA2NTUwM1owezELMAkGA1UEBhMCQ04xETAPBgNVBAgMCHNoYW5naGFp\n" + + "MRUwEwYDVQQKDAx3d3cudGVzdC5jb20xDTALBgNVBAsMBHRlc3QxFTATBgNVBAMM\n" + + "DHd3dy50ZXN0LmNvbTEcMBoGCSqGSIb3DQEJARYNdGVzdEB0ZXN0LmNvbTCCASIw\n" + + "DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJmY9T4SzXXwKvfMvnvMWY7TqUJK\n" + + "jnWf2Puv0YUQ2fdvyoKQ2LQXdtzoUL53j587oI+IXelOr7dg020zPyun0cmZHZ4y\n" + + "l/qAcrWbDjZeEGcbbb5UtQtn1WOEnv8pkXluO355mbZQUKK9L3gFWseXJKGbIXw0\n" + + "NRpaJZzqvPor4m3a5pmJKPHOlivUdYfLaKSkNj3DlaFzCWKV82k5ee6gzVyETtG+\n" + + "XN+vq8qLybT+fIFsLNMmAHzRxlqz3NiH7yh+1/p/Knvf8bkkRVR2btH51RyX2RSu\n" + + "DjPM0/VRL8fxDSDeWBq+Gvn/E6AbOVMmkx63tcyWHhklCSaZtyz7kq39TQMCAwEA\n" + + "AaN7MHkwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0\n" + + "ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFFiFDysfADQCzRZCOSPupQxFicwzMB8G\n" + + "A1UdIwQYMBaAFNYQRQiPsG8HefOTsmsVhaVjY7IPMA0GCSqGSIb3DQEBCwUAA4IB\n" + + "AQAeppxf6sKQJxJQXKPTT3xHKaskidNwDBbOSIvnVvWXicZXDs+1sF6tUaRgvPxL\n" + + "OL58+P2Jy0tfSwj2WhqQRGe9MvQ5iFHcdelZc0ciW6EQ0VDHIaDAQc2nQzej/79w\n" + + "UE7BJJV3b9n1be2iCsuodKO14pOkMb84WcIxng+8SD+MiFqV5BPO1QyKGdO1PE1b\n" + + "+evjyTpFSTgZf2Mw3fGtu5hfEXyHw1lnsFY2MlSwiRlAym/gm4aXy+4H6LyXKd56\n" + + "UYQ6fituD0ziaw3RI6liyIe7aENHCkZf6bAvMRhk4QiU4xu6emwX8Qt1bT7RthP0\n" + + "1Vsro0IOeXT9WAcqEtQUegsi\n" + + "-----END CERTIFICATE-----\n"; + +var certExtensionNormal01 = [ + 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, +]; + +var certExtensionNormal02 = [ + 0x30, 0x81, 0xc6, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, + 0x14, 0x8c, 0xa3, 0x3b, 0x42, 0x63, 0x01, 0xb3, 0x4d, 0x51, 0xf6, 0xe4, 0x2d, + 0xb5, 0x83, 0x7f, 0x18, 0x39, 0x2f, 0xb7, 0xb5, 0x30, 0x1f, 0x06, 0x03, 0x55, + 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x8c, 0xa3, 0x3b, 0x42, 0x63, + 0x01, 0xb3, 0x4d, 0x51, 0xf6, 0xe4, 0x2d, 0xb5, 0x83, 0x7f, 0x18, 0x39, 0x2f, + 0xb7, 0xb5, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, + 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x02, 0x30, 0x0b, 0x06, 0x03, + 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, + 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, + 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, + 0x02, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x1a, 0x30, 0x18, 0x81, + 0x16, 0x63, 0x61, 0x40, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x66, 0x72, 0x61, + 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x21, 0x06, + 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1a, 0x30, 0x18, 0x81, 0x16, 0x63, 0x61, 0x40, + 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x77, 0x6f, + 0x72, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, +]; + +var certExtensionInvalid01 = [ + 0x40, 0x81, 0xc6, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, + 0x14, 0x8c, 0xa3, 0x3b, 0x42, 0x63, 0x01, 0xb3, 0x4e, 0x51, 0xf9, 0xe4, 0x2d, + 0xb5, 0x83, 0x7f, 0x18, 0x39, 0x2f, 0xb7, 0xb5, 0x30, 0x1f, 0x06, 0x03, 0x55, + 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x8c, 0xa3, 0x3a, 0x42, 0x63, + 0x01, 0xb3, 0x4d, 0x51, 0xf6, 0xe4, 0x2d, 0xb5, 0x83, 0x7f, 0x18, 0x39, 0x2f, + 0xb7, 0xb5, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, + 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x02, 0x30, 0x0b, 0x06, 0x03, + 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x03, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, + 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, + 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, + 0x02, 0x30, 0x21, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x1a, 0x30, 0x18, 0x81, + 0x16, 0x63, 0x61, 0x40, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x66, 0x72, 0x61, + 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x21, 0x06, + 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1a, 0x30, 0x18, 0x82, 0x16, 0x63, 0x61, 0x40, + 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x77, 0x6f, + 0x72, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, +]; + +var certExtensionInvalid02 = [ + 0x30, 0x51, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, + 0xb7, 0xb3, 0x20, 0x09, 0xd4, 0xcb, 0xea, 0x53, 0xc1, 0xe2, 0xd6, 0x8e, 0xa7, + 0x4a, 0x34, 0x25, 0xf0, 0xce, 0x26, 0xdf, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, + 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb7, 0xb3, 0x20, 0x09, 0xd4, 0xcb, + 0xea, 0x53, 0xc1, 0xe2, 0xd6, 0x8e, 0xa7, 0x4a, 0x34, 0x25, 0xf0, 0xce, 0x26, + 0xdf, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, + 0x30, 0x03, 0x01, 0x01, 0xff, +]; + +export { + certDataDER01, + certDataPEM01, + certExtensionNormal01, + certExtensionNormal02, + certExtensionInvalid01, + certExtensionInvalid02, +}; diff --git a/security/certificate_framework/js_api_test_oh40/src/main/resources/base/element/color.json b/security/certificate_framework/js_api_test_oh40/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..2a604a0205123ca3cd4100ea10a183b6d488e944 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/resources/base/element/string.json b/security/certificate_framework/js_api_test_oh40/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b1240f32723ead7ca2b47df20ea5e673e5bfd262 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/resources/base/media/icon.png b/security/certificate_framework/js_api_test_oh40/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/security/certificate_framework/js_api_test_oh40/src/main/resources/base/media/icon.png differ diff --git a/security/certificate_framework/js_api_test_oh40/src/main/resources/en_US/element/string.json b/security/certificate_framework/js_api_test_oh40/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0260ecbe43ed50a0b3d0e60e2389b586dee8afc5 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/resources/en_US/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} diff --git a/security/certificate_framework/js_api_test_oh40/src/main/resources/zh_CN/element/string.json b/security/certificate_framework/js_api_test_oh40/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..01559b35da59c252aa5c75fb6bb643143184d9a6 --- /dev/null +++ b/security/certificate_framework/js_api_test_oh40/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} diff --git a/security/certificate_framework/js_api_test_one/BUILD.gn b/security/certificate_framework/js_api_test_one/BUILD.gn index 804f1feb3ba931bf4da2380b76e3a2a944b6aae4..f6cd5b4bb683de4bd85ae0e4c052825d1e361eb9 100644 --- a/security/certificate_framework/js_api_test_one/BUILD.gn +++ b/security/certificate_framework/js_api_test_one/BUILD.gn @@ -23,7 +23,7 @@ ohos_js_hap_suite("ActsCertificateFrameworkJSNormalTest") { certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "ActsCertificateFrameworkJSNormalTest" subsystem_name = "security" - part_name = "crypto_framework" + part_name = "certificate_framework" } ohos_js_assets("hjs_demo_js_assets") { js2abc = true