提交 6cc4f447 编写于 作者: Q Qwink2016

加解密算法库新增测试套以及XTS测试套结构修改

Signed-off-by: NQwink2016 <714794360@qq.com>
Change-Id: Ic0a7de381e3c1b574f4da6f47ec65d490dc65ba4
上级 3bd23b21
...@@ -19,7 +19,8 @@ group("security") { ...@@ -19,7 +19,8 @@ group("security") {
deps = [ deps = [
"access_token/AccessTokenTest_Normal_js:ActsAccessTokenApiJSNormalTest", "access_token/AccessTokenTest_Normal_js:ActsAccessTokenApiJSNormalTest",
"cipher/datacipher:datacipher", "cipher/datacipher:datacipher",
"cryptoFramework:ActsCryptoFrameworkJSNormalTest", "cryptoFramework/js_api_test_one:ActsCryptoFrameworkJSNormalTest",
"cryptoFramework/js_api_test_two:ActsCryptoFrameworkJSNormalTwoTest",
"huks_napi_BasicTest:ActsHuksNAPITest", "huks_napi_BasicTest:ActsHuksNAPITest",
"security_huks_basic", "security_huks_basic",
"security_huks_reformed_test", "security_huks_reformed_test",
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"type": "OHJSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "900000", "test-timeout": "900000",
"shell-timeout": "900000", "shell-timeout": "900000",
"bundle-name": "com.openharmony.cryptoFramework", "bundle-name": "com.openharmony.cryptoFramework1",
"package-name": "com.openharmony.cryptoFramework" "package-name": "com.openharmony.cryptoFramework1"
}, },
"kits": [ "kits": [
{ {
......
{ {
"app": { "app": {
"bundleName": "com.openharmony.cryptoFramework", "bundleName": "com.openharmony.cryptoFramework1",
"vendor": "acts", "vendor": "acts",
"version": { "version": {
"code": 12, "code": 12,
...@@ -14,15 +14,10 @@ ...@@ -14,15 +14,10 @@
}, },
"deviceConfig": {}, "deviceConfig": {},
"module": { "module": {
"package": "com.openharmony.cryptoFramework", "package": "com.openharmony.cryptoFramework1",
"name": ".entry", "name": ".entry",
"mainAbility": ".MainAbility", "mainAbility": ".MainAbility",
"deviceType": [ "deviceType": ["default", "tablet", "tv", "wearable", "phone"],
"default",
"tablet",
"tv",
"wearable"
],
"distro": { "distro": {
"deliveryWithInstall": true, "deliveryWithInstall": true,
"moduleName": "entry", "moduleName": "entry",
......
...@@ -15,16 +15,10 @@ ...@@ -15,16 +15,10 @@
import SymmetricCryptographyJsunit from "./SymmetricCryptography.test"; import SymmetricCryptographyJsunit from "./SymmetricCryptography.test";
import AsymmetricCryptographyJsunit from "./AsymmetricCryptography.test"; import AsymmetricCryptographyJsunit from "./AsymmetricCryptography.test";
import SecurityRandomJsunit from "./SecurityRandom.test";
import DigestAlgorithmJsunit from "./DigestAlgorithm.test"; import DigestAlgorithmJsunit from "./DigestAlgorithm.test";
import CertificateJsunit from "./Certificate.test";
import CertificateCrlJsunit from "./CertificateCrl.test";
export default function testsuite() { export default function testsuite() {
SymmetricCryptographyJsunit(); SymmetricCryptographyJsunit();
AsymmetricCryptographyJsunit(); AsymmetricCryptographyJsunit();
SecurityRandomJsunit();
CertificateJsunit();
CertificateCrlJsunit();
DigestAlgorithmJsunit(); DigestAlgorithmJsunit();
} }
...@@ -109,37 +109,37 @@ var chainFirstCaCert = ...@@ -109,37 +109,37 @@ var chainFirstCaCert =
var chainSecondCaCert = var chainSecondCaCert =
"-----BEGIN CERTIFICATE-----\n" + "-----BEGIN CERTIFICATE-----\n" +
"MIIFwjCCA6qgAwIBAgIUTUs0/9mQvlKZ67Q3nDR+5bwvyoowDQYJKoZIhvcNAQEL\n" + "MIIFvDCCA6SgAwIBAgIUZDZSgan7tFvmeMmUD80kk+opOZwwDQYJKoZIhvcNAQEL\n" +
"BQAwejELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNIQU5HSEFJMREwDwYDVQQHDAhT\n" + "BQAwbzELMAkGA1UEBhMCQ0kxCzAJBgNVBAgMAmhuMQswCQYDVQQHDAJzaDELMAkG\n" +
"SEFOR0hBSTELMAkGA1UECgwCQUExCzAJBgNVBAsMAkJCMQswCQYDVQQDDAJDQzEe\n" + "A1UECgwCaGgxCzAJBgNVBAsMAmlpMQswCQYDVQQDDAJhYjEfMB0GCSqGSIb3DQEJ\n" +
"MBwGCSqGSIb3DQEJARYPZmlyc3RAaGVsbG8uY29tMB4XDTIyMDgyMzExMzQwMFoX\n" + "ARYQY3J5cHRvQGhlbGxvLmNvbTAeFw0yMjA4MjAxMjI4MDhaFw00MjA4MjAxMjI4\n" +
"DTQyMDgyMzExMzQwMFowezELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNIQU5HSEFJ\n" + "MDhaMHwxCzAJBgNVBAYTAkNOMQ4wDAYDVQQIDAVIVU5BTjERMA8GA1UEBwwIU0hB\n" +
"MREwDwYDVQQHDAhTSEFOR0hBSTELMAkGA1UECgwCQUExCzAJBgNVBAsMAkJCMQsw\n" + "R05IQUkxCzAJBgNVBAoMAmhoMQswCQYDVQQLDAJpaTEPMA0GA1UEAwwGYXV0aG9y\n" +
"CQYDVQQDDAJDQzEfMB0GCSqGSIb3DQEJARYQc2Vjb25kQGhlbGxvLmNvbTCCAiIw\n" + "MR8wHQYJKoZIhvcNAQkBFhBjcnlwdG9AaGVsbG8uY29tMIICIjANBgkqhkiG9w0B\n" +
"DQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAJkLbBN8iHBWDHCdoMPpUwIeCSpW\n" + "AQEFAAOCAg8AMIICCgKCAgEAuSVyrlsC5nO+64mTYGAVJb1bdRJhz7ATMy2CE2AC\n" +
"nWdqJJ83Hmp3KQvm2sY9l2VOMFE+D9QJr3rRLuzQLYwcGjCcqcq+a7up7jfyB+wm\n" + "yo/RAl2p4Yoz8uJ6U23Ip4F+HmAGqXnIRGezwb+U1XaMkxX6WJQybngbYhdJX0As\n" +
"FR+H1d9Mnv3G4n1ljwBuGqYr7QQh/6tZ7OsMaSdj6hAQe6b2eFeB1qpTORA2smX+\n" + "rElz2CZsh0ZE9bsfAakpMtSrCm7RCucHxDD9R6WDWO2p3ARq8QbmLPk6M0tl9Ibo\n" +
"uQZ6C47kKOVkna/P8ipSgnQZejX5f+O/SsystdCLbtkZCGXOahMhi9mmdbK0jNuy\n" + "4y/nJ84rvNfEkjgVNnWh3JLJ8a9OnaPBm+3j/1fPhzcTAo5VAXzEcUomxoV/JZdU\n" +
"ZhM2sea8NiQONQjSFQm1pC0wpMyvCsZt0Xucxgv9pBvcX/w2BV8DrJ67yD61Lac2\n" + "Dc0uFjqVeG9svMEx0dbn/xYrPm3OygmNjmbwuWkU9wx1aBDB0k5EwZ2pEagus7Wb\n" +
"4x9u7FgBlJRHqBz8pdMo11dwXaBKLL0RHEJR5eZYivX9krRdWH5/8YUwAFnZ09HH\n" + "Qx37MryvLIMZIlOfqCnygwi478FLD2Ml0+1S/3VQR8S4MptlPrlpfNtkFuh5In/l\n" +
"IajVxZMBRSuUcHmFrGFbQcNCEsERx1DnWzb6j2iNo55s6kYWbvuF2vdAdZEJPWWk\n" + "EgN340I8cdQfv4ZFlZ1BcFhz09MYJFo+toQm62umoZFBdH76wy634FGb1JlhJv6v\n" +
"NKRn+OJYQR1t0micL+RRS0rvktc49AOa25xqHIDK9wV6kXlJA36mRa2x9/ijB2c8\n" + "MguyM8QUTYsF9NBLXKqT5GtuiK4paqwwiNz/mu7ulfxAwKh2u5Jiw0xd+QCNNk3d\n" +
"ZSn5vKhWRZOYQAQpB9kG5H2cK4xx48EOCNDnQ74RSVsP/xq8yJx6NOHDFkXhOq4M\n" + "i3Kchx0ZtomjvmHQh57OZRRfO3lNplnujd9/4oloP+N4xGZ9Uknw9KH+Xx0VZy68\n" +
"7daCtrY57GjyUgIEhhGi7DIAjfLqrwdihLWvUip1gS32lc9Qy806r+yQYHFzqImI\n" + "1luyaW2BtEKc3K5vcFBAt8FSSAYp9/bJbqfXNIDLPJogQ8EKsccOfs/IiMDP3Wgt\n" +
"GACoP9i5MfZDq5TUbwx4Z9yDQ0Djraa9GCU+GHmaZc84hiXwh2PsPCswG3mme87G\n" + "T3v1Cr76z+dbBo05fHew3n2Y5STCnxnxxth/jo59bO6IeUhN+kfnnKGA7uxwPppk\n" +
"OydzdjYF/KKO9P33AgMBAAGjPzA9MAwGA1UdEwQFMAMBAf8wLQYDVR0fBCYwJDAi\n" + "/CECAwEAAaNDMEEwDAYDVR0TBAUwAwEB/zAxBgNVHR8EKjAoMCagJKAihiBodHRw\n" +
"oCCgHoYcaHR0cHM6Ly9jYS5zZWNvbmQuY24vY3JsLnBlbTANBgkqhkiG9w0BAQsF\n" + "czovL2NhLnhpZXhpYW5iaW4uY24vY3JsLnBlbTANBgkqhkiG9w0BAQsFAAOCAgEA\n" +
"AAOCAgEASJmN9D3Nf5YHOSa28gZLKhGziwNG9ykRXK59vLNIeYYDuoR51m+zkqtm\n" + "KVB7IIZ2WHSvRLnkMkaDdIu37l60VMhj79MfOTTI/0CcZ0p8G+fqOKGTCtOTFLfz\n" +
"I5SuYDb+IfjicJCyMnrMlP/d/Lv/YUi/rEF/BS0YF2YlnX+5JmG8RG1Sh2OSfp28\n" + "nXCgDOYH9F5tugLLd9B7FiLys5eBdXRym22BHs/jtzUXFrxSFWBhxvW0cwCwy59g\n" +
"rmh5srMg76EuDXIPN1+qHeQqpbNj11DzKL3Z2Tv+ohj2+/WauJt2KTdRWbRU7AT7\n" + "5c/vX3QcvliJfjaLq67CwHIdKlKocogJp1qeROy7HfLQMQJHE/Fc30QZXp5bJcmg\n" +
"xRlgFOofQUFUo78JG+Op1yfQnbDqJNBB04ASwEi4ru9yliBgS6Ves/zn5xAjwe98\n" + "KDYGdvrgKGpzgf4zjOYH+OMhwB2G9Nd6en7TCihq3A8HiGj+M3OzrKgWR4qiHmPg\n" +
"1tGuGFhEYXEKzP3cPGShefdFgyI53YrsVxXy4+x5OdfyRiq9+ao/jAAezZc6fcBe\n" + "3SX7njPLPVerly+o8oh2pSwxSLQMKgPHpbvMHIr5vRIAklGg2TP7WV5+Wc+MC+Ls\n" +
"V6gADyhpt9vSDinTcI3xBRqwLIa+ujTd/HEqSu9Di8xYJ+RbKJ0wFRK1VJqMZXKu\n" + "fZ5M7WSZWD6BV2XIHA2iM3N7wYzvH0lNlgR1Pu8vhflPfSjFouILbEHnsokHPsUd\n" +
"HIo7mgfBUwojxFbIk+FSXWWvWBtaOQxy4BZxv5NjAFlYU2k3p0rJOhQ3CCpTd6Sf\n" + "bxnNmOyMpCDCg3cjuZYIyjAIB/OoADAekAHX3cAitBBzzD9MBK/UXRkMded6JVwf\n" +
"HVd68XS0xK+RLCYxbTK0ejZ8gGN3DHpdtCWRcVXOo47mR3eCgIWAdkWeRO+xs2LV\n" + "bZGq+2LLNzXzqMWQeCcGocRHiV+7uw3klLANfF9NyXvW6FYN50LhnoroGwsuGetY\n" +
"5afFCeGtpITsNUkqh9YVTvMxLEBwSmNH4SHVzJN5Xj6hgfLg2ZhbI7r1DC8CaTr7\n" + "22F/8s1N0oC7Ucn/JmZUA9xjaCDEeoTDoefv8/3zSr2sR6wR7hIHgvC9NNOTzdSS\n" +
"H56qZfZmrvZbBc1q9yIhqJNPwwOZ0N0QJnZObBE1E8PX7if3lPlOoGIlbYcyEyu4\n" + "Rqc3AfUz90kdsAoZowql7CrZy7LiqzaJMy1F+2H8jmzfCV6DBaCYgzlBGS/dq/Q7\n" +
"neNdebXmjLY6R8J9/eLy36xX7vRdjDBT1gva9AIthH0dg0tpPJI=\n" + "A9kbZrfCeb/yEgz0h0LrWnBWww7r2T+Hk4LQ/jLtC1Q=\n" +
"-----END CERTIFICATE-----\n"; "-----END CERTIFICATE-----\n";
var testInvalidCert = var testInvalidCert =
...@@ -374,32 +374,42 @@ var testCrlDer = ...@@ -374,32 +374,42 @@ var testCrlDer =
"1784fecfb85e1130bab8bdfce2d188c21bdf"; "1784fecfb85e1130bab8bdfce2d188c21bdf";
var crlVerifyPriKeyHex = var crlVerifyPriKeyHex =
"00040000800000000300000080000000C3DDD24AEB" + "30820277020100300D06092A864886F70D0101010500048202613082025D020100028" +
"337612204443B8ACDBD52206B004D65777CC1BB3E021C24CD13FA486A89A862957D" + "18100DC4C2D57493D42521A09ED3E902951F77015FE76B0DBDFA12C6C6795DA633D4F" +
"9294120DCFA9B2CE485E9F39962B07AC5768A6D4D6C86086B4C7EA832E3DBE9C14F" + "71488C3EFA2479E9F2F220CBF1596BEDC872666E31D4F3CE0B12C41739B45216D3E3C" +
"95EE2702537D32BB8B3C962FB199EBAF2B467E7981332904240C18A79CF25DA9823" + "0F848B3F640D54723307FA7C55A5ABB5C7BEF69E27435242225457EFCE8C45265A04E" +
"9CFB2094A69EEC1AABF57A4DA4A6A60021300E814B8E101000133EE3C3360E8E405" + "BCFD3FD985148A5A9302246C19BA81BE652ECBBBE9917B7C47C261020301000102818" +
"2A48EF2BA7A92179440CA73BAD353608A2486AAAF973014CBDE736111C250E8EC19" + "05ACF0FF5A61C19658C9440F6842874404234DEC3005E724D96E94CBDC9DB149FD5BB" +
"5D5011CE36A339733DF172B7361A76C4C4E9AD76EA403CCDFB45A8D9AEFB39FA290" + "A90C20C2BE7A8089EC9904F0EE7B83201D37195585F68E3BFB16F3D36FEE731253CA7" +
"25063111E0A569BAF17B15B770361C1B5788E4FDA99E93CF7B8B6D49AA7C2D195E9" + "7D76C29F508A309010B000557AD4DF092B25A8B19098186FE66B9338828F33773095F" +
"73FD0875DF24C56F4E3771BAEEC555B69210A01"; "D7C9C6FA1374FEAE53A97167CE3AE68D35D1B8FD6F0D43C2D1024100F733E56C295A3" +
"058A45265A039C2E8AE5FA32D0C65B17BFD92BF47879740CB54F9BB50277051D0D848" +
"0DC64760F84E0A32766DA4BA40E558F84A394EF83F4E2D024100E4232A5F59CF7C912" +
"40DA24417CD37DE1F534D339F904DD9726425BAAB4791C4999586B58AEA77F764725E" +
"B7BB16A164A4E12D766DEFB15ED617E8AAB6A0D985024100DFC85B284F4715FD28C46" +
"EBB5D8ED495067EF1890786647869203FE0BF4C28C6044D4D82666BAA6420D65768C6" +
"A00205B928FC98E3035C9BEE294337FA0355010240695B7C2410DBEB9133EF3FF2E67" +
"315CBF4F7897DBFC0EAD2F32B20E976545513504267B5CB73C0F77562043021ACAFD8" +
"44F4E104027D61928499021064CB1FE9024100AB4B7D907C57086BC04372098A18353" +
"6649D848DF1849448C6809DB9A2580A4D0ACA1ED605555BFED7AA70ED76B3402EA0B3" +
"3237B0A0B9962DC470E99910678D";
var crlVerifyPubKeyHex = var crlVerifyPubKeyHex =
"00040000800000000300000000000000C3DDD24AEB" + "30819F300D06092A864886F70D010101050003818D0030818902818100DC4C2D57493" +
"337612204443B8ACDBD52206B004D65777CC1BB3E021C24CD13FA486A89A862957D" + "D42521A09ED3E902951F77015FE76B0DBDFA12C6C6795DA633D4F71488C3EFA2479E9" +
"9294120DCFA9B2CE485E9F39962B07AC5768A6D4D6C86086B4C7EA832E3DBE9C14F" + "F2F220CBF1596BEDC872666E31D4F3CE0B12C41739B45216D3E3C0F848B3F640D5472" +
"95EE2702537D32BB8B3C962FB199EBAF2B467E7981332904240C18A79CF25DA9823" + "3307FA7C55A5ABB5C7BEF69E27435242225457EFCE8C45265A04EBCFD3FD985148A5A" +
"9CFB2094A69EEC1AABF57A4DA4A6A60021300E814B8E1010001"; "9302246C19BA81BE652ECBBBE9917B7C47C2610203010001";
var crlHex = var crlHex =
"3081F3305E020103300D06092A864886F70D010104050030153113" + "3081F3305E020103300D06092A864886F70D010104050030153113301106035504031" +
"30110603550403130A43524C20697373756572170D3232303932343232313631365" + "30A43524C20697373756572170D3137303830373131313935355A170D333231323134" +
"A170D3332313231343030353332305A30153013020203E8170D3332313231343030" + "3030353332305A30153013020203E8170D3332313231343030353332305A300D06092" +
"353332305A300D06092A864886F70D01010405000381810071573DC03B03D19D0D2" + "A864886F70D010104050003818100210F1E195A093580E36CA479A3B24744864081C8" +
"CF40D2AB7D3C7D7FA92D8A03DD340EC1090F30C7D273D3C80F2225665CF4C1BDCDF" + "39447781C0C72752DA37088BFA00F123DACC426961B1418998F20F751B3DB98C88F9F" +
"94C1DB9EC6E4D4EC742B48E736F39C7B3229D53CB363854FE78834CC51E45F797A8" + "F39E25B16622B03D8F504A67DC36C4BF3C18790E52A90A0F0E833E61F6596B6DE1A13" +
"61C572D9C6B54F6C2FCD45DF92F5107799E8D33E77FD9FD221F1C66A0CAB68CC9BB" + "2ECBB9DADA17A1B3FBE2C7FFF4AE74D69FFEF219B844E30B068453F3A190298EA079A" +
"05BFE952B17849379205D144BCAF7F613D73"; "BEC1F4437";
export { export {
rootCert, rootCert,
......
# 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("ActsCryptoFrameworkJSNormalTwoTest") {
hap_profile = "./src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCryptoFrameworkJSNormalTwoTest"
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"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "900000",
"shell-timeout": "900000",
"bundle-name": "com.openharmony.cryptoFramework2",
"package-name": "com.openharmony.cryptoFramework2"
},
"kits": [
{
"test-file-name": ["ActsCryptoFrameworkJSNormalTwoTest.hap"],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": ["remount", "mkdir /data/test"]
},
{
"type": "PushKit",
"push": [
"ActsCryptoFrameworkJSNormalTwoTest.hap->/data/test/ActsCryptoFrameworkJSNormalTwoTest.hap"
]
},
{
"type": "ShellKit",
"run-command": ["chmod 644 /data/test/*.hap", "chmod 777 -R data"]
}
]
}
{
"app": {
"bundleName": "com.openharmony.cryptoFramework2",
"vendor": "acts",
"version": {
"code": 12,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.openharmony.cryptoFramework2",
"name": ".entry",
"mainAbility": ".MainAbility",
"deviceType": ["default", "tablet", "tv", "wearable", "phone"],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": ["entity.system.home"],
"actions": ["action.system.home"]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": ["pages/index/index"],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
},
{
"pages": ["pages/index/index"],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"srcPath": ""
}
}
/*
* 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('SecurityApplication onCreate');
},
onDestroy() {
console.info('SecurityApplication onDestroy');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
.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;
}
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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() {
},
}
/*
* 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");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.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
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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');
}
}
/*
* 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);
})
}
};
...@@ -75,6 +75,98 @@ export default function CertificateJsunit() { ...@@ -75,6 +75,98 @@ export default function CertificateJsunit() {
done(); 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")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CertCallback("pem")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509Cert_0400
* @tc.name verify ECC algorithm for X509 certificate
* @tc.desc The X509 certificate FORMAT is FORMAT_DER
*/
it("Security_crypto_framework_X509Cert_0400", 0, async function (done) {
await certPromise
.verifyX509CertPromise("der")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CertCallback("der")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509Cert_0500
* @tc.name verify RSA algorithm for X509 certificate with invalid pubKey
* @tc.desc The X509 certificate FORMAT is FORMAT_PEM
*/
it("Security_crypto_framework_X509Cert_0500", 0, async function (done) {
await certPromise
.verifyX509CertPromise("pem", "NULL")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CertCallback("pem", "000")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509Cert_0600
* @tc.name verify RSA algorithm for X509 certificate with not matched pubKey
* @tc.desc The X509 certificate FORMAT is FORMAT_PEM
*/
it("Security_crypto_framework_X509Cert_0600", 0, async function (done) {
await certPromise
.verifyX509CertPromise("pem", "wrong")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/** /**
* @tc.number Security_crypto_framework_X509Cert_0700 * @tc.number Security_crypto_framework_X509Cert_0700
* @tc.name check getEncoded interface * @tc.name check getEncoded interface
...@@ -128,8 +220,9 @@ export default function CertificateJsunit() { ...@@ -128,8 +220,9 @@ export default function CertificateJsunit() {
/** /**
* @tc.number Security_crypto_framework_X509Cert_0900 * @tc.number Security_crypto_framework_X509Cert_0900
* @tc.name check validity of the date for X509 certificate * @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 The X509 certificate FORMAT is FORMAT_DER,date format:20220922145628+0800(YmdHMSz)
* @tc.desc Use the Promise Style of Interface * @tc.desc Use the Promise Style of Interface;
* @tc.desc period of validity:2022/8/19/12:49:06 - 2032/8/16/12:49:06
*/ */
it("Security_crypto_framework_X509Cert_0900", 0, async function (done) { it("Security_crypto_framework_X509Cert_0900", 0, async function (done) {
await certPromise await certPromise
...@@ -143,6 +236,50 @@ export default function CertificateJsunit() { ...@@ -143,6 +236,50 @@ export default function CertificateJsunit() {
done(); done();
}); });
/**
* @tc.number Security_crypto_framework_X509Cert_1000
* @tc.name check validity of the date for X509 certificate
* @tc.desc The X509 certificate FORMAT is FORMAT_DER,date format:20330830000000+0800(YmdHMSz)
* @tc.desc period of validity:2022/8/19/12:49:06 - 2032/8/16/12:49:06
*/
it("Security_crypto_framework_X509Cert_1000", 0, async function (done) {
await certCallback
.checkValidityX509CertCallback("der", "20330830000000+0800")
.then((data) => {
expect(data == 17630004).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509Cert_1100
* @tc.name check validity of the date for X509 certificate
* @tc.desc The X509 certificate FORMAT is FORMAT_DER,date format: NULL or Exception parameters
* @tc.desc period of validity:2022/8/19/12:49:06 - 2032/8/16/12:49:06
*/
it("Security_crypto_framework_X509Cert_1100", 0, async function (done) {
await certCallback
.checkValidityX509CertCallback("der", "NULL")
.then((data) => {
expect(data == 17630001).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.checkValidityX509CertCallback("der", "string")
.then((data) => {
expect(data == 17630001).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/** /**
* @tc.number Security_crypto_framework_X509Cert_1200 * @tc.number Security_crypto_framework_X509Cert_1200
* @tc.name getVersion for X509 certificate * @tc.name getVersion for X509 certificate
...@@ -412,5 +549,84 @@ export default function CertificateJsunit() { ...@@ -412,5 +549,84 @@ export default function CertificateJsunit() {
}); });
done(); 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")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.checkValidateOfCertChainValidatorCallback("PKIX")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_CertChainValidator_0200
* @tc.name check validate interface for CertChainValidator with invalid param
* @tc.desc The X509 certificate FORMAT is FORMAT_PEM
*/
it(
"Security_crypto_framework_CertChainValidator_0200",
0,
async function (done) {
await certPromise
.checkValidateOfCertChainValidatorPromise("PKI111")
.then((data) => {
expect(data == 801).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_CertChainValidator_0300
* @tc.name check validate interface for CertChainValidator with invalid Certs
* @tc.desc The X509 certificate FORMAT is FORMAT_PEM
*/
it(
"Security_crypto_framework_CertChainValidator_0300",
0,
async function (done) {
await certPromise
.checkValidateOfCertChainValidatorPromise("PKIX", "error")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.checkValidateOfCertChainValidatorCallback("PKIX", "error")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
}
);
}); });
} }
...@@ -77,7 +77,7 @@ export default function CertificateCrlJsunit() { ...@@ -77,7 +77,7 @@ export default function CertificateCrlJsunit() {
/** /**
* @tc.number Security_crypto_framework_X509CRL_0300 * @tc.number Security_crypto_framework_X509CRL_0300
* @tc.name Check isRevoked for X509 Crl * @tc.name Check isRevoked success for X509 Crl
* @tc.desc The X509 Crl FORMAT is FORMAT_PEM * @tc.desc The X509 Crl FORMAT is FORMAT_PEM
*/ */
it("Security_crypto_framework_X509CRL_0300", 0, async function (done) { it("Security_crypto_framework_X509CRL_0300", 0, async function (done) {
...@@ -114,6 +114,60 @@ export default function CertificateCrlJsunit() { ...@@ -114,6 +114,60 @@ export default function CertificateCrlJsunit() {
done(); done();
}); });
/**
* @tc.number Security_crypto_framework_X509CRL_0400
* @tc.name Check isRevoked failed for X509 Crl
* @tc.desc The X509 Crl FORMAT is FORMAT_PEM
*/
it("Security_crypto_framework_X509CRL_0400", 0, async function (done) {
await certPromise
.createX509CrlInstancePromise("pem")
.then((crlInstance) => {
return certPromise.checkIsRevokedX509CrlPromise(crlInstance, "error");
})
.then((result) => {
expect(result == false).assertTrue();
})
.catch((err) => {
console.error("[promise] isRevoked failed! error is: " + err);
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509CRL_0500
* @tc.name Check isRevoked failed with invalid param for X509 Crl
* @tc.desc The X509 Crl FORMAT is FORMAT_PEM
*/
it("Security_crypto_framework_X509CRL_0500", 0, async function (done) {
await certPromise
.createX509CrlInstancePromise("pem")
.then((crlInstance) => {
return certPromise.checkIsRevokedX509CrlPromise(crlInstance, "NULL");
})
.then((result) => {
expect(result == 401).assertTrue();
})
.catch((err) => {
console.error("[promise] isRevoked failed! error is: " + err);
expect(null).assertFail();
});
await certPromise
.createX509CrlInstancePromise("pem")
.then((crlInstance) => {
return certPromise.checkIsRevokedX509CrlPromise(crlInstance, "000");
})
.then((result) => {
expect(result == 401).assertTrue();
})
.catch((err) => {
console.error("[promise] isRevoked failed! error is: " + err);
expect(null).assertFail();
});
done();
});
/** /**
* @tc.number Security_crypto_framework_X509CRL_0600 * @tc.number Security_crypto_framework_X509CRL_0600
* @tc.name Check getEncoded for X509 Crl * @tc.name Check getEncoded for X509 Crl
...@@ -516,5 +570,109 @@ export default function CertificateCrlJsunit() { ...@@ -516,5 +570,109 @@ export default function CertificateCrlJsunit() {
}); });
done(); 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("pem")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CrlCallback("pem")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509CRL_0900
* @tc.name Check verify for X509 Crl
* @tc.desc The X509 Crl FORMAT is FORMAT_DER
*/
it("Security_crypto_framework_X509CRL_0900", 0, async function (done) {
await certPromise
.verifyX509CrlPromise("der")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CrlCallback("der")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509CRL_1000
* @tc.name Check verify for X509 Crl with invalid PublicKey
* @tc.desc The X509 Crl FORMAT is FORMAT_PEM
*/
it("Security_crypto_framework_X509CRL_1000", 0, async function (done) {
await certPromise
.verifyX509CrlPromise("der", "NULL")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CrlCallback("der", "000")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_X509CRL_1100
* @tc.name Check verify for X509 Crl with wrong PublicKey and right PublicKey
* @tc.desc The X509 Crl FORMAT is FORMAT_PEM
*/
it("Security_crypto_framework_X509CRL_1100", 0, async function (done) {
await certPromise
.verifyX509CrlPromise("pem", "error")
.then((data) => {
expect(data == 401).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await certCallback
.verifyX509CrlCallback("pem")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
}); });
} }
/*
* 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";
import CertificateJsunit from "./Certificate.test";
import CertificateCrlJsunit from "./CertificateCrl.test";
export default function testsuite() {
SecurityRandomJsunit();
CertificateJsunit();
CertificateCrlJsunit();
}
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { expect } from "@ohos/hypium"; import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework"; import cryptoFramework from "@ohos.security.cryptoFramework";
import { import {
stringTouInt8Array, stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString, uInt8ArrayToString,
} from "../common/publicDoString"; } from "../common/publicDoString";
import { import {
...@@ -24,8 +24,6 @@ import { ...@@ -24,8 +24,6 @@ import {
chainSecondCaCert, chainSecondCaCert,
selfSignedCaCertPem, selfSignedCaCertPem,
selfSignedCaCertDer, selfSignedCaCertDer,
rootCert,
testInvalidCert,
testErrorCert, testErrorCert,
testCert, testCert,
testCrlPem, testCrlPem,
...@@ -76,13 +74,16 @@ function createX509CertInstanceCallback(certType) { ...@@ -76,13 +74,16 @@ function createX509CertInstanceCallback(certType) {
function createX509CertInstanceforCrlTestCallback(flag) { function createX509CertInstanceforCrlTestCallback(flag) {
var certformat; var certformat;
var encodingData; var encodingData;
var invalidParams = false;
if (flag == "normal") { if (flag == "normal") {
certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; certformat = cryptoFramework.EncodingFormat.FORMAT_PEM;
encodingData = stringTouInt8Array(testCert); encodingData = stringTouInt8Array(testCert);
} else { } else if (flag == "error") {
certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; certformat = cryptoFramework.EncodingFormat.FORMAT_PEM;
encodingData = stringTouInt8Array(testErrorCert); encodingData = stringTouInt8Array(testErrorCert);
} else {
invalidParams = true;
} }
var encodingBlob = { var encodingBlob = {
...@@ -101,7 +102,11 @@ function createX509CertInstanceforCrlTestCallback(flag) { ...@@ -101,7 +102,11 @@ function createX509CertInstanceforCrlTestCallback(flag) {
console.warn( console.warn(
"[callback] create X509 Cert success! format is: " + certformat "[callback] create X509 Cert success! format is: " + certformat
); );
resolve(data); if (invalidParams == true) {
resolve(flag);
} else {
resolve(data);
}
} }
}); });
}); });
...@@ -137,7 +142,7 @@ async function verifyX509Cert(certInstance, pubKey) { ...@@ -137,7 +142,7 @@ async function verifyX509Cert(certInstance, pubKey) {
}); });
} }
async function verifyX509CertCallback(certType) { async function verifyX509CertCallback(certType, flag) {
var gInstance; var gInstance;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
createX509CertInstanceCallback(certType) createX509CertInstanceCallback(certType)
...@@ -147,6 +152,13 @@ async function verifyX509CertCallback(certType) { ...@@ -147,6 +152,13 @@ async function verifyX509CertCallback(certType) {
}) })
.then((pubKey) => { .then((pubKey) => {
expect(pubKey != null).assertTrue(); expect(pubKey != null).assertTrue();
if (flag != undefined) {
if (flag == "wrong") {
pubKey = crlVerifyPubKeyHex;
} else {
pubKey = flag;
}
}
return verifyX509Cert(gInstance, pubKey); return verifyX509Cert(gInstance, pubKey);
}) })
.then((output) => { .then((output) => {
...@@ -156,59 +168,54 @@ async function verifyX509CertCallback(certType) { ...@@ -156,59 +168,54 @@ async function verifyX509CertCallback(certType) {
console.error( console.error(
"[callback] verifyX509CertCallback failed! error is: " + err "[callback] verifyX509CertCallback failed! error is: " + err
); );
reject(err); if (flag != undefined) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
async function checkValidityX509CertCallback(certType, date) { async function checkValidityWithDate(certInstance, 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) => { return new Promise((resolve, reject) => {
cryptoFramework.createX509Cert(encodingBlob, (err, instance) => { certInstance.checkValidityWithDate(date, (err) => {
if (instance == null) { if (err) {
console.error( console.error(
"[callback] create X509 Cert failed! err code: " + err.code "[Callback]checkValidityWithDate failed. error is " + err
); );
reject(instance); reject(err);
} else { } else {
console.warn( console.log("[Callback]checkValidityWithDate success!");
"[callback] create X509 Cert success! format is: " + certformat resolve();
);
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 checkValidityX509CertCallback(certType, date) {
return new Promise((resolve, reject) => {
createX509CertInstanceCallback(certType)
.then((instance) => {
return checkValidityWithDate(instance, date);
})
.then((result) => {
console.warn("[callback] checkValidityX509Cert success!");
resolve(result);
})
.catch((err) => {
console.error(
"[callback] checkValidityX509Cert failed! error is: " + err.code
);
if (String(err).indexOf("check cert validity failed") != -1) {
resolve(err.code);
} else {
reject(err);
}
});
});
}
async function getX509CertInfoCallback(certType, processType) { async function getX509CertInfoCallback(certType, processType) {
var gInstance; var gInstance;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -426,8 +433,12 @@ function checkIsRevokedX509CrlCallback(crlInstance, flag) { ...@@ -426,8 +433,12 @@ function checkIsRevokedX509CrlCallback(crlInstance, flag) {
}); });
}) })
.catch((err) => { .catch((err) => {
console.error("[callback] isRevoked failed!"); console.error("[callback] isRevoked failed! err is: " + err);
reject(err); if (String(err).indexOf("get array data failed") != -1) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
...@@ -493,39 +504,41 @@ async function verifyX509Crl(crlInstance, pubKey) { ...@@ -493,39 +504,41 @@ async function verifyX509Crl(crlInstance, pubKey) {
}); });
} }
function verifyX509CrlCallback() { function verifyX509CrlCallback(crlType, flag) {
var certformat; var certformat;
var priKeyEncodingData; var priKeyEncodingData;
var pubKeyEncodingData; var pubKeyEncodingData;
var crlEncodingData; var crlEncodingData;
var globalCrlInstance; var globalCrlInstance;
certformat = cryptoFramework.EncodingFormat.FORMAT_DER; if (crlType == "pem" || crlType == "der") {
priKeyEncodingData = new Uint8Array( certformat = cryptoFramework.EncodingFormat.FORMAT_DER;
crlVerifyPriKeyHex.match(/[\da-f]{2}/gi).map(function (h) { priKeyEncodingData = new Uint8Array(
return parseInt(h, 16); 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) { pubKeyEncodingData = new Uint8Array(
return parseInt(h, 16); 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) { crlEncodingData = new Uint8Array(
return parseInt(h, 16); crlHex.match(/[\da-f]{2}/gi).map(function (h) {
}) return parseInt(h, 16);
); })
var priEncodingBlob = { );
data: priKeyEncodingData, var priEncodingBlob = {
}; data: priKeyEncodingData,
var pubEncodingBlob = { };
data: pubKeyEncodingData, var pubEncodingBlob = {
}; data: pubKeyEncodingData,
var crlEncodingBlob = { };
data: crlEncodingData, var crlEncodingBlob = {
encodingFormat: certformat, data: crlEncodingData,
}; encodingFormat: certformat,
};
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var asyKeyGenerator = var asyKeyGenerator =
...@@ -541,6 +554,13 @@ function verifyX509CrlCallback() { ...@@ -541,6 +554,13 @@ function verifyX509CrlCallback() {
.then((convertKeyPair) => { .then((convertKeyPair) => {
expect(convertKeyPair != null).assertTrue(); expect(convertKeyPair != null).assertTrue();
let pubKey = convertKeyPair.pubKey; let pubKey = convertKeyPair.pubKey;
if (flag != undefined) {
if (flag != "error") {
pubKey = flag;
} else {
pubKey = convertKeyPair.PriKey;
}
}
return verifyX509Crl(globalCrlInstance, pubKey); return verifyX509Crl(globalCrlInstance, pubKey);
}) })
.then((result) => { .then((result) => {
...@@ -550,7 +570,11 @@ function verifyX509CrlCallback() { ...@@ -550,7 +570,11 @@ function verifyX509CrlCallback() {
console.error( console.error(
"[Callback]verifyX509CrlCallback failed. error is " + err "[Callback]verifyX509CrlCallback failed. error is " + err
); );
reject(err); if (flag != undefined) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
...@@ -754,21 +778,35 @@ async function checkGetRevokedCertX509CrlCallback(certType) { ...@@ -754,21 +778,35 @@ async function checkGetRevokedCertX509CrlCallback(certType) {
}); });
} }
function checkValidateOfCertChainValidatorCallback(algName) { function checkValidateOfCertChainValidatorCallback(algName, flag) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var validator = cryptoFramework.createCertChainValidator(algName); try {
expect(validator != null).assertTrue(); var validator = cryptoFramework.createCertChainValidator(algName);
var algorithm = validator.algorithm; var algorithm = validator.algorithm;
console.log("createCertChainValidator success! algorithm is: " + algorithm); console.log(
"createCertChainValidator success! algorithm is: " + algorithm
);
} catch (err) {
console.error("createCertChainValidator error is: " + err);
if (String(err).indexOf("create cert chain validator failed") != -1) {
resolve(err.code);
} else {
reject(err);
}
return;
}
var certArray1 = stringTouInt8Array(chainFirstCaCert); var certArray1 = stringTouInt8Array(chainFirstCaCert);
var byteLength1 = certArray1.byteLength; var byteLength1 = certArray1.byteLength;
var uInt16CertLength1 = new Uint16Array([byteLength1]); var uInt16CertLength1 = new Uint16Array([byteLength1]);
var uInt8CertLength1 = new Uint8Array([uInt16CertLength1.buffer]); if (flag == "error") {
var uInt8CertLength1 = new Uint8Array([uInt16CertLength1.buffer]);
} else {
var uInt8CertLength1 = new Uint8Array(uInt16CertLength1.buffer);
}
var certArray2 = stringTouInt8Array(chainSecondCaCert); var certArray2 = stringTouInt8Array(chainSecondCaCert);
var byteLength2 = certArray2.byteLength; var byteLength2 = certArray2.byteLength;
var uInt16CertLength2 = new Uint16Array([byteLength2]); var uInt16CertLength2 = new Uint16Array([byteLength2]);
var uInt8CertLength2 = new Uint8Array([uInt16CertLength2.buffer]); var uInt8CertLength2 = new Uint8Array(uInt16CertLength2.buffer);
var dataArray = new Uint8Array( var dataArray = new Uint8Array(
uInt8CertLength2.length + uInt8CertLength2.length +
...@@ -799,10 +837,15 @@ function checkValidateOfCertChainValidatorCallback(algName) { ...@@ -799,10 +837,15 @@ function checkValidateOfCertChainValidatorCallback(algName) {
count: 2, count: 2,
encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM, encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM,
}; };
console.log("certChainData.data is: " + certChainData.data);
validator.validate(certChainData, (err) => { validator.validate(certChainData, (err) => {
if (err) { if (err) {
console.error("[callback]: validate error: " + err); console.error("[callback]: validate error: " + err);
reject(err); if (flag == "error") {
resolve(err.code);
} else {
reject(err);
}
} else { } else {
console.warn("[callback]: validate success!"); console.warn("[callback]: validate success!");
resolve(); resolve();
......
...@@ -17,7 +17,6 @@ import { expect } from "@ohos/hypium"; ...@@ -17,7 +17,6 @@ import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework"; import cryptoFramework from "@ohos.security.cryptoFramework";
import { import {
stringTouInt8Array, stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString, uInt8ArrayToString,
} from "../common/publicDoString"; } from "../common/publicDoString";
import { import {
...@@ -25,8 +24,6 @@ import { ...@@ -25,8 +24,6 @@ import {
chainSecondCaCert, chainSecondCaCert,
selfSignedCaCertPem, selfSignedCaCertPem,
selfSignedCaCertDer, selfSignedCaCertDer,
rootCert,
testInvalidCert,
testErrorCert, testErrorCert,
testCert, testCert,
testCrlPem, testCrlPem,
...@@ -78,13 +75,16 @@ function createX509CertInstancePromise(certType) { ...@@ -78,13 +75,16 @@ function createX509CertInstancePromise(certType) {
function createX509CertInstanceforCrlTestPromise(flag) { function createX509CertInstanceforCrlTestPromise(flag) {
var certformat; var certformat;
var encodingData; var encodingData;
var invalidParams = false;
if (flag == "normal") { if (flag == "normal") {
certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; certformat = cryptoFramework.EncodingFormat.FORMAT_PEM;
encodingData = stringTouInt8Array(testCert); encodingData = stringTouInt8Array(testCert);
} else { } else if (flag == "error") {
certformat = cryptoFramework.EncodingFormat.FORMAT_PEM; certformat = cryptoFramework.EncodingFormat.FORMAT_PEM;
encodingData = stringTouInt8Array(testErrorCert); encodingData = stringTouInt8Array(testErrorCert);
} else {
invalidParams = true;
} }
var encodingBlob = { var encodingBlob = {
...@@ -99,7 +99,11 @@ function createX509CertInstanceforCrlTestPromise(flag) { ...@@ -99,7 +99,11 @@ function createX509CertInstanceforCrlTestPromise(flag) {
console.warn( console.warn(
"[promise] create X509 Cert success! format is: " + certformat "[promise] create X509 Cert success! format is: " + certformat
); );
resolve(data); if (invalidParams == true) {
resolve(flag);
} else {
resolve(data);
}
}) })
.catch((err) => { .catch((err) => {
console.error( console.error(
...@@ -110,7 +114,7 @@ function createX509CertInstanceforCrlTestPromise(flag) { ...@@ -110,7 +114,7 @@ function createX509CertInstanceforCrlTestPromise(flag) {
}); });
} }
async function verifyX509CertPromise(certType) { async function verifyX509CertPromise(certType, flag) {
var gInstance; var gInstance;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
createX509CertInstancePromise(certType) createX509CertInstancePromise(certType)
...@@ -120,7 +124,14 @@ async function verifyX509CertPromise(certType) { ...@@ -120,7 +124,14 @@ async function verifyX509CertPromise(certType) {
}) })
.then((publicKey) => { .then((publicKey) => {
expect(publicKey != null).assertTrue(); expect(publicKey != null).assertTrue();
console.warn("[promise] getPublickey success!"); console.log("[promise] getPublickey success!");
if (flag != undefined) {
if (flag == "wrong") {
publicKey = crlVerifyPubKeyHex;
} else {
publicKey = flag;
}
}
return gInstance.verify(publicKey); return gInstance.verify(publicKey);
}) })
.then((verifyret) => { .then((verifyret) => {
...@@ -128,7 +139,11 @@ async function verifyX509CertPromise(certType) { ...@@ -128,7 +139,11 @@ async function verifyX509CertPromise(certType) {
}) })
.catch((err) => { .catch((err) => {
console.error("[promise] getPublickey failed! error is: " + err); console.error("[promise] getPublickey failed! error is: " + err);
reject(err); if (flag != undefined) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
...@@ -143,14 +158,17 @@ async function checkValidityX509CertPromise(certType, date) { ...@@ -143,14 +158,17 @@ async function checkValidityX509CertPromise(certType, date) {
}) })
.then((result) => { .then((result) => {
console.warn("[promise] checkValidityX509Cert success!"); console.warn("[promise] checkValidityX509Cert success!");
expect(result == null).assertTrue(); resolve(result);
resolve();
}) })
.catch((err) => { .catch((err) => {
console.error( console.error(
"[promise] checkValidityX509Cert failed! error is: " + err "[promise] checkValidityX509Cert failed! error is: " + err
); );
reject(err); if (String(err).indexOf("check cert validity failed") != -1) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
...@@ -356,8 +374,12 @@ function checkIsRevokedX509CrlPromise(crlInstance, flag) { ...@@ -356,8 +374,12 @@ function checkIsRevokedX509CrlPromise(crlInstance, flag) {
resolve(status); resolve(status);
}) })
.catch((err) => { .catch((err) => {
console.error("[promise] isRevoked failed!"); console.error("[promise] isRevoked failed! err is: " + err);
reject(err); if (String(err).indexOf("get array data failed") != -1) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
...@@ -384,40 +406,41 @@ async function checkGetEncodedX509CrlPromise(certType) { ...@@ -384,40 +406,41 @@ async function checkGetEncodedX509CrlPromise(certType) {
}); });
} }
function verifyX509CrlPromise() { function verifyX509CrlPromise(crlType, flag) {
var certFormat; var certFormat;
var priKeyEncodingData; var priKeyEncodingData;
var pubKeyEncodingData; var pubKeyEncodingData;
var crlEncodingData; var crlEncodingData;
var globalCrlInstance; var globalCrlInstance;
if (crlType == "pem" || crlType == "der") {
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);
})
);
certFormat = cryptoFramework.EncodingFormat.FORMAT_DER; var priEncodingBlob = {
priKeyEncodingData = new Uint8Array( data: priKeyEncodingData,
crlVerifyPriKeyHex.match(/[\da-f]{2}/gi).map(function (h) { };
return parseInt(h, 16); var pubEncodingBlob = {
}) data: pubKeyEncodingData,
); };
pubKeyEncodingData = new Uint8Array( var crlEncodingBlob = {
crlVerifyPubKeyHex.match(/[\da-f]{2}/gi).map(function (h) { data: crlEncodingData,
return parseInt(h, 16); encodingFormat: certFormat,
}) };
); }
crlEncodingData = new Uint8Array(
crlHex.match(/[\da-f]{2}/gi).map(function (h) {
return parseInt(h, 16);
})
);
var priEncodingBlob = {
data: priKeyEncodingData,
};
var pubEncodingBlob = {
data: pubKeyEncodingData,
};
var crlEncodingBlob = {
data: crlEncodingData,
encodingFormat: certFormat,
};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var asyKeyGenerator = var asyKeyGenerator =
...@@ -433,14 +456,27 @@ function verifyX509CrlPromise() { ...@@ -433,14 +456,27 @@ function verifyX509CrlPromise() {
.then((convertKeyPair) => { .then((convertKeyPair) => {
expect(convertKeyPair != null).assertTrue(); expect(convertKeyPair != null).assertTrue();
let pubKey = convertKeyPair.pubKey; let pubKey = convertKeyPair.pubKey;
if (flag != undefined) {
if (flag != "error") {
pubKey = flag;
} else {
pubKey = convertKeyPair.priKey;
}
}
return globalCrlInstance.verify(pubKey); return globalCrlInstance.verify(pubKey);
}) })
.then((result) => { .then((result) => {
resolve(result); resolve(result);
}) })
.catch((err) => { .catch((err) => {
console.error("[Promise]verifyX509CrlPromise failed. error is " + err); console.error(
reject(err); "[Promise]verifyX509CrlPromise failed. error is " + err.code
);
if (flag != undefined) {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
...@@ -653,22 +689,35 @@ async function checkGetRevokedCertX509CrlPromise(certType) { ...@@ -653,22 +689,35 @@ async function checkGetRevokedCertX509CrlPromise(certType) {
}); });
} }
function checkValidateOfCertChainValidatorPromise(algName) { function checkValidateOfCertChainValidatorPromise(algName, flag) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var validator = cryptoFramework.createCertChainValidator(algName); try {
expect(validator != null).assertTrue(); var validator = cryptoFramework.createCertChainValidator(algName);
var algorithm = validator.algorithm; var algorithm = validator.algorithm;
console.log("createCertChainValidator success! algorithm is: " + algorithm); console.log(
"createCertChainValidator success! algorithm is: " + algorithm
);
} catch (err) {
console.error("createCertChainValidator error is: " + err);
if (String(err).indexOf("create cert chain validator failed") != -1) {
resolve(err.code);
} else {
reject(err);
}
return;
}
var certArray1 = stringTouInt8Array(chainFirstCaCert); var certArray1 = stringTouInt8Array(chainFirstCaCert);
var byteLength1 = certArray1.byteLength; var byteLength1 = certArray1.byteLength;
var uInt16CertLength1 = new Uint16Array([byteLength1]); var uInt16CertLength1 = new Uint16Array([byteLength1]);
var uInt8CertLength1 = new Uint8Array([uInt16CertLength1.buffer]); if (flag == "error") {
var uInt8CertLength1 = new Uint8Array([uInt16CertLength1.buffer]);
} else {
var uInt8CertLength1 = new Uint8Array(uInt16CertLength1.buffer);
}
var certArray2 = stringTouInt8Array(chainSecondCaCert); var certArray2 = stringTouInt8Array(chainSecondCaCert);
var byteLength2 = certArray2.byteLength; var byteLength2 = certArray2.byteLength;
var uInt16CertLength2 = new Uint16Array([byteLength2]); var uInt16CertLength2 = new Uint16Array([byteLength2]);
var uInt8CertLength2 = new Uint8Array([uInt16CertLength2.buffer]); var uInt8CertLength2 = new Uint8Array(uInt16CertLength2.buffer);
var dataArray = new Uint8Array( var dataArray = new Uint8Array(
uInt8CertLength2.length + uInt8CertLength2.length +
...@@ -699,15 +748,20 @@ function checkValidateOfCertChainValidatorPromise(algName) { ...@@ -699,15 +748,20 @@ function checkValidateOfCertChainValidatorPromise(algName) {
count: 2, count: 2,
encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM, encodingFormat: cryptoFramework.EncodingFormat.FORMAT_PEM,
}; };
console.log("certChainData.data is: " + certChainData.data);
validator validator
.validate(certChainData) .validate(certChainData)
.then(() => { .then((data) => {
console.warn("[promise]: validate success!"); console.warn("[promise]: validate success!");
resolve(); resolve(data);
}) })
.catch((err) => { .catch((err) => {
console.error("[promise]: validate error: " + err); console.error("[promise]: validate error: " + err);
reject(err); if (flag == "error") {
resolve(err.code);
} else {
reject(err);
}
}); });
}); });
} }
......
/*
* 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,
};
{
"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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册