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 = 10;
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         ret = CmUpdate(&handleBlob, &updateInput);
180         EXPECT_EQ(ret, expectRet) << "update failed, i:" << i;
181 
182         uint8_t tmpOutput[DEFAULT_SIGNATURE_LEN] = {0};
183         struct CmBlob finishInput = { 0, nullptr };
184         struct CmBlob finishOutput = { sizeof(tmpOutput), tmpOutput };
185         ret = CmFinish(&handleBlob, &finishInput, &finishOutput);
186         EXPECT_EQ(ret, expectRet) << "finish failed, i:" << i;
187     }
188 
189     for (uint32_t i = 0; i < MAX_SESSION_NUM_MORE_1; ++i) {
190         struct CmBlob handleBlob = { sizeof(uint64_t), (uint8_t *)&handle[i] };
191         ret = CmAbort(&handleBlob);
192         EXPECT_EQ(ret, CM_SUCCESS) << "abort failed, i:" << i;
193     }
194 }
195 
196 
197 /**
198 * @tc.name: CmFinishTest001
199 * @tc.desc: Test CmFinish handle is null
200 * @tc.type: FUNC
201 * @tc.require: AR000H0MIA /SR000H09NA
202 */
203 HWTEST_F(CmFinishTest, CmFinishTest001, TestSize.Level0)
204 {
205     struct CmBlob *handle = nullptr;
206     struct CmBlob inData = { 0, nullptr };
207     struct CmBlob outData = { 0, nullptr };
208 
209     int32_t ret = CmFinish(handle, &inData, &outData);
210     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
211 }
212 
213 /**
214  * @tc.name: CmFinishTest002
215  * @tc.desc: Test CmFinish handle size is 0
216  * @tc.type: FUNC
217  * @tc.require: AR000H0MIA /SR000H09NA
218  */
219 HWTEST_F(CmFinishTest, CmFinishTest002, TestSize.Level0)
220 {
221     uint64_t handleValue = 0;
222     struct CmBlob handle = { 0, (uint8_t *)&handleValue };
223     struct CmBlob inData = { 0, nullptr };
224     struct CmBlob outData = { 0, nullptr };
225 
226     int32_t ret = CmFinish(&handle, &inData, &outData);
227     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
228 }
229 
230 /**
231  * @tc.name: CmFinishTest003
232  * @tc.desc: Test CmFinish handle data is null
233  * @tc.type: FUNC
234  * @tc.require: AR000H0MIA /SR000H09NA
235  */
236 HWTEST_F(CmFinishTest, CmFinishTest003, TestSize.Level0)
237 {
238     uint64_t handleValue = 0;
239     struct CmBlob handle = { sizeof(handleValue), nullptr };
240     struct CmBlob inData = { 0, nullptr };
241     struct CmBlob outData = { 0, nullptr };
242 
243     int32_t ret = CmFinish(&handle, &inData, &outData);
244     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
245 }
246 
247 /**
248 * @tc.name: CmFinishTest004
249 * @tc.desc: Test CmFinish inData is null
250 * @tc.type: FUNC
251 * @tc.require: AR000H0MIA /SR000H09NA
252 */
253 HWTEST_F(CmFinishTest, CmFinishTest004, TestSize.Level0)
254 {
255     uint64_t handleValue = 0;
256     struct CmBlob handle = { sizeof(handleValue), (uint8_t *)&handleValue };
257     struct CmBlob *inData = nullptr;
258     struct CmBlob outData = { 0, nullptr };
259 
260     int32_t ret = CmFinish(&handle, inData, &outData);
261     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
262 }
263 
264 /**
265  * @tc.name: CmFinishTest005
266  * @tc.desc: Test CmFinish outData is null
267  * @tc.type: FUNC
268  * @tc.require: AR000H0MIA /SR000H09NA
269  */
270 HWTEST_F(CmFinishTest, CmFinishTest005, TestSize.Level0)
271 {
272     uint64_t handleValue = 0;
273     struct CmBlob handle = { sizeof(handleValue), (uint8_t *)&handleValue };
274     struct CmBlob inData = { 0, nullptr };
275     struct CmBlob *outData = nullptr;
276 
277     int32_t ret = CmFinish(&handle, &inData, outData);
278     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
279 }
280 
281 /**
282 * @tc.name: CmFinishTest006
283 * @tc.desc: Test CmFinish handle not exist
284 * @tc.type: FUNC
285 * @tc.require: AR000H0MIA /SR000H09NA
286 */
287 HWTEST_F(CmFinishTest, CmFinishTest006, TestSize.Level0)
288 {
289     uint64_t handleValue = 0;
290     struct CmBlob handle = { sizeof(handleValue), (uint8_t *)&handleValue };
291     struct CmBlob inData = { 0, nullptr };
292     struct CmBlob outData = { 0, nullptr };
293 
294     int32_t ret = CmFinish(&handle, &inData, &outData);
295     EXPECT_EQ(ret, CMR_ERROR_NOT_EXIST);
296 }
297 
298 /**
299 * @tc.name: CmFinishTest007
300 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss sha256
301 * @tc.type: FUNC
302 * @tc.require: AR000H0MIA /SR000H09NA
303 */
304 HWTEST_F(CmFinishTest, CmFinishTest007, TestSize.Level0)
305 {
306     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
307     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
308 }
309 
310 /**
311 * @tc.name: CmFinishTest008
312 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha256
313 * @tc.type: FUNC
314 * @tc.require: AR000H0MIA /SR000H09NA
315 */
316 HWTEST_F(CmFinishTest, CmFinishTest008, TestSize.Level0)
317 {
318     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
319     TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
320 }
321 
322 /**
323 * @tc.name: CmFinishTest009
324 * @tc.desc: Test CmFinish abnormal case: caller is producer, rsa sign verify(sign invalid)
325 * @tc.type: FUNC
326 * @tc.require: AR000H0MIA /SR000H09NA
327 */
328 HWTEST_F(CmFinishTest, CmFinishTest009, TestSize.Level0)
329 {
330     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
331     TestSignVerify(CERT_KEY_ALG_RSA, false, &spec);
332 }
333 
334 /**
335 * @tc.name: CmFinishTest010
336 * @tc.desc: Test CmFinish abnormal case: caller is producer, ecc sign verify(sign invalid)
337 * @tc.type: FUNC
338 * @tc.require: AR000H0MIA /SR000H09NA
339 */
340 HWTEST_F(CmFinishTest, CmFinishTest010, TestSize.Level0)
341 {
342     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
343     TestSignVerify(CERT_KEY_ALG_ECC, false, &spec);
344 }
345 
346 /**
347 * @tc.name: CmFinishTest011
348 * @tc.desc: Test CmFinish normal case: normal case: caller is producer, max times + 1(first fail)
349 * @tc.type: FUNC
350 * @tc.require: AR000H0MIA /SR000H09NA
351 */
352 HWTEST_F(CmFinishTest, CmFinishTest011, TestSize.Level0)
353 {
354     TestInstallAppCert(CERT_KEY_ALG_ECC);
355     ProducerSessionMaxTest();
356     TestUninstallAppCert();
357 }
358 
359 /**
360 * @tc.name: CmFinishTestPerformance012
361 * @tc.desc: 1000 times normal case: caller is producer, ecc sign verify
362 * @tc.type: FUNC
363 * @tc.require: AR000H0MIA /SR000H09NA
364 */
365 HWTEST_F(CmFinishTest, CmFinishTestPerformance012, TestSize.Level1)
366 {
367     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
368     for (uint32_t i = 0; i < PERFORMACE_COUNT; ++i) {
369         TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
370     }
371 }
372 
373 /**
374 * @tc.name: CmFinishTestPerformance013
375 * @tc.desc: 1000 times normal case: caller is producer, rsa sign verify
376 * @tc.type: FUNC
377 * @tc.require: AR000H0MIA /SR000H09NA
378 */
379 HWTEST_F(CmFinishTest, CmFinishTestPerformance013, TestSize.Level1)
380 {
381     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA256 };
382     for (uint32_t i = 0; i < PERFORMACE_COUNT; ++i) {
383         TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
384     }
385 }
386 
387 /**
388 * @tc.name: CmFinishTest014
389 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha512
390 * @tc.type: FUNC
391 * @tc.require: AR000H0MIA /SR000H09NA
392 */
393 HWTEST_F(CmFinishTest, CmFinishTest014, TestSize.Level0)
394 {
395     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA512 };
396     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
397 }
398 
399 /**
400 * @tc.name: CmFinishTest015
401 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha384
402 * @tc.type: FUNC
403 * @tc.require: AR000H0MIA /SR000H09NA
404 */
405 HWTEST_F(CmFinishTest, CmFinishTest015, TestSize.Level0)
406 {
407     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA384 };
408     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
409 }
410 
411 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
412 /**
413 * @tc.name: CmFinishTest016
414 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha224
415 * @tc.type: FUNC
416 * @tc.require: AR000H0MIA /SR000H09NA
417 */
418 HWTEST_F(CmFinishTest, CmFinishTest016, TestSize.Level0)
419 {
420     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA224 };
421     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
422 }
423 
424 /**
425 * @tc.name: CmFinishTest017
426 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pss, sha1
427 * @tc.type: FUNC
428 * @tc.require: AR000H0MIA /SR000H09NA
429 */
430 HWTEST_F(CmFinishTest, CmFinishTest017, TestSize.Level0)
431 {
432     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA1 };
433     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
434 }
435 #endif
436 
437 /**
438 * @tc.name: CmFinishTest018
439 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, nosha
440 * @tc.type: FUNC
441 * @tc.require: AR000H0MIA /SR000H09NA
442 */
443 HWTEST_F(CmFinishTest, CmFinishTest018, TestSize.Level0)
444 {
445     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_NONE };
446     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
447 }
448 
449 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
450 /**
451 * @tc.name: CmFinishTest019
452 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, md5
453 * @tc.type: FUNC
454 * @tc.require: AR000H0MIA /SR000H09NA
455 */
456 HWTEST_F(CmFinishTest, CmFinishTest019, TestSize.Level0)
457 {
458     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_MD5 };
459     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
460 }
461 
462 /**
463 * @tc.name: CmFinishTest020
464 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha224
465 * @tc.type: FUNC
466 * @tc.require: AR000H0MIA /SR000H09NA
467 */
468 HWTEST_F(CmFinishTest, CmFinishTest020, TestSize.Level0)
469 {
470     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA224 };
471     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
472 }
473 #endif
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 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
512 /**
513 * @tc.name: CmFinishTest024
514 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, pkcs1, sha1
515 * @tc.type: FUNC
516 * @tc.require: AR000H0MIA /SR000H09NA
517 */
518 HWTEST_F(CmFinishTest, CmFinishTest024, TestSize.Level0)
519 {
520     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA1 };
521     TestSignVerify(CERT_KEY_ALG_RSA, true, &spec);
522 }
523 
524 /**
525 * @tc.name: CmFinishTest025
526 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha1
527 * @tc.type: FUNC
528 * @tc.require: AR000H0MIA /SR000H09NA
529 */
530 HWTEST_F(CmFinishTest, CmFinishTest025, TestSize.Level0)
531 {
532     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA1 };
533     TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
534 }
535 
536 /**
537 * @tc.name: CmFinishTest026
538 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha224
539 * @tc.type: FUNC
540 * @tc.require: AR000H0MIA /SR000H09NA
541 */
542 HWTEST_F(CmFinishTest, CmFinishTest026, TestSize.Level0)
543 {
544     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA224 };
545     TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
546 }
547 #endif
548 
549 /**
550 * @tc.name: CmFinishTest027
551 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha384
552 * @tc.type: FUNC
553 * @tc.require: AR000H0MIA /SR000H09NA
554 */
555 HWTEST_F(CmFinishTest, CmFinishTest027, TestSize.Level0)
556 {
557     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA384 };
558     TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
559 }
560 
561 /**
562 * @tc.name: CmFinishTest028
563 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, sha512
564 * @tc.type: FUNC
565 * @tc.require: AR000H0MIA /SR000H09NA
566 */
567 HWTEST_F(CmFinishTest, CmFinishTest028, TestSize.Level0)
568 {
569     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA512 };
570     TestSignVerify(CERT_KEY_ALG_ECC, true, &spec);
571 }
572 
573 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
574 /**
575 * @tc.name: CmFinishTest029
576 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 512
577 * @tc.type: FUNC
578 * @tc.require: AR000H0MIA /SR000H09NA
579 */
580 HWTEST_F(CmFinishTest, CmFinishTest029, TestSize.Level0)
581 {
582     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA224 };
583     TestSignVerify(CERT_KEY_ALG_RSA_512, true, &spec);
584 }
585 
586 /**
587 * @tc.name: CmFinishTest030
588 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 1024
589 * @tc.type: FUNC
590 * @tc.require: AR000H0MIA /SR000H09NA
591 */
592 HWTEST_F(CmFinishTest, CmFinishTest030, TestSize.Level0)
593 {
594     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PSS, CM_DIGEST_SHA384 };
595     TestSignVerify(CERT_KEY_ALG_RSA_1024, true, &spec);
596 }
597 #endif
598 
599 /**
600 * @tc.name: CmFinishTest031
601 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 3072
602 * @tc.type: FUNC
603 * @tc.require: AR000H0MIA /SR000H09NA
604 */
605 HWTEST_F(CmFinishTest, CmFinishTest031, TestSize.Level0)
606 {
607     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_NONE };
608     TestSignVerify(CERT_KEY_ALG_RSA_3072, true, &spec);
609 }
610 
611 /**
612 * @tc.name: CmFinishTest032
613 * @tc.desc: Test CmFinish normal case: caller is producer, rsa sign verify, 4096
614 * @tc.type: FUNC
615 * @tc.require: AR000H0MIA /SR000H09NA
616 */
617 HWTEST_F(CmFinishTest, CmFinishTest032, TestSize.Level0)
618 {
619     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, CM_PADDING_PKCS1_V1_5, CM_DIGEST_SHA512 };
620     TestSignVerify(CERT_KEY_ALG_RSA_4096, true, &spec);
621 }
622 
623 #ifdef DEPS_HKS_UNTRUSTED_RUNNING_ENV
624 /**
625 * @tc.name: CmFinishTest033
626 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P224
627 * @tc.type: FUNC
628 * @tc.require: AR000H0MIA /SR000H09NA
629 */
630 HWTEST_F(CmFinishTest, CmFinishTest033, TestSize.Level0)
631 {
632     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA256 };
633     TestSignVerify(CERT_KEY_ALG_ECC_P224, true, &spec);
634 }
635 #endif
636 
637 /**
638 * @tc.name: CmFinishTest034
639 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P384
640 * @tc.type: FUNC
641 * @tc.require: AR000H0MIA /SR000H09NA
642 */
643 HWTEST_F(CmFinishTest, CmFinishTest034, TestSize.Level0)
644 {
645     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA384 };
646     TestSignVerify(CERT_KEY_ALG_ECC_P384, true, &spec);
647 }
648 
649 /**
650 * @tc.name: CmFinishTest035
651 * @tc.desc: Test CmFinish normal case: caller is producer, ecc sign verify, P521
652 * @tc.type: FUNC
653 * @tc.require: AR000H0MIA /SR000H09NA
654 */
655 HWTEST_F(CmFinishTest, CmFinishTest035, TestSize.Level0)
656 {
657     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, CM_DIGEST_SHA512 };
658     TestSignVerify(CERT_KEY_ALG_ECC_P521, true, &spec);
659 }
660 
661 /**
662 * @tc.name: CmFinishTest036
663 * @tc.desc: Test CmFinish normal case: caller is producer, ed25519 sign verify
664 * @tc.type: FUNC
665 * @tc.require: AR000H0MIA /SR000H09NA
666 */
667 HWTEST_F(CmFinishTest, CmFinishTest036, TestSize.Level0)
668 {
669     struct CmSignatureSpec spec = { CM_KEY_PURPOSE_SIGN, 0, 0 };
670     TestSignVerify(CERT_KEY_ALG_ED25519, true, &spec);
671 }
672 } // end of namespace
673 
674