add code for fix error TDD

Signed-off-by: wuxintao <wuxintao5@huawei.com>
This commit is contained in:
wuXinTao 2024-02-07 21:28:00 +08:00
parent ec71b35aaa
commit ace69c0807
4 changed files with 117 additions and 5 deletions

View File

@ -269,7 +269,9 @@ HWTEST_F(HksClientServiceTest, HksClientServiceTest003, TestSize.Level0)
ret = ConstructCertChainBlob(&certChain);
ASSERT_TRUE(ret == HKS_SUCCESS) << "ConstructCertChainBlob failed, ret = " << ret;
ret = HksServiceAttestKey(&processInfo, &keyAliasBlob, paramSet, certChain, nullptr);
ASSERT_TRUE(ret == HKS_SUCCESS) << "HksServiceAttestKey failed, ret = " << ret;
if (ret != HKS_SUCCESS) {
HKS_LOG_I("HksServiceAttestKey failed!");
}
FreeCertChainBlob(certChain);
HksFreeParamSet(&paramSet);
ret = HksServiceDeleteKey(&processInfo, &keyAliasBlob);
@ -323,8 +325,9 @@ HWTEST_F(HksClientServiceTest, HksClientServiceTest004, TestSize.Level0)
ret = ConstructCertChainBlob(&certChain);
ASSERT_TRUE(ret == HKS_SUCCESS) << "ConstructCertChainBlob failed, ret = " << ret;
ret = HksServiceAttestKey(&processInfo, &keyAlias, paramSet, certChain, nullptr);
ASSERT_TRUE(ret == HKS_SUCCESS) << "HksServiceAttestKey failed, ret = " << ret;
HKS_LOG_I("Attest key success!");
if (ret != HKS_SUCCESS) {
HKS_LOG_I("HksServiceAttestKey failed!");
}
FreeCertChainBlob(certChain);
HksFreeParamSet(&paramSet);
@ -383,8 +386,9 @@ HWTEST_F(HksClientServiceTest, HksClientServiceTest005, TestSize.Level0)
ret = ConstructCertChainBlob(&certChain);
ASSERT_TRUE(ret == HKS_SUCCESS) << "HksClientServiceTest005 ConstructCertChainBlob failed, ret = " << ret;
ret = HksServiceAttestKey(&processInfo, &keyAlias, paramSet, certChain, nullptr);
ASSERT_TRUE(ret == HKS_SUCCESS) << "HksClientServiceTest005 HksServiceAttestKey failed, ret = " << ret;
HKS_LOG_I("Attest key success!");
if (ret != HKS_SUCCESS) {
HKS_LOG_I("HksServiceAttestKey failed!");
}
FreeCertChainBlob(certChain);
HksFreeParamSet(&paramSet);

View File

@ -55,6 +55,8 @@ void FreeCertChain(struct HksCertChain **certChain, const uint32_t pos);
int32_t TestGenerateKey(const struct HksBlob *keyAlias, uint32_t keyPadding);
int32_t TestGenerateKeyCommon(const struct HksBlob *keyAlias, const struct HksParam *tmpParams, int32_t arrNum);
int32_t ConstructDataToCertChain(struct HksCertChain **certChain,
const struct HksTestCertChain *certChainParam);

View File

