提交 52ec5b51 编写于 作者: H hu-jixiang1

update

Signed-off-by: Nhu-jixiang1 <hujixiang1@huawei.com>
上级 7cb97c98
......@@ -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.
* 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');
}
};
/*
* 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"
}
{
"strings": {
"hello": "Hello",
"world": "world",
"start": "test start"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
{
"strings": {
"hello": "您好",
"world": "世界",
"start": "测试开始"
}
}
\ 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;
}
}
.container {
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
.title {
font-size: 40px;
color: #000000;
opacity: 0.9;
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
@media screen and (device-type: wearable) {
.title {
font-size: 28px;
color: #ffffff;
}
}
@media screen and (device-type: tv) {
.container {
background-image: url('/common/images/Wallpaper.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.title {
font-size: 100px;
color: #ffffff;
}
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
<div class="container">
<text class="title" >
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
\ 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 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 = 3000000;
configService.setConfig(this);
require('../../../test/hks_xts_concurrency.test.js');
core.execute();
}
}
/*
* 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 { Core, ExpectExtend } 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',
});
core.addService('expect', expectExtend);
core.init();
const configService = core.getDefaultService('config');
this.timeout = 1500000;
configService.setConfig(this);
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("//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("//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
{
"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
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册