• 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 <gtest/gtest.h>
17 
18 #include "cert_manager_api.h"
19 #include "cm_cert_data_ecc.h"
20 #include "cm_cert_data_part1_rsa.h"
21 #include "cm_cert_data_part3_rsa.h"
22 #include "cm_mem.h"
23 #include "cm_test_common.h"
24 
25 #include "accesstoken_kit.h"
26 #include "token_setproc.h"
27 #include "access_token.h"
28 
29 using namespace testing::ext;
30 using namespace CertmanagerTest;
31 using namespace OHOS::Security::AccessToken;
32 namespace {
33 struct CredentialResult {
34     struct Credential certificate;
35     bool bExpectResult;
36 };
37 
38 struct CredentialResult g_credentialexpectResult[] = {
39     {
40         { 1, "ak", "keyA", "oh:t=ak;o=keyA;u=0;a=0", 2, 1, { 1961, nullptr } }, true /* cert num is 2, len is 1961 */
41     }
42 };
43 
44 struct CredentialAbstractResult {
45     struct CredentialAbstract credentialAbstract;
46     bool bExpectResult;
47 };
48 
49 struct CredentialAbstractResult g_expectList[] = {
50     {
51         { "ak", "keyA", "oh:t=ak;o=keyA;u=100;a=500" }, false
52     },
53     {
54         { "ak", "keyA", "oh:t=ak;o=keyA;u=0;a=0" }, true
55     },
56     {
57         { "ak", "keyA", "oh:t=ak;o=keyA;u=200;a=0" }, false
58     }
59 };
60 
61 static const struct CmBlob g_appCert = { sizeof(g_rsa2048P12CertInfo), const_cast<uint8_t *>(g_rsa2048P12CertInfo) };
62 static const struct CmBlob g_eccAppCert = { sizeof(g_eccP256P12CertInfo), const_cast<uint8_t *>(g_eccP256P12CertInfo) };
63 static const struct CmBlob g_appCertPwd = { sizeof(g_certPwd), const_cast<uint8_t *>(g_certPwd) };
64 
65 static const uint8_t g_p12AbnormalCertinfo[] = {
66     0x30, 0x82, 0x0b, 0xc1, 0x02, 0x01, 0x03, 0x30, 0x82, 0x0b, 0x87, 0x06, 0x09, 0x2a, 0x86, 0x48,
67     0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x0b, 0x78, 0x04, 0x82, 0x0b, 0x74, 0x30, 0x82,
68     0x0b, 0x70, 0x30, 0x82, 0x06, 0x27, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07,
69     0x06, 0xa0, 0x82, 0x06, 0x18, 0x30, 0x82, 0x06, 0x14, 0x02, 0x01, 0x00, 0x30, 0x82, 0x06, 0x0d,
70     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x0a, 0x2a,
71     0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30, 0x0e, 0x04, 0x08, 0x1a, 0x8f, 0xc1,
72     0xd1, 0xda, 0x6c, 0xd1, 0xa9, 0x02, 0x02, 0x08, 0x00, 0x80, 0x82, 0x05, 0xe0, 0xd0, 0x2f, 0x2d,
73     0x52, 0x09, 0x86, 0x55, 0x53, 0xf0, 0x49, 0x8f, 0x00, 0xa1, 0x4d, 0x21, 0xc8, 0xb4, 0xad, 0x27,
74     0x12, 0x44, 0xab, 0x4d, 0x10, 0x14, 0xe3, 0x3c, 0x9a, 0x05, 0x77, 0x51, 0x90, 0x4a, 0x3a, 0x8a,
75     0x09, 0xa9, 0x4b, 0x36, 0x50, 0x60, 0x22, 0x4b, 0x77, 0x12, 0x5c, 0x2f, 0x60, 0xd3, 0xd9, 0x30,
76     0x94, 0x4d, 0x9e, 0x81, 0xc3, 0xe9, 0x9d, 0xd9, 0x47, 0xb3, 0x54, 0xa2, 0x9a, 0x8f, 0xe7, 0x58,
77     0x95, 0xd7, 0x48, 0x87, 0xc4, 0x40, 0xad, 0x9a, 0x42, 0x1d, 0x36, 0xb7, 0x48, 0xbc, 0x70, 0x8c,
78     0x84, 0xcb, 0x3c, 0x02, 0x25, 0x9f, 0xfe, 0x2c, 0x4a, 0x76, 0xb1, 0x27, 0x94, 0x8f, 0xb0, 0x07,
79     0xf0, 0xc0, 0x00, 0x3a, 0x69, 0x16, 0xe1, 0x63, 0x0c, 0xe5, 0x92, 0xc2, 0x7d, 0x99, 0xd9, 0x11,
80     0x40, 0xd8, 0x64, 0xab, 0x13, 0xda, 0x73, 0x7b, 0x12, 0x53, 0xb1, 0x0b, 0x0c, 0x67, 0x81, 0xe1,
81     0xf5, 0x59, 0x3a, 0xc7, 0xe0, 0xe9, 0xda, 0x12, 0xc7, 0x2b, 0xab, 0x3d, 0xbc, 0x10, 0x3d, 0x1a,
82     0x88, 0xc7, 0x1d, 0x31, 0x5f, 0x39, 0x63, 0x51, 0x8b, 0x11, 0x99, 0x05, 0xf9, 0x40, 0x42, 0x27,
83     0xad, 0x75, 0x6f, 0xe2, 0x2d, 0x66, 0x28, 0x97, 0x7c, 0x6f, 0xf4, 0xfc, 0x95, 0xaa, 0x67, 0x81,
84     0xd8, 0x15, 0x3c, 0xf4, 0x7b, 0x97, 0x08, 0x7b, 0x1b, 0x8c, 0xd3, 0x45, 0x8b, 0x96, 0x54, 0x2c,
85     0xb1, 0x00, 0x87, 0x59, 0x5c, 0x94, 0x78, 0x29, 0xaa, 0x7b, 0x9c, 0x5c, 0x61, 0xff, 0xcc, 0x32,
86     0x14, 0x4e, 0xc3, 0x1b, 0x96
87 };
88 
FindCredentialAbstract(const struct CredentialAbstract * abstract,const struct CredentialList * listCert)89 static bool FindCredentialAbstract(const struct CredentialAbstract *abstract, const struct CredentialList *listCert)
90 {
91     if (abstract == nullptr || listCert == nullptr || listCert->credentialCount == 0) {
92         return false;
93     }
94     for (uint32_t i = 0; i < listCert->credentialCount; ++i) {
95         if (CompareCredentialList(abstract, &(listCert->credentialAbstract[i]))) {
96             return true;
97         }
98     }
99     return false;
100 }
101 
102 class CmAppCertTest : public testing::Test {
103 public:
104     static void SetUpTestCase(void);
105 
106     static void TearDownTestCase(void);
107 
108     void SetUp();
109 
110     void TearDown();
111 };
112 
SetUpTestCase(void)113 void CmAppCertTest::SetUpTestCase(void)
114 {
115     SetATPermission();
116 }
117 
TearDownTestCase(void)118 void CmAppCertTest::TearDownTestCase(void)
119 {
120 }
121 
SetUp()122 void CmAppCertTest::SetUp()
123 {
124 }
125 
TearDown()126 void CmAppCertTest::TearDown()
127 {
128 }
129 
130 /**
131  * @tc.name: AppCertInstallBaseTest001
132  * @tc.desc: Test CertManager Install app cert interface base function
133  * @tc.type: FUNC
134  * @tc.require: AR000H0MI8 /SR000H09N9
135  */
136 HWTEST_F(CmAppCertTest, AppCertInstallBaseTest001, TestSize.Level0)
137 {
138     char retUriBuf[MAX_LEN_URI] = {0};
139     struct CmBlob keyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
140 
141     uint8_t certAliasBuf[] = "keyA";
142     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
143 
144     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
145     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertInstallBaseTest001 credentail test failed, retcode:" << ret;
146 
147     ret = CmUninstallAllAppCert();
148     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllTest test failed, retcode:" << ret;
149 
150     ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
151     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertInstallBaseTest001 pri_credentail test failed, retcode:" << ret;
152 
153     char uriBuf[] = "oh:t=ak;o=keyA;u=0;a=0";
154     EXPECT_EQ(strcmp(uriBuf, (char *)keyUri.data), 0) << "strcmp failed";
155 
156     ret = CmUninstallAllAppCert();
157     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllTest test failed, retcode:" << ret;
158 }
159 
160 /**
161  * @tc.name: AppCertInstallBaseTest002
162  * @tc.desc: Test CertManager Install app cert interface base function
163  * @tc.type: FUNC
164  * @tc.require: AR000H0MI8 /SR000H09N9
165  */
166 HWTEST_F(CmAppCertTest, AppCertInstallBaseTest002, TestSize.Level0)
167 {
168     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
169     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
170 
171     uint8_t appCertPwdBuf[] = "12345678";
172     struct CmBlob appCertPwd = { sizeof(appCertPwdBuf), appCertPwdBuf };
173 
174     uint8_t certAliasBuf[] = "keyA";
175     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
176 
177     int32_t ret = CmInstallAppCert(&g_appCert, &appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
178     EXPECT_EQ(ret, CMR_ERROR_PASSWORD_IS_ERR) << "AppCertInstallBaseTest002 credentail test failed, retcode:" << ret;
179 
180     ret = CmInstallAppCert(&g_appCert, &appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
181     EXPECT_EQ(ret, CMR_ERROR_PASSWORD_IS_ERR)
182         << "AppCertInstallBaseTest002 pri_credentail test failed, retcode:" << ret;
183 }
184 
185 /**
186  * @tc.name: AppCertInstallTest003
187  * @tc.desc: Test CertManager Install app cert interface base function
188  * @tc.type: FUNC
189  * @tc.require: AR000H0MI8 /SR000H09N9
190  */
191 HWTEST_F(CmAppCertTest, AppCertInstallTest003, TestSize.Level0)
192 {
193     uint8_t certAliasBuf[] = "AppCertInstallTest003";
194     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
195 
196     struct CmBlob appCert = { sizeof(g_p12AbnormalCertinfo), const_cast<uint8_t *>(g_p12AbnormalCertinfo) };
197 
198     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
199     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
200 
201     int32_t ret = CmInstallAppCert(&appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
202     EXPECT_EQ(ret, CMR_ERROR_INVALID_CERT_FORMAT) << "AppCertInstallTest003 credentail test failed, retcode:" << ret;
203 
204     ret = CmInstallAppCert(&appCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
205     EXPECT_EQ(ret, CMR_ERROR_INVALID_CERT_FORMAT) <<
206         "AppCertInstallTest003 pri_credentail test failed, retcode:" << ret;
207 }
208 
209 /**
210  * @tc.name: AppCertInstallAbnormalTest004
211  * @tc.desc: Test CertManager install app cert interface abnormal function
212  * @tc.type: FUNC
213  * @tc.require: AR000H0MI8 /SR000H09N9
214  */
215 HWTEST_F(CmAppCertTest, AppCertInstallAbnormalTest004, TestSize.Level0)
216 {
217     uint8_t certAliasBuf[] = "keyA";
218     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
219 
220     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
221     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
222 
223     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_SYS_CREDENTIAL_STORE + 1, &keyUri);
224     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "AppCertInstallAbnormalTest004 test failed, retcode:" << ret;
225 
226     ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_SYS_CREDENTIAL_STORE + 1, &keyUri);
227     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "AppCertInstallAbnormalTest004 privite test failed, retcode:" << ret;
228 
229     ret = CmUninstallAllAppCert();
230     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllTest 005 test failed, retcode:" << ret;
231 }
232 
233 /**
234  * @tc.name: AppCertInstallBaseEccTest005
235  * @tc.desc: Test CertManager Install app cert interface base function
236  * @tc.type: FUNC
237  * @tc.require: AR000H0MI8 /SR000H09N9
238  */
239 HWTEST_F(CmAppCertTest, AppCertInstallBaseEccTest005, TestSize.Level0)
240 {
241     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
242     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
243 
244     uint8_t certAliasBuf[] = "keyB";
245     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
246 
247     int32_t ret = CmInstallAppCert(&g_eccAppCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
248     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertInstallBaseEccTest005 test failed, retcode:" << ret;
249 
250     ret = CmUninstallAllAppCert();
251     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllTest 005 test failed, retcode:" << ret;
252 
253     ret = CmInstallAppCert(&g_eccAppCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
254     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertInstallBaseEccTest005 privite test failed, retcode:" << ret;
255 
256     ret = CmUninstallAllAppCert();
257     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllTest 005 test failed, retcode:" << ret;
258 }
259 
260 /**
261  * @tc.name: AppCertInstallBaseSM2Test001
262  * @tc.desc: install public and private sm2, oid is valid
263  * @tc.type: FUNC
264  */
265 HWTEST_F(CmAppCertTest, AppCertInstallBaseSM2Test001, TestSize.Level0)
266 {
267     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
268     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
269 
270     uint8_t certAliasBuf[] = "testForSm2";
271     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
272 
273     int32_t ret = CmInstallAppCert(&g_sm2AppCert, &g_appSM2CertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
274     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test001 public test failed, retcode:" << ret;
275 
276     ret = CmUninstallAllAppCert();
277     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test001 test failed, retcode:" << ret;
278 
279     keyUri.size = sizeof(keyUriBuf);
280     ret = CmInstallAppCert(&g_sm2AppCert, &g_appSM2CertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
281     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test001 privite test failed, retcode:" << ret;
282 
283     ret = CmUninstallAllAppCert();
284     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test001 test failed, retcode:" << ret;
285 }
286 
287 /**
288  * @tc.name: AppCertInstallBaseSM2Test002
289  * @tc.desc: install public and private sm2, oid is valid data2
290  * @tc.type: FUNC
291  */
292 HWTEST_F(CmAppCertTest, AppCertInstallBaseSM2Test002, TestSize.Level0)
293 {
294     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
295     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
296 
297     uint8_t certAliasBuf[] = "testForSm2_2";
298     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
299 
300     int32_t ret = CmInstallAppCert(&g_sm2AppCert2, &g_appSM2CertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
301     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test002 public test failed, retcode:" << ret;
302 
303     ret = CmUninstallAllAppCert();
304     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test001 test failed, retcode:" << ret;
305 
306     keyUri.size = sizeof(keyUriBuf);
307     ret = CmInstallAppCert(&g_sm2AppCert2, &g_appSM2CertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
308     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test002 privite test failed, retcode:" << ret;
309 
310     ret = CmUninstallAllAppCert();
311     EXPECT_EQ(ret, CM_SUCCESS) << "BaseSM2Test001 test failed, retcode:" << ret;
312 }
313 
314 /**
315  * @tc.name: AppCertInstallBaseSM2Test003
316  * @tc.desc: install public and private sm2, oid is invalid
317  * @tc.type: FUNC
318  */
319 HWTEST_F(CmAppCertTest, AppCertInstallBaseSM2Test003, TestSize.Level0)
320 {
321     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
322     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
323 
324     uint8_t certAliasBuf[] = "testForSm2_2";
325     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
326 
327     int32_t ret = CmInstallAppCert(&g_sm2AppCert3, &g_appSM2CertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
328     EXPECT_EQ(ret, CMR_ERROR_INVALID_CERT_FORMAT) << "BaseSM2Test002 public test failed, retcode:" << ret;
329 
330     keyUri.size = sizeof(keyUriBuf);
331     ret = CmInstallAppCert(&g_sm2AppCert3, &g_appSM2CertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
332     EXPECT_EQ(ret, CMR_ERROR_INVALID_CERT_FORMAT) << "BaseSM2Test002 privite test failed, retcode:" << ret;
333 }
334 
335 /**
336  * @tc.name: AppCertInstallAbnormalTest005
337  * @tc.desc: Test CertManager Install app cert alias not include \0
338  * @tc.type: FUNC
339  * @tc.require: AR000H0MI8 /SR000H09N9
340  */
341 HWTEST_F(CmAppCertTest, AppCertInstallAbnormalTest005, TestSize.Level0)
342 {
343     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
344     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
345 
346     uint8_t aliasBuf[] = "keyB";
347     struct CmBlob certAlias = { sizeof(aliasBuf) - 1, aliasBuf }; /* not include '\0' */
348 
349     int32_t ret = CmInstallAppCert(&g_eccAppCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
350     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "AppCertInstallAbnormalTest005 test failed, retcode:" << ret;
351 }
352 
353 /**
354  * @tc.name: AppCertInstallBaseEccTest006
355  * @tc.desc: Test CertManager Install app cert pwd not include \0
356  * @tc.type: FUNC
357  * @tc.require: AR000H0MI8 /SR000H09N9
358  */
359 HWTEST_F(CmAppCertTest, AppCertInstallAbnormalTest006, TestSize.Level0)
360 {
361     uint8_t keyUriBuf[MAX_LEN_URI] = {0};
362     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
363 
364     uint8_t aliasBuf[] = "keyC";
365     struct CmBlob certAlias = { sizeof(aliasBuf), aliasBuf };
366 
367     uint8_t pwdBuf[] = "123";
368     struct CmBlob pwd = { sizeof(pwdBuf) - 1, pwdBuf }; /* not include '\0' */
369 
370     int32_t ret = CmInstallAppCert(&g_eccAppCert, &pwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
371     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "AppCertInstallAbnormalTest006 test failed, retcode:" << ret;
372 }
373 
374 /**
375  * @tc.name: CmGetAppCertBaseTest001
376  * @tc.desc: Test CertManager get app cert interface base function
377  * @tc.type: FUNC
378  * @tc.require: AR000H0MI8 /SR000H09N9
379  */
380 HWTEST_F(CmAppCertTest, CmGetAppCertBaseTest001, TestSize.Level0)
381 {
382     uint8_t certAliasBuf[] = "keyA";
383     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
384 
385     uint8_t uriBuf[MAX_LEN_URI] = {0};
386     struct CmBlob retUri = { sizeof(uriBuf), uriBuf };
387 
388     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &retUri);
389     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertBaseTest001 test failed, retcode:" << ret;
390 
391     struct Credential certificate;
392     (void)memset_s(&certificate, sizeof(Credential), 0, sizeof(Credential));
393     certificate.credData.data = static_cast<uint8_t *>(CmMalloc(MAX_LEN_CERTIFICATE_CHAIN));
394     ASSERT_TRUE(certificate.credData.data != nullptr);
395     certificate.credData.size = MAX_LEN_CERTIFICATE_CHAIN;
396 
397     ret = CmGetAppCert(&retUri, CM_CREDENTIAL_STORE, &certificate);
398     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertBaseTest001 test failed, retcode:" << ret;
399 
400     FreeCMBlobData(&certificate.credData);
401 }
402 
403 /**
404  * @tc.name: CmGetAppCertPerformanceTest002
405  * @tc.desc: Test CertManager get app cert interface performance
406  * @tc.type: FUNC
407  * @tc.require: AR000H0MI8 /SR000H09N9
408  */
409 HWTEST_F(CmAppCertTest, CmGetAppCertPerformanceTest002, TestSize.Level0)
410 {
411     uint32_t times = 1;
412     uint8_t certAliasBuf[] = "keyA";
413     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
414 
415     uint8_t uriBuf[MAX_LEN_URI] = {0};
416     struct CmBlob retUri = { sizeof(uriBuf), uriBuf };
417 
418     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &retUri);
419     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertPerformanceTest002 install failed, retcode:" << ret;
420 
421     struct Credential certificate;
422     for (uint32_t i = 0; i < times; i++) {
423         (void)memset_s(&certificate, sizeof(Credential), 0, sizeof(Credential));
424         certificate.credData.data = static_cast<uint8_t *>(CmMalloc(MAX_LEN_CERTIFICATE_CHAIN));
425         ASSERT_TRUE(certificate.credData.data != nullptr);
426         certificate.credData.size = MAX_LEN_CERTIFICATE_CHAIN;
427 
428         ret = CmGetAppCert(&retUri, CM_CREDENTIAL_STORE, &certificate);
429         EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertPerformanceTest002 get failed,retcode:" << ret;
430 
431         EXPECT_EQ(CompareCredential(&certificate, &(g_credentialexpectResult[0].certificate)), true);
432         FreeCMBlobData(&(certificate.credData));
433     }
434 }
435 
436 /**
437  * @tc.name: CmGetAppBaseCertTest003
438  * @tc.desc: Test CertManager get app cert interface base function
439  * @tc.type: FUNC
440  * @tc.require: AR000H0MI8 /SR000H09N9
441  */
442 HWTEST_F(CmAppCertTest, CmGetAppBaseCertTest003, TestSize.Level0)
443 {
444     uint8_t certAliasBuf[] = "keyC";
445     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
446 
447     uint8_t uriBuf[MAX_LEN_URI] = {0};
448     struct CmBlob retUri = { sizeof(uriBuf), uriBuf };
449 
450     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &retUri);
451     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppBaseCertTest003 install failed, retcode:" << ret;
452 
453     struct Credential firstcertificate;
454     (void)memset_s(&firstcertificate, sizeof(Credential), 0, sizeof(Credential));
455     firstcertificate.credData.data = static_cast<uint8_t *>(CmMalloc(MAX_LEN_CERTIFICATE_CHAIN));
456     ASSERT_TRUE(firstcertificate.credData.data != nullptr);
457     firstcertificate.credData.size = MAX_LEN_CERTIFICATE_CHAIN;
458 
459     ret = CmGetAppCert(&retUri, CM_CREDENTIAL_STORE, &firstcertificate);
460     EXPECT_EQ(ret, CM_SUCCESS) << "first CmGetAppCert failed, retcode:" << ret;
461 
462     struct Credential secondcertificate;
463     (void)memset_s(&secondcertificate, sizeof(Credential), 0, sizeof(Credential));
464     secondcertificate.credData.data = static_cast<uint8_t *>(CmMalloc(MAX_LEN_CERTIFICATE_CHAIN));
465     ASSERT_TRUE(secondcertificate.credData.data != nullptr);
466     secondcertificate.credData.size = MAX_LEN_CERTIFICATE_CHAIN;
467 
468     ret = CmGetAppCert(&retUri, CM_CREDENTIAL_STORE, &secondcertificate);
469     EXPECT_EQ(ret, CM_SUCCESS) << "second CmGetAppCert failed, retcode:" << ret;
470 
471     EXPECT_EQ(CompareCredential(&firstcertificate, &secondcertificate), true);
472     FreeCMBlobData(&(firstcertificate.credData));
473     FreeCMBlobData(&(secondcertificate.credData));
474 
475     (void)CmUninstallAppCert(&retUri, CM_CREDENTIAL_STORE);
476 }
477 
478 /**
479  * @tc.name: CmGetAppCertAbnormalTest004
480  * @tc.desc: Test CertManager get app cert interface abnormal function
481  * @tc.type: FUNC
482  * @tc.require: AR000H0MI8 /SR000H09N9
483  */
484 HWTEST_F(CmAppCertTest, CmGetAppCertAbnormalTest004, TestSize.Level0)
485 {
486     uint8_t keyUriBuf[] = "oh:t=ak;o=key004;u=0;a=0";
487     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
488 
489     struct Credential certificate;
490     (void)memset_s(&certificate, sizeof(Credential), 0, sizeof(Credential));
491     certificate.credData.data = static_cast<uint8_t *>(CmMalloc(MAX_LEN_CERTIFICATE_CHAIN));
492     ASSERT_TRUE(certificate.credData.data != nullptr);
493     certificate.credData.size = MAX_LEN_CERTIFICATE_CHAIN;
494 
495     int32_t ret = CmGetAppCert(nullptr, CM_CREDENTIAL_STORE, &certificate);
496     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "CmGetAppCertAbnormalTest004 01 failed, retcode:" << ret;
497 
498     ret = CmGetAppCert(&keyUri, CM_CREDENTIAL_STORE, nullptr);
499     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "CmGetAppCertAbnormalTest004 02 failed, retcode:" << ret;
500 
501     ret = CmGetAppCert(&keyUri, CM_SYS_CREDENTIAL_STORE + 1, &certificate);
502     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "CmGetAppCertAbnormalTest004 03 failed, retcode:" << ret;
503 
504     ret = CmUninstallAllAppCert();
505     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllTest 004 test failed, retcode:" << ret;
506 
507     FreeCMBlobData(&(certificate.credData));
508 }
509 
510 /**
511  * @tc.name: CmGetAppCertListPerformanceTest001
512  * @tc.desc: Test CertManager get app cert list interface performance
513  * @tc.type: FUNC
514  * @tc.require: AR000H0MI8 /SR000H09N9
515  */
516 HWTEST_F(CmAppCertTest, CmGetAppCertListPerformanceTest001, TestSize.Level0)
517 {
518     uint8_t certAliasBuf[] = "keyA";
519     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
520 
521     uint8_t uriBuf[MAX_LEN_URI] = {0};
522     struct CmBlob keyUri = { sizeof(uriBuf), uriBuf };
523 
524     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
525     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertListPerformanceTest001 install failed, retcode:" << ret;
526 
527     ret = CmUninstallAllAppCert();
528     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertListPerformanceTest001 test failed, retcode:" << ret;
529 
530     ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
531     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertListPerformanceTest001 private install failed, retcode:" << ret;
532 
533     struct CredentialList certificateList = { 0, nullptr };
534     uint32_t buffSize = MAX_COUNT_CERTIFICATE * sizeof(struct CredentialAbstract);
535     certificateList.credentialAbstract = static_cast<struct CredentialAbstract *>(CmMalloc(buffSize));
536     ASSERT_TRUE(certificateList.credentialAbstract != nullptr);
537 
538     uint32_t times = 1;
539     for (uint32_t i = 0; i < times; i++) {
540         certificateList.credentialCount = MAX_COUNT_CERTIFICATE;
541         (void)memset_s(certificateList.credentialAbstract, buffSize, 0, buffSize);
542         ret = CmGetAppCertList(CM_PRI_CREDENTIAL_STORE, &certificateList);
543         EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertListTest test failed, retcode:" << ret;
544     }
545 
546     if (certificateList.credentialAbstract != nullptr) {
547         CmFree(certificateList.credentialAbstract);
548     }
549 }
550 
551 /**
552  * @tc.name: CmGetAppCertListBaseTest002
553  * @tc.desc: Test CertManager get app cert list interface base function
554  * @tc.type: FUNC
555  * @tc.require: AR000H0MI8 /SR000H09N9
556  */
557 HWTEST_F(CmAppCertTest, CmGetAppCertListBaseTest002, TestSize.Level0)
558 {
559     uint8_t certAliasBuf[] = "keyA";
560     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
561 
562     uint8_t uriBuf[MAX_LEN_URI] = {0};
563     struct CmBlob keyUri = { sizeof(uriBuf), uriBuf };
564 
565     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
566     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertListBaseTest002 install failed, retcode:" << ret;
567 
568     struct CredentialList certificateList = { 0, nullptr };
569     uint32_t buffSize = MAX_COUNT_CERTIFICATE * sizeof(struct CredentialAbstract);
570     certificateList.credentialAbstract = static_cast<struct CredentialAbstract *>(CmMalloc(buffSize));
571     ASSERT_TRUE(certificateList.credentialAbstract != nullptr);
572     certificateList.credentialCount = MAX_COUNT_CERTIFICATE;
573     (void)memset_s(certificateList.credentialAbstract, buffSize, 0, buffSize);
574 
575     ret = CmGetAppCertList(CM_CREDENTIAL_STORE, &certificateList);
576     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetAppCertListBaseTest002 test failed, retcode:" << ret;
577 
578     uint32_t length = sizeof(g_expectList) / sizeof(g_expectList[0]);
579     for (uint32_t j = 0; j < length; ++j) {
580         bool bFind = FindCredentialAbstract(&(g_expectList[j].credentialAbstract), &certificateList);
581         EXPECT_EQ(bFind, g_expectList[j].bExpectResult);
582     }
583 
584     if (certificateList.credentialAbstract != nullptr) {
585         CmFree(certificateList.credentialAbstract);
586     }
587 }
588 
589 /**
590  * @tc.name: CmGetAppCertListBaseTest003
591  * @tc.desc: Test CertManager get app cert list interface base function
592  * @tc.type: FUNC
593  * @tc.require: AR000H0MI8 /SR000H09N9
594  */
595 HWTEST_F(CmAppCertTest, CmGetAppCertListBaseTest003, TestSize.Level0)
596 {
597     int32_t ret = CmGetAppCertList(CM_CREDENTIAL_STORE, nullptr);
598     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "Abnormal CmGetAppCertListBaseTest003 test failed, retcode:" << ret;
599 }
600 
601 /**
602  * @tc.name: CmGetAppCertListAbnormalTest004
603  * @tc.desc: Test CertManager get app cert list interface abnormal function
604  * @tc.type: FUNC
605  * @tc.require: AR000H0MI8 /SR000H09N9
606  */
607 HWTEST_F(CmAppCertTest, CmGetAppCertListAbnormalTest004, TestSize.Level0)
608 {
609     struct CredentialList certificateList = { 0, nullptr };
610     uint32_t buffSize = MAX_COUNT_CERTIFICATE * sizeof(struct CredentialAbstract);
611     certificateList.credentialAbstract = static_cast<struct CredentialAbstract *>(CmMalloc(buffSize));
612     ASSERT_TRUE(certificateList.credentialAbstract != nullptr);
613     certificateList.credentialCount = MAX_COUNT_CERTIFICATE;
614     (void)memset_s(certificateList.credentialAbstract, buffSize, 0, buffSize);
615 
616     int32_t ret = CmGetAppCertList(CM_SYS_CREDENTIAL_STORE + 1, &certificateList);
617     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "Abnormal AppCertInstallTest04 test failed, retcode:" << ret;
618 
619     if (certificateList.credentialAbstract != nullptr) {
620         CmFree(certificateList.credentialAbstract);
621     }
622 }
623 
624 /**
625  * @tc.name: CmGetCallingAppCertListPriCert005
626  * @tc.desc: Test CertManager get app cert list interface own private
627  * @tc.type: FUNC
628  * @tc.require: AR000H0MI8 /SR000H09N9
629  */
630 HWTEST_F(CmAppCertTest, CmGetCallingAppCertListPriCert005, TestSize.Level0)
631 {
632     uint8_t certAliasBuf[] = "OtherKeyA";
633     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
634 
635     uint8_t uriBuf[MAX_LEN_URI] = {0};
636     struct CmBlob keyUri = { sizeof(uriBuf), uriBuf };
637 
638     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
639     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetCallingAppCertListPriCert005 install failed, retcode:" << ret;
640 
641     struct CredentialList certificateList = { 0, nullptr };
642     uint32_t buffSize = MAX_COUNT_CERTIFICATE * sizeof(struct CredentialAbstract);
643     certificateList.credentialAbstract = static_cast<struct CredentialAbstract *>(CmMalloc(buffSize));
644     ASSERT_TRUE(certificateList.credentialAbstract != nullptr);
645     certificateList.credentialCount = MAX_COUNT_CERTIFICATE;
646     (void)memset_s(certificateList.credentialAbstract, buffSize, 0, buffSize);
647 
648     ret = CmCallingGetAppCertList(CM_PRI_CREDENTIAL_STORE, &certificateList);
649     EXPECT_EQ(ret, CM_SUCCESS) << "CmGetCallingAppCertListPriCert005 test failed, retcode:" << ret;
650 
651     struct CredentialAbstractResult expectList[] = {
652         {
653             { "ak", "OtherKeyA", "oh:t=ak;o=keyA;u=100;a=500" }, false
654         }
655     };
656     uint32_t length = sizeof(expectList) / sizeof(expectList[0]);
657     for (uint32_t j = 0; j < length; ++j) {
658         bool bFind = FindCredentialAbstract(&(expectList[j].credentialAbstract), &certificateList);
659         EXPECT_EQ(bFind, expectList[j].bExpectResult);
660     }
661 
662     if (certificateList.credentialAbstract != nullptr) {
663         CmFree(certificateList.credentialAbstract);
664     }
665 }
666 
667 /**
668  * @tc.name: AppCertUnInstallBaseTest001
669  * @tc.desc: Test CertManager unInstall app cert interface base function
670  * @tc.type: FUNC
671  * @tc.require: AR000H0MI8 /SR000H09N9
672  */
673 HWTEST_F(CmAppCertTest, AppCertUnInstallBaseTest001, TestSize.Level0)
674 {
675     uint8_t certAliasBuf[] = "keyA";
676     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
677 
678     uint8_t uriBuf[MAX_LEN_URI] = {0};
679     struct CmBlob retUri = { sizeof(uriBuf), uriBuf };
680 
681     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &retUri);
682     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallBaseTest001 install failed, retcode:" << ret;
683 
684     ret = CmUninstallAppCert(&retUri, CM_CREDENTIAL_STORE);
685     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallBaseTest001 uninstall failed, retcode:" << ret;
686 }
687 
688 /**
689  * @tc.name: AppCertUnInstallAbnormalTest002
690  * @tc.desc: Test CertManager unInstall app cert interface abnormal function
691  * @tc.type: FUNC
692  * @tc.require: AR000H0MI8 /SR000H09N9
693  */
694 HWTEST_F(CmAppCertTest, AppCertUnInstallAbnormalTest002, TestSize.Level0)
695 {
696     int32_t ret = CmUninstallAppCert(nullptr, CM_CREDENTIAL_STORE);
697     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "AppCertUnInstallAbnormalTest002 test failed, retcode:" << ret;
698 }
699 
700 /**
701  * @tc.name: AppCertUnInstallAbnormalTest003
702  * @tc.desc: Test CertManager unInstall app cert interface abnormal function
703  * @tc.type: FUNC
704  * @tc.require: AR000H0MI8 /SR000H09N9
705  */
706 HWTEST_F(CmAppCertTest, AppCertUnInstallAbnormalTest003, TestSize.Level0)
707 {
708     uint8_t keyUriBuf[] = "oh:t=ak;o=keyA;u=0;a=0";
709     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
710 
711     int32_t ret = CmUninstallAppCert(&keyUri, CM_SYS_CREDENTIAL_STORE + 1);
712     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "AppCertUnInstallAbnormalTest003 test failed, retcode:" << ret;
713 }
714 
715 /**
716  * @tc.name: AppCertUnInstallAbnormalTest004
717  * @tc.desc: Test CertManager unInstall app cert interface abnormal function
718  * @tc.type: FUNC
719  * @tc.require: AR000H0MI8 /SR000H09N9
720  */
721 HWTEST_F(CmAppCertTest, AppCertUnInstallAbnormalTest004, TestSize.Level0)
722 {
723     uint8_t keyUriBuf[] = "oh:t=ak;o=NOTEXIST;u=0;a=0";
724     struct CmBlob keyUri = { sizeof(keyUriBuf), keyUriBuf };
725 
726     int32_t ret = CmUninstallAppCert(&keyUri, CM_CREDENTIAL_STORE);
727     EXPECT_EQ(ret, CMR_ERROR_NOT_EXIST) << "AppCertUnInstallAbnormalTest004 test failed, retcode:" << ret;
728 }
729 
730 /**
731  * @tc.name: AppCertUnInstallAllAppCertBaseTest001
732  * @tc.desc: Test CertManager unInstall all app cert interface base function
733  * @tc.type: FUNC
734  * @tc.require: AR000H0MI8 /SR000H09N9
735  */
736 HWTEST_F(CmAppCertTest, AppCertUnInstallAllAppCertBaseTest001, TestSize.Level0)
737 {
738     uint8_t certAliasBuf[] = "keyB";
739     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
740 
741     uint8_t uriBuf[MAX_LEN_URI] = {0};
742     struct CmBlob keyUri = { sizeof(uriBuf), uriBuf };
743 
744     int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
745     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllAppCertBaseTest001 1 failed, retcode:" << ret;
746 
747     ret = CmUninstallAllAppCert();
748     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllAppCertBaseTest001 test failed, retcode:" << ret;
749 
750     ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri);
751     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllAppCertBaseTest001 2 failed, retcode:" << ret;
752 
753     ret = CmUninstallAllAppCert();
754     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllAppCertBaseTest001 test failed, retcode:" << ret;
755 }
756 
757 /**
758  * @tc.name: AppCertUnInstallAllAppCertAbnormalTest002
759  * @tc.desc: Test CertManager unInstall all app cert interface abnormal function
760  * @tc.type: FUNC
761  * @tc.require: AR000H0MI8 /SR000H09N9
762  */
763 HWTEST_F(CmAppCertTest, AppCertUnInstallAllAppCertAbnormalTest002, TestSize.Level0)
764 {
765     int32_t ret = CmUninstallAllAppCert();
766     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertUnInstallAllAppCertAbnormalTest002 test failed, retcode:" << ret;
767 }
768 
769 /**
770  * @tc.name: AppCertInstallPwdTest001
771  * @tc.desc: Test CertManager Install app cert interface base function with 12 bytes special pwd, success
772  * @tc.type: FUNC
773  */
774 HWTEST_F(CmAppCertTest, AppCertInstallPwdTest001, TestSize.Level0)
775 {
776     uint8_t appCertPwdBuf[] = "123456!@#$%^";
777     struct CmBlob appCertPwd = { sizeof(appCertPwdBuf), appCertPwdBuf };
778 
779     const struct CmBlob appCert = { sizeof(g_rsa2048P12CertInfoPwd12),
780         const_cast<uint8_t *>(g_rsa2048P12CertInfoPwd12) };
781 
782     char retUriBuf[MAX_LEN_URI] = {0};
783     struct CmBlob keyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
784 
785     uint8_t certAliasBuf[] = "keyA";
786     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
787 
788     int32_t ret = CmInstallAppCert(&appCert, &appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
789     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertInstallPwdTest001 12 bytes sepcial pwd test failed, retcode:" << ret;
790 
791     (void)CmUninstallAppCert(&keyUri, CM_CREDENTIAL_STORE);
792 }
793 
794 /**
795  * @tc.name: AppCertInstallPwdTest002
796  * @tc.desc: Test CertManager Install app cert interface base function with 32 bytes special pwd, success
797  * @tc.type: FUNC
798  */
799 HWTEST_F(CmAppCertTest, AppCertInstallPwdTest002, TestSize.Level0)
800 {
801     uint8_t appCertPwdBuf[] = "1234567890!@#$%^&*()_+0987654321";
802     struct CmBlob appCertPwd = { sizeof(appCertPwdBuf), appCertPwdBuf };
803 
804     const struct CmBlob appCert = { sizeof(g_rsa2048P12CertInfoPwd32),
805         const_cast<uint8_t *>(g_rsa2048P12CertInfoPwd32) };
806 
807     char retUriBuf[MAX_LEN_URI] = {0};
808     struct CmBlob keyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
809 
810     uint8_t certAliasBuf[] = "keyA";
811     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
812 
813     int32_t ret = CmInstallAppCert(&appCert, &appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
814     EXPECT_EQ(ret, CM_SUCCESS) << "AppCertInstallPwdTest002 32 bytes sepcial pwd test failed, retcode:" << ret;
815 
816     (void)CmUninstallAppCert(&keyUri, CM_CREDENTIAL_STORE);
817 }
818 
819 /**
820  * @tc.name: AppCertInstallPwdTest003
821  * @tc.desc: Test CertManager Install app cert interface base function with 33 bytes special pwd, failed
822  * @tc.type: FUNC
823  */
824 HWTEST_F(CmAppCertTest, AppCertInstallPwdTest003, TestSize.Level0)
825 {
826     uint8_t appCertPwdBuf[] = "1234567890!@#$%^&*()_+0987654321~";
827     struct CmBlob appCertPwd = { sizeof(appCertPwdBuf), appCertPwdBuf };
828 
829     const struct CmBlob appCert = { sizeof(g_rsa2048P12CertInfoPwd33),
830         const_cast<uint8_t *>(g_rsa2048P12CertInfoPwd33) };
831 
832     char retUriBuf[MAX_LEN_URI] = {0};
833     struct CmBlob keyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
834 
835     uint8_t certAliasBuf[] = "keyA";
836     struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
837 
838     int32_t ret = CmInstallAppCert(&appCert, &appCertPwd, &certAlias, CM_CREDENTIAL_STORE, &keyUri);
839     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << \
840         "AppCertInstallPwdTest003 33 bytes sepcial pwd test failed, retcode:" << ret;
841 }
842 } // end of namespace
843 
844