@ -403,4 +403,79 @@ HWTEST_F(HksAttestKeyNonIdsTest, HksAttestKeyNonIdsTest011, TestSize.Level0)
ret = HksDeleteKey(&g_keyAlias, NULL);
ASSERT_EQ(ret, HKS_SUCCESS);
}
/**
* @tc.name: HksAttestKeyNonIdsTest.HksAttestKeyNonIdsTest012
* @tc.desc: attest ECC with right params.
* @tc.type: FUNC
*/
HWTEST_F(HksAttestKeyNonIdsTest, HksAttestKeyNonIdsTest012, TestSize.Level0)
{
struct HksParamSet *paramSet = nullptr;
HksCertChain *certChain = nullptr;
HKS_LOG_I("enter HksAttestKeyNonIdsTest012");
const struct HksParam tmpParams[] = {
{ .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_ECC },
{ .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_ECC_KEY_SIZE_256 },
{ .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY },
{ .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SHA384 },
{ .tag = HKS_TAG_PADDING, .uint32Param = HKS_PADDING_NONE },
};
int32_t ret = TestGenerateKeyCommon(&g_keyAlias, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0]));
ASSERT_EQ(ret, HKS_SUCCESS);
GenerateParamSet(&paramSet, g_commonParams, sizeof(g_commonParams) / sizeof(g_commonParams[0]));
const struct HksTestCertChain certParam = { true, true, true, g_size };
(void)ConstructDataToCertChain(&certChain, &certParam);
const struct OH_Huks_Blob oh_g_keyAlias = { sizeof(ALIAS), (uint8_t *)ALIAS };
ret = OH_Huks_AnonAttestKeyItem(&oh_g_keyAlias, (struct OH_Huks_ParamSet *) paramSet,
(struct OH_Huks_CertChain *) certChain).errorCode;
if (ret != HKS_SUCCESS) {
HKS_LOG_I("OH_Huks_AnonAttestKeyItem fail, ret is %" LOG_PUBLIC "d!", ret);
}
ASSERT_EQ(ret, HKS_SUCCESS);
for (uint32_t i = 0; i < certChain->certsCount; i++) {
printf("Get certChain[%d]:\n %s \n", i, certChain->certs[i].data);
}
FreeCertChain(&certChain, certChain->certsCount);
HksFreeParamSet(&paramSet);
ret = HksDeleteKey(&g_keyAlias, NULL);
ASSERT_EQ(ret, HKS_SUCCESS);
}
/**
* @tc.name: HksAttestKeyNonIdsTest.HksAttestKeyNonIdsTest013
* @tc.desc: attest with right params.
* @tc.type: FUNC
*/
HWTEST_F(HksAttestKeyNonIdsTest, HksAttestKeyNonIdsTest013, TestSize.Level0)
{
struct HksParamSet *paramSet = nullptr;
HksCertChain *certChain = nullptr;
HKS_LOG_I("enter HksAttestKeyNonIdsTest013");
const struct HksParam tmpParams[] = {
{ .tag = HKS_TAG_ALGORITHM, .uint32Param = HKS_ALG_SM2 },
{ .tag = HKS_TAG_KEY_SIZE, .uint32Param = HKS_SM2_KEY_SIZE_256 },
{ .tag = HKS_TAG_PURPOSE, .uint32Param = HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT },
{ .tag = HKS_TAG_DIGEST, .uint32Param = HKS_DIGEST_SM3},
};
int32_t ret = TestGenerateKeyCommon(&g_keyAlias, tmpParams, sizeof(tmpParams) / sizeof(tmpParams[0]));
ASSERT_EQ(ret, HKS_SUCCESS);
GenerateParamSet(&paramSet, g_commonParams, sizeof(g_commonParams) / sizeof(g_commonParams[0]));
const struct HksTestCertChain certParam = { true, true, true, g_size };
(void)ConstructDataToCertChain(&certChain, &certParam);
const struct OH_Huks_Blob oh_g_keyAlias = { sizeof(ALIAS), (uint8_t *)ALIAS };
ret = OH_Huks_AnonAttestKeyItem(&oh_g_keyAlias, (struct OH_Huks_ParamSet *) paramSet,
(struct OH_Huks_CertChain *) certChain).errorCode;
if (ret != HKS_SUCCESS) {
HKS_LOG_I("OH_Huks_AnonAttestKeyItem fail, ret is %" LOG_PUBLIC "d!", ret);
}
ASSERT_EQ(ret, HKS_SUCCESS);
for (uint32_t i = 0; i < certChain->certsCount; i++) {
printf("Get certChain[%d]:\n %s \n", i, certChain->certs[i].data);
}
FreeCertChain(&certChain, certChain->certsCount);
HksFreeParamSet(&paramSet);
ret = HksDeleteKey(&g_keyAlias, NULL);
ASSERT_EQ(ret, HKS_SUCCESS);
}
}

View File

@ -102,6 +102,37 @@ int32_t TestGenerateKey(const struct HksBlob *keyAlias, uint32_t keyPadding)
return ret;
}
int32_t TestGenerateKeyCommon(const struct HksBlob *keyAlias, const struct HksParam *tmpParams, int32_t arrNum)
{
struct HksParamSet *paramSet = nullptr;
int32_t ret = HksInitParamSet(&paramSet);
if (ret != HKS_SUCCESS) {
HKS_LOG_E("HksInitParamSet failed");
return ret;
}
ret = HksAddParams(paramSet, tmpParams, arrNum);
if (ret != HKS_SUCCESS) {
HKS_LOG_E("HksAddParams failed");
HksFreeParamSet(&paramSet);
return ret;
}
ret = HksBuildParamSet(&paramSet);
if (ret != HKS_SUCCESS) {
HKS_LOG_E("HksBuildParamSet failed");
HksFreeParamSet(&paramSet);
return ret;
}
ret = HksGenerateKey(keyAlias, paramSet, nullptr);
if (ret != HKS_SUCCESS) {
HKS_LOG_E("HksGenerateKey failed");
}
HksFreeParamSet(&paramSet);
return ret;
}
int32_t ConstructDataToCertChain(struct HksCertChain **certChain,
const struct HksTestCertChain *certChainParam)
{