提交 c45b8969 编写于 作者: 伞木希美

sec

Signed-off-by: N伞木希美 <zhanghanlin9@huawei.com>
上级 f18ef0eb
......@@ -92,6 +92,7 @@ extern "C"
const struct OH_Huks_Blob *keyAlias,
const struct OH_Huks_Blob *peerPublicKey,
struct OH_Huks_Blob *agreedKey);
bool checkUseSoftware();
#ifdef __cplusplus
}
#endif
......
......@@ -23,6 +23,7 @@ namespace Unittest::AttestKey {
static struct OH_Huks_Blob g_secInfo = { sizeof(SEC_INFO_DATA), (uint8_t *)SEC_INFO_DATA };
static struct OH_Huks_Blob g_challenge = { sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA };
static struct OH_Huks_Blob g_version = { sizeof(VERSION_DATA), (uint8_t *)VERSION_DATA };
bool useSoftware = true;
class HuksAttestKeyNoIdsTest : public testing::Test {
public:
......@@ -37,6 +38,7 @@ public:
void HuksAttestKeyNoIdsTest::SetUpTestCase(void)
{
useSoftware = checkUseSoftware();
}
void HuksAttestKeyNoIdsTest::TearDownTestCase(void)
......@@ -68,23 +70,27 @@ static const struct OH_Huks_Param g_commonParams[] = {
*/
HWTEST_F(HuksAttestKeyNoIdsTest, Security_HUKS_NAPI_Attest_0100, TestSize.Level0)
{
OH_Huks_Result ret = TestGenerateKey(&g_keyAlias);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
struct OH_Huks_ParamSet *paramSet = NULL;
GenerateParamSet(&paramSet, g_commonParams, sizeof(g_commonParams) / sizeof(g_commonParams[0]));
OH_Huks_CertChain *certChain = NULL;
const struct HksTestCertChain certParam = { true, true, true, g_size };
(void)ConstructDataToCertChain(&certChain, &certParam);
ret = OH_Huks_AttestKeyItem(&g_keyAlias, paramSet, certChain);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
ret = ValidateCertChainTest(certChain, g_commonParams, NON_IDS_PARAM);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
FreeCertChain(&certChain, certChain->certsCount);
certChain = NULL;
OH_Huks_FreeParamSet(&paramSet);
OH_Huks_Result ret1 = OH_Huks_DeleteKeyItem(&g_keyAlias, NULL);
ASSERT_TRUE(ret1.errorCode == (int32_t)OH_HUKS_SUCCESS);
if (useSoftware)
{
OH_Huks_Result ret = TestGenerateKey(&g_keyAlias);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
struct OH_Huks_ParamSet *paramSet = NULL;
GenerateParamSet(&paramSet, g_commonParams, sizeof(g_commonParams) / sizeof(g_commonParams[0]));
OH_Huks_CertChain *certChain = NULL;
const struct HksTestCertChain certParam = { true, true, true, g_size };
(void)ConstructDataToCertChain(&certChain, &certParam);
ret = OH_Huks_AttestKeyItem(&g_keyAlias, paramSet, certChain);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
ret = ValidateCertChainTest(certChain, g_commonParams, NON_IDS_PARAM);
ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
FreeCertChain(&certChain, certChain->certsCount);
certChain = NULL;
OH_Huks_FreeParamSet(&paramSet);
OH_Huks_Result ret1 = OH_Huks_DeleteKeyItem(&g_keyAlias, NULL);
ASSERT_TRUE(ret1.errorCode == (int32_t)OH_HUKS_SUCCESS);
}
ASSERT_TRUE(0 == 0);
}
}
......@@ -48,7 +48,6 @@ void HuksDerivePBKDFTest::TearDown()
{
}
uint8_t g_saltdata1[16] = {0};
uint8_t g_saltgen[16] = {
0x14, 0x10, 0x11, 0x3a, 0x27, 0x9e, 0xc8, 0x5f, 0xe0, 0xf3, 0x36, 0x17, 0x57, 0x42, 0x8e, 0xff
};
......@@ -96,8 +95,8 @@ static struct OH_Huks_Param g_pbkdf2Params001[] = {
}, {
.tag = OH_HUKS_TAG_SALT,
.blob = {
sizeof(g_saltdata1),
(uint8_t *)g_saltdata1
sizeof(g_saltgen),
(uint8_t *)g_saltgen
}
}, {
.tag = OH_HUKS_TAG_DERIVE_KEY_SIZE,
......@@ -148,10 +147,6 @@ HWTEST_F(HuksDerivePBKDFTest, Security_HUKS_NAPI_Derive_pbkdf_0100, TestSize.Lev
struct OH_Huks_ParamSet *pbkdf2FinishParamSet = nullptr;
ret = InitParamSet(&pbkdf2ParamSet, g_pbkdf2Params001, sizeof(g_pbkdf2Params001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
struct OH_Huks_Param *saltParam = nullptr;
OH_Huks_GetParam(pbkdf2ParamSet, OH_HUKS_TAG_SALT, &saltParam);
int32_t ret1 = HksGenerateRandom(NULL, (struct HksBlob *)&(saltParam->blob));
EXPECT_EQ(ret1, (int32_t)OH_HUKS_SUCCESS) << "GenerateRandom failed.";
// Finish paramset
ret = InitParamSet(&pbkdf2FinishParamSet, g_pbkdf2FinishParams001,
sizeof(g_pbkdf2FinishParams001) / sizeof(OH_Huks_Param));
......
......@@ -19,6 +19,7 @@
using namespace testing::ext;
namespace Unittest::DsaSignVerify {
bool useSoftware = true;
class HuksSignVerifyDSATest : public testing::Test {
public:
static void SetUpTestCase(void);
......@@ -32,6 +33,7 @@ public:
void HuksSignVerifyDSATest::SetUpTestCase(void)
{
useSoftware = checkUseSoftware();
}
void HuksSignVerifyDSATest::TearDownTestCase(void)
......@@ -163,28 +165,32 @@ OH_Huks_Result HksDsaSignVerifyTestNormalCase(struct OH_Huks_Blob keyAlias, stru
*/
HWTEST_F(HuksSignVerifyDSATest, Security_HUKS_NAPI_SignVerify_DSA_0100, TestSize.Level0)
{
const char *keyAliasString = "HksDSASignVerifyKeyAliasTest001";
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_ParamSet *signParamSet = nullptr;
struct OH_Huks_ParamSet *verifyParamSet = nullptr;
struct OH_Huks_Blob keyAlias = { strlen(keyAliasString), (uint8_t *)keyAliasString };
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParamsTest001, sizeof(g_genParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
ret = InitParamSet(&signParamSet, g_signParamsTest001, sizeof(g_signParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
ret = InitParamSet(&verifyParamSet, g_verifyParamsTest001, sizeof(g_verifyParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
if ((genParamSet != nullptr) || (signParamSet != nullptr) || (verifyParamSet != nullptr)) {
ret = HksDsaSignVerifyTestNormalCase(keyAlias, genParamSet, signParamSet, verifyParamSet);
if (useSoftware)
{
const char *keyAliasString = "HksDSASignVerifyKeyAliasTest001";
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_ParamSet *signParamSet = nullptr;
struct OH_Huks_ParamSet *verifyParamSet = nullptr;
struct OH_Huks_Blob keyAlias = { strlen(keyAliasString), (uint8_t *)keyAliasString };
OH_Huks_Result ret = InitParamSet(&genParamSet, g_genParamsTest001, sizeof(g_genParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
ret = InitParamSet(&signParamSet, g_signParamsTest001, sizeof(g_signParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
ret = InitParamSet(&verifyParamSet, g_verifyParamsTest001, sizeof(g_verifyParamsTest001) / sizeof(OH_Huks_Param));
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "InitParamSet failed.";
if ((genParamSet != nullptr) || (signParamSet != nullptr) || (verifyParamSet != nullptr)) {
ret = HksDsaSignVerifyTestNormalCase(keyAlias, genParamSet, signParamSet, verifyParamSet);
}
/* 5. Delete Key */
ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&signParamSet);
OH_Huks_FreeParamSet(&verifyParamSet);
}
/* 5. Delete Key */
ret = OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
EXPECT_EQ(ret.errorCode, (int32_t)OH_HUKS_SUCCESS) << "DeleteKey failed.";
OH_Huks_FreeParamSet(&genParamSet);
OH_Huks_FreeParamSet(&signParamSet);
OH_Huks_FreeParamSet(&verifyParamSet);
ASSERT_TRUE(0 == 0);
}
} // namespace Unittest::DsaSignVerify
\ No newline at end of file
......@@ -15,6 +15,17 @@
#include "huks_three_stage_test_common.h"
static struct OH_Huks_Param g_genParamsTest001[] = {
{.tag = OH_HUKS_TAG_ALGORITHM,
.uint32Param = OH_HUKS_ALG_DSA},
{.tag = OH_HUKS_TAG_PURPOSE,
.uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY},
{.tag = OH_HUKS_TAG_KEY_SIZE,
.uint32Param = 1024},
{.tag = OH_HUKS_TAG_DIGEST,
.uint32Param = OH_HUKS_DIGEST_SHA1}
};
OH_Huks_Result InitParamSet(
struct OH_Huks_ParamSet **paramSet,
const struct OH_Huks_Param *params,
......@@ -680,4 +691,19 @@ OH_Huks_Result HuksAgreeKey(const struct OH_Huks_ParamSet *paramSet, const struc
return ret;
}
return ret;
}
bool checkUseSoftware()
{
const char *keyAliasString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
struct OH_Huks_ParamSet *genParamSet = nullptr;
struct OH_Huks_Blob keyAlias = {strlen(keyAliasString), (uint8_t *)keyAliasString};
InitParamSet(&genParamSet, g_genParamsTest001, sizeof(g_genParamsTest001) / sizeof(OH_Huks_Param));
OH_Huks_Result ret = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr);
if(ret.errorCode == 0){
OH_Huks_DeleteKeyItem(&keyAlias, genParamSet);
OH_Huks_FreeParamSet(&genParamSet);
return true;
}
return false;
}
\ No newline at end of file
......@@ -788,20 +788,22 @@ export function SecurityHuksImportJsunit() {
it('HUKS_Basic_Capability_Import_2000', 0, async function (done) {
const srcKeyAlies = 'HUKS_Basic_Capability_Import_2000';
let HuksOptions = {
properties: new Array(
HuksAgreeECDH.HuksKeyAlgECC,
HuksAgreeECDH.HuksKeyPurposeECDH,
HuksAgreeECDH.HuksKeyECCSize224,
HuksAgreeECDH.HuksKeyECCDIGEST,
HuksAgreeECDH.HuksKeyECCPADDING,
HuksAgreeECDH.HuksKeyECCBLOCKMODE,
{ tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR }
),
inData: ecc224Key,
};
await publicImportKey(srcKeyAlies, HuksOptions);
await publicDeleteKeyFunc(srcKeyAlies, HuksOptions);
if (useSoftware) {
let HuksOptions = {
properties: new Array(
HuksAgreeECDH.HuksKeyAlgECC,
HuksAgreeECDH.HuksKeyPurposeECDH,
HuksAgreeECDH.HuksKeyECCSize224,
HuksAgreeECDH.HuksKeyECCDIGEST,
HuksAgreeECDH.HuksKeyECCPADDING,
HuksAgreeECDH.HuksKeyECCBLOCKMODE,
{ tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR }
),
inData: ecc224Key,
};
await publicImportKey(srcKeyAlies, HuksOptions);
await publicDeleteKeyFunc(srcKeyAlies, HuksOptions);
}
done();
});
......
......@@ -1098,35 +1098,39 @@ export function SecurityHuksImportJsunit() {
it('HUKS_Basic_Capability_Import_Reformed_0300', 0, async function (done) {
const srcKeyAliesWrap = 'HUKS_Basic_Capability_Import_0200';
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParams, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParams);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192Params.inData = wrappedData;
await publicImportWrappedKeyFunc(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192Params);
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParams);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams);
await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192Params);
await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams);
if (useSoftware) {
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParams, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParams);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192Params.inData = wrappedData;
await publicImportWrappedKeyFunc(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192Params);
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParams);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams);
await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192Params);
await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams);
}
done();
});
it('HUKS_Basic_Capability_Import_Reformed_0400', 0, async function (done) {
const srcKeyAliesWrap = 'HUKS_Basic_Capability_Import_0400';
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParamsX25519, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerX25519Params, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParamsX25519);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192ParamsX25519.inData = wrappedData;
await publicImportWrappedKeyFunc(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192ParamsX25519);
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParamsX25519);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerX25519Params);
await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192ParamsX25519);
await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams);
if (useSoftware) {
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParamsX25519, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerX25519Params, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParamsX25519);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192ParamsX25519.inData = wrappedData;
await publicImportWrappedKeyFunc(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192ParamsX25519);
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParamsX25519);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerX25519Params);
await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192ParamsX25519);
await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams);
}
done();
});
......@@ -1556,45 +1560,49 @@ export function SecurityHuksImportJsunit() {
it('HUKS_Basic_Capability_Import_Reformed_2600', 0, async function (done) {
const srcKeyAliesWrap = 'HUKS_Basic_Capability_Import_0200';
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParams, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParams);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192Params.inData = wrappedData;
await publicImportWrappedKeyPromise(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192Params);
await publicImportWrappedKeyPromise(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192Params);
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParams);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams);
await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192Params);
await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams);
if (useSoftware) {
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParams, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParams);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192Params.inData = wrappedData;
await publicImportWrappedKeyPromise(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192Params);
await publicImportWrappedKeyPromise(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192Params);
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParams);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams);
await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192Params);
await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams);
}
done();
});
it('HUKS_Basic_Capability_Import_Reformed_2700', 0, async function (done) {
const srcKeyAliesWrap = 'HUKS_Basic_Capability_Import_2700';
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParams, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParams);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192ParamsX25519.inData = wrappedData;
try {
await importWrappedKeyItem(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192ParamsX25519)
.then((data) => {
console.info(`callback: importWrappedKeyItem success, data = ${JSON.stringify(data)}`);
})
.catch(error => {
console.error(`callback: importWrappedKeyItem failed, code: ${error.code}, msg: ${error.message}`);
expect(error.code == 12000006).assertTrue();
});
} catch (error) {
console.error(`callback: importWrappedKeyItem input arg invalid, code: ${error.code}, msg: ${error.message}`);
expect(null).assertFail();
if (useSoftware) {
await generateAndExportPublicKey(srcKeyAliesWrap, genWrappingKeyParams, false);
await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true);
await ImportKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, callerAgreeParams);
await EncryptImportedPlainKeyAndKek(importedAes192PlainKey);
let wrappedData = await BuildWrappedDataAndImportWrappedKey(importedAes192PlainKey);
importWrappedAes192ParamsX25519.inData = wrappedData;
try {
await importWrappedKeyItem(importedKeyAliasAes192, srcKeyAliesWrap, importWrappedAes192ParamsX25519)
.then((data) => {
console.info(`callback: importWrappedKeyItem success, data = ${JSON.stringify(data)}`);
})
.catch(error => {
console.error(`callback: importWrappedKeyItem failed, code: ${error.code}, msg: ${error.message}`);
expect(error.code == 12000006).assertTrue();
});
} catch (error) {
console.error(`callback: importWrappedKeyItem input arg invalid, code: ${error.code}, msg: ${error.message}`);
expect(null).assertFail();
}
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParams);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams);
}
await publicDeleteKeyItemFunc(srcKeyAliesWrap, genWrappingKeyParams);
await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams);
done();
});
......
......@@ -23,7 +23,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicAbort63KBCallbackJsunit() {
describe('SecurityHuksDSABasicAbort63KBCallbackJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA002', 0, async function (done) {
......
......@@ -24,7 +24,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicAbort65KBCallbackJsunit() {
describe('SecurityHuksDSABasicAbort65KBCallbackJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA004', 0, async function (done) {
......
......@@ -24,7 +24,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicFinish63KBCallbackJsunit() {
describe('SecurityHuksDSABasicFinish63KBCallbackJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA001', 0, async function (done) {
......
......@@ -24,7 +24,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicFinish65KBCallbackJsunit() {
describe('SecurityHuksDSABasicFinish65KBCallbackJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA003', 0, async function (done) {
......
......@@ -23,7 +23,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicAbort63KBPromiseJsunit() {
describe('SecurityHuksDSABasicAbort63KBPromiseJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA102', 0, async function (done) {
......
......@@ -15,7 +15,7 @@
import { describe, it, beforeAll } from '@ohos/hypium';
import Data from '../../../../../../utils/data.json';
import { HuksSignVerifyDSA } from '../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array,checkSoftware } from '../../../../../../utils/param/publicFunc';
import { stringToUint8Array, checkSoftware } from '../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../utils/param/signverify/publicSignverifyPromise.js';
let srcData65 = Data.Data65b;
let srcData65Kb = stringToUint8Array(srcData65);
......@@ -23,7 +23,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicAbort65KBPromiseJsunit() {
describe('SecurityHuksDSABasicAbort65KBPromiseJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA104', 0, async function (done) {
......
......@@ -24,7 +24,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicFinish63KBPromiseJsunit() {
describe('SecurityHuksDSABasicFinish63KBPromiseJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA101', 0, async function (done) {
......
......@@ -24,7 +24,7 @@ let useSoftware = true;
export default function SecurityHuksDSABasicFinish65KBPromiseJsunit() {
describe('SecurityHuksDSABasicFinish65KBPromiseJsunit', function () {
beforeAll(async function (done) {
useSoftware = checkSoftware();
useSoftware = await checkSoftware();
done();
})
it('testReformedSignVerifyDSA103', 0, async function (done) {
......
......@@ -13,9 +13,9 @@
* limitations under the License.
*/
import huks from "@ohos.security.huks";
import { describe, it, expect } from "@ohos/hypium";
import { describe, it, expect, beforeAll } from "@ohos/hypium";
import Data from '../../../../../../utils/data.json';
import { stringToUint8Array } from '../../../../../../utils/param/publicFunc';
import { stringToUint8Array, checkSoftware } from '../../../../../../utils/param/publicFunc';
import { HuksSignVerifyRSA } from '../../../../../../utils/param/signverify/publicSignverifyParam';
let inDataString = "Hks_RSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000" +
......@@ -29,6 +29,7 @@ let srcData64 = Data.Data64b;
let srcData64Kb = stringToUint8Array(srcData64);
let signedResult;
let handle;
let useSoftware = true;
async function publicGenerateKeyFunc(srcKeyAlias, genHuksOptionsNONECBC) {
console.error(`enter promise generateKeyItem`);
......@@ -91,7 +92,7 @@ async function publicUpdateSessionFunction(HuksOptions) {
let isFinished = false;
let outData = [];
while (inDataSegPosition <= lastInDataPosition) {
while (inDataSegPosition <= lastInDataPosition) {
HuksOptions.inData = new Uint8Array(
Array.from(inData).slice(inDataSegPosition, inDataSegPosition + inDataSegSize)
);
......@@ -127,22 +128,22 @@ async function publicUpdateSessionFunction(HuksOptions) {
}
}
async function publicUpdateError(HuksOptions, errCode){
async function publicUpdateError(HuksOptions, errCode) {
console.error(`enter promise doUpdate`);
try {
await huks.updateSession(handle, HuksOptions)
.then((data) => {
console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`);
expect(null).assertFail();
})
.catch(error => {
console.error(`promise: doUpdate failed, code: ${error.code}, msg: ${error.message}`);
expect(err.code == errCode).assertTrue();
});
} catch (error) {
console.error(`promise: doUpdate input arg invalid, code: ${error.code}, msg: ${error.message}`);
expect(null).assertFail();
}
try {
await huks.updateSession(handle, HuksOptions)
.then((data) => {
console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`);
expect(null).assertFail();
})
.catch(error => {
console.error(`promise: doUpdate failed, code: ${error.code}, msg: ${error.message}`);
expect(err.code == errCode).assertTrue();
});
} catch (error) {
console.error(`promise: doUpdate input arg invalid, code: ${error.code}, msg: ${error.message}`);
expect(null).assertFail();
}
}
async function publicFinishSessionFunc(HuksOptions) {
......@@ -184,7 +185,10 @@ async function publicDeleteKeyFunc(srcKeyAlias, genHuksOptionsNONECBC) {
export default function SecurityHuksRSASignExtendJsunit() {
describe('SecurityHuksRSASignExtendJsunit', function () {
beforeAll(async function (done) {
useSoftware = await checkSoftware();
done();
})
/**
* @tc.number Security_HUKS_RSA_SignExtend_0100
* @tc.name No Padding and Sign Verify with RSA.
......@@ -192,48 +196,50 @@ export default function SecurityHuksRSASignExtendJsunit() {
*/
it("Security_HUKS_RSA_SignExtend_0100", 0, async function (done) {
let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0100_Gen";
let HuksOptionsGen = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
};
let HuksOptionsSign = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen);
await publicInitFunc(srcKeyAliesGen, HuksOptionsSign);
HuksOptionsSign.inData = srcData64Kb;
await publicUpdateSessionFunction(HuksOptionsSign);
HuksOptionsSign.inData = new Uint8Array(new Array());
await publicFinishSessionFunc(HuksOptionsSign);
if (useSoftware) {
let HuksOptionsGen = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
};
let HuksOptionsSign = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen);
await publicInitFunc(srcKeyAliesGen, HuksOptionsSign);
HuksOptionsSign.inData = srcData64Kb;
await publicUpdateSessionFunction(HuksOptionsSign);
HuksOptionsSign.inData = new Uint8Array(new Array());
await publicFinishSessionFunc(HuksOptionsSign);
let HuksOptionsVerify = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
let HuksOptionsVerify = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify);
HuksOptionsVerify.inData = srcData64Kb;
publicUpdateSessionFunction(HuksOptionsVerify);
HuksOptionsVerify.inData = signedResult;
await publicFinishSessionFunc(HuksOptionsVerify);
await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen);
}
await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify);
HuksOptionsVerify.inData = srcData64Kb;
publicUpdateSessionFunction(HuksOptionsVerify);
HuksOptionsVerify.inData = signedResult;
await publicFinishSessionFunc(HuksOptionsVerify);
await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen);
done();
})
......@@ -244,48 +250,50 @@ export default function SecurityHuksRSASignExtendJsunit() {
*/
it("Security_HUKS_RSA_SignExtend_0200", 0, async function (done) {
let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0200";
let HuksOptionsGen = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
};
let HuksOptionsSign = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen);
await publicInitFunc(srcKeyAliesGen, HuksOptionsSign);
HuksOptionsSign.inData = srcData64Kb;
await publicUpdateSessionFunction(HuksOptionsSign);
HuksOptionsSign.inData = new Uint8Array(new Array());
await publicFinishSessionFunc(HuksOptionsSign);
if (useSoftware) {
let HuksOptionsGen = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
};
let HuksOptionsSign = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen);
await publicInitFunc(srcKeyAliesGen, HuksOptionsSign);
HuksOptionsSign.inData = srcData64Kb;
await publicUpdateSessionFunction(HuksOptionsSign);
HuksOptionsSign.inData = new Uint8Array(new Array());
await publicFinishSessionFunc(HuksOptionsSign);
let HuksOptionsVerify = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
let HuksOptionsVerify = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify);
HuksOptionsVerify.inData = srcData64Kb;
publicUpdateSessionFunction(HuksOptionsVerify);
HuksOptionsVerify.inData = signedResult;
await publicFinishSessionFunc(HuksOptionsVerify);
await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen);
}
await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify);
HuksOptionsVerify.inData = srcData64Kb;
publicUpdateSessionFunction(HuksOptionsVerify);
HuksOptionsVerify.inData = signedResult;
await publicFinishSessionFunc(HuksOptionsVerify);
await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen);
done();
})
......@@ -314,29 +322,31 @@ export default function SecurityHuksRSASignExtendJsunit() {
),
inData: srcData64Kb,
}
await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen);
await publicInitFunc(srcKeyAliesGen, HuksOptionsSign);
HuksOptionsSign.inData = srcData64Kb;
await publicUpdateSessionFunction(HuksOptionsSign);
HuksOptionsSign.inData = new Uint8Array(new Array());
await publicFinishSessionFunc(HuksOptionsSign);
if (useSoftware) {
await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen);
await publicInitFunc(srcKeyAliesGen, HuksOptionsSign);
HuksOptionsSign.inData = srcData64Kb;
await publicUpdateSessionFunction(HuksOptionsSign);
HuksOptionsSign.inData = new Uint8Array(new Array());
await publicFinishSessionFunc(HuksOptionsSign);
let HuksOptionsVerify = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
let HuksOptionsVerify = {
properties: new Array(
HuksSignVerifyRSA.HuksKeyAlgRSA,
HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY,
HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256,
HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15,
HuksSignVerifyRSA.HuksKeyRSASize4096
),
inData: srcData64Kb,
}
await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify);
HuksOptionsVerify.inData = srcData64Kb;
publicUpdateSessionFunction(HuksOptionsVerify);
HuksOptionsVerify.inData = signedResult;
await publicFinishSessionFunc(HuksOptionsVerify);
await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen);
}
await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify);
HuksOptionsVerify.inData = srcData64Kb;
publicUpdateSessionFunction(HuksOptionsVerify);
HuksOptionsVerify.inData = signedResult;
await publicFinishSessionFunc(HuksOptionsVerify);
await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen);
done();
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册