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 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
416 /**
417 * @tc.name: CmFinishTest016
418 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha224
419 * @tc.type: FUNC
420 * @tc.require: AR000H0MIA /SR000H09NA
421 */
422 HWTEST_F(CmFinishTest, CmFinishTest016, TestSize.Level0)
423 {
424 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA224 };
425 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
426 }
427
428 /**
429 * @tc.name: CmFinishTest017
430 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha1
431 * @tc.type: FUNC
432 * @tc.require: AR000H0MIA /SR000H09NA
433 */
434 HWTEST_F(CmFinishTest, CmFinishTest017, TestSize.Level0)
435 {
436 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA1 };
437 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
438 }
439 #endif
440
441 /**
442 * @tc.name: CmFinishTest018
443 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, nosha
444 * @tc.type: FUNC
445 * @tc.require: AR000H0MIA /SR000H09NA
446 */
447 HWTEST_F(CmFinishTest, CmFinishTest018, TestSize.Level0)
448 {
449 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_NONE };
450 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
451 }
452
453 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
454 /**
455 * @tc.name: CmFinishTest019
456 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, md5
457 * @tc.type: FUNC
458 * @tc.require: AR000H0MIA /SR000H09NA
459 */
460 HWTEST_F(CmFinishTest, CmFinishTest019, TestSize.Level0)
461 {
462 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_MD5 };
463 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
464 }
465
466 /**
467 * @tc.name: CmFinishTest020
468 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha224
469 * @tc.type: FUNC
470 * @tc.require: AR000H0MIA /SR000H09NA
471 */
472 HWTEST_F(CmFinishTest, CmFinishTest020, TestSize.Level0)
473 {
474 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA224 };
475 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
476 }
477 #endif
478
479 /**
480 * @tc.name: CmFinishTest021
481 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha256
482 * @tc.type: FUNC
483 * @tc.require: AR000H0MIA /SR000H09NA
484 */
485 HWTEST_F(CmFinishTest, CmFinishTest021, TestSize.Level0)
486 {
487 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA256 };
488 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
489 }
490
491 /**
492 * @tc.name: CmFinishTest022
493 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha384
494 * @tc.type: FUNC
495 * @tc.require: AR000H0MIA /SR000H09NA
496 */
497 HWTEST_F(CmFinishTest, CmFinishTest022, TestSize.Level0)
498 {
499 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA384 };
500 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
501 }
502
503 /**
504 * @tc.name: CmFinishTest023
505 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha512
506 * @tc.type: FUNC
507 * @tc.require: AR000H0MIA /SR000H09NA
508 */
509 HWTEST_F(CmFinishTest, CmFinishTest023, TestSize.Level0)
510 {
511 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA512 };
512 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
513 }
514
515 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
516 /**
517 * @tc.name: CmFinishTest024
518 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha1
519 * @tc.type: FUNC
520 * @tc.require: AR000H0MIA /SR000H09NA
521 */
522 HWTEST_F(CmFinishTest, CmFinishTest024, TestSize.Level0)
523 {
524 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA1 };
525 TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
526 }
527
528 /**
529 * @tc.name: CmFinishTest025
530 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha1
531 * @tc.type: FUNC
532 * @tc.require: AR000H0MIA /SR000H09NA
533 */
534 HWTEST_F(CmFinishTest, CmFinishTest025, TestSize.Level0)
535 {
536 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA1 };
537 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
538 }
539
540 /**
541 * @tc.name: CmFinishTest026
542 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha224
543 * @tc.type: FUNC
544 * @tc.require: AR000H0MIA /SR000H09NA
545 */
546 HWTEST_F(CmFinishTest, CmFinishTest026, TestSize.Level0)
547 {
548 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA224 };
549 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
550 }
551 #endif
552
553 /**
554 * @tc.name: CmFinishTest027
555 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha384
556 * @tc.type: FUNC
557 * @tc.require: AR000H0MIA /SR000H09NA
558 */
559 HWTEST_F(CmFinishTest, CmFinishTest027, TestSize.Level0)
560 {
561 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA384 };
562 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
563 }
564
565 /**
566 * @tc.name: CmFinishTest028
567 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha512
568 * @tc.type: FUNC
569 * @tc.require: AR000H0MIA /SR000H09NA
570 */
571 HWTEST_F(CmFinishTest, CmFinishTest028, TestSize.Level0)
572 {
573 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA512 };
574 TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
575 }
576
577 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
578 /**
579 * @tc.name: CmFinishTest029
580 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 512
581 * @tc.type: FUNC
582 * @tc.require: AR000H0MIA /SR000H09NA
583 */
584 HWTEST_F(CmFinishTest, CmFinishTest029, TestSize.Level0)
585 {
586 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA224 };
587 TestSignVerify(CERT_KEY_ALG_RSA_512, true, &spec);
588 }
589
590 /**
591 * @tc.name: CmFinishTest030
592 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 1024
593 * @tc.type: FUNC
594 * @tc.require: AR000H0MIA /SR000H09NA
595 */
596 HWTEST_F(CmFinishTest, CmFinishTest030, TestSize.Level0)
597 {
598 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA384 };
599 TestSignVerify(CERT_KEY_ALG_RSA_1024, true, &spec);
600 }
601 #endif
602
603 /**
604 * @tc.name: CmFinishTest031
605 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 3072
606 * @tc.type: FUNC
607 * @tc.require: AR000H0MIA /SR000H09NA
608 */
609 HWTEST_F(CmFinishTest, CmFinishTest031, TestSize.Level0)
610 {
611 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_NONE };
612 TestSignVerify(CERT_KEY_ALG_RSA_3072, true, &spec);
613 }
614
615 /**
616 * @tc.name: CmFinishTest032
617 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 4096
618 * @tc.type: FUNC
619 * @tc.require: AR000H0MIA /SR000H09NA
620 */
621 HWTEST_F(CmFinishTest, CmFinishTest032, TestSize.Level0)
622 {
623 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA512 };
624 TestSignVerify(CERT_KEY_ALG_RSA_4096, true, &spec);
625 }
626
627 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
628 /**
629 * @tc.name: CmFinishTest033
630 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P224
631 * @tc.type: FUNC
632 * @tc.require: AR000H0MIA /SR000H09NA
633 */
634 HWTEST_F(CmFinishTest, CmFinishTest033, TestSize.Level0)
635 {
636 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
637 TestSignVerify(CERT_KEY_ALG_ECC_P224, true, &spec);
638 }
639 #endif
640
641 /**
642 * @tc.name: CmFinishTest034
643 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P384
644 * @tc.type: FUNC
645 * @tc.require: AR000H0MIA /SR000H09NA
646 */
647 HWTEST_F(CmFinishTest, CmFinishTest034, TestSize.Level0)
648 {
649 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA384 };
650 TestSignVerify(CERT_KEY_ALG_ECC_P384, true, &spec);
651 }
652
653 /**
654 * @tc.name: CmFinishTest035
655 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P521
656 * @tc.type: FUNC
657 * @tc.require: AR000H0MIA /SR000H09NA
658 */
659 HWTEST_F(CmFinishTest, CmFinishTest035, TestSize.Level0)
660 {
661 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA512 };
662 TestSignVerify(CERT_KEY_ALG_ECC_P521, true, &spec);
663 }
664
665 /**
666 * @tc.name: CmFinishTest036
667 * @tc.desc: Test CmFinish normal case: caller is producer, ed25519 sign verify
668 * @tc.type: FUNC
669 * @tc.require: AR000H0MIA /SR000H09NA
670 */
671 HWTEST_F(CmFinishTest, CmFinishTest036, TestSize.Level0)
672 {
673 struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, 0 };
674 TestSignVerify(CERT_KEY_ALG_ED25519, true, &spec);
675 }
676 } // end of namespace
677
678