未验证 提交 607f9ebf 编写于 作者: O openharmony_ci 提交者: Gitee

!3388 release测试套名称修改,和更新basic代码

Merge pull request !3388 from 胡吉翔/security_20220531_3
......@@ -18,6 +18,7 @@ group("security") {
if (is_standard_system) {
deps = [
"access_token/AccessTokenTest_Normal_js:ActsAccessTokenJSApiTestNormal",
"cipher/datacipher:datacipher",
"huks_standard",
"security_huks_basic",
]
......
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (C) 2021 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
......@@ -10,22 +10,11 @@
# 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("ActsHuksJSTimingTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsHuksJSTimingTest"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/js/default"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/js/resources" ]
hap_profile = "./entry/src/main/config.json"
group("datacipher") {
testonly = true
if (is_standard_system) {
deps = [ "cipher:ActsSecurityCipherTest" ]
}
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (C) 2021 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
......@@ -10,22 +10,21 @@
# 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("ActsHuksStressTest") {
ohos_js_hap_suite("ActsSecurityCipherTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
":huks_js_assets",
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsHuksStressTest"
hap_name = "ActsSecurityCipherTest"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/js/default"
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
}
ohos_resources("hjs_demo_resources") {
ohos_resources("huks_js_resources") {
sources = [ "./entry/src/main/js/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for keystoretest js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "com.huawei.keystoretest",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsSecurityCipherTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.example.huksjstiming",
"vendor": "example",
"bundleName": "com.huawei.keystoretest",
"vendor": "huawei",
"version": {
"code": 1,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"compatible": 6,
"target": 6,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.huksjstiming",
"package": "com.huawei.keystoretest",
"name": ".MyApplication",
"mainAbility": "com.example.huksjstiming.MainAbility",
"mainAbility": "com.huawei.keystoretest.MainAbility",
"deviceType": [
"phone"
],
......@@ -38,12 +38,12 @@
]
}
],
"name": "com.example.huksjstiming.MainAbility",
"name": "com.huawei.keystoretest.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "singleton",
"launchType": "standard",
"visible": true,
"isVisible": "true"
}
......
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021 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
......@@ -19,5 +19,5 @@ export default {
},
onDestroy() {
console.info('AceApplication onDestroy');
}
},
};
......@@ -2,6 +2,8 @@
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
.title {
......@@ -19,13 +21,13 @@
@media screen and (device-type: wearable) {
.title {
font-size: 28px;
color: #FFFFFF;
color: #ffffff;
}
}
@media screen and (device-type: tv) {
.container {
background-image: url("../../common/images/Wallpaper.png");
background-image: url('/common/images/Wallpaper.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
......@@ -33,7 +35,7 @@
.title {
font-size: 100px;
color: #FFFFFF;
color: #ffffff;
}
}
......
<div class="container">
<text class="title">
<text class="title" >
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021 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
......@@ -13,12 +13,11 @@
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index';
import { Core, ExpectExtend } from 'deccjsunit/index';
export default {
data: {
title: ""
title: '',
},
onInit() {
this.title = this.$t('strings.world');
......@@ -26,16 +25,16 @@ export default {
onShow() {
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
id: 'extend',
});
const reportExtend = new ReportExtend(file);
core.addService('expect', expectExtend);
core.addService('report', reportExtend);
core.init();
const configService = core.getDefaultService('config');
this.timeout = 3000000;
this.timeout = 1500000;
configService.setConfig(this);
require('../../../test/hks_xts_concurrency.test.js');
console.log('test start');
require('../../../test/List.test');
core.execute();
}
}
},
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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import cipher from '@system.cipher';
describe('cipher1.test.js', function () {
let plainTextRsa;
let cipherTextRsa;
let rsaPublicKey;
let rsaPrivateKey;
let plainTextAes;
let cipherTextAes;
let aesKey;
let cipherResult;
let cipherResultFail;
beforeAll(function () {
plainTextRsa = 'Hello,World! 123 rsa key2###';
cipherTextRsa = 'EGyJbxPvBjX4m+hxfbFxojT9KjjLII7Sz8NmjWiy/K+F4WvlGhSOQS9RME2hu208EjvaLvKTgv7Ijo2\n' +
'dGKO0OD4UlEI3LiNFT+cFhfXIVYs16vKQhWtkJEfkJIPjmO5NekxpelYcqmdxUqq5T/7+uq4vRbVyK1/4P57VWLyMTM=';
rsaPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCU9YGbkTHKMi6iFFiPC8fYQkrt\n' +
'jG9Y3gwmQkhDD31MtqvaMZyIus2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4\n' +
'SoaaUsh/hb7HyUFEWWcGHQEFXNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7\n' +
'ahs3QFPDo5+CSwxIoQIDAQAB';
rsaPrivateKey = 'MIICXQIBAAKBgQCU9YGbkTHKMi6iFFiPC8fYQkrtjG9Y3gwmQkhQQ31MtqvaMZyI\n' +
'us2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4SoaaUsh/hb7HyUFEWWcGHQEF\n' +
'XNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7ahs3QFPDo5+CSwxIoQIDAQAB\n' +
'AoGAAPIIfDotgfIbExLfsG3G5fEe9ZbM7kVH25JOuF3ycUIrQnk81RJTDJbxItJw\n' +
'JbKKzZTWTVNylvw7JzkHdLZvrNzsI8c/0abMrl64ZUugtumhkmrn6xW6H6z4GQnR\n' +
'havHgRlFL2giWX99J/bMRntMzGCXH8elwIwuPZrYCcdQ5PECQQDw+qsWqTGJyGXr\n' +
'SGyR5Djn+ZAuqFQvfH6vj6b2ridSbZ0RKgRGTXgH4JsaNnqnVpGilWjUHVbSRvPD\n' +
'lZu28qpNAkEAnj52PkGPG9tvG4eaC4Y+LNDKOcU4Ybn07Jz+mZwOGkxb8sgw/kw6\n' +
'H8xPV/7F7GWLjopUsaHnWuWIegzxQY8ZpQJBAKdmGm+VfRovoc099F2sYnOTA7vF\n' +
'pvWNoBuo+N0nwZ0bFB8WRv3nVthyCIy/B5kzI9wvz7B56RQNwcxqmM8P54kCQAbY\n' +
'Zt8MkPdAh87mD8jdlsSzh3v2RxkbJTgzFmRotsd2dCfNdykYtRN5EBmbYM54GhBh\n' +
'dYZlnX92HHBDLRCL8y0CQQDuKZNoBooqVUwcrCFqpeAX/bGYiVmFxcIqyu5vYzVJ\n' +
'Ff5Fpkxm4FLmrjhiGwL1CKIm5RRL9kT6tsv4do6ALylb';
plainTextAes = '%%%%Hello,World! 123 aes key2###(^^^)';
cipherTextAes = 'IclkeCOt6pPODqNyprSZizYdJLBFLwXsEFJo34IJwZp7JmfQJXDbqGpexINBMke4';
aesKey = 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjMONTY3ODkwMzI=';
cipherResult = true;
cipherResultFail = false;
});
beforeEach(function () {});
afterEach(function () {});
/**
* @tc.number SUB_SEC_DataPro_cipher_1300
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1300', 2, function () {
cipher.aes({
action: 'encrypt123',
text: plainTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data, code) => {
this.err = `${code}: ${data}`;
console.log(`action is invalid, cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1400
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1400', 2, function () {
cipher.aes({
action: 'encrypt',
text: plainTextAes,
key: '439B96R030A475BF9E2D0BEF8W56C5BD',
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`action is invalid, cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1500
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1500', 2, function () {
cipher.aes({
action: 'encrypt',
text: '~!@#$%^&*()_+<>?:"~,./183456789012345678901234567890123456789',
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResult).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1600
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1600', 2, function () {
cipher.aes({
action: 'encrypt',
text: plainTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 15,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`action is invalid, cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
cipher.aes({
action: 'encrypt',
text: plainTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data, code) => {
this.err = `${code}: ${data}`;
console.log(`iv is invalid, cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1700
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1700', 2, function () {
cipher.aes({
action: 'encrypt',
text: plainTextAes,
key: aesKey,
transformation: 'AES',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`transformation is invalid, cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1800
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1800', 2, function () {
cipher.aes({
action: 'decrypt123',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`ation is invalid, cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1900
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1900', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: '439B96R030A475BF9E2D0BEF8W56C5BD',
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`key is invalid, cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2000
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2000', 3, function () {
cipher.aes({
action: 'decrypt',
text: '~!@#$%^&*()_+<>?:"~,./183456789012345678901234567890123456789',
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2100
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2100', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResult).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Njc4',
ivOffset: 2,
ivLen: 18,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`ivlen is invalid,cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2200
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2200', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
ivOffset: -1,
ivLen: 16,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResult).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`ivOffset is invalid, cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Njc4',
ivOffset: 2,
ivLen: 16,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2300
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2300', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`transformation is invalid, cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
});
\ No newline at end of file
/*
* 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, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import cipher from '@system.cipher';
describe('cipher2.test.js', function () {
let plainTextRsa;
let cipherTextRsa;
let rsaPublicKey;
let rsaPrivateKey;
let plainTextAes;
let cipherTextAes;
let aesKey;
let cipherResult;
let cipherResultFail;
beforeAll(function () {
plainTextRsa = 'Hello,World! 123 rsa key2###';
cipherTextRsa = 'EGyJbxPvBjX4m+hxfbFxojT9KjjLII7Sz8NmjWiy/K+F4WvlGhSOQS9RME2hu208EjvaLvKTgv7Ijo2\n'+
'dGKO0OD4UlEI3LiNFT+cFhfXIVYs16vKQhWtkJEfkJIPjmO5NekxpelYcqmdxUqq5T/7+uq4vRbVyK1/4P57VWLyMTM=';
rsaPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCU9YGbkTHKMi6iFFiPC8fYQkrt\n' +
'jG9Y3gwmQkhDD31MtqvaMZyIus2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4\n' +
'SoaaUsh/hb7HyUFEWWcGHQEFXNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7\n' +
'ahs3QFPDo5+CSwxIoQIDAQAB';
rsaPrivateKey = 'MIICXQIBAAKBgQCU9YGbkTHKMi6iFFiPC8fYQkrtjG9Y3gwmQkhQQ31MtqvaMZyI\n' +
'us2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4SoaaUsh/hb7HyUFEWWcGHQEF\n' +
'XNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7ahs3QFPDo5+CSwxIoQIDAQAB\n' +
'AoGAAPIIfDotgfIbExLfsG3G5fEe9ZbM7kVH25JOuF3ycUIrQnk81RJTDJbxItJw\n' +
'JbKKzZTWTVNylvw7JzkHdLZvrNzsI8c/0abMrl64ZUugtumhkmrn6xW6H6z4GQnR\n' +
'havHgRlFL2giWX99J/bMRntMzGCXH8elwIwuPZrYCcdQ5PECQQDw+qsWqTGJyGXr\n' +
'SGyR5Djn+ZAuqFQvfH6vj6b2ridSbZ0RKgRGTXgH4JsaNnqnVpGilWjUHVbSRvPD\n' +
'lZu28qpNAkEAnj52PkGPG9tvG4eaC4Y+LNDKOcU4Ybn07Jz+mZwOGkxb8sgw/kw6\n' +
'H8xPV/7F7GWLjopUsaHnWuWIegzxQY8ZpQJBAKdmGm+VfRovoc099F2sYnOTA7vF\n' +
'pvWNoBuo+N0nwZ0bFB8WRv3nVthyCIy/B5kzI9wvz7B56RQNwcxqmM8P54kCQAbY\n' +
'Zt8MkPdAh87mD8jdlsSzh3v2RxkbJTgzFmRotsd2dCfNdykYtRN5EBmbYM54GhBh\n' +
'dYZlnX92HHBDLRCL8y0CQQDuKZNoBooqVUwcrCFqpeAX/bGYiVmFxcIqyu5vYzVJ\n' +
'Ff5Fpkxm4FLmrjhiGwL1CKIm5RRL9kT6tsv4do6ALylb';
plainTextAes = '%%%%Hello,World! 123 aes key2###(^^^)';
cipherTextAes = 'IclkeCOt6pPODqNyprSZizYdJLBFLwXsEFJo34IJwZp7JmfQJXDbqGpexINBMke4';
aesKey = 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjMONTY3ODkwMzI=';
cipherResult = true;
cipherResultFail = false;
});
beforeEach(function () {});
afterEach(function () {});
/**
* @tc.number SUB_SEC_DataPro_cipher_0100
* @tc.name RSA algorithm encryption succeeded
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0100', 0, function () {
cipher.rsa({
action: 'encrypt',
text: plainTextRsa,
key: rsaPublicKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa encrypt success: ${data.text}`);
expect(cipherResult).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0200
* @tc.name RSA algorithm decryption succeeded
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0200', 1, function () {
cipher.rsa({
action: 'decrypt',
text: plainTextRsa,
key: rsaPrivateKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResult).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`action is invalid, cipher.aes encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0300
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0300', 2, function () {
cipher.rsa({
action: 'encrypt123',
text: plainTextRsa,
key: rsaPublicKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`action is invalid,cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0400
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0400', 2, function () {
cipher.rsa({
action: 'encrypt',
text: plainTextRsa,
key: '1234560GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCU9YGbkTHKMi6iFFiPC8fYQkrt\n' +
'jG9Y3gwmQkhDD31MtqvaMZyIus2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4\n' +
'SoaaUsh/hb7HyUFEWWcGHQEFXNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7\n' +
'ahs3QFPDo5+CSwxIoQIDAQAB',
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`key is invalid, cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0500
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0500', 2, function () {
cipher.rsa({
action: 'encrypt',
text: '~!@#$%^&*()_+<>?:"~,./183456789012345678901234567890123456789',
key: rsaPublicKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa encrypt success: ${data.text}`);
expect(cipherResult).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0600
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0600', 2, function () {
cipher.rsa({
action: 'decrypt',
text: plainTextRsa,
key: rsaPublicKey,
transformation: 'RSA',
success: data => {
console.log(`cipher.rsa encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`transformation is invalid, cipher.rsa decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0700
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0700', 2, function () {
cipher.rsa({
action: 'decrypt123',
text: cipherTextRsa,
key: rsaPublicKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`action is invalid, cipher.rsa decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0800
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0800', 3, function () {
cipher.rsa({
action: 'decrypt',
text: cipherTextRsa,
key: '123456IBAAKBgQCU9YGbkTHKMi6iFFiPC8fYQkrtjG9Y3gwmQkhQQ31MtqvaMZyI\n' +
'us2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4SoaaUsh/hb7HyUFEWWcGHQEF\n' +
'XNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7ahs3QFPDo5+CSwxIoQIDAQAB\n' +
'AoGAAPIIfDotgfIbExLfsG3G5fEe9ZbM7kVH25JOuF3ycUIrQnk81RJTDJbxItJw\n' +
'JbKKzZTWTVNylvw7JzkHdLZvrNzsI8c/0abMrl64ZUugtumhkmrn6xW6H6z4GQnR\n' +
'havHgRlFL2giWX99J/bMRntMzGCXH8elwIwuPZrYCcdQ5PECQQDw+qsWqTGJyGXr\n' +
'SGyR5Djn+ZAuqFQvfH6vj6b2ridSbZ0RKgRGTXgH4JsaNnqnVpGilWjUHVbSRvPD\n' +
'lZu28qpNAkEAnj52PkGPG9tvG4eaC4Y+LNDKOcU4Ybn07Jz+mZwOGkxb8sgw/kw6\n' +
'H8xPV/7F7GWLjopUsaHnWuWIegzxQY8ZpQJBAKdmGm+VfRovoc099F2sYnOTA7vF\n' +
'pvWNoBuo+N0nwZ0bFB8WRv3nVthyCIy/B5kzI9wvz7B56RQNwcxqmM8P54kCQAbY\n' +
'Zt8MkPdAh87mD8jdlsSzh3v2RxkbJTgzFmRotsd2dCfNdykYtRN5EBmbYM54GhBh\n' +
'dYZlnX92HHBDLRCL8y0CQQDuKZNoBooqVUwcrCFqpeAX/bGYiVmFxcIqyu5vYzVJ\n' +
'Ff5Fpkxm4FLmrjhiGwL1CKIm5RRL9kT6tsv4do6ALylb',
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`key is invalid,cipher.rsa decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_0900
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_0900', 3, function () {
cipher.rsa({
action: 'decrypt',
text: '~!@#$%^&*()_+<>?:"~,./183456789012345678901234567890123456789',
key: rsaPrivateKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
console.log(`cipher.rsa decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1000
* @tc.name RSA encryption test when the value of action is abnormal
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1000', 3, function () {
cipher.rsa({
action: 'decrypt',
text: cipherTextRsa,
key: rsaPrivateKey,
transformation: 'RSA',
success: data => {
console.log(`cipher.rsa decrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`transformation is invalid, cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Rsa encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1100
* @tc.name The AES algorithm is successfully encrypted
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1100', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(data.text).toEqual(cipherTextAes);
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_1200
* @tc.name The AES algorithm is successfully encrypted
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_1200', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(data.text).toEqual(plainTextAes);
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResultFail).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2300
* @tc.name The AES algorithm is successfully encrypted
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2300', 3, function () {
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
console.log(`cipher.aes encrypt success: ${data.text}`);
expect(cipherResultFail).toBeTrue();
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`transformation is invalid,cipher.aes decrypt fail: ${code}: ${data}`);
expect(cipherResult).toBeTrue();
},
complete: () => {
console.log(`Aes encrypt end...`);
}
});
});
});
\ No newline at end of file
/*plainTextAes
* 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, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import cipher from '@system.cipher';
describe('hitscipher.test.js', function () {
let plainTextRsa;
let cipherTextRsa;
let rsaPublicKey;
let rsaPrivateKey;
let plainTextAes;
let cipherTextAes;
let aesKey;
let cipherResultFail;
beforeAll(function () {
plainTextRsa = 'Hello,World! 123 rsa key2###';
cipherTextRsa = 'EGyJbxPvBjX4m+hxfbFxojT9KjjLII7Sz8NmjWiy/K+F4WvlGhSOQS9RME2hu208EjvaLvKTgv7Ijo2\n' +
'dGKO0OD4UlEI3LiNFT+cFhfXIVYs16vKQhWtkJEfkJIPjmO5NekxpelYcqmdxUqq5T/7+uq4vRbVyK1/4P57VWLyMTM=';
rsaPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCU9YGbkTHKMi6iFFiPC8fYQkrt\n' +
'jG9Y3gwmQkhDD31MtqvaMZyIus2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4\n' +
'SoaaUsh/hb7HyUFEWWcGHQEFXNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7\n' +
'ahs3QFPDo5+CSwxIoQIDAQAB';
rsaPrivateKey = 'MIICXQIBAAKBgQCU9YGbkTHKMi6iFFiPC8fYQkrtjG9Y3gwmQkhQQ31MtqvaMZyI\n' +
'us2eKZcAiSIGE8Yt3j0Y5Yej6m5OYxICB9oZ88T4SoaaUsh/hb7HyUFEWWcGHQEF\n' +
'XNLWtRXs+LCPE6/VETbY66o+BcALlUxyQeq8AqK7ahs3QFPDo5+CSwxIoQIDAQAB\n' +
'AoGAAPIIfDotgfIbExLfsG3G5fEe9ZbM7kVH25JOuF3ycUIrQnk81RJTDJbxItJw\n' +
'JbKKzZTWTVNylvw7JzkHdLZvrNzsI8c/0abMrl64ZUugtumhkmrn6xW6H6z4GQnR\n' +
'havHgRlFL2giWX99J/bMRntMzGCXH8elwIwuPZrYCcdQ5PECQQDw+qsWqTGJyGXr\n' +
'SGyR5Djn+ZAuqFQvfH6vj6b2ridSbZ0RKgRGTXgH4JsaNnqnVpGilWjUHVbSRvPD\n' +
'lZu28qpNAkEAnj52PkGPG9tvG4eaC4Y+LNDKOcU4Ybn07Jz+mZwOGkxb8sgw/kw6\n' +
'H8xPV/7F7GWLjopUsaHnWuWIegzxQY8ZpQJBAKdmGm+VfRovoc099F2sYnOTA7vF\n' +
'pvWNoBuo+N0nwZ0bFB8WRv3nVthyCIy/B5kzI9wvz7B56RQNwcxqmM8P54kCQAbY\n' +
'Zt8MkPdAh87mD8jdlsSzh3v2RxkbJTgzFmRotsd2dCfNdykYtRN5EBmbYM54GhBh\n' +
'dYZlnX92HHBDLRCL8y0CQQDuKZNoBooqVUwcrCFqpeAX/bGYiVmFxcIqyu5vYzVJ\n' +
'Ff5Fpkxm4FLmrjhiGwL1CKIm5RRL9kT6tsv4do6ALylb';
plainTextAes = '%%%%Hello,World! 123 aes key2###(^^^)';
cipherTextAes = 'IclkeCOt6pPODqNyprSZizYdJLBFLwXsEFJo34IJwZp7JmfQJXDbqGpexINBMke4';
aesKey = 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjMONTY3ODkwMzI=';
cipherResultFail = false;
});
beforeEach(function () {console.log('xxx')});
afterEach(function () {});
/**
* @tc.number SUB_SEC_DataPro_cipher_2400
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2400', 4, function () {
for (var j = 0; j < 1000; j++)
{
cipher.rsa({
action: 'encrypt',
text: plainTextRsa,
key: rsaPublicKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
},
fail: (data, code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).asset(false);
},
complete: () => {
}
});
cipher.rsa({
action: 'decrypt',
text: cipherTextRsa,
key: rsaPrivateKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
},
fail: (data, code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).asset(false);
},
complete: () => {
}
});
}
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2500
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2500', 4, function () {
for (var i = 0; i < 1000; i++)
{
cipher.aes({
action: 'encrypt',
text: plainTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).asset(false);
},
complete: () => {
}
});
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
expect(cipherResultFail).asset(false);
},
complete: () => {
}
});
}
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2600
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2600', 3, function () {
var timestamp1 = new Date().getTime();
for (var j = 0; j < 10; j++)
{
cipher.rsa({
action: 'encrypt',
text: plainTextRsa,
key: rsaPublicKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
},
complete: () => {
}
});
cipher.rsa({
action: 'decrypt',
text: cipherTextRsa,
key: rsaPrivateKey,
transformation: 'RSA/None/OAEPWithSHA256AndMGF1Padding',
success: data => {
},
fail: (data, code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.rsa encrypt fail: ${code}: ${data}`);
},
complete: () => {
}
});
}
var timestamp2 = new Date().getTime();
if ((timestamp2-timestamp1) < 600){
cipherResultFail = true;
}
expect(cipherResultFail).assertTrue();
console.log(`cipher.rsa performance time: ${timestamp2-timestamp1}`);
});
/**
* @tc.number SUB_SEC_DataPro_cipher_2700
* @tc.name Pressure test on the RSA algorithm encryption and decryption interface
* @tc.desc [C-SECURITY-1800]
*/
it('SUB_SEC_DataPro_cipher_2700', 3, function () {
var timestamp1 = new Date().getTime();
for (var i = 0; i < 10; i++)
{
cipher.aes({
action: 'encrypt',
text: plainTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
},
fail: (data,code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes encrypt fail: ${code}: ${data}`);
},
complete: () => {
}
});
cipher.aes({
action: 'decrypt',
text: cipherTextAes,
key: aesKey,
transformation: 'AES/CBC/PKCS5Padding',
iv: 'MTIzNDU2Nzg5MDEyMzQ1Ng==',
ivOffset: 0,
ivLen: 16,
success: data => {
},
fail: (data, code) => {
this.err = `${code}: ${data}`;
console.log(`cipher.aes decrypt fail: ${code}: ${data}`);
},
complete: () => {
}
});
}
var timestamp2 = new Date().getTime();
if ((timestamp2-timestamp1) < 20){
cipherResultFail = true;
}
expect(cipherResultFail).assertTrue();
console.log(`cipher.rsa performance time: ${timestamp2-timestamp1}`);
});
});
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* 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
......@@ -12,4 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require('./hks_concurrency_App1.test.js');
\ No newline at end of file
require('./Agree/hitscipher.test.js');
require('./Agree/cipher1.test.js');
require('./Agree/cipher2.test.js');
......@@ -19,12 +19,6 @@ group("huks_standard") {
deps = [
"HuksAbnormalTest:ActsHuksAbnormalTest",
"HuksAlgCompletionTest:ActsHuksAlgCompletionTest",
"HuksConcurrencyApp1:ActsHuksConcurrencyApp1Test",
"HuksConcurrencyApp2:ActsHuksConcurrencyApp2Test",
"HuksConcurrencyTest:ActsHuksConcurrencyTest",
"HuksJSTimingTest:ActsHuksJSTimingTest",
#"HuksStressTest:ActsHuksStressTest",
]
}
}
# Copyright (c) 2021 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("ActsHuksConcurrencyApp1Test") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsHuksConcurrencyApp1Test"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/js/default"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/js/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for concurrency test",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "com.example.concurrencyapp1",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsHuksConcurrencyApp1Test.hap",
"ActsHuksConcurrencyApp2Test.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.example.concurrencyapp1",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.concurrencyapp1",
"name": ".MyApplication",
"mainAbility": "com.example.concurrencyapp1.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.example.concurrencyapp1.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "singleton",
"visible": true,
"isVisible": "true"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
}
}
\ No newline at end of file
/*
* Copyright (C) 2021 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');
}
};
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.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;
}
}
/*
* Copyright (C) 2021 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 file from '@system.file';
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index';
import featureAbility from '@ohos.ability.featureability'
export default {
data: {
title: ""
},
onInit() {
this.title = 'Hks APP_A';
},
onShow(){
this.title = 'Hks APP_A';
featureAbility.startAbility({
want:
{
deviceId: "",
bundleName: "com.example.concurrencyapp2",
abilityName: "com.example.concurrencyapp2.MainAbility",
parameters:
{},
},
});
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
});
const reportExtend = new ReportExtend(file);
core.addService('expect', expectExtend);
core.addService('report', reportExtend);
core.init();
const configService = core.getDefaultService('config');
this.timeout = 3600000;
configService.setConfig(this);
require('../../../test/hks_concurrencyTestList.test.js');
core.execute();
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "HksA"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import huks from '@ohos.security.huks'
import { describe, it, expect } from 'deccjsunit/index'
import {
makeGenerateKeyOption,
makeImportOption,
makeEncryptAndDecryptOption,
makeSignAndVerifyOption,
makeAgreeOptions,
makeMacOption,
makeRandomArr,
emptyOption,
loop,
timer
} from '../../../../../../hks_xts_common.test'
describe('HKS_CONCURRENCY_APP1_TEST', function () {
var appName = 'app1';
var defaultAlias = 'defaultAlias';
var defaultAliasA = 'defaultAliasA';
var defaultAliasB = 'defaultAliasB';
var emptyOptionForApp1 = emptyOption;
var plainText = makeRandomArr(64);
var signPlainText = makeRandomArr(16);
var ciphertext = [];
var publicKey = [];
var agreeKeyAOption = {};
var agreeKeyBOption = {};
var aes128KeyOptForApp1 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeySize.HKS_AES_KEY_SIZE_128,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC
);
var rsa512KeyOptForApp1 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var ecc224OptForApp1 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var agreeKeyOptionForApp1 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_AGREE,
null,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var macKeyOptionForApp1 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_HMAC,
160,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC,
null,
null,
huks.HksKeyDigest.HKS_DIGEST_SHA1
);
var encryptAes128OptForApp1 = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
plainText
);
var signOptionForApp1 = makeSignAndVerifyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksKeyDigest.HKS_DIGEST_NONE,
signPlainText
);
var verifyOptionForApp1 = makeSignAndVerifyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksKeyDigest.HKS_DIGEST_NONE,
signPlainText
);
var macOptionForApp1 = makeMacOption(plainText);
async function generateAesKeyForApp1() {
var genKeyRet = await huks.generateKey(defaultAlias, aes128KeyOptForApp1);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(true);
};
async function generateRsaKeyForApp1() {
var genKeyRet = await huks.generateKey(defaultAliasA, rsa512KeyOptForApp1);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAliasA, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(true);
};
async function deleteAesKeyForApp1() {
var delKeyRet = await huks.deleteKey(defaultAlias, emptyOptionForApp1);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(false);
};
async function deleteKeyABForApp1() {
var delKeyARet = await huks.deleteKey(defaultAliasA, emptyOptionForApp1);
expect(delKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyAExistRet = await huks.isKeyExist(defaultAliasA, emptyOptionForApp1);
expect(isKeyAExistRet).assertEqual(false);
var delKeyBRet = await huks.deleteKey(defaultAliasB, emptyOptionForApp1);
expect(delKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyBExistRet = await huks.isKeyExist(defaultAliasB, emptyOptionForApp1);
expect(isKeyBExistRet).assertEqual(false);
};
function isKeyExistAfterDelKeyForApp1(index, done) {
huks.isKeyExist(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(false);
if (index < loop) {
index++;
generateKeyCallbackForApp1(index, done);
} else {
done();
}
});
};
function deleteKeyCallbackForApp1(index, done) {
huks.deleteKey(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyExistAfterDelKeyForApp1(index, done);
});
};
function isKeyExistAfterGenKeyForApp1(index, done) {
huks.isKeyExist(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(true);
deleteKeyCallbackForApp1(index, done);
});
};
function generateKeyCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00100 callback index ' + index);
huks.generateKey(defaultAlias, aes128KeyOptForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyExistAfterGenKeyForApp1(index, done);
});
};
function genAndDelKeyCallbackForApp1(done) {
var index = 0
generateKeyCallbackForApp1(index, done);
};
function isKeyNotExistForApp1(alias, done) {
huks.isKeyExist(alias, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(false);
done();
})
};
function deleteKeyForApp1(alias, done) {
huks.deleteKey(alias, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyNotExistForApp1(alias, done);
})
};
function aesDecryptCallbackForApp1(index, done) {
var decryptOpt = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
ciphertext
);
huks.decrypt(defaultAlias, decryptOpt, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(data.outData));
if (index < loop) {
index++;
aesEncryptCallbackForApp1(index, done);
} else {
deleteKeyForApp1(defaultAlias, done);
}
});
};
function aesEncryptCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00400 callback index ' + index);
huks.encrypt(defaultAlias, encryptAes128OptForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
ciphertext = data.outData
aesDecryptCallbackForApp1(index, done);
})
};
function aesEncryptAndDecryptCallbackForApp1(done) {
var index = 0;
aesEncryptCallbackForApp1(index, done);
};
function isAliasBExistForApp1(done) {
huks.isKeyExist(defaultAliasB, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(false);
done();
});
};
function isAliasAExistForApp1(done) {
huks.isKeyExist(defaultAliasA, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(false);
isAliasBExistForApp1(done);
});
};
function deleteAliasBForAPP1(done) {
huks.deleteKey(defaultAliasB, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isAliasAExistForApp1(done);
});
};
function deleteAliasAForApp1(done) {
huks.deleteKey(defaultAliasA, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteAliasBForAPP1(done);
});
};
function rsaImportCallbackForApp1(index, done) {
var importRsa512KeyOpt = makeImportOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE,
publicKey
);
huks.importKey(defaultAliasB, importRsa512KeyOpt, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
rsaExportCallbackForApp1(index, done);
} else {
deleteAliasAForApp1(done);
}
});
};
function rsaExportCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00600 callback index ' + index);
huks.exportKey(defaultAliasA, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKey = data.outData;
rsaImportCallbackForApp1(index, done);
});
};
function rsaExportAndImportCallbackForApp1(done) {
var index = 0;
rsaExportCallbackForApp1(index, done);
};
function getKeyPropertiesCallbackForApp1(index, done) {
huks.getKeyProperties(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
getKeyPropertiesCallbackForApp1(index, done);
} else {
deleteKeyForApp1(defaultAlias, done);
}
});
};
function isKeyNotExistCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00800 callback not exist key index ' + index);
huks.isKeyExist(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(false);
if (index < loop) {
index++;
isKeyNotExistCallbackForApp1(index, done);
} else {
done();
}
});
};
function deleteExistKeyCallbackForApp1(done) {
huks.deleteKey(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyNotExistCallbackForApp1(0, done);
});
};
function isKeyExistCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00800 callback exist key index ' + index);
huks.isKeyExist(defaultAlias, emptyOptionForApp1, function (err, data) {
expect(data).assertEqual(true);
if (index < loop) {
index++;
isKeyExistCallbackForApp1(index, done);
} else {
deleteExistKeyCallbackForApp1(done);
}
});
};
async function generateSignKeyForApp1() {
var generateKeyRet = await huks.generateKey(defaultAliasA, ecc224OptForApp1);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyRet = await huks.exportKey(defaultAliasA, emptyOptionForApp1);
var importOptions = makeImportOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE,
exportKeyRet.outData
);
var importKeyRet = await huks.importKey(defaultAliasB, importOptions);
expect(importKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
};
function verifyWithCallbackForApp1(index, done) {
huks.verify(defaultAliasB, verifyOptionForApp1, ciphertext, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
signWithCallbackForApp1(index, done);
} else {
deleteAliasAForApp1(done);
}
});
}
function signWithCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_01100 callback index ' + index);
huks.sign(defaultAliasA, signOptionForApp1, function (err, data) {
ciphertext = data.outData;
verifyWithCallbackForApp1(index, done);
});
}
function signAndVerifyCallbackForApp1(done) {
signWithCallbackForApp1(0, done);
};
function agreeKeyBWithCallbackForApp1(key, index, done) {
huks.agreeKey(defaultAliasB, agreeKeyBOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(data.outData)).assertEqual(JSON.stringify(key));
if (index < loop) {
index++;
agreeKeyAWithCallbackForApp1(index, done);
} else {
deleteAliasAForApp1(done);
}
});
};
function agreeKeyAWithCallbackForApp1(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_01200 promise callback index ' + index);
huks.agreeKey(defaultAliasA, agreeKeyAOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var key = data.outData;
console.log('agreeKeyARet.outData' + key);
agreeKeyBWithCallbackForApp1(key, index, done);
});
};
function agreeWithCallbackForApp1(done) {
agreeKeyAWithCallbackForApp1(0, done);
};
function macWithCallbackForApp1(index, done) {
huks.mac(defaultAlias, macOptionForApp1, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
macWithCallbackForApp1(index, done);
} else {
deleteKeyForApp1(defaultAlias, done);
}
});
};
/**
* @tc.number HUKS_Concurrency_Test_00100
* @tc.name Concurrency_Test_GenKey_AES
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00100', 0, async function (done) {
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00100 promise index ' + index);
var genKeyRet = await huks.generateKey(defaultAlias, aes128KeyOptForApp1);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(true);
var delKeyRet = await huks.deleteKey(defaultAlias, emptyOptionForApp1);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(false);
}
genAndDelKeyCallbackForApp1(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00200
* @tc.name Concurrency_Test_GetSdkVersion
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00200', 0, async function (done) {
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00200 promise index ' + index);
var sdkVersion = await huks.getSdkVersion(emptyOptionForApp1);
console.log('sdk version ' + JSON.stringify(sdkVersion));
var result = false;
if (sdkVersion.length > 0) {
result = true;
}
expect(result).assertEqual(true);
}
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00300
* @tc.name Concurrency_Test_Encrypt_Decrypt_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00300', 0, async function (done) {
await generateAesKeyForApp1();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00300 promise index ' + index);
var encryptRet = await huks.encrypt(defaultAlias, encryptAes128OptForApp1);
expect(encryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var decryptOpt = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
encryptRet.outData
);
var decryptRet = await huks.decrypt(defaultAlias, decryptOpt);
expect(decryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(decryptRet.outData));
}
await deleteAesKeyForApp1();
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00400
* @tc.name Concurrency_Test_Encrypt_Decrypt_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00400', 0, async function (done) {
await generateAesKeyForApp1();
aesEncryptAndDecryptCallbackForApp1(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00500
* @tc.name Concurrency_Test_Import_Export_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00500', 0, async function (done) {
await generateRsaKeyForApp1();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00500 promise index ' + index);
var exportPublicKeyRet = await huks.exportKey(defaultAliasA, emptyOptionForApp1);
expect(exportPublicKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var importRsa512KeyOpt = makeImportOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE,
exportPublicKeyRet.outData
);
var importRsa512KeyRet = await huks.importKey(defaultAliasB, importRsa512KeyOpt);
expect(importRsa512KeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
await deleteKeyABForApp1();
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00600
* @tc.name Concurrency_Test_Import_Export_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00600', 0, async function (done) {
await generateRsaKeyForApp1();
rsaExportAndImportCallbackForApp1(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00700
* @tc.name Concurrency_Test_GetKeyProperties
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00700', 0, async function (done) {
await generateAesKeyForApp1();
for (let index = 0; index < loop; index++) {
var getKeyPropertiesRet = await huks.getKeyProperties(defaultAlias, emptyOptionForApp1);
expect(getKeyPropertiesRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
getKeyPropertiesCallbackForApp1(0, done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00800
* @tc.name Concurrency_Test_IsKeyExist_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00800', 0, async function (done) {
await generateAesKeyForApp1();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00800 exist key index ' + index);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(true);
}
await deleteAesKeyForApp1();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00800 not exist key index ' + index);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp1);
expect(isKeyExistRet).assertEqual(false);
}
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00900
* @tc.name Concurrency_Test_IsKeyExist_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00900', 0, async function (done) {
await generateAesKeyForApp1();
isKeyExistCallbackForApp1(0, done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01000
* @tc.name Concurrency_Test_Sign_Verify_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01000', 0, async function (done) {
await generateSignKeyForApp1();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_01000 promise index ' + index);
var signRet = await huks.sign(defaultAliasA, signOptionForApp1);
var verifyRet = await huks.verify(defaultAliasB, verifyOptionForApp1, signRet.outData);
expect(verifyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
await deleteKeyABForApp1();
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01100
* @tc.name Concurrency_Test_Sign_Verify_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01100', 0, async function (done) {
await generateSignKeyForApp1();
signAndVerifyCallbackForApp1(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01200
* @tc.name Concurrency_Test_agree
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01200', 0, async function (done) {
var generateKeyARet = await huks.generateKey(defaultAliasA, agreeKeyOptionForApp1);
expect(generateKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var generateKeyBRet = await huks.generateKey(defaultAliasB, agreeKeyOptionForApp1);
expect(generateKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyARet = await huks.exportKey(defaultAliasA, emptyOptionForApp1);
expect(exportKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyBRet = await huks.exportKey(defaultAliasB, emptyOptionForApp1);
expect(exportKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
agreeKeyBOption = makeAgreeOptions(exportKeyARet.outData);
agreeKeyAOption = makeAgreeOptions(exportKeyBRet.outData);
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_01200 promise index ' + index);
var agreeKeyARet = await huks.agreeKey(defaultAliasA, agreeKeyAOption);
expect(agreeKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var agreeKeyBRet = await huks.agreeKey(defaultAliasB, agreeKeyBOption);
expect(agreeKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(agreeKeyARet.outData)).assertEqual(JSON.stringify(agreeKeyBRet.outData));
}
agreeWithCallbackForApp1(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01300
* @tc.name Concurrency_Test_mac
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01300', 0, async function (done) {
var generateKeyRet = await huks.generateKey(defaultAlias, macKeyOptionForApp1);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var macOptionForApp1 = makeMacOption(plainText);
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_01300 promise index ' + index);
var macRet = await huks.mac(defaultAlias, macOptionForApp1);
expect(macRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
macWithCallbackForApp1(0, done);
setTimeout(function () {
}, timer);
});
});
\ No newline at end of file
# Copyright (c) 2021 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("ActsHuksConcurrencyApp2Test") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsHuksConcurrencyApp2Test"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/js/default"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/js/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for concurrecny test",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "com.example.concurrencyapp2",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsHuksConcurrencyApp1Test.hap",
"ActsHuksConcurrencyApp2Test.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.example.concurrencyapp2",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.concurrencyapp2",
"name": ".MyApplication",
"mainAbility": "com.example.concurrencyapp2.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.example.concurrencyapp2.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "singleton",
"visible": true,
"isVisible": "true"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
}
}
\ No newline at end of file
/*
* Copyright (C) 2021 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');
}
};
{
"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;
}
.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) 2021 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 file from '@system.file';
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index';
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow(){
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
});
const reportExtend = new ReportExtend(file);
core.addService('expect', expectExtend);
core.addService('report', reportExtend);
core.init();
const configService = core.getDefaultService('config');
this.timeout = 3600000;
configService.setConfig(this);
require('../../../test/hks_concurrencyTestList.test.js');
this.title = 'Hks APP_B';
core.execute();
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "HksB"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2021 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.
*/
require('./hks_concurrency_APP2.test')
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import huks from '@ohos.security.huks'
import { describe, it, expect } from 'deccjsunit/index'
import {
makeGenerateKeyOption,
makeImportOption,
makeEncryptAndDecryptOption,
makeSignAndVerifyOption,
makeAgreeOptions,
makeMacOption,
makeRandomArr,
emptyOption,
loop,
timer
} from '../../../../../../hks_xts_common.test'
describe('HKS_CONCURRENCY_APP2_TEST', function () {
var appName = 'app2';
var defaultAlias = 'defaultAlias';
var defaultAliasA = 'defaultAliasA';
var defaultAliasB = 'defaultAliasB';
var emptyOptionForApp2 = emptyOption;
var plainText = makeRandomArr(64);
var signPlainText = makeRandomArr(16);
var ciphertext = [];
var publicKey = [];
var agreeKeyAOption = {};
var agreeKeyBOption = {};
var aes128KeyOptForApp2 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeySize.HKS_AES_KEY_SIZE_128,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC
);
var rsa512KeyOptForApp2 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var ecc224OptForApp2 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var agreeKeyOptionForApp2 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_AGREE,
null,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var macKeyOptionForApp2 = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_HMAC,
160,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC,
null,
null,
huks.HksKeyDigest.HKS_DIGEST_SHA1
);
var encryptAes128OptForApp2 = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
plainText
);
var signOptionForApp2 = makeSignAndVerifyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksKeyDigest.HKS_DIGEST_NONE,
signPlainText
);
var verifyOptionForApp2 = makeSignAndVerifyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksKeyDigest.HKS_DIGEST_NONE,
signPlainText
);
var macOptionForApp2 = makeMacOption(plainText);
async function generateAesKeyForApp2() {
var genKeyRet = await huks.generateKey(defaultAlias, aes128KeyOptForApp2);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(true);
};
async function generateRsaKeyForApp2() {
var genKeyRet = await huks.generateKey(defaultAliasA, rsa512KeyOptForApp2);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAliasA, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(true);
};
async function deleteAesKeyForApp2() {
var delKeyRet = await huks.deleteKey(defaultAlias, emptyOptionForApp2);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(false);
};
async function deleteKeyABForApp2() {
var delKeyARet = await huks.deleteKey(defaultAliasA, emptyOptionForApp2);
expect(delKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyAExistRet = await huks.isKeyExist(defaultAliasA, emptyOptionForApp2);
expect(isKeyAExistRet).assertEqual(false);
var delKeyBRet = await huks.deleteKey(defaultAliasB, emptyOptionForApp2);
expect(delKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyBExistRet = await huks.isKeyExist(defaultAliasB, emptyOptionForApp2);
expect(isKeyBExistRet).assertEqual(false);
};
function isKeyExistAfterDelKeyForApp2(index, done) {
huks.isKeyExist(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(false);
if (index < loop) {
index++;
generateKeyCallbackForApp2(index, done);
} else {
done();
}
});
};
function deleteKeyCallbackForApp2(index, done) {
huks.deleteKey(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyExistAfterDelKeyForApp2(index, done);
});
};
function isKeyExistAfterGenKeyForApp2(index, done) {
huks.isKeyExist(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(true);
deleteKeyCallbackForApp2(index, done);
});
};
function generateKeyCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00100 callback index ' + index);
huks.generateKey(defaultAlias, aes128KeyOptForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyExistAfterGenKeyForApp2(index, done);
});
};
function genAndDelKeyCallbackForApp2(done) {
var index = 0
generateKeyCallbackForApp2(index, done);
};
function isKeyNotExistForApp2(alias, done) {
huks.isKeyExist(alias, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(false);
done();
})
};
function deleteKeyForApp2(alias, done) {
huks.deleteKey(alias, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyNotExistForApp2(alias, done);
})
};
function aesDecryptCallbackForApp2(index, done) {
var decryptOpt = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
ciphertext
);
huks.decrypt(defaultAlias, decryptOpt, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(data.outData));
if (index < loop) {
index++;
aesEncryptCallbackForApp2(index, done);
} else {
deleteKeyForApp2(defaultAlias, done);
}
});
};
function aesEncryptCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00400 callback index ' + index);
huks.encrypt(defaultAlias, encryptAes128OptForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
ciphertext = data.outData
aesDecryptCallbackForApp2(index, done);
})
};
function aesEncryptAndDecryptCallbackForApp2(done) {
var index = 0;
aesEncryptCallbackForApp2(index, done);
};
function isAliasBExistForApp2(done) {
huks.isKeyExist(defaultAliasB, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(false);
done();
});
};
function isAliasAExistForApp2(done) {
huks.isKeyExist(defaultAliasA, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(false);
isAliasBExistForApp2(done);
});
};
function deleteAliasBForAPP1(done) {
huks.deleteKey(defaultAliasB, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isAliasAExistForApp2(done);
});
};
function deleteAliasAForApp2(done) {
huks.deleteKey(defaultAliasA, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteAliasBForAPP1(done);
});
};
function rsaImportCallbackForApp2(index, done) {
var importRsa512KeyOpt = makeImportOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE,
publicKey
);
huks.importKey(defaultAliasB, importRsa512KeyOpt, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
rsaExportCallbackForApp2(index, done);
} else {
deleteAliasAForApp2(done);
}
});
};
function rsaExportCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00600 callback index ' + index);
huks.exportKey(defaultAliasA, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKey = data.outData;
rsaImportCallbackForApp2(index, done);
});
};
function rsaExportAndImportCallbackForApp2(done) {
var index = 0;
rsaExportCallbackForApp2(index, done);
};
function getKeyPropertiesCallbackForApp2(index, done) {
huks.getKeyProperties(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
getKeyPropertiesCallbackForApp2(index, done);
} else {
deleteKeyForApp2(defaultAlias, done);
}
});
};
function isKeyNotExistCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00800 callback not exist key index ' + index);
huks.isKeyExist(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(false);
if (index < loop) {
index++;
isKeyNotExistCallbackForApp2(index, done);
} else {
done();
}
});
};
function deleteExistKeyCallbackForApp2(done) {
huks.deleteKey(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyNotExistCallbackForApp2(0, done);
});
};
function isKeyExistCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_00800 callback exist key index ' + index);
huks.isKeyExist(defaultAlias, emptyOptionForApp2, function (err, data) {
expect(data).assertEqual(true);
if (index < loop) {
index++;
isKeyExistCallbackForApp2(index, done);
} else {
deleteExistKeyCallbackForApp2(done);
}
});
};
async function generateSignKeyForApp2() {
var generateKeyRet = await huks.generateKey(defaultAliasA, ecc224OptForApp2);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyRet = await huks.exportKey(defaultAliasA, emptyOptionForApp2);
var importOptions = makeImportOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE,
exportKeyRet.outData
);
var importKeyRet = await huks.importKey(defaultAliasB, importOptions);
expect(importKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
};
function verifyWithCallbackForApp2(index, done) {
huks.verify(defaultAliasB, verifyOptionForApp2, ciphertext, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
signWithCallbackForApp2(index, done);
} else {
deleteAliasAForApp2(done);
}
});
}
function signWithCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_01100 callback index ' + index);
huks.sign(defaultAliasA, signOptionForApp2, function (err, data) {
ciphertext = data.outData;
verifyWithCallbackForApp2(index, done);
});
}
function signAndVerifyCallbackForApp2(done) {
signWithCallbackForApp2(0, done);
};
function agreeKeyBWithCallbackForApp2(key, index, done) {
huks.agreeKey(defaultAliasB, agreeKeyBOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(data.outData)).assertEqual(JSON.stringify(key));
if (index < loop) {
index++;
agreeKeyAWithCallbackForApp2(index, done);
} else {
deleteAliasAForApp2(done);
}
});
};
function agreeKeyAWithCallbackForApp2(index, done) {
console.log(appName + ' HUKS_Concurrency_Test_01200 promise callback index ' + index);
huks.agreeKey(defaultAliasA, agreeKeyAOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var key = data.outData;
console.log('agreeKeyARet.outData' + key);
agreeKeyBWithCallbackForApp2(key, index, done);
});
};
function agreeWithCallbackForApp2(done) {
agreeKeyAWithCallbackForApp2(0, done);
};
function macWithCallbackForApp2(index, done) {
huks.mac(defaultAlias, macOptionForApp2, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index < loop) {
index++;
macWithCallbackForApp2(index, done);
} else {
deleteKeyForApp2(defaultAlias, done);
}
});
};
/**
* @tc.number HUKS_Concurrency_Test_00100
* @tc.name Concurrency_Test_GenKey_AES
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00100', 0, async function (done) {
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00100 promise index ' + index);
var genKeyRet = await huks.generateKey(defaultAlias, aes128KeyOptForApp2);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(true);
var delKeyRet = await huks.deleteKey(defaultAlias, emptyOptionForApp2);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(false);
}
genAndDelKeyCallbackForApp2(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00200
* @tc.name Concurrency_Test_GetSdkVersion
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00200', 0, async function (done) {
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00200 promise index ' + index);
var sdkVersion = await huks.getSdkVersion(emptyOptionForApp2);
console.log('sdk version ' + JSON.stringify(sdkVersion));
var result = false;
if (sdkVersion.length > 0) {
result = true;
}
expect(result).assertEqual(true);
}
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00300
* @tc.name Concurrency_Test_Encrypt_Decrypt_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00300', 0, async function (done) {
await generateAesKeyForApp2();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00300 promise index ' + index);
var encryptRet = await huks.encrypt(defaultAlias, encryptAes128OptForApp2);
expect(encryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var decryptOpt = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
encryptRet.outData
);
var decryptRet = await huks.decrypt(defaultAlias, decryptOpt);
expect(decryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(decryptRet.outData));
}
await deleteAesKeyForApp2();
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00400
* @tc.name Concurrency_Test_Encrypt_Decrypt_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00400', 0, async function (done) {
await generateAesKeyForApp2();
aesEncryptAndDecryptCallbackForApp2(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00500
* @tc.name Concurrency_Test_Import_Export_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00500', 0, async function (done) {
await generateRsaKeyForApp2();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00500 promise index ' + index);
var exportPublicKeyRet = await huks.exportKey(defaultAliasA, emptyOptionForApp2);
expect(exportPublicKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var importRsa512KeyOpt = makeImportOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE,
exportPublicKeyRet.outData
);
var importRsa512KeyRet = await huks.importKey(defaultAliasB, importRsa512KeyOpt);
expect(importRsa512KeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
await deleteKeyABForApp2();
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00600
* @tc.name Concurrency_Test_Import_Export_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00600', 0, async function (done) {
await generateRsaKeyForApp2();
rsaExportAndImportCallbackForApp2(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00700
* @tc.name Concurrency_Test_GetKeyProperties
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00700', 0, async function (done) {
await generateAesKeyForApp2();
for (let index = 0; index < loop; index++) {
var getKeyPropertiesRet = await huks.getKeyProperties(defaultAlias, emptyOptionForApp2);
expect(getKeyPropertiesRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
getKeyPropertiesCallbackForApp2(0, done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00800
* @tc.name Concurrency_Test_IsKeyExist_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00800', 0, async function (done) {
await generateAesKeyForApp2();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00800 exist key index ' + index);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(true);
}
await deleteAesKeyForApp2();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_00800 not exist key index ' + index);
var isKeyExistRet = await huks.isKeyExist(defaultAlias, emptyOptionForApp2);
expect(isKeyExistRet).assertEqual(false);
}
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_00900
* @tc.name Concurrency_Test_IsKeyExist_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_00900', 0, async function (done) {
await generateAesKeyForApp2();
isKeyExistCallbackForApp2(0, done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01000
* @tc.name Concurrency_Test_Sign_Verify_Promise
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01000', 0, async function (done) {
await generateSignKeyForApp2();
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_01000 promise index ' + index);
var signRet = await huks.sign(defaultAliasA, signOptionForApp2);
var verifyRet = await huks.verify(defaultAliasB, verifyOptionForApp2, signRet.outData);
expect(verifyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
await deleteKeyABForApp2();
done();
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01100
* @tc.name Concurrency_Test_Sign_Verify_Callback
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01100', 0, async function (done) {
await generateSignKeyForApp2();
signAndVerifyCallbackForApp2(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01200
* @tc.name Concurrency_Test_agree
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01200', 0, async function (done) {
var generateKeyARet = await huks.generateKey(defaultAliasA, agreeKeyOptionForApp2);
expect(generateKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var generateKeyBRet = await huks.generateKey(defaultAliasB, agreeKeyOptionForApp2);
expect(generateKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyARet = await huks.exportKey(defaultAliasA, emptyOptionForApp2);
expect(exportKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyBRet = await huks.exportKey(defaultAliasB, emptyOptionForApp2);
expect(exportKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
agreeKeyBOption = makeAgreeOptions(exportKeyARet.outData);
agreeKeyAOption = makeAgreeOptions(exportKeyBRet.outData);
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_01200 promise index ' + index);
var agreeKeyARet = await huks.agreeKey(defaultAliasA, agreeKeyAOption);
expect(agreeKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var agreeKeyBRet = await huks.agreeKey(defaultAliasB, agreeKeyBOption);
expect(agreeKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(agreeKeyARet.outData)).assertEqual(JSON.stringify(agreeKeyBRet.outData));
}
agreeWithCallbackForApp2(done);
setTimeout(function () {
}, timer);
});
/**
* @tc.number HUKS_Concurrency_Test_01300
* @tc.name Concurrency_Test_mac
* @tc.desc Test for APP Concurrency.
*/
it('HUKS_Concurrency_Test_01300', 0, async function (done) {
var generateKeyRet = await huks.generateKey(defaultAlias, macKeyOptionForApp2);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var macOptionForApp2 = makeMacOption(plainText);
for (let index = 0; index < loop; index++) {
console.log(appName + ' HUKS_Concurrency_Test_01300 promise index ' + index);
var macRet = await huks.mac(defaultAlias, macOptionForApp2);
expect(macRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
macWithCallbackForApp2(0, done);
setTimeout(function () {
}, timer);
});
});
\ No newline at end of file
# Copyright (c) 2021 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("ActsHuksConcurrencyTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":hjs_demo_js_assets",
":hjs_demo_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsHuksConcurrencyTest"
}
ohos_js_assets("hjs_demo_js_assets") {
source_dir = "./entry/src/main/js/default"
}
ohos_resources("hjs_demo_resources") {
sources = [ "./entry/src/main/js/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for algorithm completion test",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "com.example.huksconcurrencytest",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsHuksConcurrencyTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.example.huksconcurrencytest",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.huksconcurrencytest",
"name": ".MyApplication",
"mainAbility": "com.example.huksconcurrencytest.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.example.huksconcurrencytest.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "singleton",
"visible": true,
"isVisible": "true"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
}
}
\ No newline at end of file
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.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) 2021 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 worker from '@ohos.worker';
import hks from '@ohos.security.huks';
import {
aliasA,
aliasB,
failStr,
loop,
successStr,
emptyOption,
makeEncryptAndDecryptOption,
makeGenerateKeyOption,
makeImportOption,
makeMacOption,
makeRandomArr,
makeSignAndVerifyOption,
makeAgreeOption
} from '../../test/hks_common.test.js';
var parentPort = worker.parentPort;
var plainText = makeRandomArr(64);
var signPlainText = makeRandomArr(16);
var generateKeyOption = makeGenerateKeyOption(
hks.HksKeyAlg.HKS_ALG_AES,
hks.HksKeySize.HKS_AES_KEY_SIZE_128,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_CBC,
null
);
var encryptAesOpt = makeEncryptAndDecryptOption(
hks.HksKeyAlg.HKS_ALG_AES,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_CBC,
null,
null,
plainText
);
var signOption = makeSignAndVerifyOption(
hks.HksKeyAlg.HKS_ALG_ECC,
hks.HksKeySize.HKS_ECC_KEY_SIZE_224,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksKeyDigest.HKS_DIGEST_NONE,
signPlainText
);
var verifyOption = makeSignAndVerifyOption(
hks.HksKeyAlg.HKS_ALG_ECC,
hks.HksKeySize.HKS_ECC_KEY_SIZE_224,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksKeyDigest.HKS_DIGEST_NONE,
signPlainText
);
var macOption = makeMacOption(plainText);
var actionMap = new Map([
['Hks_Concurrency_Test_00100', function() {
hksConcurrencyTest001();
}],
['Hks_Concurrency_Test_00200', function() {
hksConcurrencyTest002(0);
}],
['Hks_Concurrency_Test_00300', function() {
hksConcurrencyTest003();
}],
['Hks_Concurrency_Test_00400', function() {
hksConcurrencyTest004(0);
}],
['Hks_Concurrency_Test_00500', function() {
hksConcurrencyTest005();
}],
['Hks_Concurrency_Test_00600', function() {
hksConcurrencyTest006(0);
}],
['Hks_Concurrency_Test_00700', function() {
hksConcurrencyTest007();
}],
['Hks_Concurrency_Test_00800', function() {
hksConcurrencyTest008();
}],
['Hks_Concurrency_Test_00900', function() {
hksConcurrencyTest009();
}],
['Hks_Concurrency_Test_01000', function() {
hksConcurrencyTest010();
}],
['Hks_Concurrency_Test_01100', function() {
hksConcurrencyTest011(0);
}],
['Hks_Concurrency_Test_01200', function() {
hksConcurrencyTest012();
}],
['Hks_Concurrency_Test_01300', function() {
hksConcurrencyTest013(0);
}],
['Hks_Concurrency_Test_01400', function() {
hksConcurrencyTest014();
}],
['Hks_Concurrency_Test_01500', function() {
hksConcurrencyTest015(0);
}],
['Hks_Concurrency_Test_01600', function() {
hksConcurrencyTest016();
}],
['Hks_Concurrency_Test_01700', function() {
hksConcurrencyTest017(0);
}],
['Hks_Concurrency_Test_01800', function() {
hksConcurrencyTest018();
}],
['Hks_Concurrency_Test_01900', function() {
hksConcurrencyTest019(0);
}],
['Hks_Concurrency_Test_02000', function() {
hksConcurrencyTest020();
}],
['Hks_Concurrency_Test_02100', function() {
hksConcurrencyTest021(0);
}]
]);
parentPort.onmessage = function(data) {
var caseId = data.data.value;
var testFunction = actionMap.get(caseId);
if (testFunction != null) {
testFunction();
} else {
console.log ('hksConcurrencyTest default check:' + caseId);
parentPort.postMessage (failStr);
}
};
async function hksConcurrencyTest001() {
for (let index = 0;index < loop; index ++) {
console.log('hksConcurrencyTest001 running index: ' + index);
var result = await hks.generateKey('alias001', generateKeyOption);
if (result.errorCode != hks.HksErrorCode.HKS_SUCCESS) {
console.log('hksConcurrencyTest001 fail detail ' + JSON.stringify(result));
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest002(index) {
console.log('hksConcurrencyTest002 running index: ' + index);
hks.generateKey('alias002', generateKeyOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
if (index < loop) {
index ++;
hksConcurrencyTest002(index);
} else {
parentPort.postMessage(successStr);
}
} else {
console.log('hksConcurrencyTest002 fail detail ' + JSON.stringify(data));
}
});
};
async function hksConcurrencyTest003() {
for (let index = 0;index < loop; index ++) {
console.log('hksConcurrencyTest003 running index: ' + index);
var result = await hks.deleteKey('alias003', emptyOption);
if (result.errorCode != hks.HksErrorCode.HKS_SUCCESS && result.errorCode != hks.HksErrorCode.HKS_ERROR_NOT_EXIST) {
console.log('hksConcurrencyTest003 fail detail ' + JSON.stringify(result));
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest004(index) {
console.log('hksConcurrencyTest004 running index: ' + index);
hks.deleteKey('alias004', emptyOption, function(err, data) {
if (data.errorCode != hks.HksErrorCode.HKS_SUCCESS && data.errorCode != hks.HksErrorCode.HKS_ERROR_NOT_EXIST) {
console.log('hksConcurrencyTest004 fail detail ' + JSON.stringify(data));
} else {
if (index < loop) {
index ++;
hksConcurrencyTest004(index);
} else {
parentPort.postMessage(successStr);
}
}
});
};
async function hksConcurrencyTest005() {
for (let index = 0;index < loop; index ++) {
console.log('hksConcurrencyTest005 running index: ' + index);
var encryptResult = await hks.encrypt('alias005', encryptAesOpt);
var decryptOption = makeEncryptAndDecryptOption(
hks.HksKeyAlg.HKS_ALG_AES,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_CBC,
null,
null,
encryptResult.outData
);
var decryptResult = await hks.decrypt('alias005', decryptOption);
if (encryptResult.errorCode != hks.HksErrorCode.HKS_SUCCESS ||
decryptResult.errorCode != hks.HksErrorCode.HKS_SUCCESS ||
JSON.stringify(plainText) != JSON.stringify(decryptResult.outData)) {
console.log('hksConcurrencyTest005 fail encrypt detail ' + JSON.stringify(encryptResult));
console.log('hksConcurrencyTest005 fail decrypt detail ' + JSON.stringify(encryptResult));
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest006(index) {
console.log('hksConcurrencyTest006 running index: ' + index);
hks.encrypt('alias006', encryptAesOpt, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
var decryptOption = makeEncryptAndDecryptOption(
hks.HksKeyAlg.HKS_ALG_AES,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_CBC,
null,
null,
data.outData
);
decryptCallback(index, decryptOption);
} else {
console.log('hksConcurrencyTest006 fail detail ' + JSON.stringify(data));
}
});
};
function decryptCallback(index, decryptOption) {
hks.decrypt('alias006', decryptOption, function(err, data) {
if (data.errorCode != hks.HksErrorCode.HKS_SUCCESS || JSON.stringify(data.outData) != JSON.stringify(plainText)) {
parentPort.postMessage(failStr);
} else {
if (index < loop) {
index ++;
hksConcurrencyTest006();
} else {
parentPort.postMessage(successStr);
}
}
});
};
async function hksConcurrencyTest007() {
var sdkVersion = '';
for (let index = 0;index < loop; index ++) {
console.log('hksConcurrencyTest007 running index: ' + index);
sdkVersion = await hks.getSdkVersion(emptyOption);
if (sdkVersion.length == 0) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
async function hksConcurrencyTest008() {
var exportKeyResult = await hks.exportKey(aliasA, emptyOption);
var importKeyOption = makeImportOption(
hks.HksKeyAlg.HKS_ALG_RSA,
hks.HksKeySize.HKS_RSA_KEY_SIZE_512,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_ECB,
hks.HksKeyDigest.HKS_DIGEST_NONE,
exportKeyResult.outData
);
for (let index = 0;index < loop; index ++) {
var importKeyResult = await hks.importKey('alias008', importKeyOption);
if (importKeyResult.errorCode != hks.HksErrorCode.HKS_SUCCESS) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function importKeyCallback(index, importKeyOption) {
hks.importKey('alias009', importKeyOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
if (index < loop) {
index ++;
importKeyCallback(index, importKeyOption);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest009() {
var exportKeyResult = await hks.exportKey(aliasA, emptyOption);
var importKeyOption = makeImportOption(
hks.HksKeyAlg.HKS_ALG_RSA,
hks.HksKeySize.HKS_RSA_KEY_SIZE_512,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_ECB,
hks.HksKeyDigest.HKS_DIGEST_NONE,
exportKeyResult.outData
);
importKeyCallback(0, importKeyOption);
};
async function hksConcurrencyTest010() {
for (let index = 0;index < loop; index ++) {
var exportKeyResult = await hks.exportKey('alias010', emptyOption);
if (exportKeyResult.errorCode != hks.HksErrorCode.HKS_SUCCESS) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest011(index) {
hks.exportKey('alias011', emptyOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
if (index < loop) {
index ++;
hksConcurrencyTest011(index);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest012() {
for (let index = 0;index < loop; index ++) {
var getKeyPropertiesResult = await hks.getKeyProperties('alias012', emptyOption);
if (getKeyPropertiesResult.errorCode != hks.HksErrorCode.HKS_SUCCESS) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest013(index) {
hks.getKeyProperties('alias013', emptyOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
if (index < loop) {
index ++;
hksConcurrencyTest013(index);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest014() {
for (let index = 0;index < loop; index ++) {
var isKeyExist = await hks.isKeyExist('alias014', emptyOption);
if (!isKeyExist) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest015(index) {
hks.isKeyExist('alias015', emptyOption, function(err, data) {
if (data) {
if (index < loop) {
index ++;
hksConcurrencyTest015(index);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest016() {
for (let index = 0;index < loop; index ++) {
var signRet = await hks.sign('alias016', signOption);
var verifyRet = await hks.verify('alias016', verifyOption, signRet.outData);
if (signRet.errorCode != hks.HksErrorCode.HKS_SUCCESS || verifyRet.errorCode != hks.HksErrorCode.HKS_SUCCESS) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function verifyCallback(index, signedData) {
hks.verify('alias017', verifyOption, signedData, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
if (index < loop) {
index ++;
hksConcurrencyTest017(index);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
}
function hksConcurrencyTest017(index) {
hks.sign('alias017', signOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
verifyCallback(index, data.outData);
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest018() {
var exportKeyAResult = await hks.exportKey(aliasA, emptyOption);
var exportKeyBResult = await hks.exportKey(aliasB, emptyOption);
var agreeKeyBOption = makeAgreeOption(exportKeyAResult.outData);
var agreeKeyAOption = makeAgreeOption(exportKeyBResult.outData);
for (let index = 0; index < loop; index ++) {
var agreeKeyAResult = await hks.agreeKey(aliasA, agreeKeyAOption);
var agreeKeyBResult = await hks.agreeKey(aliasB, agreeKeyBOption);
if (agreeKeyAResult.errorCode != hks.HksErrorCode.HKS_SUCCESS ||
agreeKeyBResult.errorCode != hks.HksErrorCode.HKS_SUCCESS ||
JSON.stringify(agreeKeyAResult.outData) != JSON.stringify(agreeKeyBResult.outData)) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function agreeKeyCallback(index, option, key) {
hks.agreeKey(aliasB, option, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS
&& JSON.stringify(key.outData) == JSON.stringify(data.outData)) {
if (index < loop) {
index ++;
hksConcurrencyTest019(index);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest019(index) {
var exportKeyAResult = await hks.exportKey(aliasA, emptyOption);
var exportKeyBResult = await hks.exportKey(aliasB, emptyOption);
var agreeKeyBOption = makeAgreeOption(exportKeyAResult.outData);
var agreeKeyAOption = makeAgreeOption(exportKeyBResult.outData);
hks.agreeKey(aliasA, agreeKeyAOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
agreeKeyCallback(index, agreeKeyBOption, data);
} else {
parentPort.postMessage(failStr);
}
});
};
async function hksConcurrencyTest020() {
for (let index = 0; index < loop; index ++) {
var macResult = await hks.mac('alias020', macOption);
if (macResult.errorCode != hks.HksErrorCode.HKS_SUCCESS) {
parentPort.postMessage(failStr);
}
}
parentPort.postMessage(successStr);
};
function hksConcurrencyTest021(index) {
hks.mac('alias021', macOption, function(err, data) {
if (data.errorCode == hks.HksErrorCode.HKS_SUCCESS) {
if (index < loop) {
index ++;
hksConcurrencyTest021(index);
} else {
parentPort.postMessage(successStr);
}
} else {
parentPort.postMessage(failStr);
}
});
};
\ No newline at end of file
/*
* Copyright (C) 2021 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 hks from '@ohos.security.huks'
export var useLib = 'openssl';
export var loop = 50;
export var successStr = 'SUCCESS';
export var failStr = 'FAIL';
export var emptyOption = makeEmptyOption ();
export var aliasA = 'aliasA';
export var aliasB = 'aliasB';
export function makeGenerateKeyOption (alg, size, purpose, padding, mode, digest) {
var properties = new Array();
properties[0] = makeAlgTagProperty (alg);
properties[1] = makeSizeProperty (size);
properties[2] = makePurposeProperty (purpose);
if (purpose == (hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT)) {
properties[3] = makePaddingProperty (padding);
properties[4] = makeModeProperty (mode);
if (alg == hks.HksKeyAlg.HKS_ALG_RSA) {
properties[5] = makeDigestProperty (digest);
properties[6] = makeKeyGenerateType ();
}
} else if (purpose == (hks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | hks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY)) {
properties[3] = makePaddingProperty (padding);
properties[4] = makeDigestProperty (digest);
} else if (purpose == hks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC) {
properties[3] = makeDigestProperty (digest);
properties[4] = makeKeyType ();
} else {
properties[3] = makeDigestProperty (digest);
}
var option = {
properties: properties
};
return option;
};
export function makeEncryptAndDecryptOption (alg, purpose, padding, mode, size, digest, text) {
var properties = new Array();
properties[0] = makeAlgTagProperty (alg);
properties[1] = makePurposeProperty (purpose);
properties[2] = makePaddingProperty (padding);
properties[3] = makeModeProperty (mode);
if (alg == hks.HksKeyAlg.HKS_ALG_AES || alg == hks.HksKeyAlg.HKS_ALG_HMAC) {
properties[4] = makeIV ();
} else if (alg == hks.HksKeyAlg.HKS_ALG_RSA) {
properties[4] = makeIsKeyAlias ();
properties[5] = makeSizeProperty (size);
properties[6] = makeDigestProperty (digest);
}
var option = {
properties: properties,
inData: text
};
return option;
};
export function makeImportOption (alg, size, purpose, padding, mode, digest, publicKey) {
var properties = new Array();
properties[0] = makeAlgTagProperty (alg);
properties[1] = makeSizeProperty (size);
properties[2] = makePurposeProperty (purpose);
properties[3] = makePaddingProperty (padding);
if (alg == hks.HksKeyAlg.HKS_ALG_RSA || alg == hks.HksKeyAlg.HKS_ALG_DSA || alg == hks.HksKeyAlg.HKS_ALG_ECC) {
if (purpose == (hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT)) {
properties[4] = makeModeProperty (mode);
properties[5] = makeDigestProperty (digest);
properties[6] = makeKeyGenerateType ();
} else {
properties[4] = makeDigestProperty (digest);
}
}
var option = {
properties: properties,
inData: publicKey
};
return option;
};
export function makeRandomArr (size) {
var arr = new Uint8Array( size);
for (var i = 0; i < size; i ++) {
arr[i] = Math.floor (Math.random () * 10);
}
return arr;
};
export function makeAgreeOption (publicKey) {
var properties = new Array();
properties[0] = {
tag: hks.HksTag.HKS_TAG_ALGORITHM,
value: hks.HksKeyAlg.HKS_ALG_ECDH
};
properties[1] = {
tag: hks.HksTag.HKS_TAG_KEY_SIZE,
value: hks.HksKeySize.HKS_ECC_KEY_SIZE_224
};
var options = {
properties: properties,
inData: publicKey
};
return options;
};
export function makeSignAndVerifyOption (alg, size, purpose, padding, digest, text) {
var properties = new Array();
properties[0] = makeAlgTagProperty (alg);
properties[1] = makeSizeProperty (size);
properties[2] = makePurposeProperty (purpose);
properties[3] = makePaddingProperty (padding);
properties[4] = makeDigestProperty (digest);
var option = {
properties: properties,
inData: text
};
return option;
};
export function makeMacOption (plaintText) {
var properties = new Array();
properties[0] = {
tag: hks.HksTag.HKS_TAG_ALGORITHM,
value: hks.HksKeyAlg.HKS_ALG_HMAC
};
properties[1] = {
tag: hks.HksTag.HKS_TAG_PURPOSE,
value: hks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC
};
properties[2] = {
tag: hks.HksTag.HKS_TAG_DIGEST,
value: hks.HksKeyDigest.HKS_DIGEST_SHA1
};
properties[3] = {
tag: hks.HksTag.HKS_TAG_KEY_TYPE,
value: hks.HksKeyType.HKS_KEY_TYPE_HMAC
};
properties[4] = {
tag: hks.HksTag.HKS_TAG_KEY_SIZE,
value: 160
};
properties[5] = {
tag: hks.HksTag.HKS_TAG_IV,
value: new Uint8Array( 16)
};
var options = {
properties: properties,
inData: plaintText
};
return options;
};
function makeAlgTagProperty (alg) {
var property = {
tag: hks.HksTag.HKS_TAG_ALGORITHM,
value: alg
}
return property;
};
function makeSizeProperty (size) {
var property = {
tag: hks.HksTag.HKS_TAG_KEY_SIZE,
value: size
};
return property;
};
function makePurposeProperty (purpose) {
var property = {
tag: hks.HksTag.HKS_TAG_PURPOSE,
value: purpose
};
return property;
};
function makePaddingProperty (padding) {
var property = {
tag: hks.HksTag.HKS_TAG_PADDING,
value: padding
};
return property;
};
function makeModeProperty (mode) {
var property = {
tag: hks.HksTag.HKS_TAG_BLOCK_MODE,
value: mode
};
return property;
};
function makeDigestProperty (digest) {
var property = {
tag: hks.HksTag.HKS_TAG_DIGEST,
value: digest
};
return property;
};
function makeKeyGenerateType () {
var property = {
tag: hks.HksTag.HKS_TAG_KEY_GENERATE_TYPE,
value: hks.HksKeyGenerateType.HKS_KEY_GENERATE_TYPE_DEFAULT
};
return property;
};
function makeKeyType () {
var property = {
tag: hks.HksTag.HKS_TAG_KEY_TYPE,
value: hks.HksKeyType.HKS_KEY_TYPE_HMAC
};
return property;
};
function makeIV () {
var property = {
tag: hks.HksTag.HKS_TAG_IV,
value: new Uint8Array( 16)
};
return property;
};
function makeIsKeyAlias () {
var property = {
tag: hks.HksTag.HKS_TAG_IS_KEY_ALIAS,
value: true
};
return property;
};
function makeEmptyOption () {
var emptyOption = {
properties: []
};
return emptyOption;
};
\ No newline at end of file
/*
* Copyright (C) 2021 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 worker from '@ohos.worker';
import hks from '@ohos.security.huks';
import {describe, it, expect} from 'deccjsunit/index'
import {
aliasA,
aliasB,
emptyOption,
successStr,
failStr,
makeGenerateKeyOption
} from './hks_common.test.js';
var generateAes128KeyOpt = makeGenerateKeyOption (
hks.HksKeyAlg.HKS_ALG_AES,
hks.HksKeySize.HKS_AES_KEY_SIZE_128,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_CBC
);
var generateRsa512KeyOpt = makeGenerateKeyOption (
hks.HksKeyAlg.HKS_ALG_RSA,
hks.HksKeySize.HKS_RSA_KEY_SIZE_512,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | hks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
hks.HksKeyPadding.HKS_PADDING_NONE,
hks.HksCipherMode.HKS_MODE_ECB,
hks.HksKeyDigest.HKS_DIGEST_NONE
);
var generateEcc224Opt = makeGenerateKeyOption (
hks.HksKeyAlg.HKS_ALG_ECC,
hks.HksKeySize.HKS_ECC_KEY_SIZE_224,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | hks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
hks.HksKeyPadding.HKS_PADDING_NONE,
null,
hks.HksKeyDigest.HKS_DIGEST_NONE
);
var generateAgreeKeyOption = makeGenerateKeyOption (
hks.HksKeyAlg.HKS_ALG_ECC,
hks.HksKeySize.HKS_ECC_KEY_SIZE_224,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_AGREE,
null,
null,
hks.HksKeyDigest.HKS_DIGEST_NONE
);
var generateMacKeyOption = makeGenerateKeyOption (
hks.HksKeyAlg.HKS_ALG_HMAC,
160,
hks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC,
null,
null,
hks.HksKeyDigest.HKS_DIGEST_SHA1
);
describe ('HKS_XTS_CONCURRENCY', function () {
var worker1 = new worker.Worker( "workers/worker.js");
var worker2 = new worker.Worker( "workers/worker.js");
var workerStatus1 = false;
var workerStatus2 = false;
function doConcurrencyTest (caseId, done) {
workerStatus1 = false;
workerStatus2 = false;
worker1.onmessage = function (data) {
workerStatus1 = true;
console.log (caseId + ' worker1.onMessage ' + JSON.stringify (data));
expect (data.data).assertEqual (successStr);
doClear (caseId, done);
};
worker2.onmessage = function (data) {
workerStatus2 = true;
console.log (caseId + ' worker2.onMessage ' + JSON.stringify (data));
expect (data.data).assertEqual (successStr);
doClear (caseId, done);
};
var obj = { type: 'normal', value: caseId };
worker1.postMessage (obj);
worker2.postMessage (obj);
};
var clearActionMap = new Map([
['Hks_Concurrency_Test_00100', async function() {
await hks.deleteKey ('alias001', emptyOption);
}],
['Hks_Concurrency_Test_00200', async function() {
await hks.deleteKey ('alias002', emptyOption);
}],
['Hks_Concurrency_Test_00300', async function() {
await hks.deleteKey ('alias003', emptyOption);
}],
['Hks_Concurrency_Test_00400', async function() {
await hks.deleteKey ('alias004', emptyOption);
}],
['Hks_Concurrency_Test_00500', async function() {
await hks.deleteKey ('alias005', emptyOption);
}],
['Hks_Concurrency_Test_00600', async function() {
await hks.deleteKey ('alias006', emptyOption);
}],
['Hks_Concurrency_Test_00800', async function() {
await hks.deleteKey (aliasA, emptyOption);
await hks.deleteKey ('alias008', emptyOption);
}],
['Hks_Concurrency_Test_00900', async function() {
await hks.deleteKey (aliasA, emptyOption);
await hks.deleteKey ('alias009', emptyOption);
}],
['Hks_Concurrency_Test_01000', async function() {
await hks.deleteKey ('alias010', emptyOption);
}],
['Hks_Concurrency_Test_01100', async function() {
await hks.deleteKey ('alias011', emptyOption);
}],
['Hks_Concurrency_Test_01200', async function() {
await hks.deleteKey ('alias012', emptyOption);
}],
['Hks_Concurrency_Test_01300', async function() {
await hks.deleteKey ('alias013', emptyOption);
}],
['Hks_Concurrency_Test_01400', async function() {
await hks.deleteKey ('alias014', emptyOption);
}],
['Hks_Concurrency_Test_01500', async function() {
await hks.deleteKey ('alias015', emptyOption);
}],
['Hks_Concurrency_Test_01600', async function() {
await hks.deleteKey ('alias016', emptyOption);
}],
['Hks_Concurrency_Test_01700', async function() {
await hks.deleteKey ('alias017', emptyOption);
}],
['Hks_Concurrency_Test_01800', async function() {
await hks.deleteKey (aliasA, emptyOption);
await hks.deleteKey (aliasB, emptyOption);
}],
['Hks_Concurrency_Test_01900', async function() {
await hks.deleteKey (aliasA, emptyOption);
await hks.deleteKey (aliasB, emptyOption);
}],
['Hks_Concurrency_Test_02000', async function() {
await hks.deleteKey ('alias020', emptyOption);
}],
['Hks_Concurrency_Test_02100', async function() {
await hks.deleteKey ('alias021', emptyOption);
}]
]);
async function doClear (caseId, done) {
if (workerStatus1 && workerStatus2) {
var testFunction = clearActionMap.get(caseId);
if (testFunction != null) {
testFunction();
} else {
console.log ('hksConcurrencyTest default check:' + caseId);
}
done();
}
}
/**
* @tc.number HUKS_Concurrency_Test_00100
* @tc.name Concurrency_Test_GenerateKey_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00100', 0, async function (done) {
doConcurrencyTest ('Hks_Concurrency_Test_00100', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00200
* @tc.name Concurrency_Test_GenerateKey_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00200', 0, async function (done) {
doConcurrencyTest ('Hks_Concurrency_Test_00200', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00300
* @tc.name Concurrency_Test_DeleteKey_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00300', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias003', generateAes128KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_00300', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00400
* @tc.name Concurrency_Test_DeleteKey_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00400', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias004', generateAes128KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_00400', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00500
* @tc.name Concurrency_Test_Encrypt_Decrypt_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00500', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias005', generateAes128KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_00500', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00600
* @tc.name Concurrency_Test_Encrypt_Decrypt_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00600', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias006', generateAes128KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_00600', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00700
* @tc.name Concurrency_Test_GetSdkVersion
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00700', 0, async function (done) {
doConcurrencyTest ('Hks_Concurrency_Test_00700', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00800
* @tc.name Concurrency_Test_ImportKey_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00800', 0, async function (done) {
var generateKeyResult = await hks.generateKey (aliasA, generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_00800', done);
});
/**
* @tc.number HUKS_Concurrency_Test_00900
* @tc.name Concurrency_Test_ImportKey_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_00900', 0, async function (done) {
var generateKeyResult = await hks.generateKey (aliasA, generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_00900', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01000
* @tc.name Concurrency_Test_ExportKey_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01000', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias010', generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01000', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01100
* @tc.name Concurrency_Test_ExportKey_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01100', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias011', generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01100', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01200
* @tc.name Concurrency_Test_GetKeyProperties_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01200', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias012', generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01200', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01300
* @tc.name Concurrency_Test_GetKeyProperties_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01300', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias013', generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01300', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01400
* @tc.name Concurrency_Test_IsKeyExist_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01400', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias014', generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01400', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01500
* @tc.name Concurrency_Test_IsKeyExist_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01500', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias015', generateRsa512KeyOpt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01500', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01600
* @tc.name Concurrency_Test_Sign_Verify_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01600', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias016', generateEcc224Opt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01600', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01700
* @tc.name Concurrency_Test_Sign_Verify_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01700', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias017', generateEcc224Opt);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01700', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01800
* @tc.name Concurrency_Test_Agree_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01800', 0, async function (done) {
var generateKeyResult = await hks.generateKey (aliasA, generateAgreeKeyOption);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
generateKeyResult = await hks.generateKey (aliasB, generateAgreeKeyOption);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01800', done);
});
/**
* @tc.number HUKS_Concurrency_Test_01900
* @tc.name Concurrency_Test_Agree_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_01900', 0, async function (done) {
var generateKeyResult = await hks.generateKey (aliasA, generateAgreeKeyOption);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
generateKeyResult = await hks.generateKey (aliasB, generateAgreeKeyOption);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_01900', done);
});
/**
* @tc.number HUKS_Concurrency_Test_02000
* @tc.name Concurrency_Test_Mac_Promise
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_02000', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias020', generateMacKeyOption);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_02000', done);
});
/**
* @tc.number HUKS_Concurrency_Test_02100
* @tc.name Concurrency_Test_Mac_Callback
* @tc.desc Test for APP Concurrency.
*/
it ('Hks_Concurrency_Test_02100', 0, async function (done) {
var generateKeyResult = await hks.generateKey ('alias021', generateMacKeyOption);
expect (generateKeyResult.errorCode).assertEqual (hks.HksErrorCode.HKS_SUCCESS);
doConcurrencyTest ('Hks_Concurrency_Test_02100', done);
});
});
\ No newline at end of file
{
"description": "Configuration for js timing test",
"driver": {
"type": "JSUnitTest",
"test-timeout": "900000",
"package": "com.example.huksjstiming",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsHuksJSTimingTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
/*
* Copyright (C) 2021 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');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (C) 2021 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 file from '@system.file';
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index';
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
this.title = 'JSAPI_1000';
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
});
const reportExtend = new ReportExtend(file);
core.addService('expect', expectExtend);
core.addService('report', reportExtend);
core.init();
const configService = core.getDefaultService('config');
this.timeout = 5000000;
configService.setConfig(this);
require('../../../test/hks_jsApi_timing.test.js');
core.execute();
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import huks from '@ohos.security.huks'
import {describe, it, expect} from 'deccjsunit/index'
describe('HKS_JSAPI_TIMING', function () {
var loop = 1000;
var emptyOption = makeEmptyOptions();
var sumGenerateKeyTiming = 0;
var sumDeleteKeyTiming = 0;
var sumGetKeyPropertiesTiming = 0;
var sumExportTiming = 0;
var sumImportTiming = 0;
var sumEncryptTiming = 0;
var sumDecryptTiming = 0;
var cipherTextArr = new Array();
var sumIsKeyExistTiming = 0;
var sumSignTiming = 0;
var sumVerifyTiming = 0;
var defaultAliasA = 'defaultAliasA';
var defaultAliasB = 'defaultAliasB';
var signedText = [];
var publicKey = [];
var sumAgreeTiming = 0;
var sumDeriveKeyTiming = 0;
var sumMacTiming = 0;
var geAesKeyProperties = makeAesKeyOption();
function makeEmptyOptions() {
var emptyOptions = {
properties: []
};
return emptyOptions;
};
function makeGenerateRSAKeyOptions() {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_RSA
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_RSA_KEY_SIZE_512
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_PKCS1_V1_5
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_MD5
};
var options = {
properties: properties
};
return options;
};
function makeAesKeyOption(){
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_AES
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_AES_KEY_SIZE_128
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_NONE
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_BLOCK_MODE,
value: huks.HksCipherMode.HKS_MODE_CBC
};
return properties;
}
function makeRsaKeyOption(){
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_RSA
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_RSA_KEY_SIZE_512
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_NONE
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_BLOCK_MODE,
value: huks.HksCipherMode.HKS_MODE_ECB
};
properties[5] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_NONE
};
properties[6] = {
tag: huks.HksTag.HKS_TAG_KEY_GENERATE_TYPE,
value: huks.HksKeyGenerateType.HKS_KEY_GENERATE_TYPE_DEFAULT
};
return properties;
}
function makeEccKeyOption(){
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_ECC
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_ECC_KEY_SIZE_224
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_AGREE
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_NONE
};
return properties;
};
function makeDriveKeyOption(){
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_AES
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_AES_KEY_SIZE_128
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_DERIVE
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_NONE
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_BLOCK_MODE,
value: huks.HksCipherMode.HKS_MODE_CBC
};
properties[5] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_SHA256
};
return properties;
};
function makeMacKeyOption(){
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_HMAC
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_SHA1
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_KEY_TYPE,
value: huks.HksKeyType.HKS_KEY_TYPE_HMAC
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: 160
};
return properties;
};
function makeGenerateKeyOption(alg) {
if (alg == huks.HksKeyAlg.HKS_ALG_AES) {
var option = {
properties: geAesKeyProperties
};
return option;
} else if (alg == huks.HksKeyAlg.HKS_ALG_RSA){
var option = {
properties: makeRsaKeyOption()
};
return option;
} else if (alg == huks.HksKeyAlg.HKS_ALG_ECC){
var option = {
properties: makeEccKeyOption()
};
return option;
} else if (alg == huks.HksKeyAlg.HKS_ALG_HMAC){
var option = {
properties: makeMacKeyOption()
};
return option;
} else if (alg == 'DERIVE_AES_KEY'){
var option = {
properties: makeDriveKeyOption()
};
return option;
} else {
return -1;
}
};
function makeRandomArr(size) {
var arr = new Uint8Array(size);
for (var i = 0; i < size; i++) {
arr[i] = Math.floor(Math.random() * 10);
}
return arr;
};
function makeEncryptOption(plainText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_AES
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_BLOCK_MODE,
value: huks.HksCipherMode.HKS_MODE_CBC
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_NONE
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_IV,
value: new Uint8Array(16)
};
var options = {
properties: properties,
inData: plainText
};
return options;
};
function makeDecryptOption(cipherText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_AES,
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_BLOCK_MODE,
value: huks.HksCipherMode.HKS_MODE_CBC
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_NONE
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_IV,
value: new Uint8Array(16)
};
var options = {
properties: properties,
inData: cipherText
};
return options;
};
function deleteKeyByAlias(alias, done) {
huks.deleteKey(alias, emptyOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
done();
});
};
function makeImportOption(importText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_RSA
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_RSA_KEY_SIZE_512
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_NONE
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_BLOCK_MODE,
value: huks.HksCipherMode.HKS_MODE_ECB
};
properties[5] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_NONE
};
properties[6] = {
tag: huks.HksTag.HKS_TAG_KEY_GENERATE_TYPE,
value: huks.HksKeyGenerateType.HKS_KEY_GENERATE_TYPE_DEFAULT
};
var options = {
properties: properties,
inData: importText
};
return options;
};
function getKeyPropertiesCallback(index, done) {
var timestampStart = (new Date()).valueOf();
huks.getKeyProperties('alias', emptyOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumGetKeyPropertiesTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
console.info('getKeyProperties callback index ' + index);
if (index == loop) {
var averageTimeGetProperties = sumGetKeyPropertiesTiming / loop;
console.info('jsApi timing get key properties callback, average time: ' + averageTimeGetProperties);
deleteKeyByAlias('alias', done);
} else {
getKeyPropertiesCallback(index, done);
}
});
};
function deleteExportAndImportKey(done) {
huks.deleteKey('alias_', emptyOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteKeyByAlias('alias', done);
});
};
function encryptCallback(index, encryptOption, done) {
console.info('encrypt callback index ' + index);
var timestampStart = (new Date()).valueOf();
huks.encrypt('alias', encryptOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('encrypt callback time consuming ' + consuming);
sumEncryptTiming += consuming;
cipherTextArr.push(data.outData);
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeEncrypt = sumEncryptTiming / loop;
console.info('jsApi timing encrypt callback, average time: ' + averageTimeEncrypt);
decryptCallback(0, done);
} else {
encryptCallback(index, encryptOption, done);
}
});
};
function decryptCallback(index, done) {
console.info('decrypt callback index ' + index);
var decryptOption = makeDecryptOption(cipherTextArr[index]);
var timestampStart = (new Date()).valueOf();
huks.decrypt('alias', decryptOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('decrypt callback time consuming ' + consuming);
sumDecryptTiming += consuming;
index++;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (index == loop) {
var averageTimeDecrypt = sumDecryptTiming / loop;
console.info('jsApi timing decrypt callback, average time: ' + averageTimeDecrypt);
deleteKeyByAlias('alias', done);
} else {
decryptCallback(index, done);
}
});
};
function exportCallback(index, done) {
console.info('export key callback index ' + index);
var timestampStart = (new Date()).valueOf();
huks.exportKey('alias', emptyOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('exportKey callback time consuming ' + consuming);
sumExportTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
console.info('exportKey callback outData ' + JSON.stringify(data));
publicKey = data.outData;
index++;
importCallback(index, done);
});
};
function importCallback(index, done) {
console.info('import key callback index ' + index);
var timestampStart = (new Date()).valueOf();
var importOption = makeImportOption(publicKey);
console.info('import callback option ' + JSON.stringify(importOption));
huks.importKey('alias_', importOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('importKey callback time consuming ' + consuming);
sumImportTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeExportKey = sumExportTiming / loop;
console.info('jsApi timing export key callback, average time: ' + averageTimeExportKey);
var averageTimeImportKey = sumImportTiming / loop;
console.info('jsApi timing import key callback, average time: ' + averageTimeImportKey);
deleteExportAndImportKey(done);
} else {
exportCallback(index, done);
}
});
};
function isKeyExistCallback(index, done) {
console.info('isKeyExist promise index ' + index);
var timestampStart = (new Date()).valueOf();
huks.isKeyExist('alias', emptyOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumIsKeyExistTiming += consuming;
expect(data).assertEqual(true);
index++;
if (index == loop) {
var averageTimeIsKeyExist = sumIsKeyExistTiming / loop;
console.info('jsApi timing isKeyExist callback, average time: ' + averageTimeIsKeyExist);
deleteKeyByAlias('alias', done);
} else {
isKeyExistCallback(index, done)
}
});
};
function makeSignOptions(plainText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_RSA
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_RSA_KEY_SIZE_512
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_PKCS1_V1_5
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_MD5
};
var options = {
properties: properties,
inData: plainText
};
return options;
};
function makeImportOptions(importText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_RSA
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_RSA_KEY_SIZE_512
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_PKCS1_V1_5
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_MD5
};
var options = {
properties: properties,
inData: importText
};
return options;
};
function makeVerifyOptions(cipherText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_RSA
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_RSA_KEY_SIZE_512
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_PADDING,
value: huks.HksKeyPadding.HKS_PADDING_PKCS1_V1_5
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_MD5
};
var options = {
properties: properties,
inData: cipherText
};
return options;
};
function deleteAliasA(done) {
huks.deleteKey(defaultAliasA, emptyOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteAliasB(done);
});
};
function deleteAliasB(done) {
huks.deleteKey(defaultAliasB, emptyOption, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
done();
});
};
function verifyCallback(index, plainText, done) {
var timestampStart = (new Date()).valueOf();
var verifyOptions = makeVerifyOptions(plainText);
huks.verify(defaultAliasB, verifyOptions, signedText, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumVerifyTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeSign = sumSignTiming / loop;
console.info('jsApi timing sign callback, average time: ' + averageTimeSign);
var averageTimeVerify = sumVerifyTiming / loop;
console.info('jsApi timing verify callback, average time: ' + averageTimeVerify);
deleteAliasA(done);
} else {
signCallback(index, done);
}
});
};
function signCallback(index, done) {
console.info('sign and verify callback index ' + index);
var plainText = makeRandomArr(16);
var signOptions = makeSignOptions(plainText);
var timestampStart = (new Date()).valueOf();
huks.sign(defaultAliasA, signOptions, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumSignTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
signedText = data.outData;
verifyCallback(index, plainText, done);
});
};
function makeAgreeOptions(publicKey) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_ECDH
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: huks.HksKeySize.HKS_ECC_KEY_SIZE_224
};
var options = {
properties: properties,
inData: publicKey
};
return options;
};
function agreeCallback(index, option, done) {
console.info('agree callback index ' + index);
var timestampStart = (new Date()).valueOf();
huks.agreeKey(defaultAliasA, option, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumAgreeTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeAgree = sumAgreeTiming / loop;
console.info('jsApi timing agree callback, average time: ' + averageTimeAgree);
done();
} else {
agreeCallback(index, option, done);
}
});
};
function makeHKDFDeriveOption() {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_HKDF
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_DERIVE
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_SHA256
};
var options = {
properties: properties
};
return options;
};
function deriveKeyCallback(index, option, done) {
console.info('agree callback index ' + index);
var timestampStart = (new Date()).valueOf();
huks.deriveKey('alias', option, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumDeriveKeyTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeDeriveKey = sumDeriveKeyTiming / loop;
console.info('jsApi timing deriveKey callback, average time: ' + averageTimeDeriveKey);
deleteKeyByAlias('alias', done);
} else {
deriveKeyCallback(index, option, done);
}
});
};
function makeMacOption(plainText) {
var properties = new Array();
properties[0] = {
tag: huks.HksTag.HKS_TAG_ALGORITHM,
value: huks.HksKeyAlg.HKS_ALG_HMAC
};
properties[1] = {
tag: huks.HksTag.HKS_TAG_PURPOSE,
value: huks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC
};
properties[2] = {
tag: huks.HksTag.HKS_TAG_DIGEST,
value: huks.HksKeyDigest.HKS_DIGEST_SHA1
};
properties[3] = {
tag: huks.HksTag.HKS_TAG_KEY_TYPE,
value: huks.HksKeyType.HKS_KEY_TYPE_HMAC
};
properties[4] = {
tag: huks.HksTag.HKS_TAG_KEY_SIZE,
value: 160
};
properties[5] = {
tag: huks.HksTag.HKS_TAG_IV,
value: new Uint8Array(16)
};
var options = {
properties: properties,
inData: plainText
};
return options;
};
function deleteKeyCallback(index, option, done) {
var timestampStart = (new Date()).valueOf();
huks.deleteKey('alias', emptyOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumDeleteKeyTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeGenKey = sumGenerateKeyTiming / loop;
console.info('jsApi timing generateKey callback, average time: ' + averageTimeGenKey);
var averageTimeDelKey = sumDeleteKeyTiming / loop;
console.info('jsApi timing deleteKey callback, average time: ' + averageTimeDelKey);
done();
} else {
generateKeyCallback(index, option, done)
}
});
};
function generateKeyCallback(index, option, done) {
var timestampStart = (new Date()).valueOf();
huks.generateKey('alias', option, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumGenerateKeyTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteKeyCallback(index, option, done);
});
};
/**
* @tc.number HKS_JSAPI_TIMING_00100
* @tc.name HKS_JSAPI_TIMING_GenerateAndDeleteKey_Promise
* @tc.desc jsApi timing test for generate key and delete key by promise
*/
it('HKS_JSAPI_TIMING_00100', 0, async function (done) {
var sumGenerateKeyTiming = 0;
var sumDeleteKeyTiming = 0;
var option = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
for (let index = 1; index <= loop; index++) {
console.info('generate and delete key promise index ' + index);
var timestampStart = (new Date()).valueOf();
var result = await huks.generateKey('alias', option);
var timestampEnd = (new Date()).valueOf();
expect(result.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var consuming = timestampEnd - timestampStart;
sumGenerateKeyTiming += consuming;
timestampStart = (new Date()).valueOf();
result = await huks.deleteKey('alias', emptyOption);
timestampEnd = (new Date()).valueOf();
expect(result.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
consuming = timestampEnd - timestampStart;
sumDeleteKeyTiming += consuming;
}
var averageTimeGenKey = sumGenerateKeyTiming / loop;
console.info('jsApi timing generateKey promise, average time: ' + averageTimeGenKey);
var averageTimeDelKey = sumDeleteKeyTiming / loop;
console.info('jsApi timing deleteKey promise, average time: ' + averageTimeDelKey);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_00200
* @tc.name HKS_JSAPI_TIMING_GenerateAndDeleteKey_Callback
* @tc.desc jsApi timing test for generate key and delete key by callback
*/
it('HKS_JSAPI_TIMING_00200', 0, async function (done) {
sumGenerateKeyTiming = 0;
sumDeleteKeyTiming = 0;
var option = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
generateKeyCallback(0, option, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_00300
* @tc.name HKS_JSAPI_TIMING_EncryptAndDecrypt_Promise
* @tc.desc jsApi timing test for encrypt and decrypt by promise
*/
it('HKS_JSAPI_TIMING_00300', 0, async function (done) {
var sumEncryptTiming = 0;
var sumDecryptTiming = 0;
var genKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', genKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var plainText = makeRandomArr(64);
var encryptOption = makeEncryptOption(plainText);
for (let index = 1; index <= loop; index++) {
console.info('encrypt and decrypt promise index ' + index);
var timestampStart = (new Date()).valueOf();
var encryptRet = await huks.encrypt('alias', encryptOption);
expect(encryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
console.info('encrypt and decrypt promise encryptRet ' + JSON.stringify(encryptRet));
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('encrypt promise time consuming ' + consuming);
sumEncryptTiming += consuming;
var decryptOption = makeDecryptOption(encryptRet.outData);
timestampStart = (new Date()).valueOf();
var decryptRet = await huks.decrypt('alias', decryptOption);
timestampEnd = (new Date()).valueOf();
consuming = timestampEnd - timestampStart;
console.info('decrypt pormise time consuming ' + consuming);
sumDecryptTiming += consuming;
expect(decryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(decryptRet.outData));
}
var delRet = await huks.deleteKey('alias', emptyOption);
expect(delRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var averageTimeEncrypt = sumEncryptTiming / loop;
var averageTimeDecrypt = sumDecryptTiming / loop;
console.info('jsApi timing encrypt promise, average time: ' + averageTimeEncrypt);
console.info('jsApi timing decrypt promise, average time: ' + averageTimeDecrypt);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_00400
* @tc.name HKS_JSAPI_TIMING_EncryptAndDecrypt_Callback
* @tc.desc jsApi timing test for encrypt and decrypt by callback
*/
it('HKS_JSAPI_TIMING_00400', 0, async function (done) {
var genKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', genKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var plainText = makeRandomArr(64);
var encryptOption = makeEncryptOption(plainText);
encryptCallback(0, encryptOption, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_00500
* @tc.name HKS_JSAPI_TIMING_GetSdkVersion
* @tc.desc jsApi timing test for getSdkVersion
*/
it('HKS_JSAPI_TIMING_00500', 0, async function (done) {
var sunGetSdkVersionTiming = 0;
var genKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', genKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var timestampStart = (new Date()).valueOf();
var sdkVersion = await huks.getSdkVersion(emptyOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('getSdkVersion time consuming ' + consuming);
sunGetSdkVersionTiming += consuming;
var result = false;
if (sdkVersion.length > 0) {
result = true;
}
expect(result).assertEqual(true);
var averageTimeGetSdkVersion = sunGetSdkVersionTiming / loop;
console.info('jsApi timing getSdkVersion, average time: ' + averageTimeGetSdkVersion);
var delRet = await huks.deleteKey('alias', emptyOption);
expect(delRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_00600
* @tc.name HKS_JSAPI_TIMING_ImportAndExport_Promise
* @tc.desc jsApi timing test for import and export by promise
*/
it('HKS_JSAPI_TIMING_00600', 0, async function (done) {
sumExportTiming = 0;
sumImportTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_RSA);
for (let index = 1; index <= loop; index++) {
console.info('generate key,export key,import key promise index ' + index);
var genKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var timestampStart = (new Date()).valueOf();
var exportRet = await huks.exportKey('alias', emptyOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('export promise time consuming ' + consuming);
sumExportTiming += consuming;
expect(exportRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var importOption = makeImportOption(exportRet.outData);
timestampStart = (new Date()).valueOf();
var importRet = await huks.importKey('alias_', importOption);
timestampEnd = (new Date()).valueOf();
consuming = timestampEnd - timestampStart;
console.info('import promise time consuming ' + consuming);
sumImportTiming += consuming;
expect(importRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var delKeyRet = await huks.deleteKey('alias', emptyOption);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
delKeyRet = await huks.deleteKey('alias_', emptyOption);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
var averageTimeExportKey = sumExportTiming / loop;
console.info('jsApi timing export key promise, average time: ' + averageTimeExportKey);
var averageTimeImportKey = sumImportTiming / loop;
console.info('jsApi timing import key promise, average time: ' + averageTimeImportKey);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_00700
* @tc.name HKS_JSAPI_TIMING_ImportAndExport_Callback
* @tc.desc jsApi timing test for import and export by callback
*/
it('HKS_JSAPI_TIMING_00700', 0, async function (done) {
sumExportTiming = 0;
sumImportTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_RSA);
var genKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
exportCallback(0, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_00800
* @tc.name HKS_JSAPI_TIMING_GetKeyProperties_Promise
* @tc.desc jsApi timing test for getKeyProperties promise
*/
it('HKS_JSAPI_TIMING_00800', 0, async function (done) {
sumGetKeyPropertiesTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
for (let index = 1; index <= loop; index++) {
console.info('get key properties promise index ' + index);
var timestampStart = (new Date()).valueOf();
var getKeyPropertiesRet = await huks.getKeyProperties('alias', emptyOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('getKeyProperties promise time consuming ' + consuming);
sumGetKeyPropertiesTiming += consuming;
expect(getKeyPropertiesRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
var averageTimeGetProperties = sumGetKeyPropertiesTiming / loop;
console.info('jsApi timing get key properties promise, average time: ' + averageTimeGetProperties);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_00900
* @tc.name HKS_JSAPI_TIMING_GetKeyProperties_Callback
* @tc.desc jsApi timing test for getKeyProperties callback
*/
it('HKS_JSAPI_TIMING_00900', 0, async function (done) {
sumGetKeyPropertiesTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
getKeyPropertiesCallback(0, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_01000
* @tc.name HKS_JSAPI_TIMING_IsKeyExist_Promise
* @tc.desc jsApi timing test for isKeyExist promise
*/
it('HKS_JSAPI_TIMING_01000', 0, async function (done) {
sumIsKeyExistTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
for (let index = 1; index <= loop; index++) {
console.info('isKeyExist promise index ' + index);
var timestampStart = (new Date()).valueOf();
var isKeyExistRet = await huks.isKeyExist('alias', emptyOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
console.info('isKeyExist promise time consuming ' + consuming);
sumIsKeyExistTiming += consuming;
expect(isKeyExistRet).assertEqual(true);
}
var delKeyRet = await huks.deleteKey('alias', emptyOption);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var averageTimeIsKeyExist = sumIsKeyExistTiming / loop;
console.info('jsApi timing isKeyExist promise, average time: ' + averageTimeIsKeyExist);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_01100
* @tc.name HKS_JSAPI_TIMING_IsKeyExist_Callback
* @tc.desc jsApi timing test for isKeyExist callback
*/
it('HKS_JSAPI_TIMING_01100', 0, async function (done) {
sumIsKeyExistTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_AES);
var genKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyExistCallback(0, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_01200
* @tc.name HKS_JSAPI_TIMING_SignAndVerify_Promise
* @tc.desc jsApi timing test for sign and verify promise
*/
it('HKS_JSAPI_TIMING_01200', 0, async function (done) {
sumSignTiming = 0;
sumVerifyTiming = 0;
var generateKeyOption = makeGenerateRSAKeyOptions();
var generateKeyRet = await huks.generateKey(defaultAliasA, generateKeyOption);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyRet = await huks.exportKey(defaultAliasA, emptyOption);
expect(exportKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKey = exportKeyRet.outData;
var importOptions = makeImportOptions(publicKey);
var importKeyRet = await huks.importKey(defaultAliasB, importOptions);
expect(importKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
for (let index = 1; index <= loop; index++) {
console.info('sign and verify promise index ' + index);
var plainText = makeRandomArr(16);
var signOptions = makeSignOptions(plainText);
var timestampStart = (new Date()).valueOf();
var signRet = await huks.sign(defaultAliasA, signOptions);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumSignTiming += consuming;
expect(signRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
signedText = signRet.outData;
var verifyOptions = makeVerifyOptions(plainText);
timestampStart = (new Date()).valueOf();
var verifyRet = await huks.verify(defaultAliasB, verifyOptions, signedText);
timestampEnd = (new Date()).valueOf();
consuming = timestampEnd - timestampStart;
sumVerifyTiming += consuming;
expect(verifyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
var deleteKeyAliasA = await huks.deleteKey(defaultAliasA, emptyOption);
var deleteKeyAliasB = await huks.deleteKey(defaultAliasB, emptyOption);
expect(deleteKeyAliasA.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(deleteKeyAliasB.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var averageTimeSign = sumSignTiming / loop;
console.info('jsApi timing sign promise, average time: ' + averageTimeSign);
var averageTimeVerify = sumVerifyTiming / loop;
console.info('jsApi timing verify promise, average time: ' + averageTimeVerify);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_01300
* @tc.name HKS_JSAPI_TIMING_SignAndVerify_Callback
* @tc.desc jsApi timing test for sign and verify callback
*/
it('HKS_JSAPI_TIMING_01300', 0, async function (done) {
sumSignTiming = 0;
sumVerifyTiming = 0;
var generateKeyOption = makeGenerateRSAKeyOptions();
var generateKeyRet = await huks.generateKey(defaultAliasA, generateKeyOption);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyRet = await huks.exportKey(defaultAliasA, emptyOption);
expect(exportKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKey = exportKeyRet.outData;
var importOptions = makeImportOptions(publicKey);
var importKeyRet = await huks.importKey(defaultAliasB, importOptions);
expect(importKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
signCallback(0, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_01400
* @tc.name HKS_JSAPI_TIMING_AgreeKey_Promise
* @tc.desc jsApi timing test for agree promise
*/
it('HKS_JSAPI_TIMING_01400', 0, async function (done) {
sumAgreeTiming = 0;
var generateKeyAOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_ECC);
var generateKeyARet = await huks.generateKey(defaultAliasA, generateKeyAOption);
expect(generateKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var generateKeyBOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_ECC);
var generateKeyBRet = await huks.generateKey(defaultAliasB, generateKeyBOption);
expect(generateKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyBRet = await huks.exportKey(defaultAliasB, emptyOption);
publicKey = exportKeyBRet.outData;
var agreeKeyAOption = makeAgreeOptions(publicKey);
for (let index = 1; index <= loop; index++) {
console.info('agree promise index ' + index);
var timestampStart = (new Date()).valueOf();
var agreeKeyARet = await huks.agreeKey(defaultAliasA, agreeKeyAOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumAgreeTiming += consuming;
expect(agreeKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
var averageTimeAgree = sumAgreeTiming / loop;
console.info('jsApi timing agree promise, average time: ' + averageTimeAgree);
var deleteKeyARet = await huks.deleteKey(defaultAliasA, emptyOption);
expect(deleteKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var deleteKeyBRet = await huks.deleteKey(defaultAliasB, emptyOption);
expect(deleteKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
done();
});
/**
* @tc.number HKS_JSAPI_TIMING_01500
* @tc.name HKS_JSAPI_TIMING_AgreeKey_Callback
* @tc.desc jsApi timing test for agree callback
*/
it('HKS_JSAPI_TIMING_01500', 0, async function (done) {
sumAgreeTiming = 0;
var generateKeyAOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_ECC);
var generateKeyARet = await huks.generateKey(defaultAliasA, generateKeyAOption);
expect(generateKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var generateKeyBOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_ECC);
var generateKeyBRet = await huks.generateKey(defaultAliasB, generateKeyBOption);
expect(generateKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyBRet = await huks.exportKey(defaultAliasB, emptyOption);
publicKey = exportKeyBRet.outData;
var agreeKeyAOption = makeAgreeOptions(publicKey);
agreeCallback(0, agreeKeyAOption, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_01600
* @tc.name HKS_JSAPI_TIMING_DeriveKey_Promise
* @tc.desc jsApi timing test for deriveKey promise
*/
it('HKS_JSAPI_TIMING_01600', 0, async function (done) {
sumDeriveKeyTiming = 0;
var generateKeyOption = makeGenerateKeyOption('DERIVE_AES_KEY');
var generateKeyResult = await huks.generateKey('alias', generateKeyOption);
expect(generateKeyResult.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var deriveKeyOption = makeHKDFDeriveOption();
for (let index = 1; index <= loop; index++) {
console.info('agree promise index ' + index);
var timestampStart = (new Date()).valueOf();
var deriveKeyResult = await huks.deriveKey('alias', deriveKeyOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumDeriveKeyTiming += consuming;
expect(deriveKeyResult.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
var averageTimeDeriveKey = sumDeriveKeyTiming / loop;
console.info('jsApi timing deriveKey promise, average time: ' + averageTimeDeriveKey);
deleteKeyByAlias('alias', done);
});
/**
* @tc.number HKS_JSAPI_TIMING_01700
* @tc.name HKS_JSAPI_TIMING_DeriveKey_Callback
* @tc.desc jsApi timing test for deriveKey promise
*/
it('HKS_JSAPI_TIMING_01700', 0, async function (done) {
sumDeriveKeyTiming = 0;
var generateKeyOption = makeGenerateKeyOption('DERIVE_AES_KEY');
var generateKeyResult = await huks.generateKey('alias', generateKeyOption);
expect(generateKeyResult.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var deriveKeyOption = makeHKDFDeriveOption();
deriveKeyCallback(0, deriveKeyOption, done);
});
/**
* @tc.number HKS_JSAPI_TIMING_01800
* @tc.name HKS_JSAPI_TIMING_Mac_Promise
* @tc.desc jsApi timing test for mac promise
*/
it('HKS_JSAPI_TIMING_01800', 0, async function (done) {
sumMacTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_HMAC);
var generateKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
for (let index = 1; index <= loop; index++) {
console.info('mac promise index ' + index);
var plainText = makeRandomArr(64);
var macOption = makeMacOption(plainText);
var timestampStart = (new Date()).valueOf();
var macRet = await huks.mac('alias', macOption);
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumMacTiming += consuming;
expect(macRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
}
var averageTimeMac = sumMacTiming / loop;
console.info('jsApi timing mac promise, average time: ' + averageTimeMac);
deleteKeyByAlias('alias', done);
});
function macCallback(index, done) {
var plainText = makeRandomArr(64);
var macOption = makeMacOption(plainText);
var timestampStart = (new Date()).valueOf();
huks.mac('alias', macOption, function (err, data) {
var timestampEnd = (new Date()).valueOf();
var consuming = timestampEnd - timestampStart;
sumMacTiming += consuming;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
index++;
if (index == loop) {
var averageTimeMac = sumMacTiming / loop;
console.info('jsApi timing mac callback, average time: ' + averageTimeMac);
deleteKeyByAlias('alias', done);
} else {
macCallback(index, done);
}
});
};
/**
* @tc.number HKS_JSAPI_TIMING_01900
* @tc.name HKS_JSAPI_TIMING_Mac_Callback
* @tc.desc jsApi timing test for mac callback
*/
it('HKS_JSAPI_TIMING_01900', 0, async function (done) {
sumMacTiming = 0;
var generateKeyOption = makeGenerateKeyOption(huks.HksKeyAlg.HKS_ALG_HMAC);
var generateKeyRet = await huks.generateKey('alias', generateKeyOption);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
macCallback(0, done);
});
});
\ No newline at end of file
{
"description": "Configuration for huks stress test",
"driver": {
"type": "JSUnitTest",
"test-timeout": "23000000",
"package": "com.example.huksstresstest",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsHuksStressTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.example.huksstresstest",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5,
"releaseType": "Beta1"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.huksstresstest",
"name": ".MyApplication",
"mainAbility": "com.example.huksstresstest.MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.example.huksstresstest.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "singleton",
"visible": true,
"isVisible": "true"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
}
}
\ No newline at end of file
/*
* Copyright (C) 2021 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');
}
};
{
"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;
}
.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) 2021 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 file from '@system.file';
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index';
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
const core = Core.getInstance();
const expectExtend = new ExpectExtend({
'id': 'extend'
});
const reportExtend = new ReportExtend(file);
core.addService('expect', expectExtend);
core.addService('report', reportExtend);
core.init();
const configService = core.getDefaultService('config');
this.timeout = 23400000;
configService.setConfig(this);
require('../../../test/hks_jsApi_stressTest.test.js');
core.execute();
}
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import huks from '@ohos.security.huks'
import {describe, it, expect} from 'deccjsunit/index'
import {
emptyOption,
makeMacOption,
makeAgreeOptions,
makeEncryptAndDecryptOption,
makeGenerateKeyOption,
makeImportOption,
makeRandomArr,
makeSignAndVerifyOption
} from '../../../../../../hks_xts_common.test'
describe('HKS_JSAPI_STRESS_TEST', function () {
var executionHour = 0.61;
var executionTime = 3600 * 1000 * executionHour;
var plainText = makeRandomArr(64);
var signText = makeRandomArr(16);
var alias = 'alias';
var aliasA = 'aliasA';
var aliasB = 'aliasB';
var publicKey = [];
var signedText = [];
var publicKeyA = [];
var publicKeyB = [];
var aesKeyOption = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeySize.HKS_AES_KEY_SIZE_128,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null
);
var rsaKeyOption = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var eccKeyOption = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var ecdhKeyOption = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_AGREE,
null,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE
);
var macKeyOption = makeGenerateKeyOption(
huks.HksKeyAlg.HKS_ALG_HMAC,
160,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_MAC,
null,
null,
huks.HksKeyDigest.HKS_DIGEST_SHA1
);
var aesEncryptOption = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
plainText
);
var rsaEncryptOption = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyDigest.HKS_DIGEST_NONE,
plainText
);
var signOption = makeSignAndVerifyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksKeyDigest.HKS_DIGEST_NONE,
signText
);
var verifyOption = makeSignAndVerifyOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksKeyDigest.HKS_DIGEST_NONE,
signText
);
var currentCase = '';
function importKey(endTime, index, done){
var option = {};
if (currentCase == '00400') {
option = makeImportOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE,
publicKey
);
} else {
option = makeImportOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE,
publicKey
);
}
huks.importKey(aliasB, option,function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (currentCase == '00400') {
encryptCallback(endTime, index, done);
} else {
signCallback(endTime, index, done);
}
});
};
function verifyCallback(endTime, index, done){
huks.verify(aliasB, verifyOption, signedText, function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteKeyCallback(endTime, index, done);
});
};
function signCallback(endTime, index, done){
huks.sign(aliasA, signOption, function (err,data){
signedText = data.outData;
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
verifyCallback(endTime, index, done);
});
};
function agreeKeyBCallback(endTime, index, done){
var agreeKeyAOption = makeAgreeOptions(publicKeyA);
huks.agreeKey(aliasB, agreeKeyAOption, function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteKeyCallback(endTime, index, done);
});
};
function agreeKeyACallback(endTime, index, done){
var agreeKeyAOption = makeAgreeOptions(publicKeyB);
huks.agreeKey(aliasA, agreeKeyAOption, function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
agreeKeyBCallback(endTime, index, done);
});
};
function exportKeyBCallback(endTime, index, done){
huks.exportKey(aliasB, emptyOption,function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKeyB = data.outData;
agreeKeyACallback(endTime, index, done);
});
};
function exportKeyCallback(endTime, index, done){
huks.exportKey(aliasA, emptyOption,function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (currentCase == '00800') {
publicKeyA = data.outData;
exportKeyBCallback(endTime, index, done);
} else {
publicKey = data.outData;
importKey(endTime, index, done);
}
});
};
function macCallback(endTime, index, done){
var macOption = makeMacOption(plainText);
huks.mac(alias, macOption, function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
deleteKeyCallback(endTime, index, done);
});
};
function generateKeyBCallback(endTime, index, done){
var option = ecdhKeyOption;
huks.generateKey(aliasB, option, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
exportKeyCallback(endTime, index, done);
});
};
function generateKeyCallback(endTime, index, done) {
var currentTime = (new Date()).valueOf();
var tmpAlias = aliasA;
if (currentTime <= endTime) {
var option = {};
if (currentCase == '00200') {
option = aesKeyOption;
tmpAlias = alias;
} else if (currentCase == '00400') {
option = rsaKeyOption;
} else if (currentCase == '00600') {
option = eccKeyOption;
} else if (currentCase == '00800') {
option = ecdhKeyOption;
} else {
tmpAlias = alias;
option = macKeyOption;
}
huks.generateKey(tmpAlias, option, function (err, data) {
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
if (currentCase == '00200') {
encryptCallback(endTime, index, done);
} else if (currentCase == '00800') {
generateKeyBCallback(endTime, index, done);
} else if (currentCase == '01000') {
macCallback(endTime, index, done);
} else {
exportKeyCallback(endTime, index, done);
}
});
} else {
done();
}
};
function isKeyExistCallback(endTime, index, done){
var tmpAlias = '';
if (currentCase == '00200' || currentCase == '01000') {
tmpAlias = alias;
} else {
tmpAlias = aliasA;
}
huks.isKeyExist(tmpAlias,emptyOption,function(err,data){
expect(data).assertEqual(false);
if (currentCase == '00200' || currentCase == '01000') {
index++;
var currentTime = (new Date()).valueOf();
var sumTime = endTime - currentTime;
console.info('HKS_STRESS_TEST_' + currentCase +' Time left ' + sumTime / 1000 + ' s,' + ' index: ' + index);
generateKeyCallback(endTime, index, done);
} else {
deleteKeyBCallback(endTime, index, done);
}
});
};
function isKeyBExistCallback(endTime, index, done){
huks.isKeyExist(aliasB,emptyOption,function(err,data){
expect(data).assertEqual(false);
index++;
var currentTime = (new Date()).valueOf();
var sumTime = endTime - currentTime;
console.info('HKS_STRESS_TEST_' + currentCase +' Time left ' + sumTime / 1000 + ' s,' + ' index: ' + index);
generateKeyCallback(endTime, index, done);
});
};
function deleteKeyBCallback(endTime, index, done){
huks.deleteKey(aliasB,emptyOption,function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyBExistCallback(endTime, index, done);
});
};
function deleteKeyCallback(endTime, index, done){
var tmpAlias = '';
if (currentCase == '00200' || currentCase == '01000') {
tmpAlias = alias;
} else {
tmpAlias = aliasA;
}
huks.deleteKey(tmpAlias,emptyOption,function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
isKeyExistCallback(endTime, index, done);
});
};
function decryptCallback(text, endTime, index, done){
var tmpAlias = '';
var option = {};
if (currentCase == '00200') {
tmpAlias = alias;
option = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
text
);
} else {
tmpAlias = aliasA;
option = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyDigest.HKS_DIGEST_NONE,
text
);
}
huks.decrypt(tmpAlias, option, function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(data.outData));
deleteKeyCallback(endTime, index, done);
});
};
function encryptCallback(endTime, index, done){
var tmpAlias = '';
var option = {};
if (currentCase == '00200') {
tmpAlias = alias;
option = aesEncryptOption;
} else {
tmpAlias = aliasB;
option = rsaEncryptOption;
}
huks.encrypt(tmpAlias, option, function(err,data){
expect(data.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
decryptCallback(data.outData, endTime, index, done);
});
};
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00100
* @tc.name HKS_STRESS_TEST_AES_ENCRYPT_DECRYPT_PROMISE
* @tc.desc stress test for aes encrypt and decrypt with promise
*/
it('HKS_JSAPI_STRESS_TEST_00100', 0, async function (done) {
var startTime = (new Date()).valueOf();
var endTime = startTime + executionTime;
var currentTime = startTime;
var index = 0;
while (currentTime <= endTime) {
currentTime = (new Date()).valueOf();
var genKeyRet = await huks.generateKey(alias, aesKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var encryptRet = await huks.encrypt(alias, aesEncryptOption);
expect(encryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var decryptOption = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_AES,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_CBC,
null,
null,
encryptRet.outData
);
var decryptRet = await huks.decrypt(alias, decryptOption);
expect(decryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(decryptRet.outData));
var delKeyRet = await huks.deleteKey(alias, emptyOption);
expect(delKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExistRet = await huks.isKeyExist(alias, emptyOption);
expect(isKeyExistRet).assertEqual(false);
console.info('HKS_STRESS_TEST_00100 Time left ' + (endTime - currentTime) / 1000 + ' s,' + ' index: ' + index);
index++;
}
done();
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00200
* @tc.name HKS_STRESS_TEST_AES_ENCRYPT_DECRYPT_CALLBACK
* @tc.desc stress test for aes encrypt and decrypt with callback
*/
it('HKS_JSAPI_STRESS_TEST_00200', 0, async function (done) {
currentCase = '00200';
var startTime = (new Date()).valueOf();
var endTime = startTime + executionTime;
var index = 0;
generateKeyCallback(endTime, index, done);
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00300
* @tc.name HKS_STRESS_TEST_RSA_ENCRYPT_DECRYPT_PROMISE
* @tc.desc stress test for rsa encrypt and decrypt with promise
*/
it('HKS_JSAPI_STRESS_TEST_00300', 0, async function (done) {
var currentTime = (new Date()).valueOf();
var endTime = currentTime + executionTime;
var index = 0;
while (currentTime <= endTime) {
currentTime = (new Date()).valueOf();
var genKeyRet = await huks.generateKey(aliasA, rsaKeyOption);
expect(genKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyRet = await huks.exportKey(aliasA, emptyOption);
expect(exportKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKey = exportKeyRet.outData;
var importRsaKeyOpt = makeImportOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeyDigest.HKS_DIGEST_NONE,
publicKey
);
var importRet = await huks.importKey(aliasB, importRsaKeyOpt);
expect(importRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var encryptRet = await huks.encrypt(aliasB, rsaEncryptOption);
expect(encryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var decryptOption = makeEncryptAndDecryptOption(
huks.HksKeyAlg.HKS_ALG_RSA,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
huks.HksKeyPadding.HKS_PADDING_NONE,
huks.HksCipherMode.HKS_MODE_ECB,
huks.HksKeySize.HKS_RSA_KEY_SIZE_512,
huks.HksKeyDigest.HKS_DIGEST_NONE,
encryptRet.outData
);
var decryptRet = await huks.decrypt(aliasA, decryptOption);
expect(decryptRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(plainText)).assertEqual(JSON.stringify(decryptRet.outData));
var delKeyARet = await huks.deleteKey(aliasA, emptyOption);
var delKeyBRet = await huks.deleteKey(aliasB, emptyOption);
expect(delKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(delKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyAExistRet = await huks.isKeyExist(aliasA, emptyOption);
expect(isKeyAExistRet).assertEqual(false);
var isKeyBExistRet = await huks.isKeyExist(aliasB, emptyOption);
expect(isKeyBExistRet).assertEqual(false);
console.info('HKS_STRESS_TEST_00300 Time left ' + (endTime - currentTime) / 1000 + ' s,' + ' index: ' + index);
index++;
}
done();
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00400
* @tc.name HKS_STRESS_TEST_RSA_ENCRYPT_DECRYPT_PROMISE
* @tc.desc stress test for rsa encrypt and decrypt with promise
*/
it('HKS_JSAPI_STRESS_TEST_00400', 0, async function (done) {
currentCase = '00400';
var startTime = (new Date()).valueOf();
var endTime = startTime + executionTime;
var index = 0;
generateKeyCallback(endTime, index, done);
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00500
* @tc.name HKS_STRESS_TEST_ECC_SIGN_VERIFY_PROMISE
* @tc.desc stress test for ecc sign and verify with promise
*/
it('HKS_JSAPI_STRESS_TEST_00500', 0, async function (done) {
var currentTime = (new Date()).valueOf();
var endTime = currentTime + executionTime;
var index = 0;
while (currentTime <= endTime) {
currentTime = (new Date()).valueOf();
var generateKeyRet = await huks.generateKey(aliasA, eccKeyOption);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var signRet = await huks.sign(aliasA, signOption);
expect(signRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
signedText = signRet.outData;
var exportKeyRet = await huks.exportKey(aliasA, emptyOption);
expect(exportKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
publicKey = exportKeyRet.outData;
var importOptions = makeImportOption(
huks.HksKeyAlg.HKS_ALG_ECC,
huks.HksKeySize.HKS_ECC_KEY_SIZE_224,
huks.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
huks.HksKeyPadding.HKS_PADDING_NONE,
null,
huks.HksKeyDigest.HKS_DIGEST_NONE,
publicKey
);
var importKeyRet = await huks.importKey(aliasB, importOptions);
expect(importKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var verifyRet = await huks.verify(aliasB, verifyOption, signedText);
expect(verifyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var deleteKeyAliasA = await huks.deleteKey(aliasA, emptyOption);
var deleteKeyAliasB = await huks.deleteKey(aliasB, emptyOption);
expect(deleteKeyAliasA.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(deleteKeyAliasB.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyAExist = await huks.isKeyExist(aliasA, emptyOption);
expect(isKeyAExist).assertEqual(false);
var isKeyBExist = await huks.isKeyExist(aliasB, emptyOption);
expect(isKeyBExist).assertEqual(false);
console.info('HKS_STRESS_TEST_00500 Time left ' + (endTime - currentTime) / 1000 + ' s,' + ' index: ' + index);
index++;
}
done();
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00600
* @tc.name HKS_STRESS_TEST_ECC_SIGN_VERIFY_CALLBACK
* @tc.desc stress test for ecc sign and verify with callback
*/
it('HKS_JSAPI_STRESS_TEST_00600', 0, async function (done) {
currentCase = '00600';
var startTime = (new Date()).valueOf();
var endTime = startTime + executionTime;
var index = 0;
generateKeyCallback(endTime, index, done);
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00700
* @tc.name HKS_STRESS_TEST_AGREE_VERIFY_PROMISE
* @tc.desc stress test for agree with promise
*/
it('HKS_JSAPI_STRESS_TEST_00700', 0, async function (done) {
var currentTime = (new Date()).valueOf();
var endTime = currentTime + executionTime;
var index = 0;
while (currentTime <= endTime) {
currentTime = (new Date()).valueOf();
var generateKeyARet = await huks.generateKey(aliasA, ecdhKeyOption);
expect(generateKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var generateKeyBRet = await huks.generateKey(aliasB, ecdhKeyOption);
expect(generateKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var exportKeyARet = await huks.exportKey(aliasA, emptyOption);
var exportKeyBRet = await huks.exportKey(aliasB, emptyOption);
publicKeyA = exportKeyARet.outData;
publicKeyB = exportKeyBRet.outData;
var agreeKeyAOption = makeAgreeOptions(publicKeyB);
var agreeKeyARet = await huks.agreeKey(aliasA, agreeKeyAOption);
expect(agreeKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var agreeKeyBOption = makeAgreeOptions(publicKeyA);
var agreeKeyBRet = await huks.agreeKey(aliasB, agreeKeyBOption);
expect(agreeKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
expect(JSON.stringify(agreeKeyARet.outData)).assertEqual(JSON.stringify(agreeKeyBRet.outData));
var deleteKeyARet = await huks.deleteKey(aliasA, emptyOption);
expect(deleteKeyARet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var deleteKeyBRet = await huks.deleteKey(aliasB, emptyOption);
expect(deleteKeyBRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyAExist = await huks.isKeyExist(aliasA, emptyOption);
expect(isKeyAExist).assertEqual(false);
var isKeyBExist = await huks.isKeyExist(aliasB, emptyOption);
expect(isKeyBExist).assertEqual(false);
console.info('HKS_STRESS_TEST_00700 Time left ' + (endTime - currentTime) / 1000 + ' s,' + ' index: ' + index);
index++;
}
done();
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00800
* @tc.name HKS_STRESS_TEST_AGREE_VERIFY_CALLBACK
* @tc.desc stress test for agree with callback
*/
it('HKS_JSAPI_STRESS_TEST_00800', 0, async function (done) {
currentCase = '00800';
var startTime = (new Date()).valueOf();
var endTime = startTime + executionTime;
var index = 0;
generateKeyCallback(endTime, index, done);
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_00900
* @tc.name HKS_STRESS_TEST_MAC_PROMISE
* @tc.desc stress test for mac with promise
*/
it('HKS_JSAPI_STRESS_TEST_00900', 0, async function (done) {
var currentTime = (new Date()).valueOf();
var endTime = currentTime + executionTime;
var index = 0;
while (currentTime <= endTime) {
currentTime = (new Date()).valueOf();
var generateKeyRet = await huks.generateKey(alias, macKeyOption);
expect(generateKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var macOption = makeMacOption(plainText);
var macRet = await huks.mac(alias, macOption);
expect(macRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var deleteKeyRet = await huks.deleteKey(alias, emptyOption);
expect(deleteKeyRet.errorCode).assertEqual(huks.HksErrorCode.HKS_SUCCESS);
var isKeyExist = await huks.isKeyExist(alias, emptyOption);
expect(isKeyExist).assertEqual(false);
var sumTime = endTime - currentTime;
console.info('HKS_JSAPI_STRESS_TEST_00900 Time left ' + sumTime / 1000 + ' s,' + ' index: ' + index);
index++;
}
done();
});
/**
* @tc.number HKS_JSAPI_STRESS_TEST_01000
* @tc.name HKS_STRESS_TEST_MAC_CALLBACK
* @tc.desc stress test for mac with callback
*/
it('HKS_JSAPI_STRESS_TEST_01000', 0, async function (done) {
currentCase = '01000';
var startTime = (new Date()).valueOf();
var endTime = startTime + executionTime;
var index = 0;
generateKeyCallback(endTime, index, done);
});
});
\ No newline at end of file
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("huksagree_callback_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksAgreeBasicCallbackJSApiTest"
hap_name = "ActsHuksAgreeBasicCallbackJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -9,7 +9,7 @@
"kits": [
{
"test-file-name": [
"huksAgreeBasicCallbackJSApiTest.hap"
"ActsHuksAgreeBasicCallbackJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("huksagree_promise_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksAgreeBasicPromiseJSApiTest"
hap_name = "ActsHuksAgreeBasicPromiseJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksAgreeBasicPromise js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "4200000",
"test-timeout": "180000",
"package": "com.example.huksagreebasicpromise",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksAgreeBasicPromiseJSApiTest.hap"
"ActsHuksAgreeBasicPromiseJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("hukscipher_callback_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksCipherBasicCallbackJSApiTest"
hap_name = "ActsHuksCipherBasicCallbackJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksCipherBasicCallback js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "2700000",
"test-timeout": "180000",
"package": "com.example.hukscipherbasiccallback",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksCipherBasicCallbackJSApiTest.hap"
"ActsHuksCipherBasicCallbackJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("hukscipher_promise_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksCipherBasicPromiseJSApiTest"
hap_name = "ActsHuksCipherBasicPromiseJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksCipherBasicPromise js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "2700000",
"test-timeout": "180000",
"package": "com.example.hukscipherbasicpromise",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksCipherBasicPromiseJSApiTest.hap"
"ActsHuksCipherBasicPromiseJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("huksderive_callback_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksDeriveBasicCallbackJSApiTest"
hap_name = "ActsHuksDeriveBasicCallbackJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksDeriveBasicCallback js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "4200000",
"test-timeout": "180000",
"package": "com.example.huksderivebasiccallback",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksDeriveBasicCallbackJSApiTest.hap"
"ActsHuksDeriveBasicCallbackJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("huksderive_promise_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksDeriveBasicPromiseJSApiTest"
hap_name = "ActsHuksDeriveBasicPromiseJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksDeriveBasicPromise js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "4200000",
"test-timeout": "180000",
"package": "com.example.huksderivebasicpromise",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksDeriveBasicPromiseJSApiTest.hap"
"ActsHuksDeriveBasicPromiseJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("hukshmac_callback_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksHmacBasicCallbackJSApiTest"
hap_name = "ActsHuksHmacBasicCallbackJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksHmacBasicCallback js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "600000",
"test-timeout": "180000",
"package": "com.example.huksHmacbasiccallback",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksHmacBasicCallbackJSApiTest.hap"
"ActsHuksHmacBasicCallbackJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("hukshmac_promise_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksHmacBasicPromiseJSApiTest"
hap_name = "ActsHuksHmacBasicPromiseJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksHmacBasicPromise js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "600000",
"test-timeout": "180000",
"package": "com.example.huksHmacbasicpromise",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksHmacBasicPromiseJSApiTest.hap"
"ActsHuksHmacBasicPromiseJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("hukssignverify_callback_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksSignVerifyBasicCallbackJSApiTest"
hap_name = "ActsHuksSignVerifyBasicCallbackJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksSignVerifyBasicCallback js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "12600000",
"test-timeout": "180000",
"package": "com.example.hukssignverifybasiccallback",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksSignVerifyBasicCallbackJSApiTest.hap"
"ActsHuksSignVerifyBasicCallbackJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -19,7 +19,7 @@ ohos_js_hap_suite("hukssignverify_promise_basic_js_test") {
":huks_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "huksSignVerifyBasicPromiseJSApiTest"
hap_name = "ActsHuksSignVerifyBasicPromiseJSApiTest"
}
ohos_js_assets("huks_js_assets") {
source_dir = "./entry/src/main/js/MainAbility"
......
......@@ -2,14 +2,14 @@
"description": "Configuration for huksSignVerifyBasicPromise js api Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "12600000",
"test-timeout": "180000",
"package": "com.example.hukssignverifybasicpromise",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"huksSignVerifyBasicPromiseJSApiTest.hap"
"ActsHuksSignVerifyBasicPromiseJSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册