From 69c249935771e9dd9b1a05b1161a4f13bb58dac9 Mon Sep 17 00:00:00 2001 From: qiaozzzh Date: Tue, 27 Sep 2022 16:09:05 +0800 Subject: [PATCH] =?UTF-8?q?ActsCryptoFrameworkJSNormalTest=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=A5=97=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qiaozzzh Change-Id: I45ed1c1e30d9a7b4d1af29972397d1a3c9d43b39 --- security/BUILD.gn | 7 +- security/cryptoFramework/BUILD.gn | 35 + security/cryptoFramework/Test.json | 39 ++ .../signature/openharmony_sx.p7b | Bin 0 -> 3447 bytes .../signature/openharmony_sx_base.p7b | Bin 0 -> 3437 bytes security/cryptoFramework/src/main/config.json | 98 +++ .../src/main/js/MainAbility/app.js | 23 + .../src/main/js/MainAbility/i18n/en-US.json | 6 + .../src/main/js/MainAbility/i18n/zh-CN.json | 6 + .../main/js/MainAbility/pages/index/index.css | 46 ++ .../main/js/MainAbility/pages/index/index.hml | 5 + .../main/js/MainAbility/pages/index/index.js | 30 + .../src/main/js/TestAbility/app.js | 31 + .../src/main/js/TestAbility/i18n/en-US.json | 8 + .../src/main/js/TestAbility/i18n/zh-CN.json | 8 + .../main/js/TestAbility/pages/index/index.css | 30 + .../main/js/TestAbility/pages/index/index.hml | 5 + .../main/js/TestAbility/pages/index/index.js | 26 + .../js/TestRunner/OpenHarmonyTestRunner.js | 59 ++ .../src/main/js/test/Certificate.test.js | 656 ++++++++++++++++++ .../src/main/js/test/DigestAlgorithm.test.js | 72 ++ .../src/main/js/test/List.test.js | 27 + .../src/main/js/test/SecurityRandom.test.js | 59 ++ .../certificate/publicCertificateCallback.js | 653 +++++++++++++++++ .../certificate/publicCertificatePromise.js | 608 ++++++++++++++++ .../js/test/utils/common/publicDoString.js | 152 ++++ .../main/js/test/utils/common/publicParam.js | 406 +++++++++++ .../digestalgorithm/publicDigestCallback.js | 106 +++ .../digestalgorithm/publicDigestPromise.js | 93 +++ .../publicSecurityRandomCallback.js | 55 ++ .../publicSecurityRandomPromise.js | 65 ++ .../main/resources/base/element/string.json | 28 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes 33 files changed, 3439 insertions(+), 3 deletions(-) create mode 100644 security/cryptoFramework/BUILD.gn create mode 100644 security/cryptoFramework/Test.json create mode 100644 security/cryptoFramework/signature/openharmony_sx.p7b create mode 100644 security/cryptoFramework/signature/openharmony_sx_base.p7b create mode 100644 security/cryptoFramework/src/main/config.json create mode 100644 security/cryptoFramework/src/main/js/MainAbility/app.js create mode 100644 security/cryptoFramework/src/main/js/MainAbility/i18n/en-US.json create mode 100644 security/cryptoFramework/src/main/js/MainAbility/i18n/zh-CN.json create mode 100644 security/cryptoFramework/src/main/js/MainAbility/pages/index/index.css create mode 100644 security/cryptoFramework/src/main/js/MainAbility/pages/index/index.hml create mode 100644 security/cryptoFramework/src/main/js/MainAbility/pages/index/index.js create mode 100644 security/cryptoFramework/src/main/js/TestAbility/app.js create mode 100644 security/cryptoFramework/src/main/js/TestAbility/i18n/en-US.json create mode 100644 security/cryptoFramework/src/main/js/TestAbility/i18n/zh-CN.json create mode 100644 security/cryptoFramework/src/main/js/TestAbility/pages/index/index.css create mode 100644 security/cryptoFramework/src/main/js/TestAbility/pages/index/index.hml create mode 100644 security/cryptoFramework/src/main/js/TestAbility/pages/index/index.js create mode 100644 security/cryptoFramework/src/main/js/TestRunner/OpenHarmonyTestRunner.js create mode 100644 security/cryptoFramework/src/main/js/test/Certificate.test.js create mode 100644 security/cryptoFramework/src/main/js/test/DigestAlgorithm.test.js create mode 100644 security/cryptoFramework/src/main/js/test/List.test.js create mode 100644 security/cryptoFramework/src/main/js/test/SecurityRandom.test.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificateCallback.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificatePromise.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/common/publicDoString.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/common/publicParam.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestCallback.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js create mode 100644 security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomPromise.js create mode 100644 security/cryptoFramework/src/main/resources/base/element/string.json create mode 100644 security/cryptoFramework/src/main/resources/base/media/icon.png diff --git a/security/BUILD.gn b/security/BUILD.gn index e83d5664c..b5a93dc29 100644 --- a/security/BUILD.gn +++ b/security/BUILD.gn @@ -17,9 +17,10 @@ group("security") { testonly = true if (is_standard_system) { deps = [ - "access_token/AccessTokenTest_Normal_js:ActsAccessTokenApiJSNormalTest", - "cipher/datacipher:datacipher", - "security_huks_basic", + #"access_token/AccessTokenTest_Normal_js:ActsAccessTokenApiJSNormalTest", + #"cipher/datacipher:datacipher", + "cryptoFramework:ActsCryptoFrameworkJSNormalTest", + #"security_huks_basic", ] } } diff --git a/security/cryptoFramework/BUILD.gn b/security/cryptoFramework/BUILD.gn new file mode 100644 index 000000000..d7404ad39 --- /dev/null +++ b/security/cryptoFramework/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2022 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsCryptoFrameworkJSNormalTest") { + hap_profile = "./src/main/config.json" + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsCryptoFrameworkJSNormalTest" + subsystem_name = "security" + part_name = "crypto_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/cryptoFramework/Test.json b/security/cryptoFramework/Test.json new file mode 100644 index 000000000..476e3b47f --- /dev/null +++ b/security/cryptoFramework/Test.json @@ -0,0 +1,39 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "900000", + "shell-timeout": "900000", + "bundle-name": "com.example.myapplication101", + "package-name": "com.example.myapplication101" + }, + "kits": [ + { + "test-file-name": [ + "ActsCryptoFrameworkJSNormalTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir /data/test" + ] + }, + { + "type": "PushKit", + "push": [ + "ActsCryptoFrameworkJSNormalTest.hap->/data/test/ActsCryptoFrameworkJSNormalTest.hap" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "chmod 644 /data/test/*.hap", + "chmod 777 -R data" + ] + } + ] +} \ No newline at end of file diff --git a/security/cryptoFramework/signature/openharmony_sx.p7b b/security/cryptoFramework/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..a35ef8b6a9103aee75de921c0676563c4600449d GIT binary patch literal 3447 zcmcgvdsGuw9wsj+ViXIC;sc0QTs3efB#@xCok=Dyn1l%l5RBp^nLHqwgk-{mSgjkk zv}o0JJ*#Ye6d#~&ee6+NWY4MA?y9xj>an$)-LBZBE@vz2)^@ekt*g5eU==+2$DW>J z{>Yr)?|yggH^2M+zI!f+3&Y8&b6d16w}qS(ZhKtl1aaXqE{6jNL0WR^vKB3e$Tp&$WNBz3t+NY0|^=3ruSi1d*}m}C<~Fer9j4T26vUF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YgT8T2{8LhLpx1fv&DDct~qde^XByTeG7Ug#i!kS?TTStsDC|iHE5;Rxj&S? zx#05xD9(Xdku74c2%zDqY~%2WI`THs?gf({+(uG)5Igq2I}8U*dk~}wpz-XXC;>%4 z3Mtt8MR6@Cd^pO7MEu;&vc*2AW8tZ?d|JKjt3P#R;-_6zt>5hVx29+L#FrwuV9bM) zoXgh$l$)2dY3b7b*n+7GEAz`%=j8QeUihqP!Zg}5^|I*pCHdiL`?$H>>?xd1ZRzCA c?udfC{VLpa7aiDilE412_S6SkH+KyD7u}>(KmY&$ literal 0 HcmV?d00001 diff --git a/security/cryptoFramework/signature/openharmony_sx_base.p7b b/security/cryptoFramework/signature/openharmony_sx_base.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 GIT binary patch literal 3437 zcmcgvX>b$g8MY4FF(5FQyMT=#m||qU)nQ9cId-MBB-<-lvSdq&snM}IENNF>t+bK| zgowuF2vC|SxSZxNN5eHhV%(WPpbeB9Fc3;JDMtzMBv1-XAc2N~c2_tCXW&OCGw6qQ z-s9VS-tT?h=bI0tMS+~WDXqHJyCPmLzdbE-fV8Nd&*MRZfG8(#POFZG3xs@Lb{0ry z=R8j3wWo!5g=yjKx#BoZMFS)uA)H}cTp@-^K`9VV?RC3J59@}eik*>n|pRKOLZ zxdn7G!Yv@9O#y<&eUy{)vMXb;fQR)ffVAADQsEMXm;IBMDLfLD0w^U;6%HVo-0Q_5 zCHEa?DBuauNpZzoF+tK27w#n~?u%toS-DhR4k@Q*{7x^8Q=D6&kd^_~J#VVG2LXkL zaAy=}U*?Jto)9hx5MGjdp9hcQAu@tfk_;l!PeyxPY<8b&+&D!CyaBh9=8BSVKLpk4 z4Ml3yY|&Th)vyK4cpC{!uU8v2YBlVV`d~(nz&<@{G1oe*DHub1z7~J5*;s2bX<)_* zV_GbsPQg`(&rpxRb_*Od7}++3+liSw-$!1 zs5*g}EHWhI3i|!-FcfzYL0`SL-rq>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Fq>xFU)&X3p@pP2u%$o}}YcRn(MhJ&B2o?KS@cIVz>Ye%o^xV?CB{_Qhu z;}_q1bvO^g{8<3!gYbo4Di{8qzV+(9 zdlmksohQmRTs@qB;(Wo?dER_ux6XQb@q$tQPW?CMu6GVQd;R=iR;-S{Kr%Zks7>b1 zNs{|-+jhObYE}NR&`TGGr^h^4bjh%c>R#@=8nM&Md>_a+zVulsl;){flFekV1t9ob z+SqfV_Pv3$2f)bQ8%Ul2>fdYR^1zs0BQF~olsOj5AodC&Q_7SMFzsz2 z9newxE&jodk~tNHwl%LBMMDbrk=(^b literal 0 HcmV?d00001 diff --git a/security/cryptoFramework/src/main/config.json b/security/cryptoFramework/src/main/config.json new file mode 100644 index 000000000..14ddadc79 --- /dev/null +++ b/security/cryptoFramework/src/main/config.json @@ -0,0 +1,98 @@ +{ + "app": { + "bundleName": "com.example.myapplication101", + "vendor": "acts", + "version": { + "code": 12, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication101", + "name": ".entry", + "mainAbility": ".MainAbility", + "deviceType": [ + "phone", + "tablet", + "tv", + "wearable" + ], + "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": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "srcPath": "" + } +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/MainAbility/app.js b/security/cryptoFramework/src/main/js/MainAbility/app.js new file mode 100644 index 000000000..830070d19 --- /dev/null +++ b/security/cryptoFramework/src/main/js/MainAbility/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 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 { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/security/cryptoFramework/src/main/js/MainAbility/i18n/en-US.json b/security/cryptoFramework/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 000000000..e63c70d97 --- /dev/null +++ b/security/cryptoFramework/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/MainAbility/i18n/zh-CN.json b/security/cryptoFramework/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 000000000..de6ee5748 --- /dev/null +++ b/security/cryptoFramework/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.css b/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 000000000..5bd756702 --- /dev/null +++ b/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,46 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; + height: 100%; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("/common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.hml b/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 000000000..f64b040a5 --- /dev/null +++ b/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.js b/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 000000000..440a39998 --- /dev/null +++ b/security/cryptoFramework/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 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 fileio from '@ohos.fileio' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow start') + }, + onReady() { + }, +} diff --git a/security/cryptoFramework/src/main/js/TestAbility/app.js b/security/cryptoFramework/src/main/js/TestAbility/app.js new file mode 100644 index 000000000..cdc31f3dc --- /dev/null +++ b/security/cryptoFramework/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/security/cryptoFramework/src/main/js/TestAbility/i18n/en-US.json b/security/cryptoFramework/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 000000000..3cb24b374 --- /dev/null +++ b/security/cryptoFramework/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/TestAbility/i18n/zh-CN.json b/security/cryptoFramework/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 000000000..c804e32c0 --- /dev/null +++ b/security/cryptoFramework/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.css b/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 000000000..b1bcd4338 --- /dev/null +++ b/security/cryptoFramework/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 (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.hml b/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 000000000..f629c71a9 --- /dev/null +++ b/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.js b/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 000000000..88b083a7f --- /dev/null +++ b/security/cryptoFramework/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 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/cryptoFramework/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/security/cryptoFramework/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 000000000..c5fa8620c --- /dev/null +++ b/security/cryptoFramework/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('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 + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/security/cryptoFramework/src/main/js/test/Certificate.test.js b/security/cryptoFramework/src/main/js/test/Certificate.test.js new file mode 100644 index 000000000..77f21a4e9 --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/Certificate.test.js @@ -0,0 +1,656 @@ +/* + * Copyright (C) 2022 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, afterEach, it, expect } from "@ohos/hypium"; +import * as certPromise from "./utils/certificate/publicCertificatePromise"; +import * as certCallback from "./utils/certificate/publicCertificateCallback"; + +export default function CertificateJsunit() { + describe("CertificateJsunit", function () { + console.info("##########start CertificateJsunit##########"); + beforeAll(function () {}); + afterEach(function () {}); + + /** + * @tc.number Security_crypto_framework_X509Cert_0100 + * @tc.name The X509 certificate list can be created for encryption and decryption. + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + */ + it("Security_crypto_framework_X509Cert_0100", 0, async function (done) { + await certPromise + .createX509CertInstancePromise("der") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + + await certCallback + .createX509CertInstanceCallback("der") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_0200 + * @tc.name The X509 certificate list can be created for encryption and decryption. + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509Cert_0200", 0, async function (done) { + await certPromise + .createX509CertInstancePromise("pem") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + + await certCallback + .createX509CertInstanceCallback("pem") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_0300 + * @tc.name verify RSA algorithm for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509Cert_0300", 0, async function (done) { + await certPromise.verifyX509CertPromise("pem"); + await certCallback.verifyX509CertCallback("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_0700 + * @tc.name check getEncoded interface + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + */ + it("Security_crypto_framework_X509Cert_0700", 0, async function (done) { + await certPromise.checkGetEncodedX509CertPromise("der"); + await certCallback.checkGetEncodedX509CertCallback("der"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_0800 + * @tc.name check getPublicKey interface + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + */ + it("Security_crypto_framework_X509Cert_0800", 0, async function (done) { + await certPromise.checkGetPublicKeyX509CertPromise("der"); + await certCallback.checkGetPublicKeyX509CertCallback("der"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_0900 + * @tc.name check validity of the date for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER,date format:20220922145628+0800(YmdHMSz); + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_0900", 0, async function (done) { + await certPromise.checkValidityX509CertPromise( + "der", + "20220830000000+0800" + ); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1200 + * @tc.name getVersion for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_1200", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getVersion"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1300 + * @tc.name getSerialNumber for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_1300", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getSerialNumber"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1400 + * @tc.name getIssuerName for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_1400", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getIssuerName"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1500 + * @tc.name getSubjectName for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_1500", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getSubjectName"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1600 + * @tc.name getNotBeforeTime for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_1600", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getNotBeforeTime"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1700 + * @tc.name getNotAfterTime for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_1700", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getNotAfterTime"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1800 + * @tc.name getSignature for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_1800", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getSignature"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_1900 + * @tc.name getSignatureAlgName for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_1900", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getSignatureAlgName"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2000 + * @tc.name getSignatureAlgOid for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_2000", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getSignatureAlgOid"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2100 + * @tc.name getSignatureAlgParams for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_2100", 0, async function (done) { + await certCallback.getX509CertInfoCallback( + "der", + "getSignatureAlgParams" + ); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2200 + * @tc.name getIssuerUid for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc getIssuerUid not exist, this case will be cancelled + */ + + /** + * @tc.number Security_crypto_framework_X509Cert_2300 + * @tc.name getSubjectUid for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc getSubjectUid not exist, this case will be cancelled + */ + + /** + * @tc.number Security_crypto_framework_X509Cert_2400 + * @tc.name getKeyUsage for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_2400", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getKeyUsage"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2500 + * @tc.name getExtKeyUsage for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_2500", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getExtKeyUsage"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2600 + * @tc.name getBasicConstraints for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_X509Cert_2600", 0, async function (done) { + await certCallback.getX509CertInfoCallback("der", "getBasicConstraints"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2700 + * @tc.name getSubjectAltNames for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_2700", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getSubjectAltNames"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509Cert_2800 + * @tc.name getIssuerAltNames for X509 certificate + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509Cert_2800", 0, async function (done) { + await certPromise.getX509CertInfoPromise("der", "getIssuerAltNames"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_0100 + * @tc.name The X509 certificate list can be revoked for encryption and decryption. + * @tc.desc The X509 certificate FORMAT is FORMAT_DER + */ + it("Security_crypto_framework_X509CRL_0100", 0, async function (done) { + await certPromise + .createX509CrlInstancePromise("der") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + + await certCallback + .createX509CrlInstanceCallback("der") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_0200 + * @tc.name The X509 certificate list can be revoked for encryption and decryption. + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_0200", 0, async function (done) { + await certPromise + .createX509CrlInstancePromise("pem") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + + await certCallback + .createX509CrlInstanceCallback("pem") + .then((data) => { + expect(data != null).assertTrue(); + }) + .catch((err) => { + expect(null).assertFail(); + }); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_0300 + * @tc.name Check isRevoked for X509 Crl + * @tc.desc The X509 Crl FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_0300", 0, async function (done) { + await certPromise + .createX509CrlInstancePromise("pem") + .then((crlInstance) => { + let result = certPromise.checkIsRevokedX509CrlPromise( + crlInstance, + "normal" + ); + return result; + }) + .then((result) => { + expect(result == true).assertTrue(); + }) + .catch((err) => { + console.error("[promise] isRevoked failed! error is: " + err); + expect(null).assertFail(); + }); + await certPromise + .createX509CrlInstancePromise("pem") + .then((crlInstance) => { + let result = certCallback.checkIsRevokedX509CrlCallback( + crlInstance, + "normal" + ); + return result; + }) + .then((result) => { + expect(result == true).assertTrue(); + }) + .catch((err) => { + console.error("[promise] isRevoked failed! error is: " + err); + expect(null).assertFail(); + }); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_0600 + * @tc.name Check getEncoded for X509 Crl + * @tc.desc The X509 Crl FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_0600", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getType"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_0700 + * @tc.name Check getEncoded for X509 Crl + * @tc.desc The X509 Crl FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_0700", 0, async function (done) { + await certPromise.checkGetEncodedX509CrlPromise("pem"); + await certCallback.checkGetEncodedX509CrlCallback("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_0800 + * @tc.name Check verify for X509 Crl + * @tc.desc The X509 Crl FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_0800", 0, async function (done) { + await certPromise.verifyX509CrlPromise(); + await certCallback.verifyX509CrlCallback(); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1200 + * @tc.name check getVersion for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509CRL_1200", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getVersion"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1300 + * @tc.name check getIssuerName for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509CRL_1300", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getIssuerName"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1400 + * @tc.name check getLastUpdate for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509CRL_1400", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getLastUpdate"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1500 + * @tc.name check getNextUpdate for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509CRL_1500", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getNextUpdate"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1600 + * @tc.name check getRevokedCert for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_1600", 0, async function (done) { + await certCallback.checkGetRevokedCertX509CrlCallback("pem"); + await certPromise.checkGetRevokedCertX509CrlPromise("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1700 + * @tc.name check getRevokedCert for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_X509CRL_1700", 0, async function (done) { + await certPromise + .createX509CrlInstancePromise("pem") + .then((crlInstance) => { + let result = certPromise.checkGetRevokedCertWithCertX509CrlPromise( + crlInstance, + "normal" + ); + return result; + }) + .then((result) => { + expect(result != null).assertTrue(); + }) + .catch((err) => { + console.error( + "[promise] checkgetRevokedCertWithCertX509CrlPromis failed! error is: " + + err + ); + expect(null).assertFail(); + }); + await certPromise + .createX509CrlInstancePromise("pem") + .then((crlInstance) => { + let result = certCallback.checkGetRevokedCertWithCertX509CrlCallback( + crlInstance, + "normal" + ); + return result; + }) + .then((result) => { + expect(result != null).assertTrue(); + }) + .catch((err) => { + console.error( + "[callback] checkgetRevokedCertWithCertX509CrlCallback failed! error is: " + + err + ); + expect(null).assertFail(); + }); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1800 + * @tc.name check getRevokedCerts for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_1800", 0, async function (done) { + await certCallback.checkGetRevokedCertsX509CrlCallback("pem"); + await certPromise.checkGetRevokedCertsX509CrlPromise("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_1900 + * @tc.name check getTbsInfo for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_1900", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getTbsInfo"); + await certCallback.getX509CrlInfoCallback("pem", "getTbsInfo"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2000 + * @tc.name check getSignature for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2000", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getSignature"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2100 + * @tc.name check getSignatureAlgName for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2100", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getSignatureAlgName"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2200 + * @tc.name check getSignatureAlgOid for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2200", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getSignatureAlgOid"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2300 + * @tc.name check getSignatureAlgOid for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2300", 0, async function (done) { + await certPromise.getX509CrlInfoPromise("pem", "getSignatureAlgParams"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2400 + * @tc.name check getRevokedCerts for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2400", 0, async function (done) { + await certCallback.checkGetRevokedCertX509CrlCallback("pem"); + await certPromise.checkGetRevokedCertX509CrlPromise("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2500 + * @tc.name check getRevokedCerts for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2500", 0, async function (done) { + await certCallback.checkGetRevokedCertX509CrlCallback("pem"); + await certPromise.checkGetRevokedCertX509CrlPromise("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2600 + * @tc.name check getRevokedCerts for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2600", 0, async function (done) { + await certCallback.checkGetRevokedCertX509CrlCallback("pem"); + await certPromise.checkGetRevokedCertX509CrlPromise("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_X509CRL_2700 + * @tc.name check getRevokedCerts for X509 Crl + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it("Security_crypto_framework_X509CRL_2700", 0, async function (done) { + await certCallback.checkGetRevokedCertX509CrlCallback("pem"); + await certPromise.checkGetRevokedCertX509CrlPromise("pem"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_CertChainValidator_0100 + * @tc.name check validate interface for CertChainValidator + * @tc.desc The X509 certificate FORMAT is FORMAT_PEM + */ + it( + "Security_crypto_framework_CertChainValidator_0100", + 0, + async function (done) { + await certPromise.checkValidateOfCertChainValidatorPromise("PKIX"); + await certCallback.checkValidateOfCertChainValidatorCallback("PKIX"); + done(); + } + ); + }); +} diff --git a/security/cryptoFramework/src/main/js/test/DigestAlgorithm.test.js b/security/cryptoFramework/src/main/js/test/DigestAlgorithm.test.js new file mode 100644 index 000000000..28cf5528d --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/DigestAlgorithm.test.js @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022 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, afterEach, it, expect } from "@ohos/hypium"; +import { + testHMACDigestPromise, + testMDDigestPromise, +} from "./utils/digestalgorithm/publicDigestPromise"; +import { + testHMACDigestCallback, + testMDDigestCallback, +} from "./utils/digestalgorithm/publicDigestCallback"; + +export default function DigestAlgorithmJsunit() { + describe("DigestAlgorithmJsunit", function () { + console.info("##########start DigestAlgorithmJsunit##########"); + beforeAll(function () {}); + afterEach(function () {}); + + /** + * @tc.number Security_crypto_framework_MD_0100 + * @tc.name Test MD5 for MD digest algotithm + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_MD_0100", 0, async function (done) { + await testMDDigestPromise("MD5"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_MD_0500 + * @tc.name Test SHA384 for MD digest algotithm + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_MD_0500", 0, async function (done) { + await testMDDigestCallback("SHA384"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_HMAC_0100 + * @tc.name Test SHA1 for HMAC digest algorithm + * @tc.desc Use the Callback Style of Interface + */ + it("Security_crypto_framework_HMAC_0100", 0, async function (done) { + await testHMACDigestCallback("SHA1", "AES128"); + done(); + }); + + /** + * @tc.number Security_crypto_framework_HMAC_0200 + * @tc.name Test SHA1 for HMAC digest algorithm + * @tc.desc Use the Promise Style of Interface + */ + it("Security_crypto_framework_HMAC_0200", 0, async function (done) { + await testHMACDigestPromise("SHA224", "AES192"); + done(); + }); + }); +} diff --git a/security/cryptoFramework/src/main/js/test/List.test.js b/security/cryptoFramework/src/main/js/test/List.test.js new file mode 100644 index 000000000..31815cb2d --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/List.test.js @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 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 SecurityRandomJsunit from "./SecurityRandom.test.js"; +import DigestAlgorithmJsunit from "./DigestAlgorithm.test.js"; +import CertificateJsunit from "./Certificate.test.js"; + + +export default function testsuite() { + // SecurityRandomJsunit(); + // DigestAlgorithmJsunit(); + CertificateJsunit(); + DigestAlgorithmJsunit(); + SecurityRandomJsunit(); +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/test/SecurityRandom.test.js b/security/cryptoFramework/src/main/js/test/SecurityRandom.test.js new file mode 100644 index 000000000..c2767c070 --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/SecurityRandom.test.js @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 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, afterEach, it, expect } from "@ohos/hypium"; +import { + testSecurityRandomPromise, + testSecurityRandomEnumPromise, +} from "./utils/securityrandom/publicSecurityRandomPromise"; +import { testSecurityRandomCallback } from "./utils/securityrandom/publicSecurityRandomCallback"; + +export default function SecurityRandomJsunit() { + describe("SecurityRandomJsunit", function () { + console.info("##########start SecurityRandomJsunit##########"); + beforeAll(function () {}); + afterEach(function () {}); + + /** + * @tc.number Security_crypto_framework_Random_0100 + * @tc.name support security random and set random seed + * @tc.desc the length of random is 32, use promise style of interface + */ + it("Security_crypto_framework_Random_0100", 0, async function (done) { + await testSecurityRandomPromise(32); + done(); + }); + + /** + * @tc.number Security_crypto_framework_Random_0200 + * @tc.name support security random and set random seed + * @tc.desc the length of random is 32, use callback style of interface + */ + it("Security_crypto_framework_Random_0200", 0, async function (done) { + await testSecurityRandomCallback(32); + done(); + }); + + /** + * @tc.number Security_crypto_framework_Random_0500 + * @tc.name test enumerated values + * @tc.desc cover 100% Enumerated values + */ + it("Security_crypto_framework_Random_0500", 0, async function (done) { + await testSecurityRandomEnumPromise(); + done(); + }); + }); +} diff --git a/security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificateCallback.js b/security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificateCallback.js new file mode 100644 index 000000000..b2e80f607 --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificateCallback.js @@ -0,0 +1,653 @@ +/* + * Copyright (C) 2022 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 cryptoFramework from "@ohos.security.cryptoFramework"; +import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString } from "../common/publicDoString"; +import { + chainFirstCaCert, + chainSecondCaCert, + selfSignedCaCertPem, + selfSignedCaCertDer, + rootCert, + testInvalidCert, + testErrorCert, + testCert, + testCrlPem, + testCrlDer, + crlVerifyPriKeyHex, + crlVerifyPubKeyHex, + crlHex +} from "../common/publicParam"; + +function createX509CertInstanceCallback(certType) { + var certformat; + var encodingData; + + if (certType == "der") { + certformat = cryptoFramework.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(selfSignedCaCertDer.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(selfSignedCaCertPem); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.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); + } + }); + }); +} + +function createX509CertInstanceforCrlTestCallback(flag) { + var certformat; + var encodingData; + + if (flag == "normal") { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(testCert); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(testErrorCert); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.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 verifyX509CertCallback(certType) { + var gInstance; + await createX509CertInstanceCallback(certType) + .then(instance => { + gInstance = instance; + gInstance.getPublicKey((err, publicKey) => { + if (publicKey == null) { + console.error("[callback] getPublickey failed, publickey is null"); + expect(null).assertFail(); + } + console.warn("[callback] getPublickey success"); + gInstance.verify(publicKey, (err1,) => { + if (err1) { + console.error("[callback] certificate verify failed"); + expect(err1.code == 0).assertFail(); + } else { + console.warn("[callback] certificate verify success"); + expect(1 == 1).assertTrue(); + } + }) + }) + }).catch(err => { + console.error("[callback] getPublickey failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +async function checkValidityX509CertCallback(certType, date) { + var certformat; + var encodingData; + + if (certType == "der") { + certformat = cryptoFramework.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(selfSignedCaCertDer.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(selfSignedCaCertPem); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.createX509Cert(encodingBlob, (err, instance) => { + if (instance == null) { + console.error("[callback] create X509 Cert failed! err code: " + err.code); + reject(instance); + } else { + console.warn("[callback] create X509 Cert success! format is: " + certformat); + instance.checkValidityWithDate(date, (err,) => { + if (err) { + console.warn("[callback] checkValidityX509Cert failed! err.code is:" + err.code); + reject(err); + } else { + console.warn("[callback] checkValidityX509Cert success!"); + resolve(""); + } + }); + } + }); + }); +} + +async function getX509CertInfoCallback(certType, processType) { + var gInstance; + await createX509CertInstanceCallback(certType) + .then(instance => { + gInstance = instance; + switch (processType) { + case "getVersion": + let version = gInstance.getVersion(); + console.log(processType + " is : " + version); + expect(version != null).assertTrue(); + break; + case "getSerialNumber": + let serialNumber = gInstance.getSerialNumber(); + console.log(processType + " is : " + serialNumber); + expect(serialNumber != null).assertTrue(); + break; + case "getIssuerName": + let issuerName = gInstance.getIssuerName(); + console.log(processType + " is : " + uInt8ArrayToString(issuerName.data)); + expect(issuerName != null).assertTrue(); + break; + case "getSubjectName": + let subjectName = gInstance.getSubjectName(); + console.log(processType + " is : " + uInt8ArrayToString(subjectName.data)); + expect(subjectName != null).assertTrue(); + break; + case "getNotBeforeTime": + let notBeforeTime = gInstance.getNotBeforeTime(); + console.log(processType + " is : " + notBeforeTime); + expect(notBeforeTime != null).assertTrue(); + break; + case "getNotAfterTime": + let notAfterTime = gInstance.getNotAfterTime(); + console.log(processType + " is : " + notAfterTime); + expect(notAfterTime != null).assertTrue(); + break; + case "getSignature": + let signature = gInstance.getSignature(); + console.log(processType + " is : " + uInt8ArrayToString(signature.data)); + expect(signature != null).assertTrue(); + break; + case "getSignatureAlgName": + let signatureAlgName = gInstance.getSignatureAlgName(); + console.log(processType + " is : " + signatureAlgName); + expect(signatureAlgName != null).assertTrue(); + break; + case "getSignatureAlgOid": + let signatureAlgOid = gInstance.getSignatureAlgOid(); + console.log(processType + " is : " + signatureAlgOid); + expect(signatureAlgOid != null).assertTrue(); + break; + case "getSignatureAlgParams": + let signatureAlgParams = gInstance.getSignatureAlgParams(); + console.log(processType + " is : " + uInt8ArrayToString(signatureAlgParams.data)); + expect(signatureAlgParams != null).assertTrue(); + break; + case "getKeyUsage": + let keyUsage = gInstance.getKeyUsage(); + console.log(processType + " is : " + uInt8ArrayToString(keyUsage.data)); + expect(keyUsage != null).assertTrue(); + break; + case "getExtKeyUsage": + let extKeyUsage = gInstance.getExtKeyUsage(); + console.log(processType + " is : " + extKeyUsage.data); + expect(extKeyUsage != null).assertTrue(); + break; + case "getBasicConstraints": + let basicConstraints = gInstance.getBasicConstraints(); + console.log(processType + " is : " + basicConstraints); + expect(basicConstraints != null).assertTrue(); + break; + case "getSubjectAltNames": + let subjectAltNames = gInstance.getSubjectAltNames(); + console.log(processType + " is : " + subjectAltNames.data); + expect(subjectAltNames != null).assertTrue(); + break; + case "getIssuerAltNames": + let issuerAltNames = gInstance.getIssuerAltNames(); + console.log(processType + " is : " + issuerAltNames.data); + expect(issuerAltNames != null).assertTrue(); + break; + default: + console.log("Invalid parameter !"); + expect(null).assertFail(); + } + }).catch(err => { + console.error("[callback] getX509CertInfo failed! error is: " + err); + expect(null).assertFail(); + }); +} + +async function checkGetEncodedX509CertCallback(certType) { + var gInstance; + await createX509CertInstanceCallback(certType) + .then(instance => { + gInstance = instance; + gInstance.getEncoded((err, EncodingBlob) => { + if (err) { + console.error("[callback] getEncoded failed, err code is:" + err.code); + expect(null).assertFail(); + } else { + console.warn("[callback] getEncoded success, EncodingBlob is:" + EncodingBlob); + expect(EncodingBlob != null).assertTrue(); + } + }) + }).catch(err => { + console.error("[callback] getPublickey failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + + +async function checkGetPublicKeyX509CertCallback(certType) { + var gInstance; + await createX509CertInstanceCallback(certType) + .then(instance => { + gInstance = instance; + gInstance.getPublicKey((err, publicKey) => { + if (err) { + console.error("[callback] getPublicKey failed, err code is:" + err.code); + expect(null).assertFail(); + } else { + console.warn("[callback] getPublicKey success, publicKey is:" + publicKey); + expect(publicKey != null).assertTrue(); + } + }) + }).catch(err => { + console.error("[callback] getPublickey failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +function createX509CrlInstanceCallback(certType) { + var certformat; + var encodingData; + + if (certType == "der") { + certformat = cryptoFramework.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(testCrlDer.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(testCrlPem); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.createX509Crl(encodingBlob, (err, data) => { + if (err) { + console.error("[callback] createX509Crl failed! error code is: " + err.code); + reject(err); + } else { + console.warn("[callback] createX509Crl success! format is: " + certformat); + resolve(data); + } + }); + }); +} + +function checkIsRevokedX509CrlCallback(crlInstance, flag) { + return new Promise((resolve, reject) => { + createX509CertInstanceforCrlTestCallback(flag) + .then(certInstance => { + crlInstance.isRevoked(certInstance, (err, status) => { + if (err) { + console.error("[callback] isRevoked failed! err code is:" + err.code); + reject(err); + } else { + console.warn("[callback] isRevoked status is:" + status); + resolve(status); + } + }); + }).catch(err => { + console.error("[callback] isRevoked failed!"); + reject(err); + }); + }); +} + +async function checkGetEncodedX509CrlCallback(certType) { + var gInstance; + await createX509CrlInstanceCallback(certType) + .then(instance => { + gInstance = instance; + gInstance.getEncoded((err, EncodingBlob) => { + if (err) { + console.error("[callback] Crl getEncoded failed, err code is:" + err.code); + expect(null).assertFail(); + } else { + console.warn("[callback] Crl getEncoded success, EncodingBlob is:" + EncodingBlob); + expect(EncodingBlob != null).assertTrue(); + } + }) + }).catch(err => { + console.error("[callback] Crl getEncoded failed, err code is: " + err.code); + expect(null).assertFail(); + }); +} + +function verifyX509CrlCallback() { + var certformat; + var priKeyEncodingData; + var pubKeyEncodingData; + var crlEncodingData; + + certformat = cryptoFramework.EncodingFormat.FORMAT_DER; + priKeyEncodingData = new Uint8Array(crlVerifyPriKeyHex.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + pubKeyEncodingData = new Uint8Array(crlVerifyPubKeyHex.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + crlEncodingData = new Uint8Array(crlHex.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + + var asyKeyGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_3"); + if (asyKeyGenerator == null) { + console.error("[callback]createAsyKeyGenerator is null"); + expect(asyKeyGenerator == null).assertFail(); + } + + var priEncodingBlob = { + data: priKeyEncodingData, + }; + + var pubEncodingBlob = { + data: pubKeyEncodingData, + }; + + var crlEncodingBlob = { + data: crlEncodingData, + encodingFormat: certformat + }; + + asyKeyGenerator.convertKey(pubEncodingBlob, priEncodingBlob, (err, keyPair) => { + if (err) { + console.error("[callback]catch err: " + err); + expect(err == null).assertFail(); + } else { + let crlInstance = cryptoFramework.createX509Crl(crlEncodingBlob); + crlInstance.verify(keyPair.pubKey, (err1,) => { + if (err1) { + console.error("[callback]catch err: " + err1); + expect(err1 == null).assertFail(); + } else { + console.log("[callback]verify success!"); + expect(null).assertTrue(); + } + }) + } + }); +} + +async function getX509CrlInfoCallback(certType, processType) { + var gInstance; + await createX509CrlInstanceCallback(certType) + .then(instance => { + gInstance = instance; + switch (processType) { + case "getType": + let type = gInstance.getType(); + console.log(processType + " is : " + type); + expect(type != null).assertTrue(); + break; + case "getVersion": + let version = gInstance.getVersion(); + console.log(processType + " is : " + version); + expect(version != null).assertTrue(); + break; + case "getIssuerName": + let issuerName = gInstance.getIssuerName(); + console.log(processType + " is : " + uInt8ArrayToString(issuerName.data)); + expect(issuerName != null).assertTrue(); + break; + case "getLastUpdate": + let lastUpdate = gInstance.getLastUpdate(); + console.log(processType + " is : " + lastUpdate); + expect(lastUpdate != null).assertTrue(); + break; + case "getNextUpdate": + let nextUpdate = gInstance.getNextUpdate(); + console.log(processType + " is : " + nextUpdate); + expect(nextUpdate != null).assertTrue(); + break; + case "getSignature": + let signature = gInstance.getSignature(); + console.log(processType + " is : " + uInt8ArrayToString(signature.data)); + expect(signature != null).assertTrue(); + break; + case "getSignatureAlgName": + let signatureAlgName = gInstance.getSignatureAlgName(); + console.log(processType + " is : " + signatureAlgName); + expect(signatureAlgName != null).assertTrue(); + break; + case "getSignatureAlgOid": + let signatureAlgOid = gInstance.getSignatureAlgOid(); + console.log(processType + " is : " + signatureAlgOid); + expect(signatureAlgOid != null).assertTrue(); + break; + case "getSignatureAlgParams": + let signatureAlgParams = gInstance.getSignatureAlgParams(); + console.log(processType + " is : " + uInt8ArrayToString(signatureAlgParams.data)); + expect(signatureAlgParams != null).assertTrue(); + break; + case "getTbsInfo": + gInstance.getTbsInfo((err, tbsInfo) => { + if (tbsInfo == null) { + console.error(processType + " is null"); + expect(null).assertFail(); + } else { + console.log(processType + " is : " + uInt8ArrayToString(tbsInfo.data)); + expect(tbsInfo != null).assertTrue(); + } + }); + break; + default: + console.log("Invalid parameter !"); + expect(null).assertFail(); + } + }).catch(err => { + console.error("[callback] getX509CrtInfo failed! error is: " + err); + expect(null).assertFail(); + }); +} + +function checkGetRevokedCertWithCertX509CrlCallback(crlInstance, flag) { + return new Promise((resolve, reject) => { + createX509CertInstanceforCrlTestCallback(flag) + .then(certInstance => { + crlInstance.getRevokedCertWithCert(certInstance, (err, crlEntry) => { + if (err) { + console.error("[callback] getRevokedCertWithCert failed! err code is:" + err.code); + reject(err); + } else { + console.warn("[callback] getRevokedCertWithCert is:" + crlEntry); + let num = crlEntry.getSerialNumber(); + console.warn("[num] getRevokedCertWithCert num is:" + num); + resolve(crlEntry); + } + }); + }).catch(err => { + console.error("[callback] getRevokedCertWithCert failed! err is:" + err); + reject(err); + }); + }); +} + +async function checkGetRevokedCertsX509CrlCallback(certType) { + var gInstance; + var gIndex; + await createX509CrlInstanceCallback(certType) + .then(instance => { + gInstance = instance; + gInstance.getRevokedCerts((err, certs) => { + if (certs == null) { + console.error("[callback] Crl get revoked certs failed, certs is null"); + expect(null).assertFail(); + } + console.warn("[callback] Crl get gevoked certs success"); + if (certs.length == 0) { + console.error("[callback] Crl revoked certs length is 0"); + expect(null).assertFail(); + } + for (var i = 0; i < certs.length; i++) { + gIndex = i; + console.log("[callback] certs i: " + gIndex + " serialNumber is: " + certs[gIndex].getSerialNumber()); + certs[gIndex].getRevocationDate((err1, revocation) => { + if (revocation == null) { + console.error("[callback] certs i: " + gIndex + " revocation date is: null"); + expect(null).assertFail(); + } + console.log("[callback] certs i: " + gIndex + " revocation date is: " + revocation); + certs[gIndex].getEncoded((err2, eData) => { + if (eData == null) { + console.error("[callback] certs i: " + gIndex + " getEncoded is: null"); + expect(null).assertFail(); + } + console.log("[callback] certs i: " + gIndex + " getEncoded is: " + eData); + }); + }); + } + }) + }).catch(err => { + console.error("[callback] Crl getPublickey failed! error is: " + err); + expect(null).assertFail(); + }); +} + +async function checkGetRevokedCertX509CrlCallback(certType) { + var gInstance; + await createX509CrlInstanceCallback(certType) + .then(instance => { + gInstance = instance; + gInstance.getRevokedCert(1, (err, cert) => { + if (cert == null) { + console.error("[callback] Crl get revoked cert failed, cert is null"); + expect(null).assertFail(); + } + console.warn("[callback] Crl get gevoked cert success"); + cert.getRevocationDate((err1, revocation) => { + if (revocation == null) { + console.error("[callback] cert revocation date is: null"); + expect(null).assertFail(); + } + console.log("[callback] cert revocation date is: " + revocation); + }); + cert.getCertIssuer((err2, certIssuer) => { + if (certIssuer == null) { + console.error("[callback] cert certIssuer is: null"); + expect(null).assertFail(); + } + console.log("[callback] cert certIssuer is: " + uInt8ArrayToString(certIssuer.data)); + }); + }) + }).catch(err => { + console.error("[callback] Crl getPublickey failed! error is: " + err); + expect(null).assertFail(); + }); +} + +function checkValidateOfCertChainValidatorCallback(algName) { + var validator = cryptoFramework.createCertChainValidator(algName); + if (validator == null) { + console.error("createCertChainValidator failed, validator is null"); + expect(null).assertFail(); + } + var algorithm = validator.algorithm; + console.log("createCertChainValidator success! algorithm is: " + algorithm); + var certArray1 = stringTouInt8Array(chainFirstCaCert); + var byteLength1 = certArray1.byteLength; + var uInt16CertLength1 = new Uint16Array([byteLength1]); + var uInt8CertLength1 = new Uint8Array([uInt16CertLength1.buffer]); + + var certArray2 = stringTouInt8Array(chainSecondCaCert); + var byteLength2 = certArray2.byteLength; + var uInt16CertLength2 = new Uint16Array([byteLength2]); + var uInt8CertLength2 = new Uint8Array([uInt16CertLength2.buffer]); + + var dataArray = new Uint8Array(uInt8CertLength2.length + certArray2.length + uInt8CertLength1.length + certArray1.length); + for (var i = 0; i < uInt8CertLength2.length; i++) { + dataArray[i] = uInt8CertLength2[i]; + } + for (var i = 0; i < certArray2.length; i++) { + dataArray[i+uInt8CertLength2.length] = certArray2[i]; + } + for (var i = 0; i < uInt8CertLength1.length; i++) { + dataArray[i + uInt8CertLength2.length + certArray2.length] = uInt8CertLength1[i]; + } + for (var i = 0; i < certArray1.length; i++) { + dataArray[i + uInt8CertLength2.length + certArray2.length + uInt8CertLength1.length] = certArray1[i]; + } + var certChainData = { + data: dataArray, + count: 2, + encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM + }; + validator.validate(certChainData, (err,) => { + if (err) { + console.error("[callback]: validate error: " + err); + expect(null).assertFail(); + } else { + console.warn("[callback]: validate success!"); + expect(1 == 1).assertTrue(); + } + }) +} + +export { + createX509CertInstanceCallback, + verifyX509CertCallback, + checkValidityX509CertCallback, + checkGetEncodedX509CertCallback, + checkGetPublicKeyX509CertCallback, + getX509CertInfoCallback, + createX509CrlInstanceCallback, + checkIsRevokedX509CrlCallback, + checkGetEncodedX509CrlCallback, + verifyX509CrlCallback, + getX509CrlInfoCallback, + checkGetRevokedCertWithCertX509CrlCallback, + checkGetRevokedCertsX509CrlCallback, + checkGetRevokedCertX509CrlCallback, + checkValidateOfCertChainValidatorCallback, +}; diff --git a/security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificatePromise.js b/security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificatePromise.js new file mode 100644 index 000000000..de7d8d50a --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/certificate/publicCertificatePromise.js @@ -0,0 +1,608 @@ +/* + * Copyright (C) 2022 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 cryptoFramework from "@ohos.security.cryptoFramework"; +import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString } from "../common/publicDoString"; +import { + chainFirstCaCert, + chainSecondCaCert, + selfSignedCaCertPem, + selfSignedCaCertDer, + rootCert, + testInvalidCert, + testErrorCert, + testCert, + testCrlPem, + testCrlDer, + crlVerifyPriKeyHex, + crlVerifyPubKeyHex, + crlHex +} from "../common/publicParam"; + +function createX509CertInstancePromise(certType) { + var certformat; + var encodingData; + + if (certType == "der") { + certformat = cryptoFramework.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(selfSignedCaCertDer.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(selfSignedCaCertPem); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.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); + }); + }) +} + +function createX509CertInstanceforCrlTestPromise(flag) { + var certformat; + var encodingData; + + if (flag == "normal") { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(testCert); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(testErrorCert); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.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 verifyX509CertPromise(certType) { + var gInstance; + await createX509CertInstancePromise(certType) + .then(instance => { + gInstance = instance; + let data = gInstance.getPublicKey(); + gInstance = instance; + return data; + }).then(publicKey => { + if (publicKey == null) { + console.error("[promise] getPublickey failed! data is null "); + return; + } + console.warn("[promise] getPublickey success!"); + let verifyret = gInstance.verify(publicKey); + return verifyret; + }).then(verifyret => { + expect(verifyret == null).assertTrue(); + }).catch(err => { + console.error("[promise] getPublickey failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +async function checkValidityX509CertPromise(certType, date) { + var gInstance; + await createX509CertInstancePromise(certType) + .then(instance => { + gInstance = instance; + let result = gInstance.checkValidityWithDate(date); + return result; + }).then(result => { + console.warn("[promise] checkValidityX509Cert success!"); + expect(result == null).assertTrue(); + }).catch(err => { + console.error("[promise] checkValidityX509Cert failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +async function getX509CertInfoPromise(certType, processType) { + var gInstance; + await createX509CertInstancePromise(certType) + .then(instance => { + gInstance = instance; + switch (processType) { + case "getVersion": + let version = gInstance.getVersion(); + console.log(processType + " is : " + version); + expect(version != null).assertTrue(); + break; + case "getSerialNumber": + let serialNumber = gInstance.getSerialNumber(); + console.log(processType + " is : " + serialNumber); + expect(serialNumber != null).assertTrue(); + break; + case "getIssuerName": + let issuerName = gInstance.getIssuerName(); + console.log(processType + " is : " + uInt8ArrayToString(issuerName.data)); + expect(issuerName != null).assertTrue(); + break; + case "getSubjectName": + let subjectName = gInstance.getSubjectName(); + console.log(processType + " is : " + uInt8ArrayToString(subjectName.data)); + expect(subjectName != null).assertTrue(); + break; + case "getNotBeforeTime": + let notBeforeTime = gInstance.getNotBeforeTime(); + console.log(processType + " is : " + notBeforeTime); + expect(notBeforeTime != null).assertTrue(); + break; + case "getNotAfterTime": + let notAfterTime = gInstance.getNotAfterTime(); + console.log(processType + " is : " + notAfterTime); + expect(notAfterTime != null).assertTrue(); + break; + case "getSignature": + let signature = gInstance.getSignature(); + console.log(processType + " is : " + uInt8ArrayToString(signature.data)); + expect(signature != null).assertTrue(); + break; + case "getSignatureAlgName": + let signatureAlgName = gInstance.getSignatureAlgName(); + console.log(processType + " is : " + signatureAlgName); + expect(signatureAlgName != null).assertTrue(); + break; + case "getSignatureAlgOid": + let signatureAlgOid = gInstance.getSignatureAlgOid(); + console.log(processType + " is : " + signatureAlgOid); + expect(signatureAlgOid != null).assertTrue(); + break; + case "getSignatureAlgParams": + let signatureAlgParams = gInstance.getSignatureAlgParams(); + console.log(processType + " is : " + uInt8ArrayToString(signatureAlgParams.data)); + expect(signatureAlgParams != null).assertTrue(); + break; + case "getKeyUsage": + let keyUsage = gInstance.getKeyUsage(); + console.log(processType + " is : " + uInt8ArrayToString(keyUsage.data)); + expect(keyUsage != null).assertTrue(); + break; + case "getExtKeyUsage": + let extKeyUsage = gInstance.getExtKeyUsage(); + console.log(processType + " is : " + extKeyUsage.data); + expect(extKeyUsage != null).assertTrue(); + break; + case "getBasicConstraints": + let basicConstraints = gInstance.getBasicConstraints(); + console.log(processType + " is : " + basicConstraints); + expect(basicConstraints != null).assertTrue(); + break; + case "getSubjectAltNames": + let subjectAltNames = gInstance.getSubjectAltNames(); + console.log(processType + " is : " + subjectAltNames.data); + expect(subjectAltNames != null).assertTrue(); + break; + case "getIssuerAltNames": + let issuerAltNames = gInstance.getIssuerAltNames(); + console.log(processType + " is : " + issuerAltNames.data); + expect(issuerAltNames != null).assertTrue(); + break; + default: + console.log("Invalid parameter !"); + expect(null).assertFail(); + } + }).catch(err => { + console.error("[promise] getX509CertInfo failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + + +async function checkGetEncodedX509CertPromise(certType) { + var gInstance; + await createX509CertInstancePromise(certType) + .then(instance => { + gInstance = instance; + let encodedBlob = gInstance.getEncoded(); + return encodedBlob; + }).then(encodedBlob => { + console.warn("[promise] getEncoded success, EncodingBlob is:" + encodedBlob); + expect(encodedBlob != null).assertTrue(); + }).catch(err => { + console.error("[promise] getEncoded failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +async function checkGetPublicKeyX509CertPromise(certType) { + var gInstance; + await createX509CertInstancePromise(certType) + .then(instance => { + gInstance = instance; + let publicKey = gInstance.getPublicKey(); + return publicKey; + }).then(publicKey => { + console.warn("[promise] publicKey success, publicKey is:" + publicKey); + expect(publicKey != null).assertTrue(); + }).catch(err => { + console.error("[promise] publicKey failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +function createX509CrlInstancePromise(certType) { + var certformat; + var encodingData; + + if (certType == "der") { + certformat = cryptoFramework.EncodingFormat.FORMAT_DER; + encodingData = new Uint8Array(testCrlDer.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + } else { + certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; + encodingData = stringTouInt8Array(testCrlPem); + } + + var encodingBlob = { + data: encodingData, + encodingFormat: certformat + }; + + return new Promise((resolve, reject) => { + cryptoFramework.createX509Crl(encodingBlob).then(data => { + console.warn("[promise] createX509Crl success! format is: " + certformat); + resolve(data); + }).catch(err => { + console.error("[promise] createX509Crl failed! error code is: " + err.code); + reject(err); + }); + }) +} + +function checkIsRevokedX509CrlPromise(crlInstance, flag) { + return new Promise((resolve, reject) => { + createX509CertInstanceforCrlTestPromise(flag) + .then(certInstance => { + let status = crlInstance.isRevoked(certInstance); + return status; + }).then(status => { + console.warn("[promise] isRevoked status is:" + status); + resolve(status); + }).catch(err => { + console.error("[promise] isRevoked failed!"); + reject(err); + }); + }); +} + +async function checkGetEncodedX509CrlPromise(certType) { + var gInstance; + await createX509CrlInstancePromise(certType) + .then(instance => { + gInstance = instance; + let encodedBlob = gInstance.getEncoded(); + return encodedBlob; + }).then(encodedBlob => { + console.warn("[promise] Crl getEncoded success, EncodingBlob is:" + encodedBlob); + expect(encodedBlob != null).assertTrue(); + }).catch(err => { + console.error("[promise] Crl getEncoded failed! error code is: " + err.code); + expect(null).assertFail(); + }); +} + +function verifyX509CrlPromise() { + var certFormat; + var priKeyEncodingData; + var pubKeyEncodingData; + var crlEncodingData; + + certFormat = cryptoFramework.EncodingFormat.FORMAT_DER; + priKeyEncodingData = new Uint8Array(crlVerifyPriKeyHex.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + pubKeyEncodingData = new Uint8Array(crlVerifyPubKeyHex.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + crlEncodingData = new Uint8Array(crlHex.match(/[\da-f]{2}/gi).map(function (h) { + return parseInt(h, 16); + })); + + var asyKeyGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_3"); + if (asyKeyGenerator == null) { + console.error("[promise]createAsyKeyGenerator is null"); + expect(asyKeyGenerator == null).assertFail(); + } + + var priEncodingBlob = { + data: priKeyEncodingData, + }; + + var pubEncodingBlob = { + data: pubKeyEncodingData, + }; + + var crlEncodingBlob = { + data: crlEncodingData, + encodingFormat: certFormat + }; + + asyKeyGenerator.convertKey(pubEncodingBlob, priEncodingBlob).then(keyPair => { + let crlInstance = cryptoFramework.createX509Crl(crlEncodingBlob); + let ret = crlInstance.verify(keyPair.pubKey); + return ret; + }).then(() => { + console.log("[promise]verify success!"); + expect(null).assertTrue(); + }).catch(err => { + console.error("[promise]catch err: " + err); + expect(err == null).assertFail(); + }); +} + +async function getX509CrlInfoPromise(certType, processType) { + var gInstance; + await createX509CrlInstancePromise(certType) + .then(instance => { + gInstance = instance; + switch (processType) { + case "getType": + let type = gInstance.getType(); + console.log(processType + " is : " + type); + expect(type != null).assertTrue(); + break; + case "getVersion": + let version = gInstance.getVersion(); + console.log(processType + " is : " + version); + expect(version != null).assertTrue(); + break; + case "getIssuerName": + let issuerName = gInstance.getIssuerName(); + console.log(processType + " is : " + uInt8ArrayToString(issuerName.data)); + expect(issuerName != null).assertTrue(); + break; + case "getLastUpdate": + let lastUpdate = gInstance.getLastUpdate(); + console.log(processType + " is : " + lastUpdate); + expect(lastUpdate != null).assertTrue(); + break; + case "getNextUpdate": + let nextUpdate = gInstance.getNextUpdate(); + console.log(processType + " is : " + nextUpdate); + expect(nextUpdate != null).assertTrue(); + break; + case "getSignature": + let signature = gInstance.getSignature(); + console.log(processType + " is : " + uInt8ArrayToString(signature.data)); + expect(signature != null).assertTrue(); + break; + case "getSignatureAlgName": + let signatureAlgName = gInstance.getSignatureAlgName(); + console.log(processType + " is : " + signatureAlgName); + expect(signatureAlgName != null).assertTrue(); + break; + case "getSignatureAlgOid": + let signatureAlgOid = gInstance.getSignatureAlgOid(); + console.log(processType + " is : " + signatureAlgOid); + expect(signatureAlgOid != null).assertTrue(); + break; + case "getSignatureAlgParams": + let signatureAlgParams = gInstance.getSignatureAlgParams(); + console.log(processType + " is : " + uInt8ArrayToString(signatureAlgParams.data)); + expect(signatureAlgParams != null).assertTrue(); + break; + case "getTbsInfo": + let tbsInfo = gInstance.getTbsInfo(); + return tbsInfo; + default: + console.log("Invalid parameter !"); + expect(null).assertFail(); + } + }).then(tbsInfo => { + if (processType == "getTbsInfo") { + if (tbsInfo == null) { + console.error(processType + " is null"); + expect(null).assertFail(); + } else { + console.log(processType + " is : " + uInt8ArrayToString(tbsInfo.data)); + expect(tbsInfo != null).assertTrue(); + } + } + }).catch(err => { + console.error("[promise] getX509CrtInfo failed! error is: " + err); + expect(null).assertFail(); + }); +} + +function checkGetRevokedCertWithCertX509CrlPromise(crlInstance, flag) { + return new Promise((resolve, reject) => { + createX509CertInstanceforCrlTestPromise(flag) + .then(certInstance => { + let crlEntry = crlInstance.getRevokedCertWithCert(certInstance); + return crlEntry; + }).then(crlEntry => { + console.warn("[promise] getRevokedCertWithCert is:" + crlEntry); + let num = crlEntry.getSerialNumber(); + console.warn("[promise] getRevokedCertWithCert num is:" + num); + resolve(crlEntry); + }).catch(err => { + console.error("[promise] getRevokedCertWithCert failed!"); + reject(err); + }); + }); +} + +async function checkGetRevokedCertsX509CrlPromise(certType) { + var gInstance; + var gIndex; + await createX509CrlInstancePromise(certType) + .then(instance => { + gInstance = instance; + let certs = gInstance.getRevokedCerts(); + return certs; + }).then(certs => { + if (certs == null) { + console.error("[Promise] Crl get revoked certs failed, certs is null"); + expect(null).assertFail(); + } + console.warn("[Promise] Crl get gevoked certs success"); + if (certs.length == 0) { + console.error("[Promise] Crl revoked certs length is 0"); + expect(null).assertFail(); + } + for (var i = 0; i < certs.length; i++) { + gIndex = i; + console.log("[Promise] certs i: " + gIndex + " serialNumber is: " + certs[gIndex].getSerialNumber()); + certs[gIndex].getRevocationDate() + .then(revocation => { + if (revocation == null) { + console.error("[Promise] certs i: " + gIndex + " revocation date is: null"); + expect(null).assertFail(); + } + console.log("[Promise] certs i: " + gIndex + " revocation date is: " + revocation); + }).catch(err => { + console.error("[Promise] certs i: " + gIndex + " revocation date is: " + err); + }) + certs[gIndex].getEncoded() + .then(eData => { + if (eData == null) { + console.error("[Promise] certs i: " + gIndex + " getEncoded is: null"); + expect(null).assertFail(); + } + console.log("[Promise] certs i: " + gIndex + " getEncoded is: " + eData); + }).catch(err => { + console.error("[Promise] certs i: " + gIndex + " getEncoded err is: " + err); + }) + } + }).catch(err => { + console.error("[Promise] Crl gevoked certs failed! error is: " + err); + expect(null).assertFail(); + }); +} + +async function checkGetRevokedCertX509CrlPromise(certType) { + var gInstance; + await createX509CrlInstancePromise(certType) + .then(instance => { + gInstance = instance; + let cert = gInstance.getRevokedCert(1); + return cert; + }).then(cert => { + if (cert == null) { + console.error("[Promise] Crl get revoked cert failed, cert is null"); + expect(null).assertFail(); + } + console.warn("[Promise] Crl get gevoked certs success"); + cert.getRevocationDate() + .then(revocation => { + if (revocation == null) { + console.error("[Promise] certs revocation date is: null"); + expect(null).assertFail(); + } + console.log("[Promise] cert revocation date is: " + revocation); + }).catch(err => { + console.error("[Promise] cert revocation date is: " + err); + }); + cert.getCertIssuer() + .then(certIssuer => { + if (certIssuer == null) { + console.error("[Promise] certs certIssuer is: null"); + expect(null).assertFail(); + } + console.log("[Promise] cert certIssuer is: " + +uInt8ArrayToString(certIssuer.data)); + }).catch(err => { + console.error("[Promise] cert certIssuer is: " + err); + }); + }).catch(err => { + console.error("[Promise] Crl gevoked cert failed! error is: " + err); + expect(null).assertFail(); + }); +} + +function checkValidateOfCertChainValidatorPromise(algName) { + var validator = cryptoFramework.createCertChainValidator(algName); + if (validator == null) { + console.error("createCertChainValidator failed, validator is null"); + expect(null).assertFail(); + } + var algorithm = validator.algorithm; + console.log("createCertChainValidator success! algorithm is: " + algorithm); + var certArray1 = stringTouInt8Array(chainFirstCaCert); + var byteLength1 = certArray1.byteLength; + var uInt16CertLength1 = new Uint16Array([byteLength1]); + var uInt8CertLength1 = new Uint8Array([uInt16CertLength1.buffer]); + + var certArray2 = stringTouInt8Array(chainSecondCaCert); + var byteLength2 = certArray2.byteLength; + var uInt16CertLength2 = new Uint16Array([byteLength2]); + var uInt8CertLength2 = new Uint8Array([uInt16CertLength2.buffer]); + + var dataArray = new Uint8Array(uInt8CertLength2.length + certArray2.length + uInt8CertLength1.length + certArray1.length); + for (var i = 0; i < uInt8CertLength2.length; i++) { + dataArray[i] = uInt8CertLength2[i]; + } + for (var i = 0; i < certArray2.length; i++) { + dataArray[i+uInt8CertLength2.length] = certArray2[i]; + } + for (var i = 0; i < uInt8CertLength1.length; i++) { + dataArray[i + uInt8CertLength2.length + certArray2.length] = uInt8CertLength1[i]; + } + for (var i = 0; i < certArray1.length; i++) { + dataArray[i + uInt8CertLength2.length + certArray2.length + uInt8CertLength1.length] = certArray1[i]; + } + var certChainData = { + data: dataArray, + count: 2, + encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM + }; + validator.validate(certChainData).then(() => { + console.warn("[promise]: validate success!"); + expect(1 == 1).assertTrue(); + }).catch(err => { + console.error("[promise]: validate error: " + err); + expect(null).assertFail(); + }); +} + +export { + createX509CertInstancePromise, + verifyX509CertPromise, + checkValidityX509CertPromise, + checkGetEncodedX509CertPromise, + checkGetPublicKeyX509CertPromise, + getX509CertInfoPromise, + createX509CrlInstancePromise, + checkIsRevokedX509CrlPromise, + checkGetEncodedX509CrlPromise, + verifyX509CrlPromise, + getX509CrlInfoPromise, + checkGetRevokedCertWithCertX509CrlPromise, + checkGetRevokedCertsX509CrlPromise, + checkGetRevokedCertX509CrlPromise, + checkValidateOfCertChainValidatorPromise, +}; diff --git a/security/cryptoFramework/src/main/js/test/utils/common/publicDoString.js b/security/cryptoFramework/src/main/js/test/utils/common/publicDoString.js new file mode 100644 index 000000000..08dedec54 --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/common/publicDoString.js @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2022 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(""); +} + +function genIvParamsSpec(n) { + var arr; + if (n == 8) { + arr = [0, 0, 0, 0, 0, 0, 0, 0]; + } else if (n == 16) { + arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + } else { + console.error("genIvParamsSpec error: n = " + n); + return null; + } + var dataIv = new Uint8Array(arr); + var dataBlob = { data: dataIv }; + var ivParamSpec = { + iv: dataBlob, + algoName: "IvParamsSpec", + } + return ivParamSpec; +} + +function genGcmParamsSpec() { + var arr = [0, 0, 0, 0, 0, 0, 0, 0]; + var dataAad = new Uint8Array(arr); + var aadBlob = { data: dataAad }; + var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + var dataIv = new Uint8Array(arr); + var ivBlob = { data: dataIv }; + var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + var dataTag = new Uint8Array(arr); + var tagBlob = { data: dataTag }; + var gcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algoName: "GcmParamsSpec", + }; + return gcmParamsSpec; +} + +function genCcmParamsSpec() { + var arr = [0, 0, 0, 0, 0, 0, 0]; + var dataIv = new Uint8Array(arr); + var ivBlob = { data: dataIv }; + var arr = [0, 0, 0, 0, 0, 0, 0, 0]; + var dataAad = new Uint8Array(arr); + var aadBlob = { data: dataAad }; + var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + var dataTag = new Uint8Array(arr); + var tagBlob = { data: dataTag }; + var ccmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algoName: "CcmParamsSpec", + }; + return ccmParamsSpec; +} + +function genKeyMaterialBlob(keyLen) { + var arr; + if (keyLen == 128) { + //16字节 + arr = [0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c]; + } else if (keyLen == 192) { + //24字节 + arr = [0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c, + 0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56]; + } else if (keyLen == 256) { + //32字节 + arr = [0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c, + 0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c]; + } else { + console.error("genKeyMaterialBlob: KeyLen may be error"); + arr = []; + for (let i = 0; i < keyLen; i++) { + arr[i] = 0xba; + } + } + + var keyMaterial = new Uint8Array(arr); + var keyMaterialBlob = { data: keyMaterial }; + return keyMaterialBlob; +} + +export { + stringToArray, + uInt8ArrayToString, + stringTouInt8Array, + uInt8ArrayToShowStr, + genGcmParamsSpec, + genIvParamsSpec, + genCcmParamsSpec, + genKeyMaterialBlob +}; \ No newline at end of file diff --git a/security/cryptoFramework/src/main/js/test/utils/common/publicParam.js b/security/cryptoFramework/src/main/js/test/utils/common/publicParam.js new file mode 100644 index 000000000..fee65403d --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/common/publicParam.js @@ -0,0 +1,406 @@ +/* + * Copyright (C) 2022 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 deviceTestCert = "-----BEGIN CERTIFICATE-----\n" ++ "MIIEQDCCAyigAwIBAgIQICAIMRlDU0ytSEUfNeOUJTANBgkqhkiG9w0BAQsFADBcMQswCQYDVQQG\n" ++ "OAYDVQQDDDFIVUFXRUlfSFdKQURfODE4ZjhjNDUtOGNmNC00ZTM2LTkxOTMtNTQ5OWMwNzM0YzM4\n" ++ "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArZcfL6ot4z6k3T4X3C26EI557Zvrx9Ci\n" ++ "hNx6RMy+vjXa3E4BkxwZ3r0ADbc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M9\n" ++ "-----END CERTIFICATE-----\n"; + +var rootCert = "-----BEGIN CERTIFICATE-----\n" ++ "MIIGQDCCBCigAwIBAgIUKNQFxqguJbKjFXanBmC2ZwUv9dkwDQYJKoZIhvcNAQEL\n" ++ "BQAwejELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNIQU5HSEFJMREwDwYDVQQHDAhT\n" ++ "SEFOR0hBSTELMAkGA1UECgwCQUExCzAJBgNVBAsMAkJCMQswCQYDVQQDDAJDQzEe\n" ++ "MBwGCSqGSIb3DQEJARYPZmlyc3RAaGVsbG8uY29tMCAXDTIyMDgyMzExMjk0MVoY\n" ++ "DzIwNjIwODIzMTEyOTQxWjB6MQswCQYDVQQGEwJDTjERMA8GA1UECAwIU0hBTkdI\n" ++ "QUkxETAPBgNVBAcMCFNIQU5HSEFJMQswCQYDVQQKDAJBQTELMAkGA1UECwwCQkIx\n" ++ "CzAJBgNVBAMMAkNDMR4wHAYJKoZIhvcNAQkBFg9maXJzdEBoZWxsby5jb20wggIi\n" ++ "MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCr4nXrmskgHytDYcp8/BRORk71\n" ++ "f2idSs6cxxSOycILA3fbhbCB3qA8Bj4k1bT592j99MsKm+djMFvUOW/mS6iEWcoS\n" ++ "sK1HvYX2d7y0GMDnltT9I/KlcYDHiwcq0UgHX4OSbB70EUt9vUmq/opYeUJFIbfq\n" ++ "QJvGu57PJw+lxdsq3mZvx8n04fIMxqJdQSXu2foh0fSIePthNIV5JNtO9tTmmKn9\n" ++ "b+L9Eb1IfhKnvxNVuq046+eUwRA3Qva4HQOkCplamfU+b2dQGXnpha/NzXfCVuZK\n" ++ "R13xhUXjuXADGAIoRl9BgxgONTVpy209xQ7W1UvVEbSVDf8r9OlPDf3olRoavTAv\n" ++ "+EaYyqrFoEtTzIRZDiLIhqjoqtpbrl5oVggfH/qn8qDyZ+a6puwa81+9Mad8CLwh\n" ++ "Q9sa0uT+AET86gCGgpOBPF31+xYgnzn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BAQCuvLoVT5em7ApBma8xtgpcFcaU\n" ++ "CbXBJSUl2NpFW2sriucbEOvKRdw9KvLa/tSP6CupPZVKIzHAP2oeW88aFBr23miG\n" ++ "iR49M52c73Iw3H3EG2ckK8M1mxEzXSqynivqiNZDKG+bA5cFzcfmk6Th1bJan9w9\n" ++ "Ci8HPSBvgg7Rc6pqNM4HjTHl3Bb6cf4Xh3/GgpjypTd9jAAEyq+l/+1pnTYVlIJA\n" ++ "WGh0Z26RosXfzwfFKH77ysTjoj9ambvGmFsMXvNXEyYmBCeYND6xGj4pa2lylsra\n" ++ "kfYmGxcFQ45Lj5oWdNQQVdvrQiYWu3SJOC/WqB5UIAq92PPrq1apznxfjqABAgMB\n" ++ "AAGjUzBRMB0GA1UdDgQWBBRI5iWwjBMAOCcgcUjUCYJdsvwEMjAfBgNVHSMEGDAW\n" ++ "gBRI5iWwjBMAOCcgcUjUCYJdsvwEMjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3\n" ++ "DQEBCwUAA4IBAQABop7EJgS2czHKWVzdEwjbi9m5ZUPy6aOV9paV1e/5IyFNHwun\n" ++ "B64iwcg03+FmIWNuynb1mglHHrUoXygXu9GIR8cWfOI3W+Pnn8fDi8MxQMn/e/Jj\n" ++ "BuGcnRwKynRhyLdkyWYn1YwqenMuFJu9yzkhfAPltGFEuPYCWDatdhm6zhFdu1PE\n" ++ "EMErHpQOT45z5cgC4XqgKlE+n8L4/5RfZnbuUJ3bV+FuI+VApLGXJQlJQAOTqBDg\n" ++ "k7DMSgPUUxYYa6AGMFy6vqQ6hcgCMK08ko8LdjVd1MobKzM9Oh480GFZA/ubR3QW\n" ++ "lv3OuOhmnIxNGcPUiqpSiWKqR5tf1KUImIR9\n" ++ "-----END CERTIFICATE-----\n"; + +/*selfSignedCaCertSource + * Certificate: + Data: + Version: 3 (0x2) + Serial Number: 272 (0x110) + Signature Algorithm: sha256WithRSAEncryption + Issuer: C = CN, ST = BJ, L = BJ, O = HD, OU = dev, CN = ca, emailAddress = ca@cryptoframework.com + Validity + Not Before: Aug 19 12:49:06 2022 GMT + Not After : Aug 16 12:49:06 2032 GMT + Subject: C = CN, ST = BJ, L = BJ, O = HD, OU = dev, CN = ca, emailAddress = ca@cryptoframework.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (2048 bit) + Modulus: + 00:9f:29:d0:85:84:ed:6c:30:6e:d0:13:83:e0:1b: + 61:08:f7:dd:63:41:06:4b:54:fb:f0:15:7f:e4:e5: + d5:a0:1a:e1:33:9e:5b:6f:d9:01:17:38:b1:dc:0b: + 55:3c:5d:5c:28:a9:16:c7:ae:88:63:77:d2:1c:17: + ad:71:54:1e:b7:0c:7f:4c:36:b0:29:33:9c:95:59: + fe:b4:1c:7c:43:b9:29:bd:6f:07:3e:83:10:47:20: + 21:26:04:86:1a:8e:05:f6:01:8a:de:6a:7e:9a:b9: + 47:6f:b6:47:f4:e1:ff:26:d5:fa:40:6b:52:5f:86: + b2:c5:db:0c:07:ba:a1:90:b2:e7:a9:46:a6:10:ef: + 98:73:14:3b:b6:b5:de:3f:92:16:64:e1:31:b2:36: + c9:ec:ae:6b:52:da:81:2a:1a:04:97:d8:d4:9f:a2: + ee:35:8f:9a:61:05:47:47:50:da:9d:04:1a:31:d3: + 81:01:a1:46:8e:55:bb:00:c7:8a:93:52:bf:45:cf: + f0:e5:00:fc:f6:1b:2f:f4:81:8f:51:6a:e0:2d:e0: + b5:fb:e3:7a:cc:14:6f:35:5a:32:8a:bf:c0:2b:b2: + d6:a7:17:23:cd:19:2d:ed:f0:85:1d:b8:73:47:17: + 60:53:b4:b8:68:bd:7a:03:e9:db:87:f0:ef:26:06: + aa:01 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Subject Key Identifier: + 8C:A3:3B:42:63:01:B3:4D:51:F6:E4:2D:B5:83:7F:18:39:2F:B7:B5 + X509v3 Authority Key Identifier: + keyid:8C:A3:3B:42:63:01:B3:4D:51:F6:E4:2D:B5:83:7F:18:39:2F:B7:B5 + + X509v3 Basic Constraints: critical + CA:TRUE, pathlen:2 + X509v3 Key Usage: + Certificate Sign, CRL Sign + X509v3 Extended Key Usage: + TLS Web Server Authentication, TLS Web Client Authentication + X509v3 Subject Alternative Name: + email:ca@cryptoframework.com + X509v3 Issuer Alternative Name: + email:ca@cryptoframework.com + Signature Algorithm: sha256WithRSAEncryption + 87:ee:11:13:a7:09:eb:6f:e0:2d:8b:2c:2e:47:3b:11:28:3b: + 7b:12:b0:66:59:a2:b0:7c:81:89:cb:b2:ff:e5:da:80:e6:77: + 71:36:e0:40:d5:e5:42:86:4a:6f:0f:e4:b3:f0:7f:70:89:db: + 40:66:1b:a4:09:b8:ed:2b:9d:a3:e2:3f:1b:dc:63:d1:7e:e0: + 40:1f:70:b5:2a:db:4a:d3:ac:e9:28:e7:2e:26:14:d3:11:5c: + 16:c7:34:8f:a9:36:4a:b9:72:8b:04:50:72:34:b8:3c:e2:a2: + 51:2d:02:9b:71:77:0c:71:9d:8f:9e:4f:94:19:17:c6:e7:57: + 0a:ad:95:dc:9d:d5:c0:a7:f6:6d:58:d0:6f:3c:f6:f8:cf:d0: + d6:6f:8f:ec:58:41:f8:99:9e:3b:c7:9e:9a:4a:8c:43:4b:45: + 31:4d:c4:33:8e:35:36:97:a3:0b:98:85:54:01:a0:a3:09:c2: + f1:2d:01:f9:fc:47:f5:d0:49:b8:73:3a:be:9c:44:5b:0d:dc: + 91:91:43:65:0d:64:77:dd:58:46:0a:fb:8d:8f:1f:73:4b:ff: + 4f:4b:73:1d:66:ce:11:5c:e4:94:42:01:58:bd:66:a2:6a:4b: + 04:2c:1e:d3:f1:b0:f8:13:ba:d1:b7:e2:d8:ca:09:c3:cb:76: + 21:c0:75:43 + * */ + +var selfSignedCaCertPem = "-----BEGIN CERTIFICATE-----\n" ++ "MIIEMjCCAxqgAwIBAgICARAwDQYJKoZIhvcNAQELBQAwdjELMAkGA1UEBhMCQ04x\n" ++ "CzAJBgNVBAgMAkJKMQ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5cHRvZnJhbWV3b3JrLmNvbTANBgkqhkiG9w0BAQsF\n" ++ "AAOCAQEAh+4RE6cJ62/gLYssLkc7ESg7exKwZlmisHyBicuy/+XagOZ3cTbgQNXl\n" ++ "QoZKbw/ks/B/cInbQGYbpAm47Sudo+I/G9xj0X7gQB9wtSrbStOs6SjnLiYU0xFc\n" ++ "Fsc0j6k2SrlyiwRQcjS4POKiUS0Cm3F3DHGdj55PlBkXxudXCq2V3J3VwKf2bVjQ\n" ++ "bzz2+M/Q1m+P7FhB+JmeO8eemkqMQ0tFMU3EM441NpejC5iFVAGgownC8S0B+fxH\n" ++ "9dBJuHM6vpxEWw3ckZFDZQ1kd91YRgr7jY8fc0v/T0tzHWbOEVzklEIBWL1mompL\n" ++ "BCwe0/Gw+BO60bfi2MoJw8t2IcB1Qw==\n" ++ "-----END CERTIFICATE-----\n"; + +var selfSignedCaCertDer = "308204323082031aa00302010202020110300d06092a864886f70d" + +"01010b05003076310b300906035504061302434e310b300906035504080c02424a310b30090603550" + +"4070c02424a310b3009060355040a0c024844310c300a060355040b0c03646576310b300906035504" + +"030c0263613125302306092a864886f70d010901161663614063727970746f6672616d65776f726b2" + +"e636f6d301e170d3232303831393132343930365a170d3332303831363132343930365a3076310b30" + +"0906035504061302434e310b300906035504080c02424a310b300906035504070c02424a310b30090" + +"60355040a0c024844310c300a060355040b0c03646576310b300906035504030c0263613125302306" + +"092a864886f70d010901161663614063727970746f6672616d65776f726b2e636f6d30820122300d0" + +"6092a864886f70d01010105000382010f003082010a02820101009f29d08584ed6c306ed01383e01b" + +"6108f7dd6341064b54fbf0157fe4e5d5a01ae1339e5b6fd9011738b1dc0b553c5d5c28a916c7ae886" + +"377d21c17ad71541eb70c7f4c36b029339c9559feb41c7c43b929bd6f073e83104720212604861a8e" + +"05f6018ade6a7e9ab9476fb647f4e1ff26d5fa406b525f86b2c5db0c07baa190b2e7a946a610ef987" + +"3143bb6b5de3f921664e131b236c9ecae6b52da812a1a0497d8d49fa2ee358f9a6105474750da9d04" + +"1a31d38101a1468e55bb00c78a9352bf45cff0e500fcf61b2ff4818f516ae02de0b5fbe37acc146f3" + +"55a328abfc02bb2d6a71723cd192dedf0851db87347176053b4b868bd7a03e9db87f0ef2606aa0102" + +"03010001a381c93081c6301d0603551d0e041604148ca33b426301b34d51f6e42db5837f18392fb7b" + +"5301f0603551d230418301680148ca33b426301b34d51f6e42db5837f18392fb7b530120603551d13" + +"0101ff040830060101ff020102300b0603551d0f040403020106301d0603551d250416301406082b0" + +"601050507030106082b0601050507030230210603551d11041a3018811663614063727970746f6672" + +"616d65776f726b2e636f6d30210603551d12041a3018811663614063727970746f6672616d65776f7" + +"26b2e636f6d300d06092a864886f70d01010b0500038201010087ee1113a709eb6fe02d8b2c2e473b" + +"11283b7b12b06659a2b07c8189cbb2ffe5da80e6777136e040d5e542864a6f0fe4b3f07f7089db406" + +"61ba409b8ed2b9da3e23f1bdc63d17ee0401f70b52adb4ad3ace928e72e2614d3115c16c7348fa936" + +"4ab9728b04507234b83ce2a2512d029b71770c719d8f9e4f941917c6e7570aad95dc9dd5c0a7f66d5" + +"8d06f3cf6f8cfd0d66f8fec5841f8999e3bc79e9a4a8c434b45314dc4338e353697a30b98855401a0" + +"a309c2f12d01f9fc47f5d049b8733abe9c445b0ddc919143650d6477dd58460afb8d8f1f734bff4f4" + +"b731d66ce115ce494420158bd66a26a4b042c1ed3f1b0f813bad1b7e2d8ca09c3cb7621c07543" + +var testErrorCert = "-----BEGIN CERTIFICATE-----\n" ++ "MIIEQDCCAyigAwIBAgIQICAIMRlDU0ytSEUfNeOUJTANBgkqhkiG9w0BAQsFADBcMQswCQYDVQQG\n" ++ "EwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMScwJQYDVQQDDB5IdWF3\n" ++ "ZWkgQ0JHIE1vYmlsZSBFcXVpcG1lbnQgQ0EwHhcNMjAwODMxMTE0MzUzWhcNMzAwODI5MTE0MzUz\n" ++ "WjB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QkBFg10ZXN0QHRlc3QuY29tFw0yMjA4MjkwNzAwMTRaFw0yMjA5Mjgw\n" ++ "NzAwMTRaMBQwEgIBARcNMjIwODI5MDY1OTUzWqAOMAwwCgYDVR0UBAMCAQAwDQYJ\n" ++ "KoZIhvcNAQELBQADggEBAHpfFhhUR59OAvOSuKDQUC5tKeLEuPbY8bYdmQVI8EFd\n" ++ "xDkZTXmT3CX1aDPYKVsG/jH9KPAmCV/ODKEGiJzclb3Z4am7tT+Wy4mpXypNS1od\n" ++ "wPDcQGsMrjT6iSp6JImiB0dDDSleBTBcYR/hhtFaiGSncyqJ0mhyaXPxIkNOO6nY\n" ++ "v+rcTEPQWavViDRyNDhnTbN868I3fzFVBcidF13CA0sCJ91ZvsE9h/YmPO2+e0YE\n" ++ "IUgzn37UOiLGObCVBY12QjGiuvVvCl7ncncsFEJuGfvONOqyFHjyxDHo5W0fqTn2\n" ++ "eCtiNcgUr9Kz2bwCmvEXhP7PuF4RMLq4vfzi0YjCG98=\n" ++ "-----END X509 CRL-----\n"; + +var testCrlDer = "308201fc3081e5020101300d06092a864886f70d01010b0500" + +"30818c310b300906035504061302434e3111300f06035504080c087368616e67686" + +"169310f300d06035504070c0668756177656931153013060355040a0c0c7777772e" + +"746573742e636f6d310d300b060355040b0c04746573743115301306035504030c0" + +"c7777772e746573742e636f6d311c301a06092a864886f70d010901160d74657374" + +"40746573742e636f6d170d3232303832393037303031345a170d323230393238303" + +"7303031345a30143012020101170d3232303832393036353935335aa00e300c300a" + +"0603551d140403020100300d06092a864886f70d01010b050003820101007a5f161" + +"854479f4e02f392b8a0d0502e6d29e2c4b8f6d8f1b61d990548f0415dc439194d79" + +"93dc25f56833d8295b06fe31fd28f026095fce0ca106889cdc95bdd9e1a9bbb53f9" + +"6cb89a95f2a4d4b5a1dc0f0dc406b0cae34fa892a7a2489a20747430d295e05305c" + +"611fe186d15a8864a7732a89d268726973f122434e3ba9d8bfeadc4c43d059abd58" + +"834723438674db37cebc2377f315505c89d175dc2034b0227dd59bec13d87f6263c" + +"edbe7b46042148339f7ed43a22c639b095058d764231a2baf56f0a5ee772772c144" + +"26e19fbce34eab21478f2c431e8e56d1fa939f6782b6235c814afd2b3d9bc029af1" + +"1784fecfb85e1130bab8bdfce2d188c21bdf"; + +var crlVerifyPriKeyHex = "00040000800000000300000080000000C3DDD24AEB" + +"337612204443B8ACDBD52206B004D65777CC1BB3E021C24CD13FA486A89A862957D" + +"9294120DCFA9B2CE485E9F39962B07AC5768A6D4D6C86086B4C7EA832E3DBE9C14F" + +"95EE2702537D32BB8B3C962FB199EBAF2B467E7981332904240C18A79CF25DA9823" + +"9CFB2094A69EEC1AABF57A4DA4A6A60021300E814B8E101000133EE3C3360E8E405" + +"2A48EF2BA7A92179440CA73BAD353608A2486AAAF973014CBDE736111C250E8EC19" + +"5D5011CE36A339733DF172B7361A76C4C4E9AD76EA403CCDFB45A8D9AEFB39FA290" + +"25063111E0A569BAF17B15B770361C1B5788E4FDA99E93CF7B8B6D49AA7C2D195E9" + +"73FD0875DF24C56F4E3771BAEEC555B69210A01"; + +var crlVerifyPubKeyHex = "00040000800000000300000000000000C3DDD24AEB" + +"337612204443B8ACDBD52206B004D65777CC1BB3E021C24CD13FA486A89A862957D" + +"9294120DCFA9B2CE485E9F39962B07AC5768A6D4D6C86086B4C7EA832E3DBE9C14F" + +"95EE2702537D32BB8B3C962FB199EBAF2B467E7981332904240C18A79CF25DA9823" + +"9CFB2094A69EEC1AABF57A4DA4A6A60021300E814B8E1010001"; + +var crlHex = "3081F3305E020103300D06092A864886F70D010104050030153113" + +"30110603550403130A43524C20697373756572170D3232303932343232313631365" + +"A170D3332313231343030353332305A30153013020203E8170D3332313231343030" + +"353332305A300D06092A864886F70D01010405000381810071573DC03B03D19D0D2" + +"CF40D2AB7D3C7D7FA92D8A03DD340EC1090F30C7D273D3C80F2225665CF4C1BDCDF" + +"94C1DB9EC6E4D4EC742B48E736F39C7B3229D53CB363854FE78834CC51E45F797A8" + +"61C572D9C6B54F6C2FCD45DF92F5107799E8D33E77FD9FD221F1C66A0CAB68CC9BB" + +"05BFE952B17849379205D144BCAF7F613D73"; + + +export { + rootCert, + chainFirstCaCert, + chainSecondCaCert, + testCert, + testCrlDer, + testCrlPem, + testErrorCert, + testInvalidCert, + deviceTestCert, + selfSignedCaCertPem, + selfSignedCaCertDer, + crlVerifyPriKeyHex, + crlVerifyPubKeyHex, + crlHex +}; diff --git a/security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestCallback.js b/security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestCallback.js new file mode 100644 index 000000000..859d9390d --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestCallback.js @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2022 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 cryptoFramework from "@ohos.security.cryptoFramework"; +import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString} from "../common/publicDoString"; + +async function testMDDigestCallback(MDAlgoName) { + var globalMd; + var globalText = "my test data"; + + globalMd = cryptoFramework.createMd(MDAlgoName); + expect(globalMd != null).assertTrue(); + console.warn("md= " + globalMd); + console.warn("MD algName is: " + globalMd.algName); + // test input data + let inBlob = { + data: stringTouInt8Array(globalText) + } + globalMd.update(inBlob, (err,) => { + if (err) { + console.error("[callback]catch err:" + err); + expect(err == null).assertFail(); + } + console.warn("[callback]: update finished"); + globalMd.digest((err1, digestBlob) => { + if (err1) { + console.error("[callback]catch err:" + err1); + expect(err == null).assertFail(); + } + console.warn("[callback]: digest result1: " + uInt8ArrayToShowStr(digestBlob.data)); + console.warn("[callback]: digest result2: " + digestBlob.data); + let mdLen = globalMd.getMdLength(); + console.warn("Md len: " + mdLen); + expect(digestBlob != null && mdLen == 16).assertTrue(); + }); + }) +} + +async function testHMACDigestCallback(HMACAlgoName, keyAlgoName) { + var globalHMAC; + var globalText = "my test data"; + var globalsymKeyGenerator; + var ginBlob = { + data: stringTouInt8Array(globalText) + }; + + globalHMAC = cryptoFramework.createMac(HMACAlgoName); + expect(globalHMAC != null).assertTrue(); + console.warn("mac= " + globalHMAC); + console.warn("HMAC algName is: " + globalHMAC.algName); + // create sym key generator + console.log("start to call createSymKeyGenerator()"); + globalsymKeyGenerator = cryptoFramework.createSymKeyGenerator(keyAlgoName); + expect(globalsymKeyGenerator != null).assertTrue(); + console.log("createSymKeyGenerator ok"); + console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName); + globalsymKeyGenerator.generateSymKey((err, key) => { + if (err) { + console.error("[callback]catch err:" + err.code); + expect(err == null).assertFail(); + } + expect(key != null).assertTrue(); + console.warn("generateSymKey ok"); + console.warn("key algName:" + key.algName); + console.warn("key format:" + key.format); + var encodedKey = key.getEncoded(); + console.warn("key getEncoded hex: " + uInt8ArrayToShowStr(encodedKey.data)); + globalHMAC.init(key, (err1,) => { + if (err1) { + console.error("[callback]catch err:" + err1.code); + expect(err1 == null).assertFail(); + } + globalHMAC.update(ginBlob, (err2,) => { + if (err2) { + console.error("[callback]catch err:" + err2.code); + expect(err2 == null).assertFail(); + } + globalHMAC.doFinal((err3, macOutput) => { + if (err3) { + console.error("[callback]catch err:" + err3.code); + expect(err3 == null).assertFail(); + } + console.warn("HMAC result:" + macOutput.data); + let macLen = globalHMAC.getMacLength(); + console.warn("MAC len:" + macLen); + expect(macOutput != null && macLen == 20).assertTrue(); + }) + }) + }) + }) +} + +export { testMDDigestCallback, testHMACDigestCallback }; diff --git a/security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js b/security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js new file mode 100644 index 000000000..7218bfa4b --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2022 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 cryptoFramework from "@ohos.security.cryptoFramework"; +import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString"; + +async function testMDDigestPromise(MDAlgoName) { + var globalMd; + var globalText = "my test data"; + + globalMd = cryptoFramework.createMd(MDAlgoName); + expect(globalMd != null).assertTrue(); + console.warn("md= " + globalMd); + console.warn("MD algName is: " + globalMd.algName); + // test input data + let inBlob = { + data: stringTouInt8Array(globalText) + } + //test functionalities by promise async + globalMd.update(inBlob).then(() => { + console.warn("[Promise]: update finished"); + let digestBlob = globalMd.digest(); + return digestBlob; + }).then((mdOutput) => { + console.warn("[Promise]: digest result1: " + uInt8ArrayToShowStr(mdOutput.data)); + console.warn("[Promise]: digest result2: " + mdOutput.data); + let mdLen = globalMd.getMdLength(); + console.warn("Md len: " + mdLen); + expect(mdOutput != null && mdLen == 16).assertTrue(); + }).catch(err => { + console.error("[promise]catch err:" + err); + expect(err == null).assertFail(); + }) +} + +async function testHMACDigestPromise(HMACAlgoName, keyAlgoName) { + var globalHMAC; + var globalText = "my test data"; + var globalsymKeyGenerator; + var ginBlob = { + data: stringTouInt8Array(globalText) + }; + + globalHMAC = cryptoFramework.createMac(HMACAlgoName); + expect(globalHMAC != null).assertTrue(); + console.warn("mac= " + globalHMAC); + console.warn("HMAC algName is: " + globalHMAC.algName); + // create sym key generator + console.log("start to call createSymKeyGenerator()"); + globalsymKeyGenerator = cryptoFramework.createSymKeyGenerator(keyAlgoName); + expect(globalsymKeyGenerator != null).assertTrue(); + console.log("createSymKeyGenerator ok"); + console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName); + globalsymKeyGenerator.generateSymKey().then(key => { + expect(key != null).assertTrue(); + console.warn("generateSymKey ok"); + console.warn("key algName:" + key.algName); + console.warn("key format:" + key.format); + var encodedKey = key.getEncoded(); + console.warn("key getEncoded hex: " + uInt8ArrayToShowStr(encodedKey.data)); + var promiseMacInit = globalHMAC.init(key); + return promiseMacInit; + }).then(() => { + var promiseMacUpdate = globalHMAC.update(ginBlob); + return promiseMacUpdate; + }).then(() => { + var promiseMacdoFinal = globalHMAC.doFinal(); + return promiseMacdoFinal; + }).then(macOutput => { + console.warn("HMAC result:" + macOutput.data); + let macLen = globalHMAC.getMacLength(); + expect(macOutput != null && macLen == 20).assertTrue(); + console.warn("MAC len:" + macLen); + }).catch(err => { + console.error("[promise]catch err:" + err); + expect(err == null).assertFail(); + }) +} + +export { testMDDigestPromise, testHMACDigestPromise }; diff --git a/security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js b/security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js new file mode 100644 index 000000000..b6f78ff78 --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomCallback.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 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 cryptoFramework from "@ohos.security.cryptoFramework"; +import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString"; + +async function testSecurityRandomCallback(length) { + var rand; + var callbackGenerateRand; + + rand = cryptoFramework.createRandom(); + expect(rand != null).assertTrue(); + rand.generateRandom(length, (err, randData)=>{ + if(err) { + console.error("[callback]catch err:" + err); + expect(null).assertFail(); + } else { + expect(randData != null).assertTrue(); + console.log("[callback] rand result first:" + uInt8ArrayToShowStr(randData.data)); + } + rand.setSeed(randData, (err1, )=>{ + if(err1) { + console.error("[callback]catch err1:" + err1); + expect(null).assertFail(); + } else { + expect(null).assertTrue(); + } + }) + }) + + rand.generateRandom(length, (err, randData)=>{ + if(err) { + console.error("[callback]catch err:" + err); + expect(null).assertFail(); + } else { + expect(randData != null).assertTrue(); + console.log("[callback] rand result second:" + uInt8ArrayToShowStr(randData.data)); + } + }) +} + +export { testSecurityRandomCallback }; diff --git a/security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomPromise.js b/security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomPromise.js new file mode 100644 index 000000000..198d77ba9 --- /dev/null +++ b/security/cryptoFramework/src/main/js/test/utils/securityrandom/publicSecurityRandomPromise.js @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 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 cryptoFramework from "@ohos.security.cryptoFramework"; +import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString"; + +async function testSecurityRandomPromise(length) { + var rand; + + rand = cryptoFramework.createRandom(); + expect(rand != null).assertTrue(); + rand.generateRandom(length).then(randData => { + expect(randData != null).assertTrue(); + console.log("[Promise] rand result first:" + uInt8ArrayToShowStr(randData.data)); + let result = rand.setSeed(randData); + return result; + }).then(() => { + console.log("[Promise] rand set Seed is success!"); + expect(null).assertTrue(); + }).catch(err => { + console.error("[promise]catch err:" + err); + expect(null).assertFail(); + }) + + rand.generateRandom(length).then(randData => { + expect(randData != null).assertTrue(); + console.log("[Promise] rand result second: " + uInt8ArrayToShowStr(randData.data)); + }).catch(err => { + console.error("[promise]catch err:" + err); + expect(null).assertFail(); + }) +} + +async function testSecurityRandomEnumPromise() { + expect(401).assertEqual(cryptoFramework.Result.INVALID_PARAMS); + expect(801).assertEqual(cryptoFramework.Result.NOT_SUPPORT); + expect(17620001).assertEqual(cryptoFramework.Result.ERR_OUT_OF_MEMORY); + expect(17620002).assertEqual(cryptoFramework.Result.ERR_INTERNAL_ERROR); + expect(17630001).assertEqual(cryptoFramework.Result.ERR_CRYPTO_OPERATION); + expect(17630002).assertEqual(cryptoFramework.Result.ERR_CERT_SIGNATURE_FAILURE); + expect(17630003).assertEqual(cryptoFramework.Result.ERR_CERT_NOT_YET_VALID); + expect(17630004).assertEqual(cryptoFramework.Result.ERR_CERT_HAS_EXPIRED); + expect(17630005).assertEqual(cryptoFramework.Result.ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY); + expect(17630006).assertEqual(cryptoFramework.Result.ERR_KEYUSAGE_NO_CERTSIGN); + expect(17630007).assertEqual(cryptoFramework.Result.ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE); + expect(0).assertEqual(cryptoFramework.EncodingFormat.FORMAT_DER); + expect(1).assertEqual(cryptoFramework.EncodingFormat.FORMAT_PEM); + expect(0).assertEqual(cryptoFramework.CryptoMode.ENCRYPT_MODE); + expect(1).assertEqual(cryptoFramework.CryptoMode.DECRYPT_MODE); +} + +export { testSecurityRandomPromise, testSecurityRandomEnumPromise }; diff --git a/security/cryptoFramework/src/main/resources/base/element/string.json b/security/cryptoFramework/src/main/resources/base/element/string.json new file mode 100644 index 000000000..8afb12da3 --- /dev/null +++ b/security/cryptoFramework/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/security/cryptoFramework/src/main/resources/base/media/icon.png b/security/cryptoFramework/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x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