1 /*
2 * Copyright (c) 2024 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 #define TEST_USERID 100
26
27 using namespace testing::ext;
28 using namespace CertmanagerTest;
29 namespace {
30 static uint32_t g_selfTokenId = 0;
31 static MockHapToken* g_MockHap = nullptr;
32
33 static const struct CmBlob g_appCert = { sizeof(g_rsa2048P12CertInfo), const_cast<uint8_t *>(g_rsa2048P12CertInfo) };
34 static const struct CmBlob g_eccAppCert = { sizeof(g_eccP256P12CertInfo), const_cast<uint8_t *>(g_eccP256P12CertInfo) };
35 static const struct CmBlob g_appCertPwd = { sizeof(g_certPwd), const_cast<uint8_t *>(g_certPwd) };
36
37 static const uint8_t g_abnormalCertData[] = {
38 0x30, 0x82, 0x0b, 0xc1, 0x02, 0x01, 0x03, 0xf7, 0x0d, 0x01, 0x07, 0x06, 0x09, 0x2a, 0x86, 0x48,
39 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x0b, 0x78, 0x04, 0x82, 0x0b, 0x74, 0x30, 0x82,
40 0x00, 0x3a, 0x69, 0x16, 0xe1, 0x63, 0x0c, 0xe5, 0x92, 0xc2, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07,
41 0x06, 0xa0, 0x82, 0x06, 0x18, 0x30, 0x82, 0x06, 0x14, 0x02, 0x01, 0x00, 0x30, 0x82, 0x06, 0x0d,
42 0x06, 0x09, 0x0b, 0x74, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x0a, 0x2a,
43 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01
44 };
45
46 class CmPriAppCertTest : public testing::Test {
47 public:
48 static void SetUpTestCase(void);
49
50 static void TearDownTestCase(void);
51
52 void SetUp();
53
54 void TearDown();
55 };
56
SetUpTestCase(void)57 void CmPriAppCertTest::SetUpTestCase(void)
58 {
59 g_selfTokenId = GetSelfTokenID();
60 CmTestCommon::SetTestEnvironment(g_selfTokenId);
61 }
62
TearDownTestCase(void)63 void CmPriAppCertTest::TearDownTestCase(void)
64 {
65 CmTestCommon::ResetTestEnvironment();
66 }
67
SetUp()68 void CmPriAppCertTest::SetUp()
69 {
70 g_MockHap = new (std::nothrow) MockHapToken();
71 }
72
TearDown()73 void CmPriAppCertTest::TearDown()
74 {
75 if (g_MockHap != nullptr) {
76 delete g_MockHap;
77 g_MockHap = nullptr;
78 }
79 }
80
81 /**
82 * @tc.name: PriAppCertTest001
83 * @tc.desc: Test CertManager Install private app cert interface base function
84 * @tc.type: FUNC
85 */
86 HWTEST_F(CmPriAppCertTest, PriAppCertTest001, TestSize.Level0)
87 {
88 char retUriBuf[MAX_LEN_URI] = {0};
89 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
90
91 uint8_t certAliasBuf[] = "PrikeyA";
92 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
93 uint8_t certAliasBuf001[] = "PrikeyB";
94 struct CmBlob certAlias01 = { sizeof(certAliasBuf001), certAliasBuf001 };
95
96 /* test g_appCert */
97 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
98 &certAlias, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
99 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
100 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest001 1 credentail test failed, retcode:" << ret;
101
102 char uriBuf[] = "oh:t=ak;o=PrikeyA;u=0;a=0";
103 EXPECT_EQ(strcmp(uriBuf, (char *)priKeyUri.data), 0) << "strcmp failed, uri: %s" << (char *)priKeyUri.data;
104
105 /* test g_eccAppCert, level=el1 */
106 struct CmAppCertParam appCertParam01 = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
107 &certAlias01, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
108 ret = CmInstallAppCertEx(&appCertParam01, &priKeyUri);
109 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest001 2 credentail test failed, retcode:" << ret;
110
111 char uriBuf001[] = "oh:t=ak;o=PrikeyB;u=0;a=0";
112 EXPECT_EQ(strcmp(uriBuf001, (char *)priKeyUri.data), 0) << "strcmp failed";
113
114 ret = CmUninstallAllAppCert();
115 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest001 test failed, retcode:" << ret;
116 }
117
118 /**
119 * @tc.name: PriAppCertTest002
120 * @tc.desc: Test CertManager Install private app cert interface base function
121 * @tc.type: FUNC
122 */
123 HWTEST_F(CmPriAppCertTest, PriAppCertTest002, TestSize.Level0)
124 {
125 char retUriBuf[MAX_LEN_URI] = {0};
126 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
127
128 uint8_t certAliasBuf[] = "PrikeyA";
129 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
130 uint8_t certAliasBuf002[] = "PrikeyB";
131 struct CmBlob certAlias02 = { sizeof(certAliasBuf002), certAliasBuf002 };
132
133 /* test g_appCert,level=el2 */
134 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
135 &certAlias, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL2 };
136 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
137 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest002 1 credentail test failed, retcode:" << ret;
138
139 char uriBuf[] = "oh:t=ak;o=PrikeyA;u=0;a=0";
140 EXPECT_EQ(strcmp(uriBuf, (char *)priKeyUri.data), 0) << "strcmp failed";
141
142 /* test g_eccAppCert */
143 struct CmAppCertParam appCertParam01 = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
144 &certAlias02, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL2 };
145 ret = CmInstallAppCertEx(&appCertParam01, &priKeyUri);
146 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest002 2 credentail test failed, retcode:" << ret;
147
148 char uriBuf001[] = "oh:t=ak;o=PrikeyB;u=0;a=0";
149 EXPECT_EQ(strcmp(uriBuf001, (char *)priKeyUri.data), 0) << "strcmp failed";
150
151 ret = CmUninstallAllAppCert();
152 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest002 test failed, retcode:" << ret;
153 }
154
155 /**
156 * @tc.name: PriAppCertTest003
157 * @tc.desc: Test CertManager Install private app cert interface base function
158 * @tc.type: FUNC
159 */
160 HWTEST_F(CmPriAppCertTest, PriAppCertTest003, TestSize.Level0)
161 {
162 char retUriBuf[MAX_LEN_URI] = {0};
163 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
164
165 uint8_t certAliasBuf[] = "PrikeyA";
166 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
167 uint8_t certAliasBuf003[] = "PrikeyB";
168 struct CmBlob certAlias03 = { sizeof(certAliasBuf003), certAliasBuf003 };
169
170 /* test g_appCert, level=el4 */
171 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
172 &certAlias, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL4 };
173 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
174 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest003 credentail test failed, retcode:" << ret;
175
176 char uriBuf[] = "oh:t=ak;o=PrikeyA;u=0;a=0";
177 EXPECT_EQ(strcmp(uriBuf, (char *)priKeyUri.data), 0) << "strcmp failed";
178
179 /* test g_eccAppCert, level=el4 */
180 struct CmAppCertParam appCertParam01 = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
181 &certAlias03, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL4 };
182 ret = CmInstallAppCertEx(&appCertParam01, &priKeyUri);
183 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest002 2 credentail test failed, retcode:" << ret;
184
185 char uriBuf001[] = "oh:t=ak;o=PrikeyB;u=0;a=0";
186 EXPECT_EQ(strcmp(uriBuf001, (char *)priKeyUri.data), 0) << "strcmp failed";
187
188 ret = CmUninstallAllAppCert();
189 EXPECT_EQ(ret, CM_SUCCESS) << "PriAppCertTest003 test failed, retcode:" << ret;
190 }
191
192 /**
193 * @tc.name: PriAppCertTest004
194 * @tc.desc: Test Install private app cert abnormal function
195 * @tc.type: FUNC
196 */
197 HWTEST_F(CmPriAppCertTest, PriAppCertTest004, TestSize.Level0)
198 {
199 char retUriBuf[MAX_LEN_URI] = {0};
200 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
201
202 uint8_t certAliasBuf[] = "PrikeyA";
203 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
204
205 /* level is invalid */
206 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
207 &certAlias, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, static_cast<CmAuthStorageLevel>(ERROR_LEVEL) };
208 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
209 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest004 credentail test failed, retcode:" << ret;
210 }
211
212 /**
213 * @tc.name: PriAppCertTest005
214 * @tc.desc: Test Install private app cert abnormal function
215 * @tc.type: FUNC
216 */
217 HWTEST_F(CmPriAppCertTest, PriAppCertTest005, TestSize.Level0)
218 {
219 char retUriBuf[MAX_LEN_URI] = {0};
220 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
221
222 uint8_t certAliasBuf[] = "PrikeyA";
223 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
224
225 /* store is not private cred */
226 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
227 &certAlias, CM_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
228 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
229 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest005 credentail test failed, retcode:" << ret;
230 }
231
232 /**
233 * @tc.name: PriAppCertTest006
234 * @tc.desc: Test Install private app cert abnormal function
235 * @tc.type: FUNC
236 */
237 HWTEST_F(CmPriAppCertTest, PriAppCertTest006, TestSize.Level0)
238 {
239 char retUriBuf[MAX_LEN_URI] = {0};
240 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
241
242 uint8_t certAliasBuf[] = "PrikeyA";
243 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
244
245 /* pri app cert data is abnormal */
246 struct CmBlob abnormalAppCert = { sizeof(g_abnormalCertData), const_cast<uint8_t *>(g_abnormalCertData) };
247
248 struct CmAppCertParam appCertParam = { &abnormalAppCert, (struct CmBlob *)&g_appCertPwd,
249 &certAlias, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
250 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
251 EXPECT_EQ(ret, CMR_ERROR_INVALID_CERT_FORMAT) << "PriAppCertTest006 credentail test failed, retcode:" << ret;
252 }
253
254 /**
255 * @tc.name: PriAppCertTest007
256 * @tc.desc: Test CertManager Install private app cert interface abnormal function
257 * @tc.type: FUNC
258 */
259 HWTEST_F(CmPriAppCertTest, PriAppCertTest007, TestSize.Level0)
260 {
261 char retUriBuf[MAX_LEN_URI] = {0};
262 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
263
264 /* certParam is nullptr */
265 int32_t ret = CmInstallAppCertEx(nullptr, &priKeyUri);
266 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest007 credentail test failed, retcode:" << ret;
267 }
268
269 /**
270 * @tc.name: PriAppCertTest008
271 * @tc.desc: Test CertManager Install private app cert interface abnormal function
272 * @tc.type: FUNC
273 */
274 HWTEST_F(CmPriAppCertTest, PriAppCertTest008, TestSize.Level0)
275 {
276 char retUriBuf[MAX_LEN_URI] = {0};
277 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
278
279 uint8_t certAliasBuf[] = "PriAppCertTest008";
280 struct CmBlob certAlias007 = { sizeof(certAliasBuf), certAliasBuf };
281
282 /* certParam->appCert is nullptr */
283 struct CmAppCertParam appCertParam = { nullptr, (struct CmBlob *)&g_appCertPwd,
284 &certAlias007, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
285 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
286 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest008 credentail test failed, retcode:" << ret;
287 }
288
289 /**
290 * @tc.name: PriAppCertTest009
291 * @tc.desc: Test CertManager Install private app cert interface abnormal function
292 * @tc.type: FUNC
293 */
294 HWTEST_F(CmPriAppCertTest, PriAppCertTest009, TestSize.Level0)
295 {
296 char retUriBuf[MAX_LEN_URI] = {0};
297 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
298
299 uint8_t certAliasBuf[] = "PriAppCertTest009";
300 struct CmBlob certAlias008 = { sizeof(certAliasBuf), certAliasBuf };
301
302 /* certParam->appCertPwd is nullptr */
303 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, nullptr,
304 &certAlias008, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
305 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
306 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest009 credentail test failed, retcode:" << ret;
307 }
308
309 /**
310 * @tc.name: PriAppCertTest010
311 * @tc.desc: Test CertManager Install private app cert interface abnormal function
312 * @tc.type: FUNC
313 */
314 HWTEST_F(CmPriAppCertTest, PriAppCertTest010, TestSize.Level0)
315 {
316 char retUriBuf[MAX_LEN_URI] = {0};
317 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
318
319 /* certParam->certAlias is nullptr */
320 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
321 nullptr, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
322 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
323 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest010 credentail test failed, retcode:" << ret;
324 }
325
326 /**
327 * @tc.name: PriAppCertTest011
328 * @tc.desc: Test CertManager Install private app cert interface abnormal function
329 * @tc.type: FUNC
330 */
331 HWTEST_F(CmPriAppCertTest, PriAppCertTest011, TestSize.Level0)
332 {
333 uint8_t certAliasBuf[] = "PriAppCertTest011";
334 struct CmBlob certAlias010 = { sizeof(certAliasBuf), certAliasBuf };
335 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
336 &certAlias010, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
337
338 /* keyUri is nullptr */
339 int32_t ret = CmInstallAppCertEx(&appCertParam, nullptr);
340 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest011 credentail test failed, retcode:" << ret;
341 }
342
343 /**
344 * @tc.name: PriAppCertTest012
345 * @tc.desc: Test CertManager Install private app cert interface abnormal function
346 * @tc.type: FUNC
347 */
348 HWTEST_F(CmPriAppCertTest, PriAppCertTest012, TestSize.Level0)
349 {
350 struct CmBlob priKeyUri = { 0, nullptr };
351 uint8_t certAliasBuf[] = "PriAppCertTest012";
352 struct CmBlob certAlias010 = { sizeof(certAliasBuf), certAliasBuf };
353 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
354 &certAlias010, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
355
356 /* keyUri->data is nullptr */
357 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
358 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest012 credentail test failed, retcode:" << ret;
359 }
360
361 /**
362 * @tc.name: PriAppCertTest013
363 * @tc.desc: Test CertManager Install private app cert interface abnormal function
364 * @tc.type: FUNC
365 */
366 HWTEST_F(CmPriAppCertTest, PriAppCertTest013, TestSize.Level0)
367 {
368 char retUriBuf[MAX_LEN_URI] = {0};
369 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
370
371 /* certAlias not include '\0' */
372 uint8_t certAliasBuf[] = "PrikeyB";
373 struct CmBlob certAlias013 = { sizeof(certAliasBuf) - 1, certAliasBuf };
374
375 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
376 &certAlias013, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
377 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
378 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest013 credentail test failed, retcode:" << ret;
379 }
380
381 /**
382 * @tc.name: PriAppCertTest014
383 * @tc.desc: Test CertManager Install private app cert interface abnormal function
384 * @tc.type: FUNC
385 */
386 HWTEST_F(CmPriAppCertTest, PriAppCertTest014, TestSize.Level0)
387 {
388 char retUriBuf[MAX_LEN_URI] = {0};
389 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
390 uint8_t certAliasBuf[] = "PrikeyB";
391 struct CmBlob certAlias014 = { sizeof(certAliasBuf), certAliasBuf };
392
393 /* cert pwd not include '\0' */
394 uint8_t errPwdBuf[] = "123789";
395 struct CmBlob errPwd = { sizeof(errPwdBuf) - 1, errPwdBuf };
396
397 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, &errPwd,
398 &certAlias014, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
399 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
400 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest014 credentail test failed, retcode:" << ret;
401 }
402
403 /**
404 * @tc.name: PriAppCertTest015
405 * @tc.desc: Test CertManager Install private app cert interface abnormal function
406 * @tc.type: FUNC
407 */
408 HWTEST_F(CmPriAppCertTest, PriAppCertTest015, TestSize.Level0)
409 {
410 char retUriBuf[MAX_LEN_URI] = {0};
411 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
412
413 /* certAlias data is nullptr */
414 uint8_t certAliasBuf[] = "PrikeyB";
415 struct CmBlob certAlias015 = { sizeof(certAliasBuf), nullptr };
416
417 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
418 &certAlias015, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
419 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
420 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest015 credentail test failed, retcode:" << ret;
421 }
422
423 /**
424 * @tc.name: PriAppCertTest016
425 * @tc.desc: Test CertManager Install private app cert interface abnormal function
426 * @tc.type: FUNC
427 */
428 HWTEST_F(CmPriAppCertTest, PriAppCertTest016, TestSize.Level0)
429 {
430 char retUriBuf[MAX_LEN_URI] = {0};
431 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
432
433 /* certAlias size is 0 */
434 uint8_t certAliasBuf[] = "PrikeyB";
435 struct CmBlob certAlias016 = { 0, certAliasBuf };
436
437 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
438 &certAlias016, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
439 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
440 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest016 credentail test failed, retcode:" << ret;
441 }
442
443 /**
444 * @tc.name: PriAppCertTest017
445 * @tc.desc: Test CertManager Install private app cert interface abnormal function
446 * @tc.type: FUNC
447 */
448 HWTEST_F(CmPriAppCertTest, PriAppCertTest017, TestSize.Level0)
449 {
450 char retUriBuf[MAX_LEN_URI] = {0};
451 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
452
453 /* certAlias size beyond max */
454 uint8_t certAliasBuf[] = "123456789012345678901234567890123456789012345678901234567890 \
455 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
456 struct CmBlob certAlias018 = { sizeof(certAliasBuf), certAliasBuf };
457
458 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, (struct CmBlob *)&g_appCertPwd,
459 &certAlias018, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
460 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
461 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) <<
462 "PriAppCertTest017 credentail test failed, retcode:" << ret;
463 }
464
465 /**
466 * @tc.name: PriAppCertTest018
467 * @tc.desc: Test CertManager Install private app cert interface abnormal function
468 * @tc.type: FUNC
469 */
470 HWTEST_F(CmPriAppCertTest, PriAppCertTest018, TestSize.Level0)
471 {
472 char retUriBuf[MAX_LEN_URI] = {0};
473 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
474 uint8_t certAliasBuf[] = "PrikeyB";
475 struct CmBlob certAlias019 = { sizeof(certAliasBuf), certAliasBuf };
476
477 /* appCert data is nullptr */
478 struct CmBlob appCert = { sizeof(g_rsa2048P12CertInfo), nullptr };
479
480 struct CmAppCertParam appCertParam = { &appCert, (struct CmBlob *)&g_appCertPwd,
481 &certAlias019, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
482 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
483 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest018 credentail test failed, retcode:" << ret;
484 }
485
486 /**
487 * @tc.name: PriAppCertTest019
488 * @tc.desc: Test CertManager Install private app cert interface abnormal function
489 * @tc.type: FUNC
490 */
491 HWTEST_F(CmPriAppCertTest, PriAppCertTest019, TestSize.Level0)
492 {
493 char retUriBuf[MAX_LEN_URI] = {0};
494 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
495 uint8_t certAliasBuf[] = "PrikeyB";
496 struct CmBlob certAlias019 = { sizeof(certAliasBuf), certAliasBuf };
497
498 /* appCert size is 0 */
499 struct CmBlob appCert = { 0, const_cast<uint8_t *>(g_rsa2048P12CertInfo) };
500
501 struct CmAppCertParam appCertParam = { &appCert, (struct CmBlob *)&g_appCertPwd,
502 &certAlias019, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
503 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
504 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest019 credentail test failed, retcode:" << ret;
505 }
506
507 /**
508 * @tc.name: PriAppCertTest020
509 * @tc.desc: Test CertManager Install private app cert interface abnormal function
510 * @tc.type: FUNC
511 */
512 HWTEST_F(CmPriAppCertTest, PriAppCertTest020, TestSize.Level0)
513 {
514 char retUriBuf[MAX_LEN_URI] = {0};
515 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
516 uint8_t certAliasBuf[] = "PrikeyB";
517 struct CmBlob certAlias019 = { sizeof(certAliasBuf), certAliasBuf };
518
519 /* appCert size beyond max */
520 uint8_t appCertData[MAX_LEN_APP_CERT + 1] = { 0 };
521 struct CmBlob appCert = { MAX_LEN_APP_CERT + 1, appCertData };
522
523 struct CmAppCertParam appCertParam = { &appCert, (struct CmBlob *)&g_appCertPwd,
524 &certAlias019, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
525 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
526 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest020 credentail test failed, retcode:" << ret;
527 }
528
529 /**
530 * @tc.name: PriAppCertTest021
531 * @tc.desc: Test CertManager Install private app cert interface abnormal function
532 * @tc.type: FUNC
533 */
534 HWTEST_F(CmPriAppCertTest, PriAppCertTest021, TestSize.Level0)
535 {
536 char retUriBuf[MAX_LEN_URI] = {0};
537 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
538 uint8_t certAliasBuf[] = "PrikeyB";
539 struct CmBlob certAlias020 = { sizeof(certAliasBuf), certAliasBuf };
540
541 /* appCertPwd->data is nullptr */
542 uint8_t pwdBuf[] = "123789";
543 struct CmBlob appCertPwd = { sizeof(pwdBuf), nullptr };
544
545 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, &appCertPwd,
546 &certAlias020, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
547 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
548 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest021 credentail test failed, retcode:" << ret;
549 }
550
551 /**
552 * @tc.name: PriAppCertTest022
553 * @tc.desc: Test CertManager Install private app cert interface abnormal function
554 * @tc.type: FUNC
555 */
556 HWTEST_F(CmPriAppCertTest, PriAppCertTest022, TestSize.Level0)
557 {
558 char retUriBuf[MAX_LEN_URI] = {0};
559 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
560 uint8_t certAliasBuf[] = "PrikeyB";
561 struct CmBlob certAlias021 = { sizeof(certAliasBuf), certAliasBuf };
562
563 /* appCertPwd->size is 0 */
564 uint8_t pwdBuf[] = "123789";
565 struct CmBlob appCertPwd = { 0, pwdBuf };
566
567 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, &appCertPwd,
568 &certAlias021, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
569 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
570 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest022 credentail test failed, retcode:" << ret;
571 }
572
573 /**
574 * @tc.name: PriAppCertTest023
575 * @tc.desc: Test CertManager Install private app cert interface abnormal function
576 * @tc.type: FUNC
577 */
578 HWTEST_F(CmPriAppCertTest, PriAppCertTest023, TestSize.Level0)
579 {
580 char retUriBuf[MAX_LEN_URI] = {0};
581 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
582 uint8_t certAliasBuf[] = "PrikeyB";
583 struct CmBlob certAlias022 = { sizeof(certAliasBuf), certAliasBuf };
584
585 /* appCertPwd->size beyond max */
586 uint8_t pwdBuf[] = "123456789012345678901234567890123456";
587 struct CmBlob appCertPwd = { sizeof(pwdBuf), pwdBuf };
588
589 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_eccAppCert, &appCertPwd,
590 &certAlias022, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
591 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
592 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest023 credentail test failed, retcode:" << ret;
593 }
594
595 /**
596 * @tc.name: PriAppCertTest024
597 * @tc.desc: Test CertManager Install private app cert interface abnormal function
598 * @tc.type: FUNC
599 */
600 HWTEST_F(CmPriAppCertTest, PriAppCertTest024, TestSize.Level0)
601 {
602 char retUriBuf[MAX_LEN_URI] = {0};
603 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
604
605 uint8_t certAliasBuf[] = "PrikeyA";
606 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
607
608 /* err password */
609 uint8_t appCertPwdBuf[] = "123456789";
610 struct CmBlob errAppCertPwd = { sizeof(appCertPwdBuf), appCertPwdBuf };
611
612 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, &errAppCertPwd,
613 &certAlias, CM_PRI_CREDENTIAL_STORE, INIT_INVALID_VALUE, CM_AUTH_STORAGE_LEVEL_EL1 };
614 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
615 EXPECT_EQ(ret, CMR_ERROR_PASSWORD_IS_ERR) << "PriAppCertTest024 credentail test failed, retcode:" << ret;
616 }
617
618 /**
619 * @tc.name: PriAppCertTest025
620 * @tc.desc: Test CertManager Install private app cert interface abnormal function
621 * @tc.type: FUNC
622 */
623 HWTEST_F(CmPriAppCertTest, PriAppCertTest025, TestSize.Level0)
624 {
625 char retUriBuf[MAX_LEN_URI] = {0};
626 struct CmBlob priKeyUri = { sizeof(retUriBuf), reinterpret_cast<uint8_t *>(retUriBuf) };
627
628 uint8_t certAliasBuf[] = "PrikeyA";
629 struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf };
630
631 /* userid is not invalid */
632 struct CmAppCertParam appCertParam = { (struct CmBlob *)&g_appCert, (struct CmBlob *)&g_appCertPwd,
633 &certAlias, CM_PRI_CREDENTIAL_STORE, TEST_USERID, CM_AUTH_STORAGE_LEVEL_EL1 };
634 int32_t ret = CmInstallAppCertEx(&appCertParam, &priKeyUri);
635 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "PriAppCertTest025 1 credentail test failed, retcode:" << ret;
636 }
637 }