• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "huks_attest_test.h"
17 
18 #include <gtest/gtest.h>
19 
20 #include "huks_attest_test_common.h"
21 
22 using namespace testing::ext;
23 namespace Unittest::AttestKey
24 {
25 static struct OH_Huks_Blob g_secInfo = {sizeof(SEC_INFO_DATA), (uint8_t *)SEC_INFO_DATA};
26 static struct OH_Huks_Blob g_challenge = {sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA};
27 static struct OH_Huks_Blob g_version = {sizeof(VERSION_DATA), (uint8_t *)VERSION_DATA};
28 bool useSoftware = true;
29 
30 class HuksAttestKeyNoIdsTest : public testing::Test
31 {
32    public:
33     static void SetUpTestCase(void);
34 
35     static void TearDownTestCase(void);
36 
37     void SetUp();
38 
39     void TearDown();
40 };
41 
SetUpTestCase(void)42 void HuksAttestKeyNoIdsTest::SetUpTestCase(void) { useSoftware = checkUseSoftware(); }
43 
TearDownTestCase(void)44 void HuksAttestKeyNoIdsTest::TearDownTestCase(void) {}
45 
SetUp()46 void HuksAttestKeyNoIdsTest::SetUp() {}
47 
TearDown()48 void HuksAttestKeyNoIdsTest::TearDown() {}
49 
50 static const struct OH_Huks_Blob g_keyAlias = {sizeof(ALIAS), (uint8_t *)ALIAS};
51 
52 static const struct OH_Huks_Param g_commonParams[] = {
53     {.tag = OH_HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO, .blob = g_secInfo},
54     {.tag = OH_HUKS_TAG_ATTESTATION_CHALLENGE, .blob = g_challenge},
55     {.tag = OH_HUKS_TAG_ATTESTATION_ID_VERSION_INFO, .blob = g_version},
56     {.tag = OH_HUKS_TAG_ATTESTATION_ID_ALIAS, .blob = g_keyAlias},
57     {.tag = OH_HUKS_TAG_AUTH_STORAGE_LEVEL, .uint32Param = OH_HUKS_AUTH_STORAGE_LEVEL_DE}};
58 
59 /**
60  * @tc.name: HuksAttestKeyNoIdsTest.Security_HUKS_NAPI_Attest_0100
61  * @tc.desc: attest with right params and validate success.
62  * @tc.type: FUNC
63  * @tc.require: issueI5NY0L
64  */
65 HWTEST_F(HuksAttestKeyNoIdsTest, Security_HUKS_NAPI_Attest_0100, TestSize.Level0)
66 {
67     if (useSoftware) {
68         OH_Huks_Result ret = TestGenerateKey(&g_keyAlias);
69         ASSERT_TRUE(ret.errorCode == (int32_t)OH_HUKS_SUCCESS);
70         struct OH_Huks_ParamSet *paramSet = NULL;
71         GenerateParamSet(&paramSet, g_commonParams, sizeof(g_commonParams) / sizeof(g_commonParams[0]));
72         OH_Huks_CertChain *certChain = NULL;
73         const struct HksTestCertChain certParam = {true, true, true, g_size};
74         (void)ConstructDataToCertChain(&certChain, &certParam);
75         ret = OH_Huks_AttestKeyItem(&g_keyAlias, paramSet, certChain);
76         ASSERT_TRUE(ret.errorCode != (int32_t)OH_HUKS_SUCCESS);
77         ret = ValidateCertChainTest(certChain, g_commonParams, NON_IDS_PARAM);
78         ASSERT_TRUE(ret.errorCode != (int32_t)OH_HUKS_SUCCESS);
79         FreeCertChain(&certChain, certChain->certsCount);
80         certChain = NULL;
81         OH_Huks_Result ret1 = OH_Huks_DeleteKeyItem(&g_keyAlias, paramSet);
82         OH_Huks_FreeParamSet(&paramSet);
83         ASSERT_TRUE(ret1.errorCode == (int32_t)OH_HUKS_SUCCESS);
84     }
85     ASSERT_TRUE(0 == 0);
86 }
87 }  // namespace Unittest::AttestKey
88