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