1 /*
2  * Copyright (c) 2024-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 #include <filesystem>
16 #include "params_run_tool.h"
17 #include "local_sign_provider.h"
18 #include "sign_hap.h"
19 #include "sign_provider.h"
20 #include "sign_tool_service_impl.h"
21 #include "remote_sign_provider.h"
22 #include "digest_common.h"
23 #include "hap_sign_test.h"
24 #include <unistd.h>
25 
26 namespace OHOS {
27 namespace SignatureTools {
28 
GenUnvaildUnSignHap(const std::string& path)29 void GenUnvaildUnSignHap(const std::string& path)
30 {
31     std::ofstream outfile(path);
32     if (!outfile) {
33         SIGNATURE_TOOLS_LOGE("Unable to open file: %s", path.c_str());
34         return;
35     }
36     outfile << "Hello, this is a Unvaild un sign Hap.\n";
37     outfile.flush();
38     outfile.close();
39     return;
40 }
41 
SetUpTestCase(void)42 void HapSignTest::SetUpTestCase(void)
43 {
44     GenUnvaildUnSignHap("./hapSign/phone-default-unsigned");
45     GenUnvaildUnSignHap("./hapSign/nohap.hap");
46 
47     (void)rename("./hapSign/phone-default-unsigned-test.txt", "./hapSign/phone-default-unsigned-test.hap");
48     (void)rename("./hapSign/phone-default-unsigned.txt", "./hapSign/phone-default-unsigned.hap");
49     (void)rename("./hapSign/unsigned_with_cd_and_eocd.txt", "./hapSign/unsigned_with_cd_and_eocd.hap");
50     (void)rename("./hapSign/unsigned_with_eocd.txt", "./hapSign/unsigned_with_eocd.hap");
51     sync();
52 }
53 
TearDownTestCase(void)54 void HapSignTest::TearDownTestCase(void)
55 {
56 }
57 /*
58  * @tc.name: hap_sign_test_001
59  * @tc.desc: This function tests success for interface SignHap
60  * @tc.type: FUNC
61  * @tc.require:
62  */
HWTEST_F(HapSignTest, hap_sign_test_001, testing::ext::TestSize.Level1)63 HWTEST_F(HapSignTest, hap_sign_test_001, testing::ext::TestSize.Level1)
64 {
65     SIGNATURE_TOOLS_LOGI("hello world !!!");
66     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
67     std::shared_ptr<Options> params = std::make_shared<Options>();
68 
69     std::string mode = "localSign";
70     std::string keyAlias = "oh-app1-key-v1";
71     std::string signAlg = "SHA256withECDSA";
72     std::string signCode = "0";
73     std::string appCertFile = "./hapSign/app-release1.pem";
74     std::string profileFile = "./hapSign/signed-profile.p7b";
75     std::string inFile = "./hapSign/phone-default-unsigned.hap";
76     std::string keystoreFile = "./hapSign/ohtest.p12";
77     std::string outFile = "./hapSign/phone-default-signed.hap";
78     char keyPwd[] = "123456";
79     char keystorePwd[] = "123456";
80 
81     (*params)["mode"] = mode;
82     (*params)["keyAlias"] = keyAlias;
83     (*params)["signAlg"] = signAlg;
84     (*params)["signCode"] = signCode;
85     (*params)["appCertFile"] = appCertFile;
86     (*params)["profileFile"] = profileFile;
87     (*params)["inFile"] = inFile;
88     (*params)["keystoreFile"] = keystoreFile;
89     (*params)["outFile"] = outFile;
90     (*params)["keyPwd"] = keyPwd;
91     (*params)["keystorePwd"] = keystorePwd;
92 
93     bool ret = api->SignHap(params.get());
94     EXPECT_EQ(ret, true);
95 }
96 /*
97  * @tc.name: hap_sign_test_002
98  * @tc.desc: This function tests success for interface SignHap
99  * @tc.type: FUNC
100  * @tc.require:
101  */
HWTEST_F(HapSignTest, hap_sign_test_002, testing::ext::TestSize.Level1)102 HWTEST_F(HapSignTest, hap_sign_test_002, testing::ext::TestSize.Level1)
103 {
104     SIGNATURE_TOOLS_LOGI("hello world !!!");
105     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
106     std::shared_ptr<Options> params = std::make_shared<Options>();
107 
108     std::string mode = "localSign";
109     std::string keyAlias = "oh-app1-key-v1";
110     std::string signAlg = "SHA256withECDSA";
111     std::string signCode = "1";
112     std::string appCertFile = "./hapSign/app-release1.pem";
113     std::string profileFile = "./hapSign/signed-profile.p7b";
114     std::string inFile = "./hapSign/phone-default-unsigned.hap";
115     std::string keystoreFile = "./hapSign/ohtest.p12";
116     std::string outFile = "./hapSign/phone-default-signed.hap";
117     char keyPwd[] = "123456";
118     char keystorePwd[] = "123456";
119 
120     (*params)["mode"] = mode;
121     (*params)["keyAlias"] = keyAlias;
122     (*params)["signAlg"] = signAlg;
123     (*params)["signCode"] = signCode;
124     (*params)["appCertFile"] = appCertFile;
125     (*params)["profileFile"] = profileFile;
126     (*params)["inFile"] = inFile;
127     (*params)["keystoreFile"] = keystoreFile;
128     (*params)["outFile"] = outFile;
129     (*params)["keyPwd"] = keyPwd;
130     (*params)["keystorePwd"] = keystorePwd;
131 
132     bool ret = api->SignHap(params.get());
133     EXPECT_EQ(ret, true);
134 }
135 /*
136  * @tc.name: hap_sign_test_003
137  * @tc.desc: This function tests success for interface SignHap
138  * @tc.type: FUNC
139  * @tc.require:
140  */
HWTEST_F(HapSignTest, hap_sign_test_003, testing::ext::TestSize.Level1)141 HWTEST_F(HapSignTest, hap_sign_test_003, testing::ext::TestSize.Level1)
142 {
143     SIGNATURE_TOOLS_LOGI("hello world !!!");
144     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
145     std::shared_ptr<Options> params = std::make_shared<Options>();
146 
147     std::string mode = "localSign";
148     std::string keyAlias = "oh-app1-key-v1";
149     std::string signAlg = "SHA256withECDSA";
150     std::string signCode = "1";
151     std::string appCertFile = "./hapSign/app-release1.pem";
152     std::string profileFile = "./hapSign/signed-profile.p7b";
153     std::string profileSigned = "0";
154     std::string inFile = "./hapSign/phone-default-unsigned.hap";
155     std::string keystoreFile = "./hapSign/ohtest.p12";
156     std::string outFile = "./hapSign/phone-default-signed.hap";
157     char keyPwd[] = "123456";
158     char keystorePwd[] = "123456";
159 
160     (*params)["mode"] = mode;
161     (*params)["keyAlias"] = keyAlias;
162     (*params)["signAlg"] = signAlg;
163     (*params)["signCode"] = signCode;
164     (*params)["appCertFile"] = appCertFile;
165     (*params)["profileFile"] = profileFile;
166     (*params)["profileSigned"] = profileSigned;
167     (*params)["inFile"] = inFile;
168     (*params)["keystoreFile"] = keystoreFile;
169     (*params)["outFile"] = outFile;
170     (*params)["keyPwd"] = keyPwd;
171     (*params)["keystorePwd"] = keystorePwd;
172 
173     bool ret = api->SignHap(params.get());
174     EXPECT_EQ(ret, false);
175 }
176 /*
177  * @tc.name: hap_sign_test_004
178  * @tc.desc: This function tests success for interface SignHap
179  * @tc.type: FUNC
180  * @tc.require:
181  */
HWTEST_F(HapSignTest, hap_sign_test_004, testing::ext::TestSize.Level1)182 HWTEST_F(HapSignTest, hap_sign_test_004, testing::ext::TestSize.Level1)
183 {
184     SIGNATURE_TOOLS_LOGI("hello world !!!");
185     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
186     std::shared_ptr<Options> params = std::make_shared<Options>();
187 
188     std::string mode = "localSign";
189     std::string keyAlias = "oh-app1-key-v1";
190     std::string signAlg = "SHA256withECDSA";
191     std::string signCode = "1";
192     std::string appCertFile = "./hapSign/app-release1.pem";
193     std::string profileFile = "./hapSign/signed-profile.p7b";
194     std::string profileSigned = "1";
195     std::string inFile = "./hapSign/phone-default-unsigned.hap";
196     std::string keystoreFile = "./hapSign/ohtest.p12";
197     std::string outFile = "./hapSign/phone-default-signed.hap";
198     char keyPwd[] = "123456";
199     char keystorePwd[] = "123456";
200 
201     (*params)["mode"] = mode;
202     (*params)["keyAlias"] = keyAlias;
203     (*params)["signAlg"] = signAlg;
204     (*params)["signCode"] = signCode;
205     (*params)["appCertFile"] = appCertFile;
206     (*params)["profileFile"] = profileFile;
207     (*params)["profileSigned"] = profileSigned;
208     (*params)["inFile"] = inFile;
209     (*params)["keystoreFile"] = keystoreFile;
210     (*params)["outFile"] = outFile;
211     (*params)["keyPwd"] = keyPwd;
212     (*params)["keystorePwd"] = keystorePwd;
213 
214     bool ret = api->SignHap(params.get());
215     EXPECT_EQ(ret, true);
216 }
217 /*
218  * @tc.name: hap_sign_test_005
219  * @tc.desc: This function tests success for interface Sign
220  * @tc.type: FUNC
221  * @tc.require:
222  */
HWTEST_F(HapSignTest, hap_sign_test_005, testing::ext::TestSize.Level1)223 HWTEST_F(HapSignTest, hap_sign_test_005, testing::ext::TestSize.Level1)
224 {
225     SIGNATURE_TOOLS_LOGI("hello world !!!");
226     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
227     std::shared_ptr<Options> params = std::make_shared<Options>();
228 
229     std::string mode = "localSign";
230     std::string keyAlias = "oh-app1-key-v1";
231     std::string signAlg = "SHA256withECDSA";
232     std::string signCode = "0";
233     std::string appCertFile = "./hapSign/app-release1.pem";
234     std::string profileFile = "./hapSign/signed-profile.p7b";
235     std::string inFile = "./hapSign/phone-default-unsigned.hap";
236     std::string keystoreFile = "./hapSign/ohtest.p12";
237     std::string outFile = "./hapSign/phone-default-signed.hap";
238     char keyPwd[] = "123456";
239     char keystorePwd[] = "123456";
240 
241     (*params)["mode"] = mode;
242     (*params)["keyAlias"] = keyAlias;
243     (*params)["signAlg"] = signAlg;
244     (*params)["signCode"] = signCode;
245     (*params)["appCertFile"] = appCertFile;
246     (*params)["profileFile"] = profileFile;
247     (*params)["inFile"] = inFile;
248     (*params)["keystoreFile"] = keystoreFile;
249     (*params)["outFile"] = outFile;
250     (*params)["keyPwd"] = keyPwd;
251     (*params)["keystorePwd"] = keystorePwd;
252 
253     signProvider->CheckInputCertMatchWithProfile(nullptr, nullptr);
254     bool retParam = signProvider->CheckParams(params.get());
255     EXPECT_EQ(retParam, true);
256 
257     std::optional<X509_CRL*> crl = signProvider->GetCrl();
258     EXPECT_EQ(crl.has_value(), false);
259 
260     bool ret = signProvider->Sign(params.get());
261     EXPECT_EQ(ret, true);
262 }
263 
264 /*
265  * @tc.name: hap_sign_test_006
266  * @tc.desc: This function tests failure for interface CheckParams due to parameter signCode is 3
267  * @tc.type: FUNC
268  * @tc.require:
269  */
HWTEST_F(HapSignTest, hap_sign_test_006, testing::ext::TestSize.Level1)270 HWTEST_F(HapSignTest, hap_sign_test_006, testing::ext::TestSize.Level1)
271 {
272     SIGNATURE_TOOLS_LOGI("hello world !!!");
273     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
274     std::shared_ptr<Options> params = std::make_shared<Options>();
275 
276     std::string mode = "localSign";
277     std::string keyAlias = "oh-app1-key-v1";
278     std::string signAlg = "SHA256withECDSA";
279     std::string signCode = "3";
280     std::string appCertFile = "./hapSign/app-release1.pem";
281     std::string profileFile = "./hapSign/signed-profile.p7b";
282     std::string inFile = "./hapSign/phone-default-unsigned.hap";
283     std::string keystoreFile = "./hapSign/ohtest.p12";
284     std::string outFile = "./hapSign/phone-default-signed.hap";
285     char keyPwd[] = "123456";
286     char keystorePwd[] = "123456";
287 
288     (*params)["mode"] = mode;
289     (*params)["keyAlias"] = keyAlias;
290     (*params)["signAlg"] = signAlg;
291     (*params)["signCode"] = signCode;
292     (*params)["appCertFile"] = appCertFile;
293     (*params)["profileFile"] = profileFile;
294     (*params)["inFile"] = inFile;
295     (*params)["keystoreFile"] = keystoreFile;
296     (*params)["outFile"] = outFile;
297     (*params)["keyPwd"] = keyPwd;
298     (*params)["keystorePwd"] = keystorePwd;
299 
300     bool retParam = signProvider->CheckParams(params.get());
301     EXPECT_EQ(retParam, false);
302 }
303 
304 /*
305  * @tc.name: hap_sign_test_007
306  * @tc.desc: This function tests failure for interface CheckParams due to parameter signCode and appCertFile
307  * @tc.type: FUNC
308  * @tc.require:
309  */
HWTEST_F(HapSignTest, hap_sign_test_007, testing::ext::TestSize.Level1)310 HWTEST_F(HapSignTest, hap_sign_test_007, testing::ext::TestSize.Level1)
311 {
312     SIGNATURE_TOOLS_LOGI("hello world !!!");
313     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
314     std::shared_ptr<Options> params = std::make_shared<Options>();
315 
316     std::string mode = "localSign";
317     std::string keyAlias = "oh-app1-key-v1";
318     std::string signAlg = "SHA256withECDSA";
319     std::string signCode = "0";
320     std::string appCertFile = "./hapSign/app-release1.pem";
321     std::string profileFile = "./hapSign/signed-profile.p7b";
322     std::string inFile = "./hapSign/phone-default-unsigned.hap";
323     std::string keystoreFile = "./hapSign/ohtest.p12";
324     std::string outFile = "./hapSign/phone-default-signed.hap";
325     char keyPwd[] = "123456";
326     char keystorePwd[] = "123456";
327 
328     (*params)["mode"] = mode;
329     (*params)["keyAlias"] = keyAlias;
330     (*params)["signAlg"] = signAlg;
331     (*params)["appCertFile"] = appCertFile;
332     (*params)["profileFile"] = profileFile;
333     (*params)["inFile"] = inFile;
334     (*params)["keystoreFile"] = keystoreFile;
335     (*params)["outFile"] = outFile;
336     (*params)["keyPwd"] = keyPwd;
337     (*params)["keystorePwd"] = keystorePwd;
338 
339     (*params)["signCode"] = std::string("3");
340     bool retParamT = signProvider->CheckParams(params.get());
341     EXPECT_EQ(retParamT, false);
342 
343     (*params)["signCode"] = signCode;
344     (*params)["appCertFile"] = std::string("");
345     bool ret = signProvider->Sign(params.get());
346     EXPECT_EQ(ret, false);
347 }
348 
349 /*
350  * @tc.name: hap_sign_test_008
351  * @tc.desc: This function tests sucess for interface Sign
352  * @tc.type: FUNC
353  * @tc.require:
354  */
HWTEST_F(HapSignTest, hap_sign_test_008, testing::ext::TestSize.Level1)355 HWTEST_F(HapSignTest, hap_sign_test_008, testing::ext::TestSize.Level1)
356 {
357     SIGNATURE_TOOLS_LOGI("hello world !!!");
358     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
359     std::shared_ptr<Options> params = std::make_shared<Options>();
360 
361     std::string mode = "localSign";
362     std::string keyAlias = "oh-app1-key-v1";
363     std::string signAlg = "SHA256withECDSA";
364     std::string signCode = "1";
365     std::string appCertFile = "./hapSign/app-release1.pem";
366     std::string profileFile = "./hapSign/signed-profile.p7b";
367     std::string inFile = "./hapSign/phone-default-unsigned.hap";
368     std::string keystoreFile = "./hapSign/ohtest.p12";
369     std::string outFile = "./hapSign/phone-default-signed.hap";
370     char keyPwd[] = "123456";
371     char keystorePwd[] = "123456";
372 
373     (*params)["mode"] = mode;
374     (*params)["keyAlias"] = keyAlias;
375     (*params)["signAlg"] = signAlg;
376     (*params)["signCode"] = signCode;
377     (*params)["appCertFile"] = appCertFile;
378     (*params)["profileFile"] = profileFile;
379     (*params)["inFile"] = inFile;
380     (*params)["keystoreFile"] = keystoreFile;
381     (*params)["outFile"] = outFile;
382     (*params)["keyPwd"] = keyPwd;
383     (*params)["keystorePwd"] = keystorePwd;
384     bool retParam = signProvider->CheckParams(params.get());
385     EXPECT_EQ(retParam, true);
386 
387     std::optional<X509_CRL*> crl = signProvider->GetCrl();
388     EXPECT_EQ(crl.has_value(), false);
389 
390     bool ret = signProvider->Sign(params.get());
391     EXPECT_EQ(ret, true);
392 }
393 
394 /*
395  * @tc.name: hap_sign_test_009
396  * @tc.desc: This function tests failure for interface Sign due to parameter profileSigned
397  * @tc.type: FUNC
398  * @tc.require:
399  */
HWTEST_F(HapSignTest, hap_sign_test_009, testing::ext::TestSize.Level1)400 HWTEST_F(HapSignTest, hap_sign_test_009, testing::ext::TestSize.Level1)
401 {
402     SIGNATURE_TOOLS_LOGI("hello world !!!");
403     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
404     std::shared_ptr<Options> params = std::make_shared<Options>();
405 
406     std::string mode = "localSign";
407     std::string keyAlias = "oh-app1-key-v1";
408     std::string signAlg = "SHA256withECDSA";
409     std::string signCode = "1";
410     std::string appCertFile = "./hapSign/app-release1.pem";
411     std::string profileFile = "./hapSign/signed-profile.p7b";
412     std::string profileSigned = "0";
413     std::string inFile = "./hapSign/phone-default-unsigned.hap";
414     std::string keystoreFile = "./hapSign/ohtest.p12";
415     std::string outFile = "./hapSign/phone-default-signed.hap";
416     char keyPwd[] = "123456";
417     char keystorePwd[] = "123456";
418 
419     (*params)["mode"] = mode;
420     (*params)["keyAlias"] = keyAlias;
421     (*params)["signAlg"] = signAlg;
422     (*params)["signCode"] = signCode;
423     (*params)["appCertFile"] = appCertFile;
424     (*params)["profileFile"] = profileFile;
425     (*params)["profileSigned"] = profileSigned;
426     (*params)["inFile"] = inFile;
427     (*params)["keystoreFile"] = keystoreFile;
428     (*params)["outFile"] = outFile;
429     (*params)["keyPwd"] = keyPwd;
430     (*params)["keystorePwd"] = keystorePwd;
431     bool retParam = signProvider->CheckParams(params.get());
432     EXPECT_EQ(retParam, true);
433 
434     std::optional<X509_CRL*> crl = signProvider->GetCrl();
435     EXPECT_EQ(crl.has_value(), false);
436 
437     bool ret = signProvider->Sign(params.get());
438     EXPECT_EQ(ret, false);
439 }
440 
441 /*
442  * @tc.name: hap_sign_test_010
443  * @tc.desc: This function tests sucess for interface Sign
444  * @tc.type: FUNC
445  * @tc.require:
446  */
HWTEST_F(HapSignTest, hap_sign_test_010, testing::ext::TestSize.Level1)447 HWTEST_F(HapSignTest, hap_sign_test_010, testing::ext::TestSize.Level1)
448 {
449     SIGNATURE_TOOLS_LOGI("hello world !!!");
450     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
451     std::shared_ptr<Options> params = std::make_shared<Options>();
452 
453     std::string mode = "localSign";
454     std::string keyAlias = "oh-app1-key-v1";
455     std::string signAlg = "SHA256withECDSA";
456     std::string signCode = "1";
457     std::string appCertFile = "./hapSign/app-release1.pem";
458     std::string profileFile = "./hapSign/signed-profile.p7b";
459     std::string profileSigned = "1";
460     std::string inFile = "./hapSign/phone-default-unsigned.hap";
461     std::string keystoreFile = "./hapSign/ohtest.p12";
462     std::string outFile = "./hapSign/phone-default-signed.hap";
463     char keyPwd[] = "123456";
464     char keystorePwd[] = "123456";
465 
466     (*params)["mode"] = mode;
467     (*params)["keyAlias"] = keyAlias;
468     (*params)["signAlg"] = signAlg;
469     (*params)["signCode"] = signCode;
470     (*params)["appCertFile"] = appCertFile;
471     (*params)["profileFile"] = profileFile;
472     (*params)["profileSigned"] = profileSigned;
473     (*params)["inFile"] = inFile;
474     (*params)["keystoreFile"] = keystoreFile;
475     (*params)["outFile"] = outFile;
476     (*params)["keyPwd"] = keyPwd;
477     (*params)["keystorePwd"] = keystorePwd;
478 
479     bool retParam = signProvider->CheckParams(params.get());
480     EXPECT_EQ(retParam, true);
481 
482     std::optional<X509_CRL*> crl = signProvider->GetCrl();
483     EXPECT_EQ(crl.has_value(), false);
484 
485     bool ret = signProvider->Sign(params.get());
486     EXPECT_EQ(ret, true);
487 }
488 
489 /*
490  * @tc.name: hap_sign_test_011
491  * @tc.desc: This function tests sucess for interface GetDigestOutputByteSize
492  * @tc.type: FUNC
493  * @tc.require:
494  */
HWTEST_F(HapSignTest, hap_sign_test_011, testing::ext::TestSize.Level1)495 HWTEST_F(HapSignTest, hap_sign_test_011, testing::ext::TestSize.Level1)
496 {
497     SIGNATURE_TOOLS_LOGI("hello world !!!");
498     ContentDigestAlgorithm alg_tmp;
499     ContentDigestAlgorithm alg_1 = ContentDigestAlgorithm::SHA256;
500     ContentDigestAlgorithm* alg_2 = &alg_1;
501     *alg_2 = alg_1;
502     alg_tmp = alg_1;
503     ContentDigestAlgorithm alg = ContentDigestAlgorithm::SHA256;
504     std::string algname = alg.GetDigestAlgorithm();
505     EXPECT_EQ(algname, std::string("SHA-256"));
506     int size = alg.GetDigestOutputByteSize();
507     EXPECT_EQ(size, 256 / 8);
508 
509     ContentDigestAlgorithm alg_384 = ContentDigestAlgorithm::SHA384;
510     std::string algname_384 = alg_384.GetDigestAlgorithm();
511     EXPECT_EQ(algname_384, std::string("SHA-384"));
512     int size384 = alg_384.GetDigestOutputByteSize();
513     EXPECT_EQ(size384, 384 / 8);
514 
515     ContentDigestAlgorithm alg_512 = ContentDigestAlgorithm::SHA512;
516     alg_512 = ContentDigestAlgorithm::SHA512;
517     std::string algname_512 = alg_512.GetDigestAlgorithm();
518     EXPECT_EQ(algname_512, std::string("SHA-512"));
519     int size512 = alg_512.GetDigestOutputByteSize();
520     EXPECT_EQ(size512, 512 / 8);
521 }
522 /*
523  * @tc.name: hap_sign_test_012
524  * @tc.desc: This function tests sucess for interface ComputeDigests
525  * @tc.type: FUNC
526  * @tc.require:
527  */
HWTEST_F(HapSignTest, hap_sign_test_012, testing::ext::TestSize.Level1)528 HWTEST_F(HapSignTest, hap_sign_test_012, testing::ext::TestSize.Level1)
529 {
530     SIGNATURE_TOOLS_LOGI("hello world !!!");
531     ByteBuffer bf1("123456789", 9);
532     ByteBuffer bf2("123456789", 9);
533     ByteBuffer bf3("123456789", 9);
534     ByteBuffer bf4("123456789", 9);
535     ByteBufferDataSource ds1(bf1);
536     ByteBufferDataSource ds2(bf2);
537     ByteBufferDataSource ds3(bf3);
538 
539     DataSource* contents[] = {&ds1, &ds2, &ds3};
540     int32_t len = 3;
541 
542     std::vector<OptionalBlock> optionalBlocks;
543     optionalBlocks.push_back({HapUtils::HAP_PROFILE_BLOCK_ID, bf4});
544     ByteBuffer dig_context;
545 
546     SignatureAlgorithm algo = SignatureAlgorithm::ALGORITHM_SHA256_WITH_ECDSA;
547     int32_t nId = DigestCommon::GetDigestAlgorithmId(algo);
548     DigestParameter digestParam = HapSignerBlockUtils::GetDigestParameter(nId);
549 
550     bool ret = SignHap::ComputeDigests(digestParam, contents, len, optionalBlocks, dig_context);
551     EXPECT_EQ(ret, true);
552 }
553 /*
554  * @tc.name: hap_sign_test_013
555  * @tc.desc: This function tests failure for interface Sign due to parameter appCertFile
556  * @tc.type: FUNC
557  * @tc.require:
558  */
HWTEST_F(HapSignTest, hap_sign_test_013, testing::ext::TestSize.Level1)559 HWTEST_F(HapSignTest, hap_sign_test_013, testing::ext::TestSize.Level1)
560 {
561     SIGNATURE_TOOLS_LOGI("hello world !!!");
562     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
563     std::shared_ptr<Options> params = std::make_shared<Options>();
564 
565     std::string mode = "localSign";
566     std::string keyAlias = "oh-app1-key-v1";
567     std::string signAlg = "SHA256withECDSA";
568     std::string signCode = "1";
569     std::string appCertFile = "./hapSign/app-release-nohave.pem";
570     std::string profileFile = "./hapSign/signed-profile.p7b";
571     std::string profileSigned = "1";
572     std::string keystoreFile = "./hapSign/ohtest.p12";
573     std::string outFile = "./hapSign/phone-default-signed.hap";
574     char keyPwd[] = "123456";
575     char keystorePwd[] = "123456";
576 
577     (*params)["mode"] = mode;
578     (*params)["keyAlias"] = keyAlias;
579     (*params)["signAlg"] = signAlg;
580     (*params)["signCode"] = signCode;
581     (*params)["appCertFile"] = appCertFile;
582     (*params)["profileFile"] = profileFile;
583     (*params)["profileSigned"] = profileSigned;
584     (*params)["keystoreFile"] = keystoreFile;
585     (*params)["outFile"] = outFile;
586     (*params)["keyPwd"] = keyPwd;
587     (*params)["keystorePwd"] = keystorePwd;
588 
589     std::optional<X509_CRL*> crl = signProvider->GetCrl();
590     EXPECT_EQ(crl.has_value(), false);
591 
592     bool ret = signProvider->Sign(params.get());
593     EXPECT_EQ(ret, false);
594 }
595 /*
596  * @tc.name: hap_sign_test_014
597  * @tc.desc: This function tests failure for interface Sign due to parameter inFile
598  * @tc.type: FUNC
599  * @tc.require:
600  */
HWTEST_F(HapSignTest, hap_sign_test_014, testing::ext::TestSize.Level1)601 HWTEST_F(HapSignTest, hap_sign_test_014, testing::ext::TestSize.Level1)
602 {
603     SIGNATURE_TOOLS_LOGI("hello world !!!");
604     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
605     std::shared_ptr<Options> params = std::make_shared<Options>();
606 
607     std::string mode = "localSign";
608     std::string keyAlias = "oh-app1-key-v1";
609     std::string signAlg = "SHA256withECDSA";
610     std::string signCode = "1";
611     std::string appCertFile = "./hapSign/app-release1.pem";
612     std::string profileFile = "./hapSign/signed-profile.p7b";
613     std::string profileSigned = "1";
614     std::string inFile = "./hapSign/nohave.hap";
615     std::string keystoreFile = "./hapSign/ohtest.p12";
616     std::string outFile = "./hapSign/phone-default-signed.hap";
617     char keyPwd[] = "123456";
618     char keystorePwd[] = "123456";
619 
620     (*params)["mode"] = mode;
621     (*params)["keyAlias"] = keyAlias;
622     (*params)["signAlg"] = signAlg;
623     (*params)["signCode"] = signCode;
624     (*params)["appCertFile"] = appCertFile;
625     (*params)["profileFile"] = profileFile;
626     (*params)["profileSigned"] = profileSigned;
627     (*params)["inFile"] = inFile;
628     (*params)["keystoreFile"] = keystoreFile;
629     (*params)["outFile"] = outFile;
630     (*params)["keyPwd"] = keyPwd;
631     (*params)["keystorePwd"] = keystorePwd;
632 
633     bool retParam = signProvider->CheckParams(params.get());
634     EXPECT_EQ(retParam, true);
635 
636     std::optional<X509_CRL*> crl = signProvider->GetCrl();
637     EXPECT_EQ(crl.has_value(), false);
638 
639     bool ret = signProvider->Sign(params.get());
640     EXPECT_EQ(ret, false);
641 }
642 
643 /*
644  * @tc.name: hap_sign_test_015
645  * @tc.desc: This function tests failure for interface Sign due to parameter appCertFile
646  * @tc.type: FUNC
647  * @tc.require:
648  */
HWTEST_F(HapSignTest, hap_sign_test_015, testing::ext::TestSize.Level1)649 HWTEST_F(HapSignTest, hap_sign_test_015, testing::ext::TestSize.Level1)
650 {
651     SIGNATURE_TOOLS_LOGI("hello world !!!");
652     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
653     std::shared_ptr<Options> params = std::make_shared<Options>();
654 
655     std::string mode = "localSign";
656     std::string keyAlias = "oh-app1-key-v1";
657     std::string signAlg = "SHA256withECDSA";
658     std::string signCode = "1";
659     std::string appCertFile = "./hapSign/app-release-.pem";
660     std::string profileFile = "./hapSign/signed-profile.p7b";
661     std::string profileSigned = "1";
662     std::string inFile = "./hapSign/phone-default-unsigned.hap";
663     std::string keystoreFile = "./hapSign/ohtest.p12";
664     std::string outFile = "./hapSign/phone-default-signed.hap";
665     char keyPwd[] = "123456";
666     char keystorePwd[] = "123456";
667 
668     (*params)["mode"] = mode;
669     (*params)["keyAlias"] = keyAlias;
670     (*params)["signAlg"] = signAlg;
671     (*params)["signCode"] = signCode;
672     (*params)["appCertFile"] = appCertFile;
673     (*params)["profileFile"] = profileFile;
674     (*params)["profileSigned"] = profileSigned;
675     (*params)["inFile"] = inFile;
676     (*params)["keystoreFile"] = keystoreFile;
677     (*params)["outFile"] = outFile;
678     (*params)["keyPwd"] = keyPwd;
679     (*params)["keystorePwd"] = keystorePwd;
680 
681     signProvider->CheckParams(params.get());
682 
683     signProvider->GetCrl();
684 
685     bool ret = signProvider->Sign(params.get());
686     EXPECT_EQ(ret, false);
687 }
688 
689 /*
690  * @tc.name: hap_sign_test_016
691  * @tc.desc: This function tests failure for interface Sign due to parameter outFile
692  * @tc.type: FUNC
693  * @tc.require:
694  */
HWTEST_F(HapSignTest, hap_sign_test_016, testing::ext::TestSize.Level1)695 HWTEST_F(HapSignTest, hap_sign_test_016, testing::ext::TestSize.Level1)
696 {
697     SIGNATURE_TOOLS_LOGI("hello world !!!");
698     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
699     std::shared_ptr<Options> params = std::make_shared<Options>();
700 
701     std::string mode = "localSign";
702     std::string keyAlias = "oh-app1-key-v1";
703     std::string signAlg = "SHA256withECDSA";
704     std::string signCode = "1";
705     std::string appCertFile = "./hapSign/app-release1.pem";
706     std::string profileFile = "./hapSign/signed-profile.p7b";
707     std::string profileSigned = "1";
708     std::string inFile = "./hapSign/phone-default-unsigned.hap";
709     std::string keystoreFile = "./hapSign/ohtest.p12";
710     std::string outFile = "/d/phone-default-signed.hap";
711     char keyPwd[] = "123456";
712     char keystorePwd[] = "123456";
713 
714     (*params)["mode"] = mode;
715     (*params)["keyAlias"] = keyAlias;
716     (*params)["signAlg"] = signAlg;
717     (*params)["signCode"] = signCode;
718     (*params)["appCertFile"] = appCertFile;
719     (*params)["profileFile"] = profileFile;
720     (*params)["profileSigned"] = profileSigned;
721     (*params)["inFile"] = inFile;
722     (*params)["keystoreFile"] = keystoreFile;
723     (*params)["outFile"] = outFile;
724     (*params)["keyPwd"] = keyPwd;
725     (*params)["keystorePwd"] = keystorePwd;
726 
727     bool retParam = signProvider->CheckParams(params.get());
728     EXPECT_EQ(retParam, true);
729 
730     std::optional<X509_CRL*> crl = signProvider->GetCrl();
731     EXPECT_EQ(crl.has_value(), false);
732 
733     bool ret = signProvider->Sign(params.get());
734     EXPECT_EQ(ret, false);
735 }
736 
737 /*
738  * @tc.name: hap_sign_test_017
739  * @tc.desc: This function tests failure for interface Sign due to parameter outFile
740  * @tc.type: FUNC
741  * @tc.require:
742  */
HWTEST_F(HapSignTest, hap_sign_test_017, testing::ext::TestSize.Level1)743 HWTEST_F(HapSignTest, hap_sign_test_017, testing::ext::TestSize.Level1)
744 {
745     SIGNATURE_TOOLS_LOGI("hello world !!!");
746     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
747     std::shared_ptr<Options> params = std::make_shared<Options>();
748 
749     std::string mode = "localSign";
750     std::string keyAlias = "oh-app1-key-v1";
751     std::string signAlg = "SHA256withECDSA";
752     std::string signCode = "1";
753     std::string appCertFile = "./hapSign/app-release1.pem";
754     std::string profileFile = "./hapSign/signed-profile.p7b";
755     std::string profileSigned = "1";
756     std::string inFile = "./hapSign/phone-default-unsigned.hap";
757     std::string keystoreFile = "./hapSign/ohtest.p12";
758     std::string outFile = "./hapSign/phone-default-unsigned.hap";
759     char keyPwd[] = "123456";
760     char keystorePwd[] = "123456";
761 
762     (*params)["mode"] = mode;
763     (*params)["keyAlias"] = keyAlias;
764     (*params)["signAlg"] = signAlg;
765     (*params)["signCode"] = signCode;
766     (*params)["appCertFile"] = appCertFile;
767     (*params)["profileFile"] = profileFile;
768     (*params)["profileSigned"] = profileSigned;
769     (*params)["inFile"] = inFile;
770     (*params)["keystoreFile"] = keystoreFile;
771     (*params)["outFile"] = outFile;
772     (*params)["keyPwd"] = keyPwd;
773     (*params)["keystorePwd"] = keystorePwd;
774 
775     bool retParam = signProvider->CheckParams(params.get());
776     EXPECT_EQ(retParam, true);
777 
778     std::optional<X509_CRL*> crl = signProvider->GetCrl();
779     EXPECT_EQ(crl.has_value(), false);
780 
781     bool ret = signProvider->Sign(params.get());
782     EXPECT_EQ(ret, true);
783 }
784 
785 /*
786  * @tc.name: hap_sign_test_018
787  * @tc.desc: This function tests failure for interface Sign due to parameter signAlg
788  * @tc.type: FUNC
789  * @tc.require:
790  */
HWTEST_F(HapSignTest, hap_sign_test_018, testing::ext::TestSize.Level1)791 HWTEST_F(HapSignTest, hap_sign_test_018, testing::ext::TestSize.Level1)
792 {
793     SIGNATURE_TOOLS_LOGI("hello world !!!");
794     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
795     std::shared_ptr<Options> params = std::make_shared<Options>();
796 
797     std::string mode = "localSign";
798     std::string keyAlias = "oh-app1-key-v1";
799     std::string signAlg = "SHA256withEA";
800     std::string signCode = "1";
801     std::string appCertFile = "./hapSign/app-release1.pem";
802     std::string profileFile = "./hapSign/signed-profile.p7b";
803     std::string profileSigned = "1";
804     std::string inFile = "./hapSign/phone-default-unsigned.hap";
805     std::string keystoreFile = "./hapSign/ohtest.p12";
806     std::string outFile = "./hapSign/phone-default-signed.hap";
807     char keyPwd[] = "123456";
808     char keystorePwd[] = "123456";
809 
810     (*params)["mode"] = mode;
811     (*params)["keyAlias"] = keyAlias;
812     (*params)["signAlg"] = signAlg;
813     (*params)["signCode"] = signCode;
814     (*params)["appCertFile"] = appCertFile;
815     (*params)["profileFile"] = profileFile;
816     (*params)["profileSigned"] = profileSigned;
817     (*params)["inFile"] = inFile;
818     (*params)["keystoreFile"] = keystoreFile;
819     (*params)["outFile"] = outFile;
820     (*params)["keyPwd"] = keyPwd;
821     (*params)["keystorePwd"] = keystorePwd;
822 
823     std::optional<X509_CRL*> crl = signProvider->GetCrl();
824     EXPECT_EQ(crl.has_value(), false);
825 
826     bool ret = signProvider->Sign(params.get());
827     EXPECT_EQ(ret, false);
828 }
829 
830 /*
831  * @tc.name: hap_sign_test_019
832  * @tc.desc: This function tests failure for interface Sign due to parameter inFile
833  * @tc.type: FUNC
834  * @tc.require:
835  */
HWTEST_F(HapSignTest, hap_sign_test_019, testing::ext::TestSize.Level1)836 HWTEST_F(HapSignTest, hap_sign_test_019, testing::ext::TestSize.Level1)
837 {
838     SIGNATURE_TOOLS_LOGI("hello world !!!");
839     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
840     std::shared_ptr<Options> params = std::make_shared<Options>();
841 
842     std::string mode = "localSign";
843     std::string keyAlias = "oh-app1-key-v1";
844     std::string signAlg = "SHA256withECDSA";
845     std::string signCode = "0";
846     std::string appCertFile = "./hapSign/app-release1.pem";
847     std::string profileFile = "./hapSign/signed-profile.p7b";
848     std::string inFile = "./hapSign/phone-default-unsigned";
849     std::string keystoreFile = "./hapSign/ohtest.p12";
850     std::string outFile = "./hapSign/phone-default-signed.hap";
851     char keyPwd[] = "123456";
852     char keystorePwd[] = "123456";
853 
854     (*params)["mode"] = mode;
855     (*params)["keyAlias"] = keyAlias;
856     (*params)["signAlg"] = signAlg;
857     (*params)["signCode"] = signCode;
858     (*params)["appCertFile"] = appCertFile;
859     (*params)["profileFile"] = profileFile;
860     (*params)["inFile"] = inFile;
861     (*params)["keystoreFile"] = keystoreFile;
862     (*params)["outFile"] = outFile;
863     (*params)["keyPwd"] = keyPwd;
864     (*params)["keystorePwd"] = keystorePwd;
865 
866     bool ret = signProvider->Sign(params.get());
867     EXPECT_EQ(ret, false);
868 }
869 
870 /*
871  * @tc.name: hap_sign_test_020
872  * @tc.desc: This function tests failure for interface Sign due to parameter inFile
873  * @tc.type: FUNC
874  * @tc.require:
875  */
HWTEST_F(HapSignTest, hap_sign_test_020, testing::ext::TestSize.Level1)876 HWTEST_F(HapSignTest, hap_sign_test_020, testing::ext::TestSize.Level1)
877 {
878     SIGNATURE_TOOLS_LOGI("hello world !!!");
879     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
880     std::shared_ptr<Options> params = std::make_shared<Options>();
881 
882     std::string mode = "localSign";
883     std::string keyAlias = "oh-app1-key-v1";
884     std::string signAlg = "SHA256withECDSA";
885     std::string signCode = "0";
886     std::string appCertFile = "./hapSign/app-release1.pem";
887     std::string profileFile = "./hapSign/signed-profile.p7b";
888     std::string inFile = "./hapSign/phone-default-unsigned";
889     std::string keystoreFile = "./hapSign/ohtest.p12";
890     std::string outFile = "./hapSign/phone-default-signed.hap";
891     char keyPwd[] = "123456";
892     char keystorePwd[] = "123456";
893 
894     (*params)["mode"] = mode;
895     (*params)["keyAlias"] = keyAlias;
896     (*params)["signAlg"] = signAlg;
897     (*params)["signCode"] = signCode;
898     (*params)["appCertFile"] = appCertFile;
899     (*params)["profileFile"] = profileFile;
900     (*params)["inFile"] = inFile;
901     (*params)["keystoreFile"] = keystoreFile;
902     (*params)["outFile"] = outFile;
903     (*params)["keyPwd"] = keyPwd;
904     (*params)["keystorePwd"] = keystorePwd;
905 
906     bool ret = signProvider->Sign(params.get());
907     EXPECT_EQ(ret, false);
908 }
909 
910 /*
911  * @tc.name: hap_sign_test_021
912  * @tc.desc: This function tests failure for interface Sign due to parameter inFile
913  * @tc.type: FUNC
914  * @tc.require:
915  */
HWTEST_F(HapSignTest, hap_sign_test_021, testing::ext::TestSize.Level1)916 HWTEST_F(HapSignTest, hap_sign_test_021, testing::ext::TestSize.Level1)
917 {
918     SIGNATURE_TOOLS_LOGI("hello world !!!");
919     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
920     std::shared_ptr<Options> params = std::make_shared<Options>();
921 
922     std::string mode = "localSign";
923     std::string keyAlias = "oh-app1-key-v1";
924     std::string signAlg = "SHA256withECDSA";
925     std::string signCode = "0";
926     std::string appCertFile = "./hapSign/app-release1.pem";
927     std::string profileFile = "./hapSign/signed-profile.p7b";
928     std::string inFile = "./hapSign/nohap.hap";
929     std::string keystoreFile = "./hapSign/ohtest.p12";
930     std::string outFile = "./hapSign/phone-default-signed.hap";
931     char keyPwd[] = "123456";
932     char keystorePwd[] = "123456";
933 
934     (*params)["mode"] = mode;
935     (*params)["keyAlias"] = keyAlias;
936     (*params)["signAlg"] = signAlg;
937     (*params)["signCode"] = signCode;
938     (*params)["appCertFile"] = appCertFile;
939     (*params)["profileFile"] = profileFile;
940     (*params)["inFile"] = inFile;
941     (*params)["keystoreFile"] = keystoreFile;
942     (*params)["outFile"] = outFile;
943     (*params)["keyPwd"] = keyPwd;
944     (*params)["keystorePwd"] = keystorePwd;
945 
946     bool ret = signProvider->Sign(params.get());
947     EXPECT_EQ(ret, false);
948 }
949 
950 /*
951  * @tc.name: hap_sign_test_022
952  * @tc.desc: This function tests failure for interface Sign due to parameter inFile
953  * @tc.type: FUNC
954  * @tc.require:
955  */
HWTEST_F(HapSignTest, hap_sign_test_022, testing::ext::TestSize.Level1)956 HWTEST_F(HapSignTest, hap_sign_test_022, testing::ext::TestSize.Level1)
957 {
958     SIGNATURE_TOOLS_LOGI("hello world !!!");
959     std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
960     std::shared_ptr<Options> params = std::make_shared<Options>();
961 
962     std::string mode = "localSign";
963     std::string keyAlias = "oh-app1-key-v1";
964     std::string signAlg = "SHA256withECDSA";
965     std::string signCode = "0";
966     std::string appCertFile = "./hapSign/app-release1.pem";
967     std::string profileFile = "./hapSign/signed-profile.p7b";
968     std::string inFile = "./hapSign/unsigned_with_eocd.hap";
969     std::string keystoreFile = "./hapSign/ohtest.p12";
970     std::string outFile = "./hapSign/phone-default-signed.hap";
971     char keyPwd[] = "123456";
972     char keystorePwd[] = "123456";
973 
974     (*params)["mode"] = mode;
975     (*params)["keyAlias"] = keyAlias;
976     (*params)["signAlg"] = signAlg;
977     (*params)["signCode"] = signCode;
978     (*params)["appCertFile"] = appCertFile;
979     (*params)["profileFile"] = profileFile;
980     (*params)["inFile"] = inFile;
981     (*params)["keystoreFile"] = keystoreFile;
982     (*params)["outFile"] = outFile;
983     (*params)["keyPwd"] = keyPwd;
984     (*params)["keystorePwd"] = keystorePwd;
985 
986     bool ret = signProvider->Sign(params.get());
987     EXPECT_EQ(ret, false);
988 }
989 
990 /*
991  * @tc.name: hap_sign_test_023
992  * @tc.desc: This function tests failure for interface SignHap due to parameter mode not support
993  * @tc.type: FUNC
994  * @tc.require:
995  */
HWTEST_F(HapSignTest, hap_sign_test_023, testing::ext::TestSize.Level1)996 HWTEST_F(HapSignTest, hap_sign_test_023, testing::ext::TestSize.Level1)
997 {
998     SIGNATURE_TOOLS_LOGI("hello world !!!");
999     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
1000     std::shared_ptr<Options> params = std::make_shared<Options>();
1001 
1002     std::string mode = "remoteSign";
1003     std::string keyAlias = "oh-app1-key-v1";
1004     std::string signAlg = "SHA256withECDSA";
1005     std::string signCode = "0";
1006     std::string appCertFile = "./hapSign/app-release1.pem";
1007     std::string profileFile = "./hapSign/signed-profile.p7b";
1008     std::string inFile = "./hapSign/phone-default-unsigned.hap";
1009     std::string keystoreFile = "./hapSign/ohtest.p12";
1010     std::string outFile = "./hapSign/phone-default-signed.hap";
1011     char keyPwd[] = "123456";
1012     char keystorePwd[] = "123456";
1013 
1014     (*params)["mode"] = mode;
1015     (*params)["keyAlias"] = keyAlias;
1016     (*params)["signAlg"] = signAlg;
1017     (*params)["signCode"] = signCode;
1018     (*params)["appCertFile"] = appCertFile;
1019     (*params)["profileFile"] = profileFile;
1020     (*params)["inFile"] = inFile;
1021     (*params)["keystoreFile"] = keystoreFile;
1022     (*params)["outFile"] = outFile;
1023     (*params)["keyPwd"] = keyPwd;
1024     (*params)["keystorePwd"] = keystorePwd;
1025 
1026     bool ret = api->SignHap(params.get());
1027     EXPECT_EQ(ret, false);
1028 }
1029 
1030 /*
1031  * @tc.name: hap_sign_test_024
1032  * @tc.desc: This function tests failure for interface SignHap due to parameter mode not support
1033  * @tc.type: FUNC
1034  * @tc.require:
1035  */
HWTEST_F(HapSignTest, hap_sign_test_024, testing::ext::TestSize.Level1)1036 HWTEST_F(HapSignTest, hap_sign_test_024, testing::ext::TestSize.Level1)
1037 {
1038     SIGNATURE_TOOLS_LOGI("hello world !!!");
1039     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
1040     std::shared_ptr<Options> params = std::make_shared<Options>();
1041 
1042     std::string mode = "remoteResign";
1043     std::string keyAlias = "oh-app1-key-v1";
1044     std::string signAlg = "SHA256withECDSA";
1045     std::string signCode = "0";
1046     std::string appCertFile = "./hapSign/app-release1.pem";
1047     std::string profileFile = "./hapSign/signed-profile.p7b";
1048     std::string inFile = "./hapSign/phone-default-unsigned.hap";
1049     std::string keystoreFile = "./hapSign/ohtest.p12";
1050     std::string outFile = "./hapSign/phone-default-signed.hap";
1051     char keyPwd[] = "123456";
1052     char keystorePwd[] = "123456";
1053 
1054     (*params)["mode"] = mode;
1055     (*params)["keyAlias"] = keyAlias;
1056     (*params)["signAlg"] = signAlg;
1057     (*params)["signCode"] = signCode;
1058     (*params)["appCertFile"] = appCertFile;
1059     (*params)["profileFile"] = profileFile;
1060     (*params)["inFile"] = inFile;
1061     (*params)["keystoreFile"] = keystoreFile;
1062     (*params)["outFile"] = outFile;
1063     (*params)["keyPwd"] = keyPwd;
1064     (*params)["keystorePwd"] = keystorePwd;
1065 
1066     bool ret = api->SignHap(params.get());
1067     EXPECT_EQ(ret, false);
1068 }
1069 
1070 /*
1071  * @tc.name: hap_sign_test_025
1072  * @tc.desc: This function tests success for interface SignHap
1073  * @tc.type: FUNC
1074  * @tc.require:
1075  */
HWTEST_F(HapSignTest, hap_sign_test_025, testing::ext::TestSize.Level1)1076 HWTEST_F(HapSignTest, hap_sign_test_025, testing::ext::TestSize.Level1)
1077 {
1078     SIGNATURE_TOOLS_LOGI("hello world !!!");
1079     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
1080     std::shared_ptr<Options> params = std::make_shared<Options>();
1081 
1082     std::string mode = "localSign";
1083     std::string keyAlias = "oh-app1-key-v1";
1084     std::string signAlg = "SHA256withECDSA";
1085     std::string signCode = "0";
1086     std::string appCertFile = "./hapSign/app-release1.pem";
1087     std::string profileFile = "./hapSign/signed-profile.p7b";
1088     std::string inFile = "./hapSign/phone-default-unsigned";
1089     std::string keystoreFile = "./hapSign/ohtest.p12";
1090     std::string outFile = "./hapSign/phone-default-signed.hap";
1091     char keyPwd[] = "123456";
1092     char keystorePwd[] = "123456";
1093 
1094     (*params)["mode"] = mode;
1095     (*params)["keyAlias"] = keyAlias;
1096     (*params)["signAlg"] = signAlg;
1097     (*params)["signCode"] = signCode;
1098     (*params)["appCertFile"] = appCertFile;
1099     (*params)["profileFile"] = profileFile;
1100     (*params)["inFile"] = inFile;
1101     (*params)["keystoreFile"] = keystoreFile;
1102     (*params)["outFile"] = outFile;
1103     (*params)["keyPwd"] = keyPwd;
1104     (*params)["keystorePwd"] = keystorePwd;
1105 
1106     bool ret = api->SignHap(params.get());
1107     EXPECT_EQ(ret, true);
1108 }
1109 
1110 /*
1111  * @tc.name: hap_sign_test_026
1112  * @tc.desc: This function tests success and failure for interface Sign & ComputeDigests
1113  * @tc.type: FUNC
1114  * @tc.require:
1115  */
HWTEST_F(HapSignTest, hap_sign_test_026, testing::ext::TestSize.Level1)1116 HWTEST_F(HapSignTest, hap_sign_test_026, testing::ext::TestSize.Level1)
1117 {
1118     SIGNATURE_TOOLS_LOGI("hello world !!!");
1119     ByteBuffer bf1("123456789", 9);
1120     ByteBuffer bf2("123456789", 9);
1121     ByteBuffer bf3("123456789", 9);
1122     ByteBuffer bf4("123456789", 9);
1123     ByteBufferDataSource ds1(bf1);
1124     ByteBufferDataSource ds2(bf2);
1125     ByteBufferDataSource ds3(bf3);
1126 
1127     DataSource* contents[] = {&ds1, &ds2, &ds3};
1128     DataSource* contents_t[] = {nullptr, nullptr, nullptr};
1129     int32_t len = 3;
1130 
1131     std::vector<OptionalBlock> optionalBlocks;
1132     std::vector<OptionalBlock> optionalBlockSTest;
1133     optionalBlocks.push_back({HapUtils::HAP_PROFILE_BLOCK_ID, bf4});
1134     ByteBuffer dig_context;
1135 
1136     SignatureAlgorithm algo = SignatureAlgorithm::ALGORITHM_SHA256_WITH_ECDSA;
1137     int32_t nId = DigestCommon::GetDigestAlgorithmId(algo);
1138     DigestParameter digestParam = HapSignerBlockUtils::GetDigestParameter(nId);
1139 
1140     SignerConfig config;
1141     ByteBuffer result;
1142     ByteBuffer result1;
1143     bool ret1 = SignHap::Sign(contents, 2, config, optionalBlocks, result);
1144     EXPECT_EQ(ret1, false);
1145 
1146     ret1 = SignHap::Sign(contents_t, 3, config, optionalBlocks, result1);
1147     EXPECT_EQ(ret1, false);
1148 
1149     std::vector<SignatureAlgorithmHelper> sig{SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE};
1150     config.SetSignatureAlgorithms(sig);
1151     ret1 = SignHap::Sign(contents_t, 3, config, optionalBlocks, result1);
1152     EXPECT_EQ(ret1, false);
1153     bool ret = SignHap::ComputeDigests(digestParam, contents, len, optionalBlockSTest, dig_context);
1154     ret = SignHap::ComputeDigests(digestParam, contents_t, len, optionalBlocks, dig_context);
1155     EXPECT_EQ(ret, false);
1156 }
1157 
1158 /*
1159  * @tc.name: hap_sign_test_027
1160  * @tc.desc: This function tests failure for interface SignHap due to parameter inFile not exist
1161  * @tc.type: FUNC
1162  * @tc.require:
1163  */
HWTEST_F(HapSignTest, hap_sign_test_027, testing::ext::TestSize.Level1)1164 HWTEST_F(HapSignTest, hap_sign_test_027, testing::ext::TestSize.Level1)
1165 {
1166     SIGNATURE_TOOLS_LOGI("hello world !!!");
1167     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
1168     std::shared_ptr<Options> params = std::make_shared<Options>();
1169 
1170     std::string mode = "localSign";
1171     std::string keyAlias = "oh-app1-key-v1";
1172     std::string signAlg = "SHA256withECDSA";
1173     std::string signCode = "0";
1174     std::string appCertFile = "./hapSign/app-release1.pem";
1175     std::string profileFile = "./hapSign/signed-profile.p7b";
1176     std::string inFile = "./hapSign/phone-default.hap";
1177     std::string keystoreFile = "./hapSign/ohtest.p12";
1178     std::string outFile = "./hapSign/phone-default-signed.hap";
1179     char keyPwd[] = "123456";
1180     char keystorePwd[] = "123456";
1181 
1182     (*params)["mode"] = mode;
1183     (*params)["keyAlias"] = keyAlias;
1184     (*params)["signAlg"] = signAlg;
1185     (*params)["signCode"] = signCode;
1186     (*params)["appCertFile"] = appCertFile;
1187     (*params)["profileFile"] = profileFile;
1188     (*params)["inFile"] = inFile;
1189     (*params)["keystoreFile"] = keystoreFile;
1190     (*params)["outFile"] = outFile;
1191     (*params)["keyPwd"] = keyPwd;
1192     (*params)["keystorePwd"] = keystorePwd;
1193 
1194     bool ret = api->SignHap(params.get());
1195     EXPECT_EQ(ret, false);
1196 }
1197 
1198 /*
1199  * @tc.name: hap_sign_test_028
1200  * @tc.desc: This function tests failure for interface SignHap due to parameter inFile damage
1201  * @tc.type: FUNC
1202  * @tc.require:
1203  */
HWTEST_F(HapSignTest, hap_sign_test_028, testing::ext::TestSize.Level1)1204 HWTEST_F(HapSignTest, hap_sign_test_028, testing::ext::TestSize.Level1)
1205 {
1206     SIGNATURE_TOOLS_LOGI("hello world !!!");
1207     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
1208     std::shared_ptr<Options> params = std::make_shared<Options>();
1209 
1210     std::string mode = "localSign";
1211     std::string keyAlias = "oh-app1-key-v1";
1212     std::string signAlg = "SHA256withECDSA";
1213     std::string signCode = "0";
1214     std::string appCertFile = "./hapSign/app-release1.pem";
1215     std::string profileFile = "./hapSign/signed-profile.p7b";
1216     std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap";
1217     std::string keystoreFile = "./hapSign/ohtest.p12";
1218     std::string outFile = "./hapSign/phone-default-signed.hap";
1219     char keyPwd[] = "123456";
1220     char keystorePwd[] = "123456";
1221 
1222     (*params)["mode"] = mode;
1223     (*params)["keyAlias"] = keyAlias;
1224     (*params)["signAlg"] = signAlg;
1225     (*params)["signCode"] = signCode;
1226     (*params)["appCertFile"] = appCertFile;
1227     (*params)["profileFile"] = profileFile;
1228     (*params)["inFile"] = inFile;
1229     (*params)["keystoreFile"] = keystoreFile;
1230     (*params)["outFile"] = outFile;
1231     (*params)["keyPwd"] = keyPwd;
1232     (*params)["keystorePwd"] = keystorePwd;
1233 
1234     bool ret = api->SignHap(params.get());
1235     EXPECT_EQ(ret, true);
1236 }
1237 
1238 /*
1239  * @tc.name: hap_sign_test_029
1240  * @tc.desc: This function tests failure for interface SignHap due to parameter signAlg not suport
1241  * @tc.type: FUNC
1242  * @tc.require:
1243  */
HWTEST_F(HapSignTest, hap_sign_test_029, testing::ext::TestSize.Level1)1244 HWTEST_F(HapSignTest, hap_sign_test_029, testing::ext::TestSize.Level1)
1245 {
1246     SIGNATURE_TOOLS_LOGI("hello world !!!");
1247     std::unique_ptr<SignToolServiceImpl> api = std::make_unique<SignToolServiceImpl>();
1248     std::shared_ptr<Options> params = std::make_shared<Options>();
1249 
1250     std::string mode = "localSign";
1251     std::string keyAlias = "oh-app1-key-v1";
1252     std::string signAlg = "SHA256w";
1253     std::string signCode = "0";
1254     std::string appCertFile = "./hapSign/app-release1.pem";
1255     std::string profileFile = "./hapSign/signed-profile.p7b";
1256     std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap";
1257     std::string keystoreFile = "./hapSign/ohtest.p12";
1258     std::string outFile = "./hapSign/phone-default-signed.hap";
1259     char keyPwd[] = "123456";
1260     char keystorePwd[] = "123456";
1261 
1262     (*params)["mode"] = mode;
1263     (*params)["keyAlias"] = keyAlias;
1264     (*params)["signAlg"] = signAlg;
1265     (*params)["signCode"] = signCode;
1266     (*params)["appCertFile"] = appCertFile;
1267     (*params)["profileFile"] = profileFile;
1268     (*params)["inFile"] = inFile;
1269     (*params)["keystoreFile"] = keystoreFile;
1270     (*params)["outFile"] = outFile;
1271     (*params)["keyPwd"] = keyPwd;
1272     (*params)["keystorePwd"] = keystorePwd;
1273 
1274     bool ret = api->SignHap(params.get());
1275     EXPECT_EQ(ret, false);
1276 }
1277 
1278 /**
1279  * @tc.name: get_options_test_001
1280  * @tc.desc: This function tests success for interface SetOptions
1281  * @tc.type: FUNC
1282  * @tc.require: SR000H63TL
1283  */
HWTEST_F(HapSignTest, get_options_test_001, testing::ext::TestSize.Level1)1284 HWTEST_F(HapSignTest, get_options_test_001, testing::ext::TestSize.Level1)
1285 {
1286     std::shared_ptr<Options> params = std::make_shared<Options>();
1287     std::string keyAlias = "oh-app1-key-v1";
1288     (*params)["keyAlias"] = keyAlias;
1289     SignerConfig signerConfig;
1290     signerConfig.SetOptions(params.get());
1291     EXPECT_EQ(params.get(), signerConfig.GetOptions());
1292 }
1293 
1294 /**
1295  * @tc.name: get_certificates_test_001
1296  * @tc.desc: Test function of GetCertificates()  interface for SUCCESS.
1297  * @tc.type: FUNC
1298  * @tc.require: SR000H63TL
1299  */
HWTEST_F(HapSignTest, get_certificates_test_001, testing::ext::TestSize.Level1)1300 HWTEST_F(HapSignTest, get_certificates_test_001, testing::ext::TestSize.Level1)
1301 {
1302     X509* newCert = X509_new();
1303     EXPECT_TRUE(X509_set_version(newCert, 2));
1304     SignerConfig signerConfig;
1305     signerConfig.SetX509CRLs(nullptr);
1306     signerConfig.GetX509CRLs();
1307     signerConfig.SetCertificates(nullptr);
1308     signerConfig.GetCertificates();
1309     signerConfig.GetSignParamMap();
1310     STACK_OF(X509) *certs = sk_X509_new_null();
1311     sk_X509_push(certs, newCert);
1312     signerConfig.SetCertificates(certs);
1313 
1314     EXPECT_NE(signerConfig.GetCertificates(), nullptr);
1315 }
1316 
1317 /**
1318  * @tc.name: get_X509_CRLs_test_001
1319  * @tc.desc: Test function of GetX509CRLs()  interface for SUCCESS.
1320  * @tc.type: FUNC
1321  * @tc.require: SR000H63TL
1322  */
HWTEST_F(HapSignTest, get_X509_CRLs_test_001, testing::ext::TestSize.Level1)1323 HWTEST_F(HapSignTest, get_X509_CRLs_test_001, testing::ext::TestSize.Level1)
1324 {
1325     STACK_OF(X509_CRL)* x509CRLs = nullptr;
1326     SignerConfig signerConfig;
1327     signerConfig.SetX509CRLs(x509CRLs);
1328     EXPECT_EQ(x509CRLs, signerConfig.GetX509CRLs());
1329 }
1330 
1331 /**
1332  * @tc.name: get_X509_CRLs_test_002
1333  * @tc.desc: This function tests failure for interface GetX509CRLs
1334  * @tc.type: FUNC
1335  * @tc.require: SR000H63TL
1336  */
HWTEST_F(HapSignTest, get_X509_CRLs_test_002, testing::ext::TestSize.Level1)1337 HWTEST_F(HapSignTest, get_X509_CRLs_test_002, testing::ext::TestSize.Level1)
1338 {
1339     STACK_OF(X509_CRL)* x509CRLs = nullptr;
1340     std::shared_ptr<Options> params = std::make_shared<Options>();
1341 
1342     std::string mode = "localSign";
1343     std::string keyAlias = "oh-app1-key-v1";
1344     std::string signAlg = "SHA256w";
1345     std::string signCode = "0";
1346     std::string appCertFile = "./hapSign/app-release1.pem";
1347     std::string profileFile = "./hapSign/signed-profile.p7b";
1348     std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap";
1349     std::string keystoreFile = "./hapSign/ohtest.p12";
1350     std::string outFile = "./hapSign/phone-default-signed.hap";
1351     char keyPwd[] = "123456";
1352     char keystorePwd[] = "123456";
1353 
1354     (*params)["mode"] = mode;
1355     (*params)["keyAlias"] = keyAlias;
1356     (*params)["signAlg"] = signAlg;
1357     (*params)["signCode"] = signCode;
1358     (*params)["appCertFile"] = appCertFile;
1359     (*params)["profileFile"] = profileFile;
1360     (*params)["inFile"] = inFile;
1361     (*params)["keystoreFile"] = keystoreFile;
1362     (*params)["outFile"] = outFile;
1363     (*params)["keyPwd"] = keyPwd;
1364     (*params)["keystorePwd"] = keystorePwd;
1365 
1366     SignerConfig signerConfig;
1367     signerConfig.SetOptions(params.get());
1368 
1369     signerConfig.GetX509CRLs();
1370     STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null();
1371     signerConfig.SetX509CRLs(crls);
1372     signerConfig.GetX509CRLs();
1373 
1374     signerConfig.SetCertificates(nullptr);
1375     signerConfig.SetX509CRLs(x509CRLs);
1376     signerConfig.GetX509CRLs();
1377 
1378     X509* newCert = X509_new();
1379     X509_set_version(newCert, 2);
1380     signerConfig.SetCertificates((STACK_OF(X509)*)newCert);
1381     signerConfig.GetX509CRLs();
1382 
1383     signerConfig.GetSigner();
1384     signerConfig.SetX509CRLs(x509CRLs);
1385     signerConfig.SetCertificates(nullptr);
1386     signerConfig.GetCertificates();
1387     EXPECT_EQ(false, (signerConfig.GetX509CRLs() != nullptr));
1388 }
1389 
1390 /**
1391  * @tc.name: get_compatible_version_test_001
1392  * @tc.desc: Test function of GetCompatibleVersion()  interface for SUCCESS.
1393  * @tc.type: FUNC
1394  * @tc.require: SR000H63TL
1395  */
HWTEST_F(HapSignTest, get_compatible_version_test_001, testing::ext::TestSize.Level1)1396 HWTEST_F(HapSignTest, get_compatible_version_test_001, testing::ext::TestSize.Level1)
1397 {
1398     int n = 5;
1399     SignerConfig signerConfig;
1400     signerConfig.SetCompatibleVersion(n);
1401     EXPECT_EQ(5, signerConfig.GetCompatibleVersion());
1402 }
1403 
1404 /**
1405  * @tc.name: find_by_id_test_001
1406  * @tc.desc: Test function of FindById()  interface for SUCCESS.
1407  * @tc.type: FUNC
1408  * @tc.require: SR000H63TL
1409  */
HWTEST_F(HapSignTest, find_by_id_test_001, testing::ext::TestSize.Level1)1410 HWTEST_F(HapSignTest, find_by_id_test_001, testing::ext::TestSize.Level1)
1411 {
1412     const SignatureAlgorithmHelper* tmp = SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::ECDSA_WITH_SHA256);
1413     EXPECT_EQ(&(SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE), tmp);
1414     const SignatureAlgorithmHelper* tmp1 = SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::ECDSA_WITH_SHA384);
1415     EXPECT_EQ(&(SignatureAlgorithmHelper::ECDSA_WITH_SHA384_INSTANCE), tmp1);
1416 }
1417 
1418 /**
1419  * @tc.name: find_by_id_test_002
1420  * @tc.desc: Test function of FindById()  interface for SUCCESS.
1421  * @tc.type: FUNC
1422  * @tc.require: SR000H63TL
1423  */
HWTEST_F(HapSignTest, find_by_id_test_002, testing::ext::TestSize.Level1)1424 HWTEST_F(HapSignTest, find_by_id_test_002, testing::ext::TestSize.Level1)
1425 {
1426     SignatureAlgorithmHelper tmp1 = SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE;
1427     SignatureAlgorithmHelper tmp3 = SignatureAlgorithmHelper::ECDSA_WITH_SHA384_INSTANCE;
1428     SignatureAlgorithmHelper* tmp2 = &tmp1;
1429     *tmp2 = tmp1;
1430     tmp3 = tmp1;
1431     const SignatureAlgorithmHelper* tmp = SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::DSA_WITH_SHA512);
1432     EXPECT_EQ(nullptr, tmp);
1433 }
1434 
1435 /*
1436  * @tc.name: remote_sign_provider_001
1437  * @tc.desc: This function tests failure for interface CheckParams due to signCode is 3
1438  * @tc.type: FUNC
1439  * @tc.require:
1440  */
HWTEST_F(HapSignTest, remote_sign_provider_001, testing::ext::TestSize.Level1)1441 HWTEST_F(HapSignTest, remote_sign_provider_001, testing::ext::TestSize.Level1)
1442 {
1443     SIGNATURE_TOOLS_LOGI("hello world !!!");
1444     std::unique_ptr<SignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1445     std::shared_ptr<Options> params = std::make_shared<Options>();
1446 
1447     std::string mode = "remoteSign";
1448     std::string keyAlias = "oh-app1-key-v1";
1449     std::string signAlg = "SHA256withECDSA";
1450     std::string profileFile = "./hapSign/signed-profile.p7b";
1451     std::string inFile = "./hapSign/phone-default-unsigned.hap";
1452     std::string outFile = "./hapSign/phone-default-signed.hap";
1453     std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12";
1454     std::string compatibleVersion = "8";
1455     std::string signerPlugin = "/mnt/d/libRemoteSigner.so";
1456     std::string signServer = "/mnt/d/testcpuls/app-release1.pem";
1457     std::string username = "test";
1458     char userPwd[] = "123456";
1459 
1460     (*params)["mode"] = mode;
1461     (*params)["keyAlias"] = keyAlias;
1462     (*params)["signAlg"] = signAlg;
1463     (*params)["profileFile"] = profileFile;
1464     (*params)["inFile"] = inFile;
1465     (*params)["outFile"] = outFile;
1466     (*params)["onlineAuthMode"] = onlineAuthMode;
1467     (*params)["compatibleVersion"] = compatibleVersion;
1468     (*params)["signerPlugin"] = signerPlugin;
1469     (*params)["signServer"] = signServer;
1470     (*params)["username"] = username;
1471     (*params)["userPwd"] = userPwd;
1472 
1473     (*params)["signCode"] = std::string("3");
1474     bool retParam = signProvider->CheckParams(params.get());
1475     EXPECT_EQ(retParam, false);
1476 }
1477 
1478 /*
1479  * @tc.name: remote_sign_provider_002
1480  * @tc.desc: This function tests failure for interface CheckInputCertMatchWithProfile due to X509 error
1481  * @tc.type: FUNC
1482  * @tc.require:
1483  */
HWTEST_F(HapSignTest, remote_sign_provider_002, testing::ext::TestSize.Level1)1484 HWTEST_F(HapSignTest, remote_sign_provider_002, testing::ext::TestSize.Level1)
1485 {
1486     SIGNATURE_TOOLS_LOGI("hello world !!!");
1487     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1488 
1489     bool ret = signProvider->CheckInputCertMatchWithProfile(nullptr, nullptr);
1490     EXPECT_EQ(ret, false);
1491 
1492     X509* cert = nullptr;
1493     STACK_OF(X509)* skCert = sk_X509_new(nullptr);
1494     BIO* certBio = BIO_new_file("./hapSign/app-release1.pem", "rb");
1495     if (certBio == nullptr) {
1496         sk_X509_pop_free(skCert, X509_free);
1497         EXPECT_NE(certBio, nullptr);
1498     }
1499     // 读取
1500     while (1) {
1501         cert = PEM_read_bio_X509(certBio, nullptr, nullptr, nullptr);
1502         if (cert == nullptr) {
1503             break;
1504         }
1505         sk_X509_push(skCert, cert);
1506     }
1507     BIO_free(certBio);
1508     if (sk_X509_num(skCert) > 1) {
1509         X509* firstCert = sk_X509_value(skCert, 0);
1510         X509* secondCert = sk_X509_value(skCert, 1);
1511         bool val = signProvider->CheckInputCertMatchWithProfile(firstCert, firstCert);
1512         val = signProvider->CheckInputCertMatchWithProfile(firstCert, secondCert);
1513         EXPECT_EQ(val, false);
1514     }
1515     sk_X509_pop_free(skCert, X509_free);
1516 }
1517 
1518 /*
1519  * @tc.name: remote_sign_provider_003
1520  * @tc.desc: This function tests failure for interface CheckInputCertMatchWithProfile due to x509 error
1521  * @tc.type: FUNC
1522  * @tc.require:
1523  */
HWTEST_F(HapSignTest, remote_sign_provider_003, testing::ext::TestSize.Level1)1524 HWTEST_F(HapSignTest, remote_sign_provider_003, testing::ext::TestSize.Level1)
1525 {
1526     SIGNATURE_TOOLS_LOGI("hello world !!!");
1527     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1528 
1529     X509* cert = X509_new();
1530     X509_REQ* issuerReq = X509_REQ_new();
1531     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1532     CertTools::SetCertIssuerName(cert, BuildDN(issuername, issuerReq));
1533 
1534     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1535     X509_set_subject_name(cert, BuildDN(subjectname, issuerReq));
1536 
1537     X509* cert1 = X509_new();
1538     X509_REQ* issuerReq1 = X509_REQ_new();
1539     std::string issuername1 = "C=wc,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1540     CertTools::SetCertIssuerName(cert1, BuildDN(issuername1, issuerReq1));
1541 
1542     std::string subjectname1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1543     X509_set_subject_name(cert1, BuildDN(subjectname1, issuerReq1));
1544 
1545     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1546     X509_free(cert);
1547     X509_free(cert1);
1548     X509_REQ_free(issuerReq);
1549     X509_REQ_free(issuerReq1);
1550     EXPECT_EQ(ret, false);
1551 }
1552 
1553 /*
1554  * @tc.name: remote_sign_provider_004
1555  * @tc.desc: This function tests failure for interface CheckInputCertMatchWithProfile due to subjectname error
1556  * @tc.type: FUNC
1557  * @tc.require:
1558  */
HWTEST_F(HapSignTest, remote_sign_provider_004, testing::ext::TestSize.Level1)1559 HWTEST_F(HapSignTest, remote_sign_provider_004, testing::ext::TestSize.Level1)
1560 {
1561     SIGNATURE_TOOLS_LOGI("hello world !!!");
1562     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1563 
1564     X509* cert = X509_new();
1565     X509_REQ* issuerReq = X509_REQ_new();
1566     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1567     CertTools::SetCertIssuerName(cert, BuildDN(issuername, issuerReq));
1568     CertTools::SetCertSerialNum(cert);
1569     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1570     X509_set_subject_name(cert, BuildDN(subjectname, issuerReq));
1571 
1572     X509* cert1 = X509_new();
1573     X509_REQ* issuerReq1 = X509_REQ_new();
1574     std::string issuername1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1575     CertTools::SetCertIssuerName(cert1, BuildDN(issuername1, issuerReq1));
1576     CertTools::SetCertSerialNum(cert1);
1577     std::string subjectname1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1578     X509_set_subject_name(cert1, BuildDN(subjectname1, issuerReq1));
1579 
1580     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1581     X509_free(cert);
1582     X509_free(cert1);
1583     X509_REQ_free(issuerReq);
1584     X509_REQ_free(issuerReq1);
1585     EXPECT_EQ(ret, false);
1586 }
1587 
1588 /*
1589  * @tc.name: remote_sign_provider_005
1590  * @tc.desc: This function tests failure for interface CheckParams due to signCode is 3
1591  * @tc.type: FUNC
1592  * @tc.require:
1593  */
HWTEST_F(HapSignTest, remote_sign_provider_005, testing::ext::TestSize.Level1)1594 HWTEST_F(HapSignTest, remote_sign_provider_005, testing::ext::TestSize.Level1)
1595 {
1596     SIGNATURE_TOOLS_LOGI("hello world !!!");
1597     std::unique_ptr<SignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1598     std::shared_ptr<Options> params = std::make_shared<Options>();
1599 
1600     std::string mode = "remoteSign";
1601     std::string keyAlias = "oh-app1-key-v1";
1602     std::string signAlg = "SHA256withECDSA";
1603     std::string profileFile = "./hapSign/signed-profile.p7b";
1604     std::string inFile = "./hapSign/phone-default-unsigned.hap";
1605     std::string outFile = "./hapSign/phone-default-signed.hap";
1606     std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12";
1607     std::string compatibleVersion = "8";
1608     std::string signerPlugin = "/mnt/d/libRemoteSigner.so";
1609     std::string signServer = "/mnt/d/testcpuls/app-release1.pem";
1610     std::string username = "test";
1611     char userPwd[] = "123456";
1612 
1613     (*params)["mode"] = mode;
1614     (*params)["keyAlias"] = keyAlias;
1615     (*params)["signAlg"] = signAlg;
1616     (*params)["profileFile"] = profileFile;
1617     (*params)["inFile"] = inFile;
1618     (*params)["outFile"] = outFile;
1619     (*params)["onlineAuthMode"] = onlineAuthMode;
1620     (*params)["compatibleVersion"] = compatibleVersion;
1621     (*params)["signerPlugin"] = signerPlugin;
1622     (*params)["signServer"] = signServer;
1623     (*params)["username"] = username;
1624     (*params)["userPwd"] = userPwd;
1625 
1626     (*params)["signCode"] = std::string("3");
1627     bool retParam = signProvider->CheckParams(params.get());
1628     EXPECT_EQ(retParam, false);
1629 }
1630 
1631 /*
1632  * @tc.name: remote_sign_provider_006
1633  * @tc.desc: This function tests success for interface CheckParams
1634  * @tc.type: FUNC
1635  * @tc.require:
1636  */
HWTEST_F(HapSignTest, remote_sign_provider_006, testing::ext::TestSize.Level1)1637 HWTEST_F(HapSignTest, remote_sign_provider_006, testing::ext::TestSize.Level1)
1638 {
1639     SIGNATURE_TOOLS_LOGI("hello world !!!");
1640     std::unique_ptr<SignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1641     std::shared_ptr<Options> params = std::make_shared<Options>();
1642 
1643     std::string mode = "remoteSign";
1644     std::string keyAlias = "oh-app1-key-v1";
1645     std::string signAlg = "SHA256withECDSA";
1646     std::string profileFile = "./hapSign/signed-profile.p7b";
1647     std::string inFile = "./hapSign/phone-default-unsigned.hap";
1648     std::string outFile = "./hapSign/phone-default-signed.hap";
1649     std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12";
1650     std::string compatibleVersion = "8";
1651     std::string signerPlugin = "/mnt/d/libRemoteSigner.so";
1652     std::string signServer = "/mnt/d/testcpuls/app-release1.pem";
1653     std::string username = "test";
1654     char userPwd[] = "123456";
1655 
1656     (*params)["mode"] = mode;
1657     (*params)["keyAlias"] = keyAlias;
1658     (*params)["signAlg"] = signAlg;
1659     (*params)["profileFile"] = profileFile;
1660     (*params)["inFile"] = inFile;
1661     (*params)["outFile"] = outFile;
1662     (*params)["onlineAuthMode"] = onlineAuthMode;
1663     (*params)["compatibleVersion"] = compatibleVersion;
1664     (*params)["signerPlugin"] = signerPlugin;
1665     (*params)["signServer"] = signServer;
1666     (*params)["username"] = username;
1667     (*params)["userPwd"] = userPwd;
1668     bool retParam = signProvider->CheckParams(params.get());
1669     EXPECT_EQ(retParam, true);
1670 }
1671 
1672 /*
1673  * @tc.name: remote_sign_provider_007
1674  * @tc.desc: This function tests failed  for interface CheckInputCertMatchWithProfile due to X509_NAME error
1675  * @tc.type: FUNC
1676  * @tc.require:
1677  */
HWTEST_F(HapSignTest, remote_sign_provider_007, testing::ext::TestSize.Level1)1678 HWTEST_F(HapSignTest, remote_sign_provider_007, testing::ext::TestSize.Level1)
1679 {
1680     SIGNATURE_TOOLS_LOGI("hello world !!!");
1681     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1682 
1683     X509* cert = X509_new();
1684     X509* cert1 = X509_new();
1685     X509_REQ* issuerReq = X509_REQ_new();
1686     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1687     CertTools::SetCertIssuerName(cert, BuildDN(issuername, issuerReq));
1688 
1689     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1690     X509_NAME* subName = BuildDN(subjectname, issuerReq);
1691     X509_set_subject_name(cert, subName);
1692     X509_set_subject_name(cert1, subName);
1693 
1694     X509_REQ* issuerReq1 = X509_REQ_new();
1695     std::string issuername1 = "C=wc,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1696     CertTools::SetCertIssuerName(cert1, BuildDN(issuername1, issuerReq1));
1697 
1698     std::string subjectname1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1699 
1700     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1701     X509_free(cert);
1702     X509_free(cert1);
1703     X509_REQ_free(issuerReq);
1704     X509_REQ_free(issuerReq1);
1705     EXPECT_EQ(ret, false);
1706 }
1707 
1708 /*
1709  * @tc.name: remote_sign_provider_008
1710  * @tc.desc: This function tests failed  for interface CheckInputCertMatchWithProfile due to EVP_PKEY error
1711  * @tc.type: FUNC
1712  * @tc.require:
1713  */
HWTEST_F(HapSignTest, remote_sign_provider_008, testing::ext::TestSize.Level1)1714 HWTEST_F(HapSignTest, remote_sign_provider_008, testing::ext::TestSize.Level1)
1715 {
1716     SIGNATURE_TOOLS_LOGI("hello world !!!");
1717     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1718 
1719     X509* cert = X509_new();
1720     X509* cert1 = X509_new();
1721     X509_REQ* issuerReq = X509_REQ_new();
1722     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1723     X509_NAME* issName = BuildDN(issuername, issuerReq);
1724     CertTools::SetCertIssuerName(cert, issName);
1725     CertTools::SetCertIssuerName(cert1, issName);
1726 
1727     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1728     X509_NAME* subName = BuildDN(subjectname, issuerReq);
1729     X509_set_subject_name(cert, subName);
1730     X509_set_subject_name(cert1, subName);
1731     KeyStoreHelper stroe;
1732     EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256);
1733     EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256);
1734 
1735     X509_set_pubkey(cert, key1);
1736     X509_set_pubkey(cert1, key2);
1737 
1738     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1739     X509_free(cert);
1740     X509_free(cert1);
1741     X509_REQ_free(issuerReq);
1742     EVP_PKEY_free(key1);
1743     EVP_PKEY_free(key2);
1744     EXPECT_EQ(ret, false);
1745 }
1746 /*
1747  * @tc.name: remote_sign_provider_009
1748  * @tc.desc: This function tests failed for interface CheckInputCertMatchWithProfile due to EVP_PKEY error
1749  * @tc.type: FUNC
1750  * @tc.require:
1751  */
HWTEST_F(HapSignTest, remote_sign_provider_009, testing::ext::TestSize.Level1)1752 HWTEST_F(HapSignTest, remote_sign_provider_009, testing::ext::TestSize.Level1)
1753 {
1754     SIGNATURE_TOOLS_LOGI("hello world !!!");
1755     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1756 
1757     X509* cert = X509_new();
1758     X509* cert1 = X509_new();
1759     X509_REQ* issuerReq = X509_REQ_new();
1760     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1761     X509_NAME* issName = BuildDN(issuername, issuerReq);
1762     CertTools::SetCertIssuerName(cert, issName);
1763     CertTools::SetCertIssuerName(cert1, issName);
1764 
1765     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1766     X509_NAME* subName = BuildDN(subjectname, issuerReq);
1767     X509_set_subject_name(cert, subName);
1768     X509_set_subject_name(cert1, subName);
1769     KeyStoreHelper stroe;
1770     EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256);
1771     EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256);
1772 
1773     X509_set_pubkey(cert, key1);
1774     X509_set_pubkey(cert1, key2);
1775 
1776     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, nullptr);
1777     X509_free(cert);
1778     X509_free(cert1);
1779     X509_REQ_free(issuerReq);
1780     EVP_PKEY_free(key1);
1781     EVP_PKEY_free(key2);
1782     EXPECT_EQ(ret, false);
1783 }
1784 
1785 /*
1786  * @tc.name: remote_sign_provider_010
1787  * @tc.desc: This function tests failed for interface CheckInputCertMatchWithProfile due to EVP_PKEY error
1788  * @tc.type: FUNC
1789  * @tc.require:
1790  */
HWTEST_F(HapSignTest, remote_sign_provider_010, testing::ext::TestSize.Level1)1791 HWTEST_F(HapSignTest, remote_sign_provider_010, testing::ext::TestSize.Level1)
1792 {
1793     SIGNATURE_TOOLS_LOGI("hello world !!!");
1794     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1795 
1796     X509* cert = X509_new();
1797     X509* cert1 = X509_new();
1798     X509_REQ* issuerReq = X509_REQ_new();
1799     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1800     X509_NAME* issName = BuildDN(issuername, issuerReq);
1801     CertTools::SetCertIssuerName(cert, issName);
1802     CertTools::SetCertIssuerName(cert1, issName);
1803 
1804     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1805     X509_NAME* subName = BuildDN(subjectname, issuerReq);
1806     X509_set_subject_name(cert, subName);
1807     X509_set_subject_name(cert1, subName);
1808     KeyStoreHelper stroe;
1809     EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256);
1810 
1811     X509_set_pubkey(cert, key1);
1812 
1813     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1814     X509_free(cert);
1815     X509_free(cert1);
1816     X509_REQ_free(issuerReq);
1817     EVP_PKEY_free(key1);
1818     EXPECT_EQ(ret, false);
1819 }
1820 
1821 /*
1822  * @tc.name: remote_sign_provider_011
1823  * @tc.desc: This function tests failed for interface CheckInputCertMatchWithProfile due to EVP_PKEY error
1824  * @tc.type: FUNC
1825  * @tc.require:
1826  */
HWTEST_F(HapSignTest, remote_sign_provider_011, testing::ext::TestSize.Level1)1827 HWTEST_F(HapSignTest, remote_sign_provider_011, testing::ext::TestSize.Level1)
1828 {
1829     SIGNATURE_TOOLS_LOGI("hello world !!!");
1830     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1831 
1832     X509* cert = X509_new();
1833     X509* cert1 = X509_new();
1834     X509_REQ* issuerReq = X509_REQ_new();
1835     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1836     X509_NAME* issName = BuildDN(issuername, issuerReq);
1837     CertTools::SetCertIssuerName(cert, issName);
1838     CertTools::SetCertIssuerName(cert1, issName);
1839 
1840     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1841     X509_NAME* subName = BuildDN(subjectname, issuerReq);
1842     X509_set_subject_name(cert, subName);
1843     X509_set_subject_name(cert1, subName);
1844     KeyStoreHelper stroe;
1845     EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256);
1846 
1847     X509_set_pubkey(cert1, key2);
1848 
1849     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1850     X509_free(cert);
1851     X509_free(cert1);
1852     X509_REQ_free(issuerReq);
1853     EVP_PKEY_free(key2);
1854     EXPECT_EQ(ret, false);
1855 }
1856 
1857 /*
1858  * @tc.name: remote_sign_provider_012
1859  * @tc.desc: This function tests failed for interface CheckInputCertMatchWithProfile due to EVP_PKEY error
1860  * @tc.type: FUNC
1861  * @tc.require:
1862  */
HWTEST_F(HapSignTest, remote_sign_provider_012, testing::ext::TestSize.Level1)1863 HWTEST_F(HapSignTest, remote_sign_provider_012, testing::ext::TestSize.Level1)
1864 {
1865     SIGNATURE_TOOLS_LOGI("hello world !!!");
1866     std::unique_ptr<RemoteSignProvider> signProvider = std::make_unique<RemoteSignProvider>();
1867 
1868     X509* cert = X509_new();
1869     X509* cert1 = X509_new();
1870     X509_REQ* issuerReq = X509_REQ_new();
1871     std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1872     X509_NAME* issName = BuildDN(issuername, issuerReq);
1873     CertTools::SetCertIssuerName(cert, issName);
1874     CertTools::SetCertIssuerName(cert1, issName);
1875 
1876     std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA";
1877     X509_NAME* subName = BuildDN(subjectname, issuerReq);
1878     X509_set_subject_name(cert, subName);
1879     X509_set_subject_name(cert1, subName);
1880     KeyStoreHelper stroe;
1881 
1882     bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert);
1883     X509_free(cert);
1884     X509_free(cert1);
1885     X509_REQ_free(issuerReq);
1886     EXPECT_EQ(ret, false);
1887 }
1888 
1889 /**
1890  * @tc.name: remote_sign_provider_013
1891  * @tc.desc: This function tests failed for interface Sign due to parameter signerPlugin error
1892  * @tc.type: FUNC
1893  * @tc.require: SR000H63TL
1894  */
HWTEST_F(HapSignTest, remote_sign_provider_013, testing::ext::TestSize.Level1)1895 HWTEST_F(HapSignTest, remote_sign_provider_013, testing::ext::TestSize.Level1)
1896 {
1897     std::string mode = "remoteSign";
1898     std::string keyAlias = "oh-app1-key-v1";
1899     std::string profileFile = "./hapSign/signed-profile.p7b";
1900     std::string signAlg = "SHA256withECDSA";
1901     std::string signCode = "1";
1902     std::string compatibleVersion = "8";
1903     std::string inFile = "./hapSign/phone-default-unsigned.hap";
1904     std::string outFile = "./hapSign/signed.hap";
1905     std::string signServer = "./hapSign/app-release1.pem";
1906     std::string signerPlugin = "./hapSign/dummy.z.so";
1907     std::string onlineAuthMode = "./hapSign/ohtest.p12";
1908     std::string username = "123456";
1909     char userPwd[] = "123456";
1910 
1911     std::shared_ptr<Options> params = std::make_shared<Options>();
1912     (*params)["mode"] = mode;
1913     (*params)["keyAlias"] = keyAlias;
1914     (*params)["profileFile"] = profileFile;
1915     (*params)["signAlg"] = signAlg;
1916     (*params)["signCode"] = signCode;
1917     (*params)["compatibleVersion"] = compatibleVersion;
1918     (*params)["inFile"] = inFile;
1919     (*params)["outFile"] = outFile;
1920     (*params)["signServer"] = signServer;
1921     (*params)["onlineAuthMode"] = onlineAuthMode;
1922     (*params)["username"] = username;
1923     (*params)["userPwd"] = userPwd;
1924     // the signerPlugin dummy.z.so is not exist
1925     (*params)["signerPlugin"] = signerPlugin;
1926 
1927     auto remoteSignProvider = std::make_unique<RemoteSignProvider>();
1928     ASSERT_FALSE(remoteSignProvider->Sign(params.get()));
1929 }
1930 
1931 /*
1932  * @tc.name: hap_sign_error_001
1933  * @tc.desc: This function tests failed for interface Sign due to parameter path not exist
1934  * @tc.type: FUNC
1935  * @tc.require:
1936  */
HWTEST_F(HapSignTest, hap_sign_error_001, testing::ext::TestSize.Level1)1937 HWTEST_F(HapSignTest, hap_sign_error_001, testing::ext::TestSize.Level1)
1938 {
1939     ByteBuffer bf1("123456789", 9);
1940     ByteBuffer bf2("123456789", 9);
1941     ByteBuffer bf3("123456789", 9);
1942     ByteBuffer bf4(0x7FFFFFFF);
1943     ByteBufferDataSource ds1(bf1);
1944     ByteBufferDataSource ds2(bf2);
1945     ByteBufferDataSource ds3(bf3);
1946     DataSource* contents[] = {&ds1, &ds2, &ds3};
1947     std::vector<OptionalBlock> optionalBlocks;
1948     optionalBlocks.push_back({HapUtils::HAP_PROFILE_BLOCK_ID, bf4});
1949     std::shared_ptr<Options> params = std::make_shared<Options>();
1950     std::string mode = "localSign";
1951     std::string keyAlias = "oh-app1-key-v1";
1952     std::string signAlg = "SHA256withECDSA";
1953     std::string signCode = "1";
1954     std::string appCertFile = "/mnt/d/testcpuls/app-release1.pem";
1955     std::string profileFile = "/mnt/d/testcpuls/signed-profile.p7b";
1956     std::string inFile = "/mnt/d/testcpuls/entry-default-unsigned-so.hap";
1957     std::string keystoreFile = "/mnt/d/testcpuls/OpenHarmony.p12";
1958     std::string outFile = "/mnt/d/testcpuls/entry-default-signed-so.hap";
1959     char keyPwd[] = "123456";
1960     char keystorePwd[] = "123456";
1961     (*params)["mode"] = mode;
1962     (*params)["keyAlias"] = keyAlias;
1963     (*params)["signAlg"] = signAlg;
1964     (*params)["signCode"] = signCode;
1965     (*params)["appCertFile"] = appCertFile;
1966     (*params)["profileFile"] = profileFile;
1967     (*params)["inFile"] = inFile;
1968     (*params)["keystoreFile"] = keystoreFile;
1969     (*params)["outFile"] = outFile;
1970     (*params)["keyPwd"] = keyPwd;
1971     (*params)["keystorePwd"] = keystorePwd;
1972     SignerConfig config;
1973     std::vector<SignatureAlgorithmHelper> sig{SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE};
1974     config.SetSignatureAlgorithms(sig);
1975     config.SetOptions(params.get());
1976     ByteBuffer result;
1977     bool ret1 = SignHap::Sign(contents, 3, config, optionalBlocks, result);
1978     EXPECT_EQ(ret1, false);
1979 }
1980 } // namespace SignatureTools
1981 } // namespace OHOS