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 "cm_test_common.h"
19
20 #include "cert_manager_api.h"
21
22 #include "cm_log.h"
23 #include "cm_mem.h"
24
25 using namespace testing::ext;
26 using namespace CertmanagerTest;
27 namespace {
28 static constexpr uint32_t DEFAULT_SIGNATURE_LEN = 1024;
29 static constexpr uint32_t MAX_SESSION_NUM_MORE_1 = 16;
30
31 class CmFinishTest : public testing::Test {
32 public:
33 static void SetUpTestCase(void);
34
35 static void TearDownTestCase(void);
36
37 void SetUp();
38
39 void TearDown();
40 };
41
SetUpTestCase(void)42 void CmFinishTest::SetUpTestCase(void)
43 {
44 SetATPermission();
45 }
46
TearDownTestCase(void)47 void CmFinishTest::TearDownTestCase(void)
48 {
49 }
50
SetUp()51 void CmFinishTest::SetUp()
52 {
53 }
54
TearDown()55 void CmFinishTest::TearDown()
56 {
57 }
58
59 static const uint8_t g_uriData[] = "oh:t=ak;o=TestFinishSignVerify;u=0;a=0";
60 static const CmBlob g_keyUri = { sizeof(g_uriData), (uint8_t *)g_uriData };
61
62 static const uint8_t g_messageData[] = "This_is_test_message_for_test_sign_and_verify";
63
TestInstallAppCert(uint32_t alg)64 static void TestInstallAppCert(uint32_t alg)
65 {
66 uint8_t aliasData[] = "TestFinishSignVerify";
67 struct CmBlob alias = { sizeof(aliasData), aliasData };
68
69 int32_t ret = TestGenerateAppCert(&alias, alg, CM_CREDENTIAL_STORE);
70 EXPECT_EQ(ret, CM_SUCCESS) << "TestGenerateAppCert failed, retcode:" << ret;
71 }
72
TestUninstallAppCert(void)73 static void TestUninstallAppCert(void)
74 {
75 int32_t ret = CmUninstallAppCert(&g_keyUri, CM_CREDENTIAL_STORE);
76 EXPECT_EQ(ret, CM_SUCCESS) << "CmUninstallAppCert failed, retcode:" << ret;
77 }
78
TestSign(const struct CmBlob * keyUri,const struct CmSignatureSpec * spec,const struct CmBlob * message,struct CmBlob * signature)79 static void TestSign(const struct CmBlob *keyUri, const struct CmSignatureSpec *spec,
80 const struct CmBlob *message, struct CmBlob *signature)
81 {
82 uint64_t handleValue = 0;
83 struct CmBlob handle = { sizeof(uint64_t), (uint8_t *)&handleValue };
84
85 int32_t ret = CmInit(keyUri, spec, &handle);
86 EXPECT_EQ(ret, CM_SUCCESS) << "TestSign CmInit test failed";
87
88 ret = CmUpdate(&handle, message);
89 EXPECT_EQ(ret, CM_SUCCESS) << "TestSign CmUpdate test failed";
90
91 struct CmBlob inDataFinish = { 0, nullptr };
92 ret = CmFinish(&handle, &inDataFinish, signature);
93 EXPECT_EQ(ret, CM_SUCCESS) << "TestSign CmFinish test failed";
94
95 ret = CmAbort(&handle);
96 EXPECT_EQ(ret, CM_SUCCESS) << "TestSign CmAbort test failed";
97 }
98
TestVerify(const struct CmBlob * keyUri,const struct CmSignatureSpec * spec,const struct CmBlob * message,const struct CmBlob * signature,bool isValidSignature)99 static void TestVerify(const struct CmBlob *keyUri, const struct CmSignatureSpec *spec,
100 const struct CmBlob *message, const struct CmBlob *signature, bool isValidSignature)
101 {
102 uint64_t handleValue = 0;
103 struct CmBlob handle = { sizeof(uint64_t), (uint8_t *)&handleValue };
104
105 int32_t ret = CmInit(keyUri, spec, &handle);
106 EXPECT_EQ(ret, CM_SUCCESS) << "TestVerify CmInit test failed";
107
108 ret = CmUpdate(&handle, message);
109 EXPECT_EQ(ret, CM_SUCCESS) << "TestVerify CmUpdate test failed";
110
111 struct CmBlob inDataFinish = { signature->size, signature->data };
112 if (!isValidSignature && signature->size > 0) {
113 signature->data[0] += 0x01; /* change the first byte of signature, ignore data flipping */
114 }
115
116 struct CmBlob outDataFinish = { 0, nullptr };
117 ret = CmFinish(&handle, &inDataFinish, &outDataFinish);
118 if (isValidSignature) {
119 EXPECT_EQ(ret, CM_SUCCESS) << "TestVerify CmFinish test failed";
120 } else {
121 EXPECT_EQ(ret, CMR_ERROR_KEY_OPERATION_FAILED) << "TestVerify CmFinish test failed";
122 }
123
124 ret = CmAbort(&handle);
125 EXPECT_EQ(ret, CM_SUCCESS) << "TestVerify CmAbort test failed";
126 }
127
TestSignVerify(uint32_t alg,bool isValidSignature,struct CmSignatureSpec * spec)128 static void TestSignVerify(uint32_t alg, bool isValidSignature, struct CmSignatureSpec *spec)
129 {
130 /* install credential */
131 TestInstallAppCert(alg);
132
133 struct CmBlob message = { 0, nullptr };
134 uint8_t srcData[] = {
135 0xc2, 0xa7, 0xc5, 0x33, 0x79, 0xb0, 0xcd, 0x86, 0x74, 0x09, 0x98, 0x16, 0xd5, 0x85, 0x1b, 0xd6,
136 0x87, 0xe3, 0xe0, 0x53, 0x7d, 0xe0, 0xff, 0x1d, 0xdb, 0x27, 0x98, 0xe8, 0x87, 0xe5, 0xb7, 0x03,
137 };
138 if (spec->digest != CM_DIGEST_NONE) {
139 message.size = sizeof(g_messageData);
140 message.data = const_cast<uint8_t *>(g_messageData);
141 } else {
142 message.size = sizeof(srcData);
143 message.data = srcData;
144 }
145
146 uint8_t signData[DEFAULT_SIGNATURE_LEN] = {0};
147 struct CmBlob signature = { DEFAULT_SIGNATURE_LEN, signData };
148
149 /* sign */
150 spec->purpose = CM_KEY_PURPOSE_SIGN;
151 TestSign(&g_keyUri, spec, &message, &signature);
152
153 /* verify */
154 spec->purpose = CM_KEY_PURPOSE_VERIFY;
155 TestVerify(&g_keyUri, spec, &message, &signature, isValidSignature);
156
157 /* uninstall rsa credential */
158 TestUninstallAppCert();
159 }
160
ProducerSessionMaxTest(void)161 static void ProducerSessionMaxTest(void)
162 {
163 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
164 uint64_t handle[MAX_SESSION_NUM_MORE_1];
165 int32_t ret;
166
167 for (uint32_t i = 0; i < MAX_SESSION_NUM_MORE_1; ++i) {
168 struct CmBlob handleBlob = { sizeof(uint64_t), (uint8_t *)&handle[i] };
169 ret = CmInit(&g_keyUri, &spec, &handleBlob);
170 EXPECT_EQ(ret, CM_SUCCESS) << "cm init failed, index[" << i << "]";
171 }
172
173 for (uint32_t i = 0; i < MAX_SESSION_NUM_MORE_1; ++i) {
174 uint8_t tmpInput[] = "thisIstestForSessionMaxTestInData";
175 struct CmBlob updateInput = { sizeof(tmpInput), tmpInput };
176 struct CmBlob handleBlob = { sizeof(uint64_t), (uint8_t *)&handle[i] };
177
178 int32_t expectRet = CM_SUCCESS;
179 if (i == 0) {
180 expectRet = CMR_ERROR_NOT_EXIST;
181 }
182
183 ret = CmUpdate(&handleBlob, &updateInput);
184 EXPECT_EQ(ret, expectRet) << "update failed, i:" << i;
185
186 uint8_t tmpOutput[DEFAULT_SIGNATURE_LEN] = {0};
187 struct CmBlob finishInput = { 0, nullptr };
188 struct CmBlob finishOutput = { sizeof(tmpOutput), tmpOutput };
189 ret = CmFinish(&handleBlob, &finishInput, &finishOutput);
190 EXPECT_EQ(ret, expectRet) << "finish failed, i:" << i;
191 }
192
193 for (uint32_t i = 0; i < MAX_SESSION_NUM_MORE_1; ++i) {
194 struct CmBlob handleBlob = { sizeof(uint64_t), (uint8_t *)&handle[i] };
195 ret = CmAbort(&handleBlob);
196 EXPECT_EQ(ret, CM_SUCCESS) << "abort failed, i:" << i;
197 }
198 }
199
200
201 /**
202 * @tc.name: CmFinishTest001
203 * @tc.desc: Test CmFinish handle is null
204 * @tc.type: FUNC
205 * @tc.require: AR000H0MIA /SR000H09NA
206 */
207 HWTEST_F(CmFinishTest, CmFinishTest001, TestSize.Level0)
208 {
209 struct CmBlob *handle = nullptr;
210 struct CmBlob inData = { 0, nullptr };
211 struct CmBlob outData = { 0, nullptr };
212
213 int32_t ret = CmFinish(handle, &inData, &outData);
214 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
215 }
216
217 /**
218 * @tc.name: CmFinishTest002
219 * @tc.desc: Test CmFinish handle size is 0
220 * @tc.type: FUNC
221 * @tc.require: AR000H0MIA /SR000H09NA
222 */
223 HWTEST_F(CmFinishTest, CmFinishTest002, TestSize.Level0)
224 {
225 uint64_t handleValue = 0;
226 struct CmBlob handle = { 0, (uint8_t *)&handleValue };
227 struct CmBlob inData = { 0, nullptr };
228 struct CmBlob outData = { 0, nullptr };
229
230 int32_t ret = CmFinish(&handle, &inData, &outData);
231 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
232 }
233
234 /**
235 * @tc.name: CmFinishTest003
236 * @tc.desc: Test CmFinish handle data is null
237 * @tc.type: FUNC
238 * @tc.require: AR000H0MIA /SR000H09NA
239 */
240 HWTEST_F(CmFinishTest, CmFinishTest003, TestSize.Level0)
241 {
242 uint64_t handleValue = 0;
243 struct CmBlob handle = { sizeof(handleValue), nullptr };
244 struct CmBlob inData = { 0, nullptr };
245 struct CmBlob outData = { 0, nullptr };
246
247 int32_t ret = CmFinish(&handle, &inData, &outData);
248 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
249 }
250
251 /**
252 * @tc.name: CmFinishTest004
253 * @tc.desc: Test CmFinish inData is null
254 * @tc.type: FUNC
255 * @tc.require: AR000H0MIA /SR000H09NA
256 */
257 HWTEST_F(CmFinishTest, CmFinishTest004, TestSize.Level0)
258 {
259 uint64_t handleValue = 0;
260 struct CmBlob handle = { sizeof(handleValue), (uint8_t *)&handleValue };
261 struct CmBlob *inData = nullptr;
262 struct CmBlob outData = { 0, nullptr };
263
264 int32_t ret = CmFinish(&handle, inData, &outData);
265 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
266 }
267
268 /**
269 * @tc.name: CmFinishTest005
270 * @tc.desc: Test CmFinish outData is null
271 * @tc.type: FUNC
272 * @tc.require: AR000H0MIA /SR000H09NA
273 */
274 HWTEST_F(CmFinishTest, CmFinishTest005, TestSize.Level0)
275 {
276 uint64_t handleValue = 0;
277 struct CmBlob handle = { sizeof(handleValue), (uint8_t *)&handleValue };
278 struct CmBlob inData = { 0, nullptr };
279 struct CmBlob *outData = nullptr;
280
281 int32_t ret = CmFinish(&handle, &inData, outData);
282 EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
283 }
284
285 /**
286 * @tc.name: CmFinishTest006
287 * @tc.desc: Test CmFinish handle not exist
288 * @tc.type: FUNC
289 * @tc.require: AR000H0MIA /SR000H09NA
290 */
291 HWTEST_F(CmFinishTest, CmFinishTest006, TestSize.Level0)
292 {
293 uint64_t handleValue = 0;
294 struct CmBlob handle = { sizeof(handleValue), (uint8_t *)&handleValue };
295 struct CmBlob inData = { 0, nullptr };
296 struct CmBlob outData = { 0, nullptr };
297
298 int32_t ret = CmFinish(&handle, &inData, &outData);
299 EXPECT_EQ(ret, CMR_ERROR_NOT_EXIST);
300 }
301
302 /**
303 * @tc.name: CmFinishTest007
304 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss sha256
305 * @tc.type: FUNC
306 * @tc.require: AR000H0MIA /SR000H09NA
307 */
308 HWTEST_F(CmFinishTest, CmFinishTest007, TestSize.Level0)
309 {
310 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
311 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
312 }
313
314 /**
315 * @tc.name: CmFinishTest008
316 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha256
317 * @tc.type: FUNC
318 * @tc.require: AR000H0MIA /SR000H09NA
319 */
320 HWTEST_F(CmFinishTest, CmFinishTest008, TestSize.Level0)
321 {
322 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
323 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
324 }
325
326 /**
327 * @tc.name: CmFinishTest009
328 * @tc.desc: Test CmFinish abnormal case: caller is producer, rsa sign verify(sign invalid)
329 * @tc.type: FUNC
330 * @tc.require: AR000H0MIA /SR000H09NA
331 */
332 HWTEST_F(CmFinishTest, CmFinishTest009, TestSize.Level0)
333 {
334 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
335 TestSignVerify(CERT_KEY_ALG_RSA, false, &spec);
336 }
337
338 /**
339 * @tc.name: CmFinishTest010
340 * @tc.desc: Test CmFinish abnormal case: caller is producer, ecc sign verify(sign invalid)
341 * @tc.type: FUNC
342 * @tc.require: AR000H0MIA /SR000H09NA
343 */
344 HWTEST_F(CmFinishTest, CmFinishTest010, TestSize.Level0)
345 {
346 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
347 TestSignVerify(CERT_KEY_ALG_ECC, false, &spec);
348 }
349
350 /**
351 * @tc.name: CmFinishTest011
352 * @tc.desc: Test CmFinish normal case: normal case: caller is producer, max times + 1(first fail)
353 * @tc.type: FUNC
354 * @tc.require: AR000H0MIA /SR000H09NA
355 */
356 HWTEST_F(CmFinishTest, CmFinishTest011, TestSize.Level0)
357 {
358 TestInstallAppCert(CERT_KEY_ALG_ECC);
359 ProducerSessionMaxTest();
360 TestUninstallAppCert();
361 }
362
363 /**
364 * @tc.name: CmFinishTestPerformance012
365 * @tc.desc: 1000 times normal case: caller is producer, ecc sign verify
366 * @tc.type: FUNC
367 * @tc.require: AR000H0MIA /SR000H09NA
368 */
369 HWTEST_F(CmFinishTest, CmFinishTestPerformance012, TestSize.Level1)
370 {
371 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
372 for (uint32_t i = 0; i < PERFORMACE_COUNT; ++i) {
373 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
374 }
375 }
376
377 /**
378 * @tc.name: CmFinishTestPerformance013
379 * @tc.desc: 1000 times normal case: caller is producer, rsa sign verify
380 * @tc.type: FUNC
381 * @tc.require: AR000H0MIA /SR000H09NA
382 */
383 HWTEST_F(CmFinishTest, CmFinishTestPerformance013, TestSize.Level1)
384 {
385 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
386 for (uint32_t i = 0; i < PERFORMACE_COUNT; ++i) {
387 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
388 }
389 }
390
391 /**
392 * @tc.name: CmFinishTest014
393 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha512
394 * @tc.type: FUNC
395 * @tc.require: AR000H0MIA /SR000H09NA
396 */
397 HWTEST_F(CmFinishTest, CmFinishTest014, TestSize.Level0)
398 {
399 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA512 };
400 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
401 }
402
403 /**
404 * @tc.name: CmFinishTest015
405 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha384
406 * @tc.type: FUNC
407 * @tc.require: AR000H0MIA /SR000H09NA
408 */
409 HWTEST_F(CmFinishTest, CmFinishTest015, TestSize.Level0)
410 {
411 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA384 };
412 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
413 }
414
415 /**
416 * @tc.name: CmFinishTest016
417 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha224
418 * @tc.type: FUNC
419 * @tc.require: AR000H0MIA /SR000H09NA
420 */
421 HWTEST_F(CmFinishTest, CmFinishTest016, TestSize.Level0)
422 {
423 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA224 };
424 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
425 }
426
427 /**
428 * @tc.name: CmFinishTest017
429 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha1
430 * @tc.type: FUNC
431 * @tc.require: AR000H0MIA /SR000H09NA
432 */
433 HWTEST_F(CmFinishTest, CmFinishTest017, TestSize.Level0)
434 {
435 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA1 };
436 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
437 }
438
439 /**
440 * @tc.name: CmFinishTest018
441 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, nosha
442 * @tc.type: FUNC
443 * @tc.require: AR000H0MIA /SR000H09NA
444 */
445 HWTEST_F(CmFinishTest, CmFinishTest018, TestSize.Level0)
446 {
447 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_NONE };
448 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
449 }
450
451 /**
452 * @tc.name: CmFinishTest019
453 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, md5
454 * @tc.type: FUNC
455 * @tc.require: AR000H0MIA /SR000H09NA
456 */
457 HWTEST_F(CmFinishTest, CmFinishTest019, TestSize.Level0)
458 {
459 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_MD5 };
460 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
461 }
462
463 /**
464 * @tc.name: CmFinishTest020
465 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha224
466 * @tc.type: FUNC
467 * @tc.require: AR000H0MIA /SR000H09NA
468 */
469 HWTEST_F(CmFinishTest, CmFinishTest020, TestSize.Level0)
470 {
471 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA224 };
472 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
473 }
474
475 /**
476 * @tc.name: CmFinishTest021
477 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha256
478 * @tc.type: FUNC
479 * @tc.require: AR000H0MIA /SR000H09NA
480 */
481 HWTEST_F(CmFinishTest, CmFinishTest021, TestSize.Level0)
482 {
483 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA256 };
484 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
485 }
486
487 /**
488 * @tc.name: CmFinishTest022
489 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha384
490 * @tc.type: FUNC
491 * @tc.require: AR000H0MIA /SR000H09NA
492 */
493 HWTEST_F(CmFinishTest, CmFinishTest022, TestSize.Level0)
494 {
495 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA384 };
496 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
497 }
498
499 /**
500 * @tc.name: CmFinishTest023
501 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha512
502 * @tc.type: FUNC
503 * @tc.require: AR000H0MIA /SR000H09NA
504 */
505 HWTEST_F(CmFinishTest, CmFinishTest023, TestSize.Level0)
506 {
507 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA512 };
508 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
509 }
510
511 /**
512 * @tc.name: CmFinishTest024
513 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha1
514 * @tc.type: FUNC
515 * @tc.require: AR000H0MIA /SR000H09NA
516 */
517 HWTEST_F(CmFinishTest, CmFinishTest024, TestSize.Level0)
518 {
519 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA1 };
520 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
521 }
522
523 /**
524 * @tc.name: CmFinishTest025
525 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha1
526 * @tc.type: FUNC
527 * @tc.require: AR000H0MIA /SR000H09NA
528 */
529 HWTEST_F(CmFinishTest, CmFinishTest025, TestSize.Level0)
530 {
531 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA1 };
532 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
533 }
534
535 /**
536 * @tc.name: CmFinishTest026
537 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha224
538 * @tc.type: FUNC
539 * @tc.require: AR000H0MIA /SR000H09NA
540 */
541 HWTEST_F(CmFinishTest, CmFinishTest026, TestSize.Level0)
542 {
543 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA224 };
544 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
545 }
546
547 /**
548 * @tc.name: CmFinishTest027
549 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha384
550 * @tc.type: FUNC
551 * @tc.require: AR000H0MIA /SR000H09NA
552 */
553 HWTEST_F(CmFinishTest, CmFinishTest027, TestSize.Level0)
554 {
555 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA384 };
556 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
557 }
558
559 /**
560 * @tc.name: CmFinishTest028
561 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha512
562 * @tc.type: FUNC
563 * @tc.require: AR000H0MIA /SR000H09NA
564 */
565 HWTEST_F(CmFinishTest, CmFinishTest028, TestSize.Level0)
566 {
567 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA512 };
568 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
569 }
570
571 /**
572 * @tc.name: CmFinishTest029
573 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 512
574 * @tc.type: FUNC
575 * @tc.require: AR000H0MIA /SR000H09NA
576 */
577 HWTEST_F(CmFinishTest, CmFinishTest029, TestSize.Level0)
578 {
579 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
580 TestSignVerify(CERT_KEY_ALG_RSA_512, true, &spec);
581 }
582
583 /**
584 * @tc.name: CmFinishTest030
585 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 1024
586 * @tc.type: FUNC
587 * @tc.require: AR000H0MIA /SR000H09NA
588 */
589 HWTEST_F(CmFinishTest, CmFinishTest030, TestSize.Level0)
590 {
591 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA384 };
592 TestSignVerify(CERT_KEY_ALG_RSA_1024, true, &spec);
593 }
594
595 /**
596 * @tc.name: CmFinishTest031
597 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 3072
598 * @tc.type: FUNC
599 * @tc.require: AR000H0MIA /SR000H09NA
600 */
601 HWTEST_F(CmFinishTest, CmFinishTest031, TestSize.Level0)
602 {
603 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_NONE };
604 TestSignVerify(CERT_KEY_ALG_RSA_3072, true, &spec);
605 }
606
607 /**
608 * @tc.name: CmFinishTest032
609 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 4096
610 * @tc.type: FUNC
611 * @tc.require: AR000H0MIA /SR000H09NA
612 */
613 HWTEST_F(CmFinishTest, CmFinishTest032, TestSize.Level0)
614 {
615 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA512 };
616 TestSignVerify(CERT_KEY_ALG_RSA_4096, true, &spec);
617 }
618
619 /**
620 * @tc.name: CmFinishTest033
621 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P224
622 * @tc.type: FUNC
623 * @tc.require: AR000H0MIA /SR000H09NA
624 */
625 HWTEST_F(CmFinishTest, CmFinishTest033, TestSize.Level0)
626 {
627 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
628 TestSignVerify(CERT_KEY_ALG_ECC_P224, true, &spec);
629 }
630
631 /**
632 * @tc.name: CmFinishTest034
633 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P384
634 * @tc.type: FUNC
635 * @tc.require: AR000H0MIA /SR000H09NA
636 */
637 HWTEST_F(CmFinishTest, CmFinishTest034, TestSize.Level0)
638 {
639 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA384 };
640 TestSignVerify(CERT_KEY_ALG_ECC_P384, true, &spec);
641 }
642
643 /**
644 * @tc.name: CmFinishTest035
645 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P521
646 * @tc.type: FUNC
647 * @tc.require: AR000H0MIA /SR000H09NA
648 */
649 HWTEST_F(CmFinishTest, CmFinishTest035, TestSize.Level0)
650 {
651 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA512 };
652 TestSignVerify(CERT_KEY_ALG_ECC_P521, true, &spec);
653 }
654
655 /**
656 * @tc.name: CmFinishTest036
657 * @tc.desc: Test CmFinish normal case: caller is producer, ed25519 sign verify
658 * @tc.type: FUNC
659 * @tc.require: AR000H0MIA /SR000H09NA
660 */
661 HWTEST_F(CmFinishTest, CmFinishTest036, TestSize.Level0)
662 {
663 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, 0 };
664 TestSignVerify(CERT_KEY_ALG_ED25519, true, &spec);
665 }
666 } // end of namespace
667
668