提交 529ce1bc 编写于 作者: J jiyong

delete c++'s code

Signed-off-by: Njiyong <jiyong@huawei.com>
上级 4a8a15ae
# 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("//build/ohos_var.gni")
group("hiviewdfxtestacts") {
testonly = true
if (is_standard_system) {
deps = [ "hiappeventtest/hiappeventjstest:ActsHiAppEventJsTest" ]
}
}
# 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("ActsHiAppEventJsTest") {
hap_profile = "./src/main/config.json"
deps = [
":hiappevent_js_assets",
":hiappevent_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsHiAppEventJsTest"
}
ohos_js_assets("hiappevent_js_assets") {
source_dir = "./src/main/js/default"
}
ohos_resources("hiappevent_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "270000",
"package": "ohos.acts.hiviewdfx.hilog.function",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsHiAppEventJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "ohos.acts.hiviewdfx.hilog.function",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.hiviewdfx.hilog.function",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "ohos.acts.hiviewdfx.hilog.function.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "MyApplication",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
/*
* 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: 100px;
}
<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 app from '@system.app'
import device from '@system.device'
import router from '@system.router'
import {Core, ExpectExtend, Constant} from 'deccjsunit/index'
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../test/List.test')
core.execute()
},
onReady() {
},
}
\ 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 HiAppEvent from '@ohos.hiAppEvent'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import Constant from 'deccjsunit/src/Constant'
describe('HiAppEventApiTest', function () {
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0100
* @tc.name testHiAppEventApi01
* @tc.desc HiAppEvent write interface test.
*/
it('testHiAppEventApi01', 1, async function (done) {
console.info('testHiAppEventApi01 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_int": 100, "key_string": "demo",
"key_bool":true, "key_float":1.1,"key_array_int": [1, 2, 3], "key_array_float": [1.1, 2.2, 3.3],
"key_array_str": ["a", "b", "c"], "key_array_bool": [true, false],"key_array_int2": [1, 2, 3],
"key_arr_float2": [1.1, 2.2, 3.3], "key_arr_str2": ["a", "b", "c"], "key_array_bool2": [true, false]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0300
* @tc.name testHiAppEventApi03
* @tc.desc HiAppEvent write EventType of STATISTIC.
*/
it('testHiAppEventApi03', 2, async function (done) {
console.info('testHiAppEventApi03 start')
HiAppEvent.write("write", HiAppEvent.EventType.STATISTIC, {"key_int": 100, "key_string": "demo",
"key_bool":true, "key_float":1.1,"key_array_int": [1, 2, 3], "key_array_float": [1.1, 2.2, 3.3],
"key_array_str": ["a", "b", "c"], "key_array_bool": [true, false],"key_array_int2": [1, 2, 3],
"key_arr_float2": [1.1, 2.2, 3.3], "key_arr_str2": ["a", "b", "c"], "key_array_bool2": [true, false]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi03 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0400
* @tc.name testHiAppEventApi04
* @tc.desc HiAppEvent write EventType of SECURITY.
*/
it('testHiAppEventApi04', 2, async function (done) {
console.info('testHiAppEventApi04 start')
HiAppEvent.write("write", HiAppEvent.EventType.SECURITY, {"key_int": 100, "key_string": "demo",
"key_bool":true, "key_float":1.1,"key_array_int": [1, 2, 3], "key_array_float": [1.1, 2.2, 3.3],
"key_array_str": ["a", "b", "c"], "key_array_bool": [true, false],"key_array_int2": [1, 2, 3],
"key_arr_float2": [1.1, 2.2, 3.3], "key_arr_str2": ["a", "b", "c"], "key_array_bool2": [true, false]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi04 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0500
* @tc.name testHiAppEventApi05
* @tc.desc HiAppEvent write EventType of BEHAVIOR.
*/
it('testHiAppEventApi05', 2, async function (done) {
console.info('testHiAppEventApi05 start')
HiAppEvent.write("write", HiAppEvent.EventType.BEHAVIOR, {"key_int": 100, "key_string": "demo",
"key_bool":true, "key_float":1.1,"key_array_int": [1, 2, 3], "key_array_float": [1.1, 2.2, 3.3],
"key_array_str": ["a", "b", "c"], "key_array_bool": [true, false],"key_array_int2": [1, 2, 3],
"key_arr_float2": [1.1, 2.2, 3.3], "key_arr_str2": ["a", "b", "c"], "key_array_bool2": [true, false]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi05 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0600
* @tc.name testHiAppEventApi06
* @tc.desc HiAppEvent write datatype of int.
*/
it('testHiAppEventApi06', 2, async function (done) {
console.info('testHiAppEventApi06 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_int":100},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi06 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0700
* @tc.name testHiAppEventApi07
* @tc.desc HiAppEvent write datatype of int array.
*/
it('testHiAppEventApi07', 2, async function (done) {
console.info('testHiAppEventApi07 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_int_array":[100, 200]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi07 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0800
* @tc.name testHiAppEventApi08
* @tc.desc HiAppEvent write datatype of float.
*/
it('testHiAppEventApi08', 2, async function (done) {
console.info('testHiAppEventApi08 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_float":1.1},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi08 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0900
* @tc.name testHiAppEventApi09
* @tc.desc HiAppEvent write datatype of float array.
*/
it('testHiAppEventApi09', 3, async function (done) {
console.info('testHiAppEventApi09 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_float_array":[1.1, 1.2]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi09 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1000
* @tc.name testHiAppEventApi10
* @tc.desc HiAppEvent write datatype of string.
*/
it('testHiAppEventApi10', 3, async function (done) {
console.info('testHiAppEventApi10 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_string":"hello world"},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi10 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1100
* @tc.name testHiAppEventApi11
* @tc.desc HiAppEvent write datatype of string array.
*/
it('testHiAppEventApi11', 3, async function (done) {
console.info('testHiAppEventApi11 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_string_array":["hello world", "hello world2"]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi11 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1200
* @tc.name testHiAppEventApi12
* @tc.desc HiAppEvent write datatype of bool with true.
*/
it('testHiAppEventApi12', 3, async function (done) {
console.info('testHiAppEventApi12 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_bool":true},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi12 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1300
* @tc.name testHiAppEventApi13
* @tc.desc HiAppEvent write datatype of bool with false.
*/
it('testHiAppEventApi13', 3, async function (done) {
console.info('testHiAppEventApi13 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_bool":false},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi13 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1400
* @tc.name testHiAppEventApi14
* @tc.desc HiAppEvent write datatype of bool array.
*/
it('testHiAppEventApi14', 3, async function (done) {
console.info('testHiAppEventApi14 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_bool_array":[false, true]},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi14 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1500
* @tc.name testHiAppEventApi15
* @tc.desc HiAppEvent write datatype of char.
*/
it('testHiAppEventApi15', 3, async function (done) {
console.info('testHiAppEventApi15 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_char":'c'},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi15 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1600
* @tc.name testHiAppEventApi16
* @tc.desc HiAppEvent write datatype of long.
*/
it('testHiAppEventApi16', 3, async function (done) {
console.info('testHiAppEventApi16 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_long":2147483647},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi16 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1700
* @tc.name testHiAppEventApi17
* @tc.desc HiAppEvent write datatype of double.
*/
it('testHiAppEventApi17', 3, async function (done) {
console.info('testHiAppEventApi17 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_double":100.123},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi17 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1800
* @tc.name testHiAppEventApi18
* @tc.desc HiAppEvent write datatype of long.
*/
it('testHiAppEventApi18', 3, async function (done) {
console.info('testHiAppEventApi18 start')
HiAppEvent.write("write", HiAppEvent.EventType.FAULT, {"key_longlong":2147483647},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi18 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1900
* @tc.name testHiAppEventApi19
* @tc.desc HiAppEvent write eventtype of none exists.
*/
it('testHiAppEventApi19', 3, async function (done) {
console.info('testHiAppEventApi19 start')
HiAppEvent.write("write", HiAppEvent.EventType.BEHAVIOR + 1, {"key_longlong":2147483647},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi19 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_2000
* @tc.name testHiAppEventApi20
* @tc.desc HiAppEvent write empty eventname .
*/
it('testHiAppEventApi20', 3, async function (done) {
console.info('testHiAppEventApi20 start')
HiAppEvent.write("", HiAppEvent.EventType.FAULT, {"key_longlong":2147483647},
(err, value) => {
console.log('HiAppEvent20 into json-callback');
if (err) {
console.error('HiAppEvent20 json-callback-error code=${err.code}');
expect(err.code == -1).assertTrue();
done();
} else {
console.log('HiAppEvent20 json-callback-success value=${value}');
expect().assertFail();
done();
}
});
console.info('testHiAppEventApi20 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_2100
* @tc.name testHiAppEventApi21
* @tc.desc HiAppEvent write long eventname .
*/
it('testHiAppEventApi21', 3, async function (done) {
console.info('testHiAppEventApi21 start')
var i = 0;
var strlong = "";
while (i < 1000) {
strlong = strlong + "eventnamelong";
i = i + 1;
}
HiAppEvent.write(strlong, HiAppEvent.EventType.FAULT, {"key_longlong":2147483647},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent21 json-callback-error code=${err.code}');
expect(err.code == -1).assertTrue();
done();
} else {
console.log('HiAppEvent21 json-callback-success value=${value}');
expect().assertFail();
done();
}
});
console.info('testHiAppEventApi21 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_2200
* @tc.name testHiAppEventApi22
* @tc.desc HiAppEvent configure interface with disable option set true.
*/
it('testHiAppEventApi22', 3, function () {
console.info('testHiAppEventApi22 start')
let configret =false;
configret = HiAppEvent.configure({disable:true});
expect(configret == true).assertTrue();
HiAppEvent.configure({disable: false});
console.info('testHiAppEventApi22 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_2300
* @tc.name testHiAppEventApi23
* @tc.desc HiAppEvent configure interface with disable option set false.
*/
it('testHiAppEventApi23', 3, function () {
console.info('testHiAppEventApi23 start')
let configret =false;
configret = HiAppEvent.configure({disable: false});
expect(configret == true).assertTrue();
console.info('testHiAppEventApi23 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_2400
* @tc.name testHiAppEventApi24
* @tc.desc HiAppEvent configure interface with maxStorage option set 100M.
*/
it('testHiAppEventApi24', 3, function () {
console.info('testHiAppEventApi24 start')
let configret =false;
configret = HiAppEvent.configure({maxStorage:'100M'});
console.info('configret = %d', configret);
expect(configret == true).assertTrue();
console.info('testHiAppEventApi24 end')
})
/**
* @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_2500
* @tc.name testHiAppEventApi25
* @tc.desc HiAppEvent with predefined event and param.
*/
it('testHiAppEventApi25', 3, async function (done) {
console.info('testHiAppEventApi25 start')
HiAppEvent.write(HiAppEvent.Event.USER_LOGIN, HiAppEvent.EventType.BEHAVIOR,
{[HiAppEvent.Param.USER_ID]: 'userlogin', [HiAppEvent.Param.DISTRIBUTED_SERVICE_NAME]: 'HiAppEvent',
[HiAppEvent.Param.DISTRIBUTED_SERVICE_INSTANCE_ID]: 100},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
HiAppEvent.write(HiAppEvent.Event.USER_LOGOUT, HiAppEvent.EventType.BEHAVIOR,
{[HiAppEvent.Param.USER_ID]: 'userlogout', [HiAppEvent.Param.DISTRIBUTED_SERVICE_NAME]: 'HiAppEvent',
[HiAppEvent.Param.DISTRIBUTED_SERVICE_INSTANCE_ID]: 100},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
HiAppEvent.write(HiAppEvent.Event.DISTRIBUTED_SERVICE_START, HiAppEvent.EventType.BEHAVIOR,
{[HiAppEvent.Param.USER_ID]: 'distributedservicestart', [HiAppEvent.Param.DISTRIBUTED_SERVICE_NAME]: 'HiAppEvent',
[HiAppEvent.Param.DISTRIBUTED_SERVICE_INSTANCE_ID]: 100},
(err, value) => {
console.log('HiAppEvent into json-callback');
if (err) {
console.error('HiAppEvent json-callback-error code=${err.code}');
expect().assertFail();
done();
} else {
console.log('HiAppEvent json-callback-success value=${value}');
expect(value == 0).assertTrue();
done();
}
});
console.info('testHiAppEventApi25 end')
})
})
/*
* 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('./HiAppEvent.test.js')
{
"string": [
{
"name": "app_name",
"value": "test2demo"
},
{
"name": "mainability_description",
"value": "hap sample empty page"
}
]
}
# 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("//build/ohos_var.gni")
import("//test/xts/tools/build/suite.gni")
group("security") {
testonly = true
if (is_standard_system) {
deps = [
# "authentication_standard/deviceauth_p2p:DeviceauthP2PFunctionCPPTest",
"dataprotect/huks_standard_adapter:ActsHuksStdFunctionTest",
"deviceauth/deviceauth_function:ActsDeviceAuthFunctionTest",
]
} else {
deps = []
}
}
# 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("//build/test.gni")
import("//test/xts/tools/build/suite.gni")
#module_output_path = "hits/huks_standard"
########################################################
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
#"unittest/include",
#"include",
"//test/xts/acts/security_lite/huks/common/include",
]
}
########################################################
ohos_moduletest_suite("ActsHuksStdFunctionTest") {
configs = [ ":module_private_config" ]
cflags_cc = [ "-DHILOG_ENABLE" ]
defines = [ "_STANDARD_SYSTEM_" ]
sources = [
"src/hks_aes_test.cpp",
"src/hks_agreement_test.cpp",
"src/hks_bn_exp_mod_test.cpp",
"src/hks_cipher_test.cpp",
"src/hks_curve25519_test.cpp",
"src/hks_delete_test.cpp",
"src/hks_derive_test.cpp",
"src/hks_exist_test.cpp",
"src/hks_generate_key_test.cpp",
"src/hks_generate_random_test.cpp",
"src/hks_hash_test.cpp",
"src/hks_mac_test.cpp",
"src/hks_modify_key_test.cpp",
"src/hks_others_test.cpp",
"src/hks_safe_cipher_key_test.cpp",
"src/hks_safe_compare_key_test.cpp",
#"src/hks_test_api_performance.c",
#"src/hks_test_cipher.c",
#"src/hks_test_common.c",
#"src/hks_test_mem.c",
#"src/hks_test_aes.c",
#"src/hks_test_curve25519.c",
#"src/hks_test_file_operator.c",
]
include_dirs = [
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
"include",
]
deps = [
"//base/security/huks/frameworks/huks_standard/main:huks_standard_frameworks",
"//base/security/huks/interfaces/innerkits/huks_standard/main:libhukssdk",
"//test/xts/acts/security_lite/huks/common:huks_test_common",
"//third_party/bounds_checking_function:libsec_static",
"//utils/native/base:utils",
]
}
group("Huksstandardtest") {
testonly = true
deps = [ ":ActsHuksStdFunctionTest" ]
}
{
"kits": [
{
"push": [
"ActsHuksStdFunctionTest->/data/local/tmp/ActsHuksStdFunctionTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsHuksStdFunctionTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsHuksStdFunctionTest Tests"
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_aes_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_aes.h"
using namespace testing::ext;
namespace {
class HksAesTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksAesTest::SetUpTestCase(void)
{
}
void HksAesTest::TearDownTestCase(void)
{
}
void HksAesTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksAesTest::TearDown()
{
}
#ifndef _CUT_AUTHENTICATE_
/**
* @tc.name: HksCipherTest.HksCipherTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest001, TestSize.Level1)
{
ASSERT_TRUE(TestAes256ByAgree() == 0);
}
/**
* @tc.name: HksCipherTest.HksCipherTest002
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest002, TestSize.Level1)
{
ASSERT_TRUE(TestAes256ByAgree1() == 0);
}
/**
* @tc.name: HksCipherTest.HksCipherTest003
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest003, TestSize.Level1)
{
ASSERT_TRUE(TestAes256ByAgree2() == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
/**
* @tc.name: HksCipherTest.HksCipherTest003
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAesTest, HksAesTest004, TestSize.Level1)
{
ASSERT_EQ(TestAes256ByLocal(), 0);
}
}
/*
* 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.
*/
#include <gtest/gtest.h>
#include "hks_agreement_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksAgreementTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksAgreementTest::SetUpTestCase(void)
{
}
void HksAgreementTest::TearDownTestCase(void)
{
}
void HksAgreementTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksAgreementTest::TearDown()
{
}
const int TMP_SIZE = 512;
const int X25519_KEY_SIZE = 32;
const struct HksTestAgreeParams g_testAgreeParams[] = {
/* ree x25519 success */
{ 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{ true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{ true, true, HKS_ALG_X25519, true, HKS_CURVE25519_KEY_SIZE_256, true,
HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY, true, HKS_DIGEST_SHA256,
false, 0, false, 0, true, HKS_STORAGE_TEMP },
{ 0 },
{ true, true, HKS_ALG_X25519, true, HKS_CURVE25519_KEY_SIZE_256, true, false },
{ true, TMP_SIZE, true, TMP_SIZE },
{ true, X25519_KEY_SIZE, true, X25519_KEY_SIZE },
{ true, X25519_KEY_SIZE, true, X25519_KEY_SIZE },
{ true, X25519_KEY_SIZE, true, X25519_KEY_SIZE }
},
};
static int32_t AgreeKey(const struct HksTestAgreeParamSet *agreeParamSetParams, struct HksBlob *privateKey,
struct HksBlob *peerPublicKey, struct HksBlob *agreedKey)
{
struct HksParamSet *agreeParamSet = NULL;
struct TestAgreeParamSetStructure paramStruct = {
&agreeParamSet,
agreeParamSetParams->paramSetExist,
agreeParamSetParams->setAlg, agreeParamSetParams->alg,
agreeParamSetParams->setKeySize, agreeParamSetParams->keySize,
agreeParamSetParams->setIsKeyAlias, agreeParamSetParams->isKeyAlias
};
int32_t ret = TestConstructAgreeParamSet(&paramStruct);
HKS_TEST_ASSERT(ret == 0);
ret = HksAgreeKeyRun(agreeParamSet, privateKey, peerPublicKey, agreedKey, 1);
HksFreeParamSet(&agreeParamSet);
return ret;
}
/**
* @tc.name: HksDeleteTest.HksDeleteTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAgreementTest, HksAgreementTest001, TestSize.Level1)
{
/* 1. generate key */
struct HksBlob *privateKey = NULL;
struct HksBlob *peerPubKeyAlias = NULL;
struct HksBlob *peerPublicKey = NULL;
int32_t ret;
if (g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag &&
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) {
ret = GenerateLocalX25519Key(&privateKey, NULL, &g_testAgreeParams[0].localPrivateKeyParams, NULL);
ASSERT_TRUE(ret == 0);
ret = GenerateLocalX25519Key(NULL, &peerPublicKey, NULL, &g_testAgreeParams[0].localPublicKeyParams);
ASSERT_TRUE(ret == 0);
}
/* 2. agreeKey */
struct HksBlob *agreeKey = NULL;
ret = TestConstuctBlob(&agreeKey,
g_testAgreeParams[0].agreedKeyParams.blobExist,
g_testAgreeParams[0].agreedKeyParams.blobSize,
g_testAgreeParams[0].agreedKeyParams.blobDataExist,
g_testAgreeParams[0].agreedKeyParams.blobDataSize);
ASSERT_TRUE(ret == 0);
ret = AgreeKey(&g_testAgreeParams[0].agreeParamSetParams, privateKey, peerPublicKey, agreeKey);
ASSERT_TRUE(ret == g_testAgreeParams[0].expectResult);
/* 3. delete key */
if (!(g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag &&
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) &&
((g_testAgreeParams[0].keyAlias1Params.blobExist) &&
(g_testAgreeParams[0].keyAlias2Params.blobExist))) {
ret = HksDeleteKey(privateKey, NULL);
ASSERT_TRUE(ret == 0);
ret = HksDeleteKey(peerPubKeyAlias, NULL);
ASSERT_TRUE(ret == 0);
}
TestFreeBlob(&privateKey);
TestFreeBlob(&peerPubKeyAlias);
TestFreeBlob(&peerPublicKey);
TestFreeBlob(&agreeKey);
ASSERT_TRUE(ret == 0);
}
/**
* @tc.name: HksDeleteTest.HksDeleteTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksAgreementTest, HksAgreementTest002, TestSize.Level1)
{
/* 1. generate key */
struct HksBlob *privateKey = NULL;
struct HksBlob *peerPubKeyAlias = NULL;
struct HksBlob *peerPublicKey = NULL;
struct HksBlob *privateKey2 = NULL;
// struct HksBlob *peerPubKeyAlias2 = NULL;
struct HksBlob *peerPublicKey2 = NULL;
int32_t ret;
if (g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag &&
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) {
ret = GenerateLocalX25519Key(&privateKey, &peerPublicKey, &g_testAgreeParams[0].localPrivateKeyParams, \
&g_testAgreeParams[0].localPublicKeyParams);
ASSERT_TRUE(ret == 0);
ret = GenerateLocalX25519Key(&privateKey2, &peerPublicKey2, &g_testAgreeParams[0].localPrivateKeyParams, \
&g_testAgreeParams[0].localPublicKeyParams);
ASSERT_TRUE(ret == 0);
}
/* 2. agreeKey */
struct HksBlob *agreeKey = NULL;
ret = TestConstuctBlob(&agreeKey, g_testAgreeParams[0].agreedKeyParams.blobExist, \
g_testAgreeParams[0].agreedKeyParams.blobSize, g_testAgreeParams[0].agreedKeyParams.blobDataExist, \
g_testAgreeParams[0].agreedKeyParams.blobDataSize);
ASSERT_TRUE(ret == 0);
struct HksBlob *agreeKey2 = NULL;
ret = TestConstuctBlob(&agreeKey2, g_testAgreeParams[0].agreedKeyParams.blobExist, \
g_testAgreeParams[0].agreedKeyParams.blobSize, g_testAgreeParams[0].agreedKeyParams.blobDataExist, \
g_testAgreeParams[0].agreedKeyParams.blobDataSize);
ASSERT_TRUE(ret == 0);
ret = AgreeKey(&g_testAgreeParams[0].agreeParamSetParams, privateKey, peerPublicKey2, agreeKey);
ASSERT_TRUE(ret == g_testAgreeParams[0].expectResult);
ret = AgreeKey(&g_testAgreeParams[0].agreeParamSetParams, privateKey2, peerPublicKey, agreeKey2);
ASSERT_TRUE(ret == g_testAgreeParams[0].expectResult);
EXPECT_EQ(agreeKey->size, agreeKey2->size);
EXPECT_EQ(memcmp(agreeKey->data, agreeKey2->data, agreeKey->size), 0);
/* 3. delete key */
if (!(g_testAgreeParams[0].genKeyParamSetParams.setKeyStorageFlag && \
(g_testAgreeParams[0].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) && \
((g_testAgreeParams[0].keyAlias1Params.blobExist) && (g_testAgreeParams[0].keyAlias2Params.blobExist))) {
ASSERT_TRUE(HksDeleteKey(privateKey, NULL) == 0);
ASSERT_TRUE(HksDeleteKey(peerPubKeyAlias, NULL) == 0);
}
TestFreeBlob(&privateKey);
TestFreeBlob(&peerPubKeyAlias);
TestFreeBlob(&peerPublicKey);
TestFreeBlob(&agreeKey);
}
#endif /* _CUT_AUTHENTICATE_ */
}
/*
* 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.
*/
#include <gtest/gtest.h>
#include "hks_bn_exp_mod_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
class HksBnExpModTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksBnExpModTest::SetUpTestCase(void)
{
}
void HksBnExpModTest::TearDownTestCase(void)
{
}
void HksBnExpModTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksBnExpModTest::TearDown()
{
}
const int DEFAULT_X_SIZE = 256;
const int DEFAULT_A_SIZE = 256;
const int DEFAULT_E_SIZE = 256;
const int DEFAULT_N_SIZE = 256;
const int HKS_TEST_2 = 2;
const int HKS_TEST_8 = 8;
const struct HksTestBnExpModParams g_testBnExpModParams[] = {
/* normal case */
{ 0, HKS_SUCCESS, false,
{ true, DEFAULT_X_SIZE, true, DEFAULT_X_SIZE },
{ true, DEFAULT_A_SIZE, true, DEFAULT_A_SIZE },
{ true, DEFAULT_E_SIZE, true, DEFAULT_E_SIZE },
{ true, DEFAULT_N_SIZE, true, DEFAULT_N_SIZE }
},
};
static int32_t TestValue()
{
HKS_TEST_LOG_I("test value");
uint8_t bufX[HKS_TEST_8] = { 0, 0, 0, 0, 0, 0, 0, 0x40 };
uint8_t bufA[HKS_TEST_8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
uint8_t bufE[HKS_TEST_2] = { 0, 2 };
uint8_t bufN[HKS_TEST_8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
uint8_t tmpBufX[HKS_TEST_8] = {0};
struct HksBlob tmpX = { HKS_TEST_8, tmpBufX };
struct HksBlob tmpA = { HKS_TEST_8, bufA };
struct HksBlob tmpE = { HKS_TEST_2, bufE };
struct HksBlob tmpN = { HKS_TEST_8, bufN };
int32_t ret = HksBnExpModRun(&tmpX, &tmpA, &tmpE, &tmpN, 1);
for (int i = 0; i < HKS_TEST_8; ++i) {
HKS_TEST_LOG_I("%x, %x", tmpBufX[i], bufX[i]);
HKS_TEST_ASSERT(tmpBufX[i] == bufX[i]);
}
return ret;
}
/**
* @tc.name: HksBnExpModTest.HksBnExpModTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksBnExpModTest, HksBnExpModTest001, TestSize.Level1)
{
int32_t ret;
if (g_testBnExpModParams[0].isTestValue) {
ret = TestValue();
ASSERT_TRUE(ret == 0);
} else {
struct HksBlob *x = NULL;
struct HksBlob *a = NULL;
struct HksBlob *e = NULL;
struct HksBlob *n = NULL;
ret = TestConstuctBlob(&x, g_testBnExpModParams[0].xParams.blobExist,
g_testBnExpModParams[0].xParams.blobSize, g_testBnExpModParams[0].xParams.blobDataExist,
g_testBnExpModParams[0].xParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstructBlobOut(&a, g_testBnExpModParams[0].aParams.blobExist,
g_testBnExpModParams[0].aParams.blobSize, g_testBnExpModParams[0].aParams.blobDataExist,
g_testBnExpModParams[0].aParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstuctBlob(&e, g_testBnExpModParams[0].eParams.blobExist,
g_testBnExpModParams[0].eParams.blobSize, g_testBnExpModParams[0].eParams.blobDataExist,
g_testBnExpModParams[0].eParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstuctBlob(&n, g_testBnExpModParams[0].nParams.blobExist,
g_testBnExpModParams[0].nParams.blobSize, g_testBnExpModParams[0].nParams.blobDataExist,
g_testBnExpModParams[0].nParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
if ((n != NULL) && (n->data != NULL) && (n->size != 0)) {
n->data[n->size - 1] = n->data[n->size - 1] | 0x00000001; /* make sure n is odd */
}
ret = HksBnExpModRun(x, a, e, n, 1);
HKS_TEST_ASSERT(ret == g_testBnExpModParams[0].expectResult);
TestFreeBlob(&x);
TestFreeBlob(&a);
TestFreeBlob(&e);
TestFreeBlob(&n);
ASSERT_TRUE(ret == 0);
}
}
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_cipher_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_cipher.h"
using namespace testing::ext;
namespace {
class HksCipherTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksCipherTest::SetUpTestCase(void)
{
}
void HksCipherTest::TearDownTestCase(void)
{
}
void HksCipherTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksCipherTest::TearDown()
{
}
/**
* @tc.name: HksCipherTest.HksCipherTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksCipherTest, HksCipherTest001, TestSize.Level1)
{
ASSERT_TRUE(BaseTestCipher(1, 0, 1) == 0);
}
#ifndef _CUT_AUTHENTICATE_
HWTEST_F(HksCipherTest, HksCipherTest002, TestSize.Level1)
{
ASSERT_TRUE(BaseTestCipher(1, 1, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest003, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 0, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest004, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 1, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest005, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 2, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest006, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 3, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest007, TestSize.Level1)
{
ASSERT_TRUE(BaseTestEncrypt(1, 4, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest008, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 0, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest009, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 1, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest010, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 2, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest011, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 3, 1) == 0);
}
HWTEST_F(HksCipherTest, HksCipherTest012, TestSize.Level1)
{
ASSERT_TRUE(BaseTestDecrypt(1, 4, 1) == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_curve25519_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_curve25519.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksCurve25519Test : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksCurve25519Test::SetUpTestCase(void)
{
}
void HksCurve25519Test::TearDownTestCase(void)
{
}
void HksCurve25519Test::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksCurve25519Test::TearDown()
{
}
/**
* @tc.name: HksCurve25519Test.HksCurve25519Test001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksCurve25519Test, HksCurve25519Test001, TestSize.Level1)
{
ASSERT_TRUE(TestCurve25519All() == 0);
}
/**
* @tc.name: HksCurve25519Test.HksCurve25519Test002
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksCurve25519Test, HksCurve25519Test002, TestSize.Level1)
{
ASSERT_TRUE(TestEd25519SignTeeVerifyLocal() == 0);
}
/**
* @tc.name: HksCurve25519Test.HksCurve25519Test003
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksCurve25519Test, HksCurve25519Test003, TestSize.Level1)
{
ASSERT_TRUE(TestCurve25519SignWrong() == 0);
}
/**
* @tc.name: HksCurve25519Test.HksCurve25519Test004
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksCurve25519Test, HksCurve25519Test004, TestSize.Level1)
{
ASSERT_TRUE(TestCurve25519verifyWrong() == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_delete_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksDeleteTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksDeleteTest::SetUpTestCase(void)
{
}
void HksDeleteTest::TearDownTestCase(void)
{
}
void HksDeleteTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksDeleteTest::TearDown()
{
}
const struct HksTestKeyExistParams g_testKeyExistParams[] = {
/* normal case */
{ 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
};
/**
* @tc.name: HksDeleteTest.HksDeleteTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksDeleteTest, HksDeleteTest001, TestSize.Level1)
{
int32_t ret;
struct HksBlob *keyAlias = NULL;
if (g_testKeyExistParams[0].isGenKey) {
HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
} else {
ret = TestConstuctBlob(&keyAlias,
g_testKeyExistParams[0].keyAliasParams.blobExist,
g_testKeyExistParams[0].keyAliasParams.blobSize,
g_testKeyExistParams[0].keyAliasParams.blobDataExist,
g_testKeyExistParams[0].keyAliasParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
}
ret = HksDeleteKeyRun(keyAlias, 1);
HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
TestFreeBlob(&keyAlias);
ASSERT_TRUE(ret == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_derive_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
using namespace testing::ext;
namespace {
class HksDeriveTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksDeriveTest::SetUpTestCase(void)
{
}
void HksDeriveTest::TearDownTestCase(void)
{
}
void HksDeriveTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksDeriveTest::TearDown()
{
}
const int DEFAULT_DERIVE_SIZE = 32;
const int DEFAULT_INFO_SIZE = 55;
const int DEFAULT_SALT_SIZE = 16;
const struct HksTestDeriveParams g_testDeriveParams[] = {
/* hkdf-sha256-salt-info */
{ 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{
true, /* genKey params */
true, HKS_ALG_AES,
true, HKS_AES_KEY_SIZE_256,
true, HKS_KEY_PURPOSE_DERIVE,
true, HKS_DIGEST_SHA256,
false, 0,
false, 0,
false, 0 },
{ 0 },
{
true, /* derive params */
true, HKS_ALG_HKDF,
true, HKS_KEY_PURPOSE_DERIVE,
true, HKS_DIGEST_SHA256,
false, 0,
true, DEFAULT_SALT_SIZE,
true, DEFAULT_INFO_SIZE,
false, true },
{
true, DEFAULT_DERIVE_SIZE, true, DEFAULT_DERIVE_SIZE },
{
false, 0, false, 0 }
},
/* local: hkdf-sha256-salt-info */
{ 1, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{
true, /* genKey params */
true, HKS_ALG_AES,
true, HKS_AES_KEY_SIZE_256,
true, HKS_KEY_PURPOSE_DERIVE,
true, HKS_DIGEST_SHA256,
false, 0,
false, 0,
true, HKS_STORAGE_TEMP },
{ 0 },
{
true, /* derive params */
true, HKS_ALG_HKDF,
true, HKS_KEY_PURPOSE_DERIVE,
true, HKS_DIGEST_SHA256,
false, 0,
true, DEFAULT_SALT_SIZE,
true, DEFAULT_INFO_SIZE,
true, false },
{
true, DEFAULT_DERIVE_SIZE, true, DEFAULT_DERIVE_SIZE },
{
true, DEFAULT_LOCAL_KEY_SIZE, true, DEFAULT_LOCAL_KEY_SIZE }
},
};
static int32_t DeriveKey(const struct HksTestDeriveParamSet *deriveParamSetParams, const struct HksBlob *masterKey,
struct HksBlob *derivedKey, struct HksBlob **saltData, struct HksBlob **infoData)
{
struct HksParamSet *deriveParamSet = NULL;
uint32_t saltSize = deriveParamSetParams->saltSize;
uint32_t infoSize = deriveParamSetParams->infoSize;
if (saltSize != 0) {
HKS_TEST_ASSERT(TestConstuctBlob(saltData, true, saltSize, true, saltSize) == 0);
}
if (infoSize != 0) {
HKS_TEST_ASSERT(TestConstuctBlob(infoData, true, infoSize, true, infoSize) == 0);
}
struct TestDeriveParamSetStructure paramStruct = {
&deriveParamSet,
deriveParamSetParams->paramSetExist,
deriveParamSetParams->setAlg, deriveParamSetParams->alg,
deriveParamSetParams->setPurpose, deriveParamSetParams->purpose,
deriveParamSetParams->setDigest, deriveParamSetParams->digest,
deriveParamSetParams->setIteration, deriveParamSetParams->iteration,
deriveParamSetParams->setSalt, *saltData,
deriveParamSetParams->setInfo, *infoData,
deriveParamSetParams->setIsKeyAlias, deriveParamSetParams->isKeyAlias
};
int32_t ret = TestConstructDeriveParamSet(&paramStruct);
HKS_TEST_ASSERT(ret == 0);
ret = HksDeriveKeyRun(deriveParamSet, masterKey, derivedKey, 1);
HksFreeParamSet(&deriveParamSet);
return ret;
}
static int32_t BaseTestDerive(uint32_t index)
{
/* 1. generate key */
struct HksBlob *keyAlias = NULL;
int32_t ret;
if (g_testDeriveParams[index].genKeyParamSetParams.setKeyStorageFlag &&
(g_testDeriveParams[index].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) {
ret = GenerateLocalRandomKey(&keyAlias, &g_testDeriveParams[index].localKeyParams);
} else {
if (g_testDeriveParams[index].keyAliasParams.blobExist) {
ret = GenerateKey(&keyAlias, &g_testDeriveParams[index].keyAliasParams,
&g_testDeriveParams[index].genKeyParamSetParams, NULL);
} else {
ret = TestConstuctBlob(&keyAlias,
g_testDeriveParams[index].masterKeyParams.blobExist,
g_testDeriveParams[index].masterKeyParams.blobSize,
g_testDeriveParams[index].masterKeyParams.blobDataExist,
g_testDeriveParams[index].masterKeyParams.blobDataSize);
}
}
HKS_TEST_ASSERT(ret == 0);
/* 2. derive */
struct HksBlob *derivedKey = NULL;
ret = TestConstuctBlob(&derivedKey,
g_testDeriveParams[index].derivedKeyParams.blobExist,
g_testDeriveParams[index].derivedKeyParams.blobSize,
g_testDeriveParams[index].derivedKeyParams.blobDataExist,
g_testDeriveParams[index].derivedKeyParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob *saltData = NULL;
struct HksBlob *infoData = NULL;
ret = DeriveKey(&g_testDeriveParams[index].deriveParamSetParams, keyAlias, derivedKey, &saltData, &infoData);
if (ret != g_testDeriveParams[index].expectResult) {
HKS_TEST_LOG_I("failed, ret[%u] = %d", g_testDeriveParams[index].testId, ret);
}
HKS_TEST_ASSERT(ret == g_testDeriveParams[index].expectResult);
/* 3. delete key */
if (!(g_testDeriveParams[index].genKeyParamSetParams.setKeyStorageFlag &&
(g_testDeriveParams[index].genKeyParamSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) &&
(g_testDeriveParams[index].keyAliasParams.blobExist)) {
HKS_TEST_ASSERT(HksDeleteKey(keyAlias, NULL) == 0);
}
TestFreeBlob(&keyAlias);
TestFreeBlob(&derivedKey);
TestFreeBlob(&saltData);
TestFreeBlob(&infoData);
return ret;
}
#ifndef _CUT_AUTHENTICATE_
/**
* @tc.name: HksDeriveTest.HksDeriveTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksDeriveTest, HksDeriveTest001, TestSize.Level1)
{
int32_t ret = BaseTestDerive(0);
ASSERT_TRUE(ret == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
/**
* @tc.name: HksDeriveTest.HksDeriveTest002
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksDeriveTest, HksDeriveTest002, TestSize.Level1)
{
int32_t ret = BaseTestDerive(1);
ASSERT_TRUE(ret == 0);
}
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_exist_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksExistTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksExistTest::SetUpTestCase(void)
{
}
void HksExistTest::TearDownTestCase(void)
{
}
void HksExistTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksExistTest::TearDown()
{
}
const struct HksTestKeyExistParams g_testKeyExistParams[] = {
/* normal case */
{ 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
};
/**
* @tc.name: HksExistTest.HksExistTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksExistTest, HksExistTest001, TestSize.Level1)
{
int32_t ret;
struct HksBlob *keyAlias = NULL;
if (g_testKeyExistParams[0].isGenKey) {
HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
ret = HksKeyExistRun(keyAlias, 1);
HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
HKS_TEST_ASSERT(HksDeleteKey(keyAlias, NULL) == HKS_SUCCESS);
} else {
ret = TestConstuctBlob(&keyAlias,
g_testKeyExistParams[0].keyAliasParams.blobExist,
g_testKeyExistParams[0].keyAliasParams.blobSize,
g_testKeyExistParams[0].keyAliasParams.blobDataExist,
g_testKeyExistParams[0].keyAliasParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = HksKeyExistRun(keyAlias, 1);
if (ret != g_testKeyExistParams[0].expectResult) {
HKS_TEST_LOG_I("HksKeyExistRun 2 failed, ret[%u] = %d", g_testKeyExistParams[0].testId, ret);
}
HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
}
TestFreeBlob(&keyAlias);
ASSERT_TRUE(ret == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_generate_key_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksGenerateKeyTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksGenerateKeyTest::SetUpTestCase(void)
{
}
void HksGenerateKeyTest::TearDownTestCase(void)
{
}
void HksGenerateKeyTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksGenerateKeyTest::TearDown()
{
}
const int DEFAULT_X25519_PARAM_SET_OUT = 104;
const struct HksTestGenKeyParams g_testGenKeyParams[] = {
/* x25519: ree sign/verify */
{ 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE }, {
true,
true, HKS_ALG_X25519,
true, HKS_CURVE25519_KEY_SIZE_256,
true, HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY,
false, 0,
false, 0,
false, 0,
true, HKS_STORAGE_TEMP },
{ true, DEFAULT_X25519_PARAM_SET_OUT },
},
};
/**
* @tc.name: HksGenerateKeyTest.HksGenerateKeyTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksGenerateKeyTest, HksGenerateKeyTest001, TestSize.Level1)
{
uint32_t times = 1;
uint32_t index = 0;
uint32_t performTimes = 1;
struct HksBlob *keyAlias = NULL;
int32_t ret = TestConstuctBlob(&keyAlias,
g_testGenKeyParams[index].keyAliasParams.blobExist,
g_testGenKeyParams[index].keyAliasParams.blobSize,
g_testGenKeyParams[index].keyAliasParams.blobDataExist,
g_testGenKeyParams[index].keyAliasParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
struct HksParamSet *paramSet = NULL;
struct GenerateKeyParamSetStructure paramStruct = { &paramSet,
g_testGenKeyParams[index].paramSetParams.paramSetExist,
g_testGenKeyParams[index].paramSetParams.setAlg, g_testGenKeyParams[index].paramSetParams.alg,
g_testGenKeyParams[index].paramSetParams.setKeySize, g_testGenKeyParams[index].paramSetParams.keySize,
g_testGenKeyParams[index].paramSetParams.setPurpose, g_testGenKeyParams[index].paramSetParams.purpose,
g_testGenKeyParams[index].paramSetParams.setDigest, g_testGenKeyParams[index].paramSetParams.digest,
g_testGenKeyParams[index].paramSetParams.setPadding, g_testGenKeyParams[index].paramSetParams.padding,
g_testGenKeyParams[index].paramSetParams.setBlockMode, g_testGenKeyParams[index].paramSetParams.mode,
g_testGenKeyParams[index].paramSetParams.setKeyStorageFlag,
g_testGenKeyParams[index].paramSetParams.keyStorageFlag };
ret = TestConstructGenerateKeyParamSet(&paramStruct);
HKS_TEST_ASSERT(ret == 0);
struct HksParamSet *paramSetOut = NULL;
ret = TestConstructGenerateKeyParamSetOut(&paramSetOut,
g_testGenKeyParams[index].paramSetParamsOut.paramSetExist,
g_testGenKeyParams[index].paramSetParamsOut.paramSetSize);
HKS_TEST_ASSERT(ret == 0);
ret = HksGenerateKeyRun(keyAlias, paramSet, paramSetOut, performTimes);
if (ret != g_testGenKeyParams[index].expectResult) {
HKS_TEST_LOG_I("failed, ret[%u] = %d", g_testGenKeyParams[index].testId, ret);
}
HKS_TEST_ASSERT(ret == g_testGenKeyParams[index].expectResult);
if ((ret == HKS_SUCCESS) &&
!(g_testGenKeyParams[index].paramSetParams.setKeyStorageFlag == true) &&
(g_testGenKeyParams[index].paramSetParams.keyStorageFlag == HKS_STORAGE_TEMP)) {
HKS_TEST_ASSERT(HksDeleteKey(keyAlias, NULL) == 0);
}
TestFreeBlob(&keyAlias);
HksFreeParamSet(&paramSet);
HksFreeParamSet(&paramSetOut);
HKS_TEST_LOG_I("[%u]TestGenerateKey, Testcase_GenerateKey_[%03u] pass!", times, g_testGenKeyParams[index].testId);
ASSERT_TRUE(ret == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_generate_random_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
class HksGenerateRandomTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksGenerateRandomTest::SetUpTestCase(void)
{
}
void HksGenerateRandomTest::TearDownTestCase(void)
{
}
void HksGenerateRandomTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksGenerateRandomTest::TearDown()
{
}
const struct HksTestGenRandomParams g_testGenRandomParams[] = {
/* normal case */
{ 0, HKS_SUCCESS, { true, HKS_MAX_RANDOM_LEN, true, HKS_MAX_RANDOM_LEN } },
};
/**
* @tc.name: HksGenerateRandomTest.HksGenerateRandomTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksGenerateRandomTest, HksGenerateRandomTest001, TestSize.Level1)
{
int32_t ret;
struct HksBlob *random = NULL;
ret = TestConstructBlobOut(&random,
g_testGenRandomParams[0].randomParams.blobExist,
g_testGenRandomParams[0].randomParams.blobSize,
g_testGenRandomParams[0].randomParams.blobDataExist,
g_testGenRandomParams[0].randomParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = HksGenerateRandomRun(random, 1);
if (ret != g_testGenRandomParams[0].expectResult) {
HKS_TEST_LOG_I("HksGenerateRandomRun failed, ret[%u] = %d", g_testGenRandomParams[0].testId, ret);
}
HKS_TEST_ASSERT(ret == g_testGenRandomParams[0].expectResult);
TestFreeBlob(&random);
ASSERT_TRUE(ret == 0);
}
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_hash_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksHashTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksHashTest::SetUpTestCase(void)
{
}
void HksHashTest::TearDownTestCase(void)
{
}
void HksHashTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksHashTest::TearDown()
{
}
const int DEFAULT_SRC_DATA_SIZE = 200;
const int DIGEST_SHA256_HASH_SIZE = 32;
const struct HksTestHashParams g_testHashParams[] = {
/* normal case */
{ 0, HKS_SUCCESS,
{ true, true, HKS_DIGEST_SHA256 },
{ true, DEFAULT_SRC_DATA_SIZE, true, DEFAULT_SRC_DATA_SIZE },
{ true, DIGEST_SHA256_HASH_SIZE, true, DIGEST_SHA256_HASH_SIZE }
},
};
/**
* @tc.name: HksHashTest.HksHashTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksHashTest, HksHashTest001, TestSize.Level1)
{
struct HksParamSet *paramSet = NULL;
struct HksBlob *srcData = NULL;
struct HksBlob *hash = NULL;
int32_t ret = TestConstructHashParamSet(&paramSet,
g_testHashParams[0].paramSetParams.paramSetExist,
g_testHashParams[0].paramSetParams.setDigest, g_testHashParams[0].paramSetParams.digest);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstuctBlob(&srcData,
g_testHashParams[0].srcDataParams.blobExist,
g_testHashParams[0].srcDataParams.blobSize,
g_testHashParams[0].srcDataParams.blobDataExist,
g_testHashParams[0].srcDataParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstructBlobOut(&hash,
g_testHashParams[0].hashParams.blobExist,
g_testHashParams[0].hashParams.blobSize,
g_testHashParams[0].hashParams.blobDataExist,
g_testHashParams[0].hashParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = HksHashRun(paramSet, srcData, hash, 1);
if (ret != g_testHashParams[0].expectResult) {
HKS_TEST_LOG_I("HksHashRun failed, ret[%u] = %d", g_testHashParams[0].testId, ret);
}
HKS_TEST_ASSERT(ret == g_testHashParams[0].expectResult);
HksFreeParamSet(&paramSet);
TestFreeBlob(&srcData);
TestFreeBlob(&hash);
HKS_TEST_LOG_I("[%u]TestHash, Testcase_Hash_[%03u] pass!", 1, g_testHashParams[0].testId);
ASSERT_TRUE(ret == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
/*
* 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.
*/
#include <gtest/gtest.h>
#include "hks_mac_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_log.h"
using namespace testing::ext;
namespace {
class HksMacTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksMacTest::SetUpTestCase(void)
{
}
void HksMacTest::TearDownTestCase(void)
{
}
void HksMacTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksMacTest::TearDown()
{
}
const int HKS_TEST_MAC_REE_KEY_SIZE_32 = 32;
const int HKS_DEFAULT_MAC_SRCDATA_SIZE = 253;
const int HKS_DEFAULT_MAC_SHA256_SIZE = 32;
const struct HksTestMacParams g_testMacParams[] = {
/* success: ree-sha256 */
{ 0, HKS_SUCCESS, HKS_TEST_MAC_TYPE_REE, { 0 }, { 0 },
{ true, HKS_TEST_MAC_REE_KEY_SIZE_32, true, HKS_TEST_MAC_REE_KEY_SIZE_32 },
{ true, true, HKS_KEY_PURPOSE_MAC, true, HKS_DIGEST_SHA256 },
{ true, HKS_DEFAULT_MAC_SRCDATA_SIZE, true, HKS_DEFAULT_MAC_SRCDATA_SIZE },
{ true, HKS_DEFAULT_MAC_SHA256_SIZE, true, HKS_DEFAULT_MAC_SHA256_SIZE }
},
/* success: tee-sha256 */
{ 1, HKS_SUCCESS, HKS_TEST_MAC_TYPE_TEE, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{ true, true, HKS_ALG_AES, true, HKS_AES_KEY_SIZE_256, true, HKS_KEY_PURPOSE_MAC,
true, HKS_DIGEST_SHA256, false, 0, false, 0 },
{ 0 },
{ true, true, HKS_KEY_PURPOSE_MAC, true, HKS_DIGEST_SHA256 },
{ true, HKS_DEFAULT_MAC_SRCDATA_SIZE, true, HKS_DEFAULT_MAC_SRCDATA_SIZE },
{ true, HKS_DEFAULT_MAC_SHA256_SIZE, true, HKS_DEFAULT_MAC_SHA256_SIZE }
},
};
static int32_t ConstructDataToBlob(struct HksBlob **srcData, struct HksBlob **macData,
const struct HksTestBlobParams *srcDataParams, const struct HksTestBlobParams *macDataParams)
{
int32_t ret = TestConstuctBlob(srcData,
srcDataParams->blobExist,
srcDataParams->blobSize,
srcDataParams->blobDataExist,
srcDataParams->blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstuctBlob(macData,
macDataParams->blobExist,
macDataParams->blobSize,
macDataParams->blobDataExist,
macDataParams->blobDataSize);
HKS_TEST_ASSERT(ret == 0);
return ret;
}
static int32_t Mac(const struct HksBlob *key, const struct HksBlob *srcData, struct HksBlob *macData,
const struct HksTestMacParamSet *macParamSetParams, enum HksTestMacType macType)
{
struct HksParamSet *macParamSet = NULL;
int32_t ret;
if (macType == HKS_TEST_MAC_TYPE_REE) {
struct TestMacParamSetStructure paramStructTrue = {
&macParamSet,
macParamSetParams->paramSetExist,
macParamSetParams->setPurpose, macParamSetParams->purpose,
macParamSetParams->setDigest, macParamSetParams->digest, true, false
};
ret = TestConstructMacParamSet(&paramStructTrue);
} else {
struct TestMacParamSetStructure paramStructFalse = {
&macParamSet,
macParamSetParams->paramSetExist,
macParamSetParams->setPurpose, macParamSetParams->purpose,
macParamSetParams->setDigest, macParamSetParams->digest, false, false
};
ret = TestConstructMacParamSet(&paramStructFalse);
}
HKS_TEST_ASSERT(ret == 0);
ret = HksMacRun(key, macParamSet, srcData, macData, 1);
HksFreeParamSet(&macParamSet);
return ret;
}
static int32_t BaseTestMac(uint32_t index)
{
/* 1. generate key */
struct HksBlob *key = NULL;
int32_t ret;
if (g_testMacParams[index].macType == HKS_TEST_MAC_TYPE_REE) {
ret = TestConstuctBlob(&key,
g_testMacParams[index].keyParams.blobExist,
g_testMacParams[index].keyParams.blobSize,
g_testMacParams[index].keyParams.blobDataExist,
g_testMacParams[index].keyParams.blobDataSize);
} else {
if (g_testMacParams[index].keyAliasParams.blobExist) {
ret = GenerateKey(&key, &(g_testMacParams[index].keyAliasParams),
&g_testMacParams[index].genKeyParamSetParams, NULL);
} else {
ret = TestConstuctBlob(&key,
g_testMacParams[index].keyParams.blobExist,
g_testMacParams[index].keyParams.blobSize,
g_testMacParams[index].keyParams.blobDataExist,
g_testMacParams[index].keyParams.blobDataSize);
}
}
HKS_TEST_ASSERT(ret == 0);
/* 2. mac */
struct HksBlob *srcData = NULL;
struct HksBlob *macData = NULL;
ret = ConstructDataToBlob(&srcData, &macData,
&g_testMacParams[index].srcDataParams, &g_testMacParams[index].macParams);
HKS_TEST_ASSERT(ret == 0);
ret = Mac(key, srcData, macData, &g_testMacParams[index].macParamSetParams, g_testMacParams[index].macType);
if (ret != g_testMacParams[index].expectResult) {
HKS_TEST_LOG_I("failed, ret[%u] = %d", g_testMacParams[index].testId, ret);
}
HKS_TEST_ASSERT(ret == g_testMacParams[index].expectResult);
/* 3. deletekey */
if ((g_testMacParams[index].macType == HKS_TEST_MAC_TYPE_TEE) &&
(g_testMacParams[index].keyAliasParams.blobExist)) {
ret = HksDeleteKey(key, NULL);
HKS_TEST_ASSERT(ret == 0);
}
TestFreeBlob(&key);
TestFreeBlob(&srcData);
TestFreeBlob(&macData);
return ret;
}
/**
* @tc.name: HksMacTest.HksMacTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksMacTest, HksMacTest001, TestSize.Level1)
{
int32_t ret = BaseTestMac(0);
ASSERT_TRUE(ret == 0);
}
#ifndef _CUT_AUTHENTICATE_
/**
* @tc.name: HksMacTest.HksMacTest002
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksMacTest, HksMacTest002, TestSize.Level1)
{
int32_t ret = BaseTestMac(1);
ASSERT_TRUE(ret == 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
/*
* 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.
*/
#include <gtest/gtest.h>
#include "hks_modify_key_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_cipher.h"
#include "hks_test_common.h"
#include "hks_test_file_operator.h"
#include "hks_test_log.h"
#include "hks_test_mem.h"
#include "securec.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksModifyKeyTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksModifyKeyTest::SetUpTestCase(void)
{
}
void HksModifyKeyTest::TearDownTestCase(void)
{
}
void HksModifyKeyTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksModifyKeyTest::TearDown()
{
}
const int DEFAULT_AES_CIPHER_PLAIN_SIZE = 1000;
const int AES_DEFAULT_GCM_NONCE_LENGTH = 12;
const int AES_DEFAULT_AAD_LEN = 4;
#ifdef _STANDARD_SYSTEM_
const char *g_storePath = "/data/data/maindata/+0+0+0+0/key";
#endif
#ifdef _LITEONE_SYSTEM_
const char *g_storePath = "/storage/maindata/hks_client/key";
#endif
const char *g_testName = "TestName";
const struct HksTestCipherParams g_testCipherParams[] = {
/* success: aes256-gcm-none */
{ 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{
true, /* genKey params */
true, HKS_ALG_AES,
true, HKS_AES_KEY_SIZE_256,
true, HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT,
false, 0,
true, HKS_PADDING_NONE,
true, HKS_MODE_GCM,
false, 0
},
{ false, 0 },
{
HKS_TEST_CIPHER_TYPE_AES, true, /* encrypt params */
true, HKS_ALG_AES,
true, HKS_KEY_PURPOSE_ENCRYPT,
false, 0,
true, HKS_PADDING_NONE,
true, HKS_MODE_GCM,
false, 0,
true, AES_DEFAULT_GCM_NONCE_LENGTH,
true, AES_DEFAULT_AAD_LEN
},
{
HKS_TEST_CIPHER_TYPE_AES, true, /* decrypt params */
true, HKS_ALG_AES,
true, HKS_KEY_PURPOSE_DECRYPT,
false, 0,
true, HKS_PADDING_NONE,
true, HKS_MODE_GCM,
false, 0,
true, AES_DEFAULT_GCM_NONCE_LENGTH,
true, AES_DEFAULT_AAD_LEN
},
{ true, DEFAULT_AES_CIPHER_PLAIN_SIZE, true, DEFAULT_AES_CIPHER_PLAIN_SIZE },
{ true, DEFAULT_AES_CIPHER_PLAIN_SIZE + 16, true, DEFAULT_AES_CIPHER_PLAIN_SIZE + 16 },
{ true, DEFAULT_AES_CIPHER_PLAIN_SIZE, true, DEFAULT_AES_CIPHER_PLAIN_SIZE },
{ false, 0, false, 0 }
},
};
static int32_t ConstructDataToBlob(struct HksBlob **inData, struct HksBlob **outData,
const struct HksTestBlobParams *inTextParams, const struct HksTestBlobParams *outTextParams)
{
int32_t ret = TestConstuctBlob(inData,
inTextParams->blobExist,
inTextParams->blobSize,
inTextParams->blobDataExist,
inTextParams->blobDataSize);
HKS_TEST_ASSERT(ret == 0);
ret = TestConstuctBlob(outData,
outTextParams->blobExist,
outTextParams->blobSize,
outTextParams->blobDataExist,
outTextParams->blobDataSize);
HKS_TEST_ASSERT(ret == 0);
return ret;
}
static int32_t Encrypt(struct CipherEncryptStructure *encryptStruct)
{
int32_t ret;
struct HksParamSet *encryptParamSet = NULL;
uint32_t ivSize = encryptStruct->cipherParms->ivSize;
uint32_t nonceSize = encryptStruct->cipherParms->nonceSize;
uint32_t aadSize = encryptStruct->cipherParms->aadSize;
if (ivSize != 0) {
ret = TestConstuctBlob(encryptStruct->ivData, true, ivSize, true, ivSize);
HKS_TEST_ASSERT(ret == 0);
}
if (nonceSize != 0) {
ret = TestConstuctBlob(encryptStruct->nonceData, true, nonceSize, true, nonceSize);
HKS_TEST_ASSERT(ret == 0);
}
if (aadSize != 0) {
ret = TestConstuctBlob(encryptStruct->aadData, true, aadSize, true, aadSize);
HKS_TEST_ASSERT(ret == 0);
}
struct AesCipherParamSetStructure enParamStruct = {
&encryptParamSet,
encryptStruct->cipherParms->paramSetExist,
encryptStruct->cipherParms->setAlg, encryptStruct->cipherParms->alg,
encryptStruct->cipherParms->setPurpose, encryptStruct->cipherParms->purpose,
encryptStruct->cipherParms->setPadding, encryptStruct->cipherParms->padding,
encryptStruct->cipherParms->setBlockMode, encryptStruct->cipherParms->mode,
encryptStruct->cipherParms->setIv, *(encryptStruct->ivData),
encryptStruct->cipherParms->setNonce, *(encryptStruct->nonceData),
encryptStruct->cipherParms->setAad, *(encryptStruct->aadData),
encryptStruct->cipherParms->setIsKeyAlias, encryptStruct->cipherParms->isKeyAlias
};
ret = TestConstructAesCipherParamSet(&enParamStruct);
HKS_TEST_ASSERT(ret == 0);
ret = HksEncryptRun(encryptStruct->keyAlias, encryptParamSet, encryptStruct->plainData, encryptStruct->cipherData,
encryptStruct->performTimes);
HksFreeParamSet(&encryptParamSet);
return ret;
}
static int32_t DecryptCipher(struct CipherDecryptStructure *decryptStruct)
{
int32_t ret = TestConstuctBlob(decryptStruct->decryptedData,
decryptStruct->cipherParms->decryptedTextParams.blobExist,
decryptStruct->cipherParms->decryptedTextParams.blobSize,
decryptStruct->cipherParms->decryptedTextParams.blobDataExist,
decryptStruct->cipherParms->decryptedTextParams.blobDataSize);
HKS_TEST_ASSERT(ret == 0);
struct HksParamSet *decryptParamSet = NULL;
struct AesCipherParamSetStructure deParamStruct = {
&decryptParamSet,
decryptStruct->cipherParms->decryptParamSetParams.paramSetExist,
decryptStruct->cipherParms->decryptParamSetParams.setAlg,
decryptStruct->cipherParms->decryptParamSetParams.alg,
decryptStruct->cipherParms->decryptParamSetParams.setPurpose,
decryptStruct->cipherParms->decryptParamSetParams.purpose,
decryptStruct->cipherParms->decryptParamSetParams.setPadding,
decryptStruct->cipherParms->decryptParamSetParams.padding,
decryptStruct->cipherParms->decryptParamSetParams.setBlockMode,
decryptStruct->cipherParms->decryptParamSetParams.mode,
decryptStruct->cipherParms->decryptParamSetParams.setIv, decryptStruct->ivData,
decryptStruct->cipherParms->decryptParamSetParams.setNonce, decryptStruct->nonceData,
decryptStruct->cipherParms->decryptParamSetParams.setAad, decryptStruct->aadData,
decryptStruct->cipherParms->decryptParamSetParams.setIsKeyAlias,
decryptStruct->cipherParms->decryptParamSetParams.isKeyAlias
};
ret = TestConstructAesCipherParamSet(&deParamStruct);
HKS_TEST_ASSERT(ret == 0);
ret = HksDecryptRun(decryptStruct->keyAlias, decryptParamSet, decryptStruct->cipherData,
*(decryptStruct->decryptedData), decryptStruct->performTimes);
HksFreeParamSet(&decryptParamSet);
return ret;
}
int32_t GenerateKeyTwo(struct HksBlob *keyAlias, const struct HksTestBlobParams *keyAliasParams,
const struct HksTestGenKeyParamsParamSet *genKeyParamSetParams,
const struct HksTestGenKeyParamsParamSetOut *genKeyParamSetParamsOut)
{
struct HksParamSet *paramSet = NULL;
struct GenerateKeyParamSetStructure paramStruct = {
&paramSet,
genKeyParamSetParams->paramSetExist,
genKeyParamSetParams->setAlg, genKeyParamSetParams->alg,
genKeyParamSetParams->setKeySize, genKeyParamSetParams->keySize,
genKeyParamSetParams->setPurpose, genKeyParamSetParams->purpose,
genKeyParamSetParams->setDigest, genKeyParamSetParams->digest,
genKeyParamSetParams->setPadding, genKeyParamSetParams->padding,
genKeyParamSetParams->setBlockMode, genKeyParamSetParams->mode,
genKeyParamSetParams->setKeyStorageFlag, genKeyParamSetParams->keyStorageFlag
};
int32_t ret = TestConstructGenerateKeyParamSet(&paramStruct);
HKS_TEST_ASSERT(ret == 0);
struct HksParamSet *paramSetOut = NULL;
if (genKeyParamSetParamsOut != NULL) {
ret = TestConstructGenerateKeyParamSetOut(&paramSet,
genKeyParamSetParamsOut->paramSetExist, genKeyParamSetParamsOut->paramSetSize);
HKS_TEST_ASSERT(ret == 0);
}
ret = HksGenerateKey(keyAlias, paramSet, paramSetOut);
HKS_TEST_ASSERT(ret == 0);
HksFreeParamSet(&paramSet);
return ret;
}
static int32_t ModifyKey(struct HksBlob *keyAlias)
{
uint32_t sizeOne = HksTestFileSize(g_storePath, (char *)keyAlias->data);
uint8_t *bufOne = (uint8_t *)HksTestMalloc(sizeOne);
if (bufOne == NULL) {
return HKS_ERROR_MALLOC_FAIL;
}
uint32_t sizeRead = HksTestFileRead(g_storePath, (char *)keyAlias->data, 0, bufOne, sizeOne);
(void)memset_s(bufOne, sizeRead, 0, sizeRead);
int32_t ret = HksTestFileWrite(g_storePath, (char *)keyAlias->data, 0, bufOne, sizeOne);
HksTestFree(bufOne);
return ret;
}
int32_t BaseTestCipherProcess(struct HksBlob *keyAlias, uint32_t index)
{
struct HksBlob *plainData = NULL;
struct HksBlob *cipherData = NULL;
int32_t ret = ConstructDataToBlob(&plainData, &cipherData,
&g_testCipherParams[index].plainTextParams, &g_testCipherParams[index].cipherTextParams);
HKS_TEST_ASSERT(ret == 0);
struct HksBlob *ivData = NULL;
struct HksBlob *nonceData = NULL;
struct HksBlob *aadData = NULL;
struct HksBlob *decryptedData = NULL;
/* 2. encrypt */
do {
struct CipherEncryptStructure testEncryptStruct = {
keyAlias, &g_testCipherParams[index].encryptParamSetParams,
plainData, cipherData, &ivData, &nonceData, &aadData, 1
};
ret = Encrypt(&testEncryptStruct);
if (ret != g_testCipherParams[index].expectResult) {
break;
}
/* 3. decrypt */
struct CipherDecryptStructure testDecryptStruct = {
keyAlias, &g_testCipherParams[index], cipherData,
&decryptedData, ivData, nonceData, aadData, 1
};
ret = DecryptCipher(&testDecryptStruct);
if (ret != g_testCipherParams[index].expectResult) {
break;
}
if (ret == g_testCipherParams[index].expectResult) {
if (plainData->size != decryptedData->size) {
break;
};
ret = memcmp(plainData->data, decryptedData->data, plainData->size);
}
} while (0);
TestFreeBlob(&plainData);
TestFreeBlob(&cipherData);
TestFreeBlob(&decryptedData);
TestFreeBlob(&ivData);
TestFreeBlob(&nonceData);
TestFreeBlob(&aadData);
return ret;
}
/**
* @tc.name: HksModifyKeyTest.HksModifyKeyTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksModifyKeyTest, HksModifyKeyTest001, TestSize.Level1)
{
uint32_t index = 0;
struct HksBlob keyAlias = { strlen(g_testName), (uint8_t *)g_testName };
int32_t ret = GenerateKeyTwo(&keyAlias, &g_testCipherParams[index].keyAliasParams,
&g_testCipherParams[index].genKeyParamSetParams, &g_testCipherParams[index].genKeyParamSetParamsOut);
EXPECT_EQ(ret, 0);
ret = BaseTestCipherProcess(&keyAlias, 0);
EXPECT_EQ(ret, 0);
struct HksBlob *plainData = NULL;
struct HksBlob *cipherData = NULL;
ret = ConstructDataToBlob(&plainData, &cipherData,
&g_testCipherParams[index].plainTextParams, &g_testCipherParams[index].cipherTextParams);
EXPECT_EQ(ret, 0);
struct HksBlob *ivData = NULL;
struct HksBlob *nonceData = NULL;
struct HksBlob *aadData = NULL;
/* 2. encrypt */
struct CipherEncryptStructure testEncryptStruct = {
&keyAlias, &g_testCipherParams[index].encryptParamSetParams,
plainData, cipherData, &ivData, &nonceData, &aadData, 1
};
ret = Encrypt(&testEncryptStruct);
EXPECT_EQ(ret, 0);
ret = ModifyKey(&keyAlias);
EXPECT_EQ(ret, 0);
/* 3. decrypt */
struct HksBlob *decryptedData = NULL;
struct CipherDecryptStructure testDecryptStruct = {
&keyAlias, &g_testCipherParams[index], cipherData,
&decryptedData, ivData, nonceData, aadData, 1
};
ret = DecryptCipher(&testDecryptStruct);
HKS_TEST_ASSERT(ret != g_testCipherParams[index].expectResult);
TestFreeBlob(&plainData);
TestFreeBlob(&cipherData);
TestFreeBlob(&decryptedData);
TestFreeBlob(&ivData);
TestFreeBlob(&nonceData);
TestFreeBlob(&aadData);
EXPECT_NE(ret, 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_others_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_type.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksOthersTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksOthersTest::SetUpTestCase(void)
{
}
void HksOthersTest::TearDownTestCase(void)
{
}
void HksOthersTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksOthersTest::TearDown()
{
}
/**
* @tc.name: HksOthersTest.HksOthersTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest001, TestSize.Level1)
{
int32_t ret = HksGetKeyParamSet(NULL, NULL, NULL);
ASSERT_TRUE(ret == HKS_ERROR_NULL_POINTER);
}
/**
* @tc.name: HksOthersTest.HksOthersTest002
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest002, TestSize.Level1)
{
int32_t ret = HksGetKeyInfoList(NULL, NULL, NULL);
ASSERT_TRUE(ret == HKS_ERROR_NULL_POINTER);
}
/**
* @tc.name: HksOthersTest.HksOthersTest003
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest003, TestSize.Level1)
{
int32_t ret = HksAttestKey(NULL, NULL, NULL);
ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
}
/**
* @tc.name: HksOthersTest.HksOthersTest004
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest004, TestSize.Level1)
{
int32_t ret = HksGetCertificateChain(NULL, NULL, NULL);
ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
}
/**
* @tc.name: HksOthersTest.HksOthersTest005
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest005, TestSize.Level1)
{
int32_t ret = HksWrapKey(NULL, NULL, NULL, NULL);
ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
}
/**
* @tc.name: HksOthersTest.HksOthersTest006
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest006, TestSize.Level1)
{
int32_t ret = HksUnwrapKey(NULL, NULL, NULL, NULL);
ASSERT_TRUE(ret == HKS_ERROR_NOT_SUPPORTED);
}
/**
* @tc.name: HksOthersTest.HksOthersTest006
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest007, TestSize.Level1)
{
int32_t ret = HksGetSdkVersion(NULL);
ASSERT_TRUE(ret == HKS_ERROR_NULL_POINTER);
}
/**
* @tc.name: HksOthersTest.HksOthersTest008
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksOthersTest, HksOthersTest008, TestSize.Level1)
{
int32_t ret = HksInitialize();
ASSERT_TRUE(ret == HKS_SUCCESS);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_safe_cipher_key_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_curve25519.h"
#include "hks_test_file_operator.h"
#include "hks_test_log.h"
#include "hks_test_mem.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksSafeCipherKeyTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksSafeCipherKeyTest::SetUpTestCase(void)
{
}
void HksSafeCipherKeyTest::TearDownTestCase(void)
{
}
void HksSafeCipherKeyTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksSafeCipherKeyTest::TearDown()
{
}
#ifdef _STANDARD_SYSTEM_
const char *g_storePath = "/data/data/maindata/+0+0+0+0/key";
#endif
#ifdef _LITEONE_SYSTEM_
const char *g_storePath = "/storage/maindata/hks_client/key";
#endif
const char *g_testEd25519 = "test_ed25519";
static int32_t CompareTwoKey(struct HksBlob *keyAliasOne, struct HksBlob *keyAliasTwo)
{
uint32_t sizeOne = HksTestFileSize(g_storePath, (char *)keyAliasOne->data);
uint8_t *bufOne = (uint8_t *)HksTestMalloc(sizeOne);
if (bufOne == NULL) {
return HKS_ERROR_MALLOC_FAIL;
}
uint32_t sizeRead = HksTestFileRead(g_storePath, (char *)keyAliasOne->data, 0, bufOne, sizeOne);
uint32_t sizeTwo = HksTestFileSize(g_storePath, (char *)keyAliasTwo->data);
uint8_t *bufTwo = (uint8_t *)HksTestMalloc(sizeTwo);
if (bufTwo == NULL) {
HksTestFree(bufOne);
return HKS_ERROR_MALLOC_FAIL;
}
sizeRead = HksTestFileRead(g_storePath, (char *)keyAliasTwo->data, 0, bufTwo, sizeOne);
int32_t ret = memcmp(bufOne, bufTwo, sizeRead);
HksTestFree(bufOne);
HksTestFree(bufTwo);
return ret;
}
/**
* @tc.name: HksSafeCipherKeyTest.HksSafeCipherKeyTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksSafeCipherKeyTest, HksSafeCipherKeyTest001, TestSize.Level1)
{
struct HksBlob ed25519Alias = { strlen(g_testEd25519), (uint8_t *)g_testEd25519 };
int32_t ret = TestGenerateEd25519Key(ed25519Alias);
uint8_t pubKey[32] = {0};
uint32_t pubKeyLen = 32;
struct HksBlob pubKeyInfo = { pubKeyLen, pubKey };
ret = HksExportPublicKey(&ed25519Alias, NULL, &pubKeyInfo);
EXPECT_EQ(ret, 0);
ret = HksDeleteKey(&ed25519Alias, NULL);
EXPECT_EQ(ret, 0);
struct HksBlob newAliasOne = { strlen("test_ed25519_1"), (uint8_t *)"test_ed25519_1" };
ret = TestImportEd25519(newAliasOne, &pubKeyInfo);
EXPECT_EQ(ret, 0);
struct HksBlob newAliasTwo = { strlen("test_ed25519_2"), (uint8_t *)"test_ed25519_2" };
ret = TestImportEd25519(newAliasTwo, &pubKeyInfo);
EXPECT_EQ(ret, 0);
ret = CompareTwoKey(&newAliasOne, &newAliasTwo);
EXPECT_NE(ret, 0);
ret = HksDeleteKey(&newAliasOne, NULL);
EXPECT_EQ(ret, 0);
ret = HksDeleteKey(&newAliasTwo, NULL);
EXPECT_EQ(ret, 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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.
*/
#include <gtest/gtest.h>
#include "hks_safe_compare_key_test.h"
#include "hks_api.h"
#include "hks_param.h"
#include "hks_test_api_performance.h"
#include "hks_test_common.h"
#include "hks_test_file_operator.h"
#include "hks_test_log.h"
#include "hks_test_mem.h"
using namespace testing::ext;
namespace {
#ifndef _CUT_AUTHENTICATE_
class HksSafeCompareKeyTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void HksSafeCompareKeyTest::SetUpTestCase(void)
{
}
void HksSafeCompareKeyTest::TearDownTestCase(void)
{
}
void HksSafeCompareKeyTest::SetUp()
{
EXPECT_EQ(HksInitialize(), 0);
}
void HksSafeCompareKeyTest::TearDown()
{
}
#ifdef _STANDARD_SYSTEM_
const char *g_storePath = "/data/data/maindata/+0+0+0+0/key";
#endif
#ifdef _LITEONE_SYSTEM_
const char *g_storePath = "/storage/maindata/hks_client/key";
#endif
const char *g_testOne = "TestOne";
const char *g_testTwo = "TestTwo";
static const struct HksTestGenKeyParams g_testGenKeyParams[] = {
/* x25519: tee sign/verify */
{ 0, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE },
{
true,
true, HKS_ALG_X25519,
true, HKS_CURVE25519_KEY_SIZE_256,
true, HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY,
false, 0,
false, 0,
false, 0,
false, 0
},
{ false, 0 },
},
};
static int32_t SafeTestGenerateKey(struct HksBlob *keyAlias)
{
uint32_t index = 0;
uint32_t performTimes = 1;
struct HksParamSet *paramSet = NULL;
struct GenerateKeyParamSetStructure paramStruct = {
&paramSet,
g_testGenKeyParams[index].paramSetParams.paramSetExist,
g_testGenKeyParams[index].paramSetParams.setAlg, g_testGenKeyParams[index].paramSetParams.alg,
g_testGenKeyParams[index].paramSetParams.setKeySize, g_testGenKeyParams[index].paramSetParams.keySize,
g_testGenKeyParams[index].paramSetParams.setPurpose, g_testGenKeyParams[index].paramSetParams.purpose,
g_testGenKeyParams[index].paramSetParams.setDigest, g_testGenKeyParams[index].paramSetParams.digest,
g_testGenKeyParams[index].paramSetParams.setPadding, g_testGenKeyParams[index].paramSetParams.padding,
g_testGenKeyParams[index].paramSetParams.setBlockMode, g_testGenKeyParams[index].paramSetParams.mode,
g_testGenKeyParams[index].paramSetParams.setKeyStorageFlag,
g_testGenKeyParams[index].paramSetParams.keyStorageFlag
};
int32_t ret = TestConstructGenerateKeyParamSet(&paramStruct);
HKS_TEST_ASSERT(ret == 0);
struct HksParamSet *paramSetOut = NULL;
ret = TestConstructGenerateKeyParamSetOut(&paramSetOut,
g_testGenKeyParams[index].paramSetParamsOut.paramSetExist,
g_testGenKeyParams[index].paramSetParamsOut.paramSetSize);
HKS_TEST_ASSERT(ret == 0);
ret = HksGenerateKeyRun(keyAlias, paramSet, paramSetOut, performTimes);
if (ret != g_testGenKeyParams[index].expectResult) {
HKS_TEST_LOG_I("failed, ret[%u] = %d", g_testGenKeyParams[index].testId, ret);
}
EXPECT_EQ(ret, g_testGenKeyParams[index].expectResult);
if (ret == g_testGenKeyParams[index].expectResult) {
ret = 0;
} else {
ret = 1;
}
HksFreeParamSet(&paramSet);
HksFreeParamSet(&paramSetOut);
return ret;
}
static int32_t CompareKeyData(struct HksBlob *keyAliasOne, struct HksBlob *keyAliasTwo)
{
uint32_t sizeOne = HksTestFileSize(g_storePath, (char *)keyAliasOne->data);
uint8_t *bufOne = (uint8_t *)HksTestMalloc(sizeOne);
if (bufOne == NULL) {
return HKS_ERROR_MALLOC_FAIL;
}
uint32_t sizeRead = HksTestFileRead(g_storePath, (char *)keyAliasOne->data, 0, bufOne, sizeOne);
uint32_t sizeTwo = HksTestFileSize(g_storePath, (char *)keyAliasTwo->data);
uint8_t *bufTwo = (uint8_t *)HksTestMalloc(sizeTwo);
if (bufTwo == NULL) {
HksTestFree(bufOne);
return HKS_ERROR_MALLOC_FAIL;
}
sizeRead = HksTestFileRead(g_storePath, (char *)keyAliasTwo->data, 0, bufTwo, sizeOne);
int32_t ret = memcmp(bufOne, bufTwo, sizeOne);
HksTestFree(bufOne);
HksTestFree(bufTwo);
return ret;
}
/**
* @tc.name: HksSafeCompareKeyTest.HksSafeCompareKeyTest001
* @tc.desc: The static function will return true;
* @tc.type: FUNC
*/
HWTEST_F(HksSafeCompareKeyTest, HksSafeCompareKeyTest001, TestSize.Level1)
{
struct HksBlob keyAliasOne = { strlen(g_testOne), (uint8_t *)g_testOne };
int32_t ret = SafeTestGenerateKey(&keyAliasOne);
EXPECT_EQ(ret, 0);
struct HksBlob keyAliasTwo = { strlen(g_testTwo), (uint8_t *)g_testTwo };
ret = SafeTestGenerateKey(&keyAliasTwo);
EXPECT_EQ(ret, 0);
ret = CompareKeyData(&keyAliasOne, &keyAliasTwo);
EXPECT_NE(ret, 0);
}
#endif /* _CUT_AUTHENTICATE_ */
}
\ 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/acts/security_lite/deviceauth_basic_deps/deviceauth.gni")
import("//test/xts/tools/build/suite.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
]
}
DEVICEAUTH_BASIC_DEPS_CPP_DIR =
"//test/xts/acts/security/deviceauth/deviceauth_basic_deps"
DEVICEAUTH_BASIC_DEPS_CPP_SOURCE = [
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/print_log.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/test_timer.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_file_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_mutex_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_file_f_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_thread_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_dev_info_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_condition_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_file_utils_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_file_iot_flash_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_time_test.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_file_common.cpp",
"${DEVICEAUTH_BASIC_DEPS_CPP_DIR}/hc_alg_test.cpp",
]
ohos_moduletest_suite("ActsDeviceAuthBasicDepsTest") {
configs = [ ":module_private_config" ]
cflags_cc = [
"-DHILOG_ENABLE",
"-Werror",
]
sources = [ "device_auth_test.cpp" ]
sources += DEVICEAUTH_BASIC_DEPS_CPP_SOURCE
include_dirs = [
"//third_party/googletest/googlemock/include",
# hctest.h compatible with c++
"//test/xts/acts/security/deviceauth/deviceauth_basic_deps",
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
"//base/security/deviceauth/deps_adapter/os_adapter/interfaces/liteos",
"//base/startup/syspara_lite/interfaces/kits",
"//test/xts/acts/security_lite/deviceauth_basic_deps",
]
include_dirs += DEVICEAUTH_BASIC_DEPS_INC
deps = [
"//base/security/deviceauth/deps_adapter:deviceauth_hal_linux",
"//third_party/bounds_checking_function:libsec_static",
"//utils/native/base:utils",
]
cflags = [ "-Werror" ]
defines = [
"MKDIR_IMPLEMENTED=1",
"STAT_IMPLEMENTED=1",
"ACCESS_IMPLEMENTED=1",
"F_API_IMPLEMENTED=1",
"FLASH_START_ADDRESS_HICHAIN=0",
"UTILS_FILE_IMPLEMENTED=0",
"TEST_PTHREAD_CREATE_DETACHED=1",
"TEST_HC_FILE_OPEN_SERIES=1",
"TEST_HKDF_WITH_KEY_ALIAS_TRUE=1",
"TEST_IMPORT_ASYMMETRIC_KEY=0",
"TEST_COMPUTEHMAC_WITH_ISALIAS_TRUE=0",
"TEST_HASH_TO_POINT=1",
"TEST_GENERATE_KEY_PAIR_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET_WITH_STORAGE=1",
"TEST_AGREE_SHARED_SECRET=1",
"TEST_BIG_NUM_EXP_MOD=1",
]
}
{
"kits": [
{
"push": [
"ActsDeviceAuthBasicDepsTest->/data/local/tmp/ActsDeviceAuthBasicDepsTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsDeviceAuthBasicDepsTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsDeviceAuthBasicDepsTest Tests"
}
/*
* 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.
*/
#include <gtest/gtest.h>
#include <securec.h>
#include <cstdbool>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include "hc_alg_test.h"
#include "hc_condition_test.h"
#include "hc_dev_info_test.h"
#include "hc_file_f_test.h"
#include "hc_file_iot_flash_test.h"
#include "hc_file_test.h"
#include "hc_file_utils_test.h"
#include "hc_mutex_test.h"
#include "hc_thread_test.h"
#include "hc_time_test.h"
#include "print_log.h"
using namespace testing::ext;
namespace {
class DeviceAuthTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void DeviceAuthTest::SetUpTestCase(void)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
void DeviceAuthTest::TearDownTestCase(void)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
void DeviceAuthTest::SetUp()
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
(void)(srand(time(nullptr)));
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
void DeviceAuthTest::TearDown()
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcMutex
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcMutex, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcMutex();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcThread
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcThread, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcThread();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcGetUdid
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcGetUdid, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcGetUdid();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcFile
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcFile, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcFile();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcFileFApi
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcFileFApi, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcFileFApi();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcFileUtilsFile
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcFileUtilsFile, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcFileUtilsFile();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseSemCondition
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseSemCondition, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcSemCondition();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCasePthreadCondition
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCasePthreadCondition, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcPthreadCondition();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcFileIotFlash
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcFileIotFlash, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcFileIotFlash();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcTime
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcTime, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcTime();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
/**
* @tc.name: DeviceAuthTest.TestCaseHcAlg
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(DeviceAuthTest, TestCaseHcAlg, TestSize.Level1)
{
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
TestHcAlg();
LOGI("++++++++++++++++++++++++++++++++++++++++\n");
}
} // namespace
../../../security_lite/deviceauth_basic_deps/hc_alg_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_condition_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_dev_info_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_file_common.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_file_f_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_file_iot_flash_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_file_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_file_utils_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_mutex_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_thread_test.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/hc_time_test.c
\ 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.
*/
#ifndef HC_COMPATIBLE_GTEST_TEST_H
#define HC_COMPATIBLE_GTEST_TEST_H
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <cstdint>
#include <vector>
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) \
EXPECT_THAT(std::vector<uint8_t>((actual), (actual) + (num_elements)), \
::testing::ElementsAreArray((expected), (num_elements)))
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) \
EXPECT_THAT(std::vector<uint8_t>((actual), (actual) + (num_elements)), \
::testing::ElementsAreArray((expected), (num_elements))) << (message)
#define TEST_ASSERT_EQUAL(expected, actual) EXPECT_EQ((actual), (expected))
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) EXPECT_EQ((actual), (expected)) << (message)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) EXPECT_STREQ((actual), (expected))
#define TEST_ASSERT_GREATER_OR_EQUAL(threshold, actual) EXPECT_GE((actual), (threshold))
#define TEST_ASSERT_GREATER_THAN(threshold, actual) EXPECT_GT((actual), (threshold))
#define TEST_ASSERT_LESS_OR_EQUAL(threshold, actual) EXPECT_LE((actual), (threshold))
#define TEST_ASSERT_LESS_THAN(threshold, actual) EXPECT_LT((actual), (threshold))
#define TEST_ASSERT_MESSAGE(condition, message) EXPECT_TRUE((condition)) << (message)
#define TEST_ASSERT_NOT_EQUAL(expected, actual) EXPECT_NE((actual), (expected))
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) EXPECT_NE((actual), (expected)) << (message)
#define TEST_ASSERT_NOT_NULL(pointer) EXPECT_NE((pointer), nullptr)
#define TEST_ASSERT_NULL(pointer) EXPECT_EQ((pointer), nullptr)
#define TEST_ASSERT_TRUE(condition) EXPECT_TRUE((condition))
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) EXPECT_TRUE((condition)) << (message)
#endif // HC_COMPATIBLE_GTEST_TEST_H
../../../security_lite/deviceauth_basic_deps/print_log.c
\ No newline at end of file
../../../security_lite/deviceauth_basic_deps/test_timer.c
\ 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")
########################################################
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"//utils/native/base/include",
"//third_party/bounds_checking_function/include",
"//test/xts/acts/security_lite/huks/common/include",
]
}
########################################################
ohos_moduletest_suite("ActsDeviceAuthFunctionTest") {
configs = [ ":module_private_config" ]
cflags_cc = [ "-DHILOG_ENABLE" ]
defines = [ "_STANDARD_SYSTEM_" ]
sources = [
"src/deviceauth_standard_test.cpp",
"src/deviceauth_test_mock.cpp",
]
include_dirs = [
"./include",
"//third_party/json/include",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//foundation/communication/dsoftbus/interfaces/inner_kits/transport",
"//base/security/deviceauth/common_lib/interfaces/",
"//base/security/deviceauth/deps_adapter/key_management_adapter/interfaces/",
"//base/security/deviceauth/deps_adapter/key_management_adapter/impl/inc",
"//base/security/deviceauth/interfaces/innerkits",
"//base/security/deviceauth/services/dev/inc",
"//base/security/deviceauth/services/data_manager/inc/",
"//base/security/deviceauth/services/group_manager/inc/broadcast_manager",
"//base/security/deviceauth/services/frameworks/inc/",
"//base/security/deviceauth/deps_adapter/os_adapter/impl/interfaces/",
"//base/security/deviceauth/deps_adapter/os_adapter/impl/interfaces/linux/",
"//base/security/deviceauth/deps_adapter/os_adapter/interfaces/liteos",
"//base/security/deviceauth/deps_adapter/os_adapter/interfaces",
]
deps = [
"//base/security/deviceauth/services:deviceauth",
"//base/security/deviceauth/services:deviceauth_service",
"//base/security/huks/interfaces/innerkits/huks_standard/main:libhukssdk",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/cJSON:cjson_static",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/openssl:libcrypto_static",
"//utils/native/base:utils",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
]
}
{
"kits": [
{
"push": [
"ActsDeviceAuthFunctionTest->/data/local/tmp/ActsDeviceAuthFunctionTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsDeviceAuthFunctionTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsDeviceAuthFunctionTest Tests"
}
/*
* 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.
*/
#ifndef DEVICEAUTH_STANDARD_TEST_H
#define DEVICEAUTH_STANDARD_TEST_H
#include <cstdint>
#include "gmock/gmock.h"
const char *TEST_APP_NAME = "TestApp";
const int32_t TEMP_REQUEST_ID = 123;
const int32_t BUFFER_SIZE = 2048;
const char *CLIENT_AUTH_ID = "3C58C27533D8";
const char *SERVER_AUTH_ID = "CAF34E13190CBA510AA8DABB70CDFF8E9F623656DED400EF0D4CFD9E88FD6202";
const char *PIN_CODE = "123456";
const int32_t CLIENT_REQUEST_ID = 123;
const int32_t SERVER_REQUEST_ID = 345;
const int32_t STR_BUFF_SZ_MIN = 32;
const int32_t STR_BUFF_SZ_NORMAL = 128;
const int32_t MAX_GROUP_NUMBER = 101;
typedef enum {
ON_REQUEST = 1,
ON_ERROR = 2,
ON_FINISH = 3,
ON_SESSION_KEY_RETURNED = 4,
ON_TRANSMIT = 5
} CallbackType;
#endif
/*
* 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.
*/
#ifndef DEVICEAUTH_STANDARD_MOCK_H
#define DEVICEAUTH_STANDARD_MOCK_H
#include <cstdbool>
#include <cstdint>
void SetClient(bool tag);
bool GetClient();
#endif
/*
* 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.
*/
#include <ctime>
#include <gtest/gtest.h>
#include "deviceauth_test_mock.h"
#include "deviceauth_standard_test.h"
extern "C" {
#include "common_defs.h"
#include "json_utils.h"
#include "device_auth.h"
#include "device_auth_defines.h"
#include "database_manager.h"
#include "hc_condition.h"
#include "hc_mutex.h"
#include "hc_types.h"
}
using namespace std;
using namespace testing::ext;
namespace
{
static bool g_isNeedContinue = false;
static int64_t g_requestId = 0L;
static int g_operationCode = -1;
static int g_errorCode = 1;
static char *g_tempStr = nullptr;
static int g_messageCode = -1;
void ClearTempValue()
{
g_isNeedContinue = false;
g_requestId = 0L;
g_operationCode = -1;
g_errorCode = 1;
g_tempStr = nullptr;
g_messageCode = -1;
}
enum {
GROUP_CREATED = 0,
GROUP_DELETED,
DEVICE_BOUND,
DEVICE_UNBOUND,
DEVICE_NOT_TRUSTED,
LAST_GROUP_DELETED,
TRUSTED_DEVICE_NUM_CHANGED
};
/* test suit - GET_INSTANCE */
class GET_INSTANCE : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void GET_INSTANCE::SetUpTestCase()
{
int32_t ret = InitDeviceAuthService();
ASSERT_EQ(ret == HC_SUCCESS, true);
}
void GET_INSTANCE::TearDownTestCase()
{
DestroyDeviceAuthService();
ClearTempValue();
}
void GET_INSTANCE::SetUp()
{
}
void GET_INSTANCE::TearDown()
{
}
class REGISTER_CALLBACK : public testing::Test {
public:
const DeviceGroupManager *gm = GetGmInstance();
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
/* start cases */
/**
* @tc.name: GET_INSTANCE.TC_GET_GM_INSTANCE
* @tc.desc: Test GetGmInstance interface function;
* @tc.type: FUNC
*/
HWTEST_F(GET_INSTANCE, TC_GET_GM_INSTANCE, TestSize.Level1)
{
const DeviceGroupManager *gm = GetGmInstance();
ASSERT_NE(gm, nullptr);
}
}
\ 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.
*/
#include <cstring>
#include "securec.h"
#include "deviceauth_test_mock.h"
static bool g_testForClient = false;
void SetClient(bool tag)
{
g_testForClient = tag;
}
bool GetClient()
{
return g_testForClient;
}
int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
{
const char *clientUdid = "D6350E39AD8F11963C181BEEDC11AC85158E04466B68F1F4E6D895237E0FE81C";
const char *serverUdid = "ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00";
if (g_testForClient) {
(void)memcpy_s(udid, udidLen - 1, clientUdid, strlen(clientUdid));
return 0;
}
(void)memcpy_s(udid, udidLen - 1, serverUdid, strlen(serverUdid));
return 0;
}
const char *GetStoragePath()
{
return "/data/data/deviceauth/hcgroup.dat";
}
......@@ -15,9 +15,11 @@ import("//test/xts/tools/build/suite.gni")
_all_test_packages = [
"${ACTS_ROOT}/global:global",
"${ACTS_ROOT}/security:security",
#"${ACTS_ROOT}/security:security",
"${ACTS_ROOT}/multimedia:multimedia",
"${ACTS_ROOT}/hiviewdfx:hiviewdfxtestacts",
#"${ACTS_ROOT}/hiviewdfx:hiviewdfxtestacts",
"${ACTS_ROOT}/barrierfree:barrierfree",
# "${ACTS_ROOT}/telephony:telephony",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册