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 "sign_provider_test.h"
16#include "params_run_tool.h"
17#include "local_sign_provider.h"
18#include "remote_sign_provider.h"
19#include "sign_hap.h"
20#include "sign_provider.h"
21#include "sign_tool_service_impl.h"
22#include <unistd.h>
23
24namespace OHOS {
25namespace SignatureTools {
26
27void GenUnvaildUnProviderHap(const std::string& path)
28{
29    std::ofstream outfile(path);
30    if (!outfile) {
31        SIGNATURE_TOOLS_LOGE("Unable to open file: %s", path.c_str());
32        return;
33    }
34    outfile << "Hello, this is a Unvaild un provider Hap.\n";
35    outfile.flush();
36    outfile.close();
37    return;
38}
39
40void SignProviderTest::SetUpTestCase(void)
41{
42    GenUnvaildUnProviderHap("./hapSign/phone-default-unsigned");
43    GenUnvaildUnProviderHap("./hapSign/phone-default-unsigned.txt");
44    GenUnvaildUnProviderHap("./hapSign/nohap.hap");
45
46    (void)rename("./hapSign/packages/phone-default-unsigned-test.txt", "./hapSign/phone-default-unsigned-test.hap");
47    (void)rename("./hapSign/packages/phone-default-unsigned.txt", "./hapSign/phone-default-unsigned.hap");
48    (void)rename("./hapSign/packages/unsigned_with_cd_and_eocd.txt", "./hapSign/unsigned_with_cd_and_eocd.hap");
49    (void)rename("./hapSign/packages/unsigned_with_eocd.txt", "./hapSign/unsigned_with_eocd.hap");
50    (void)rename("./codeSigning/unsigned-file.txt", "./codeSigning/unsigned-file.hap");
51    sync();
52}
53
54void SignProviderTest::TearDownTestCase(void)
55{
56}
57
58/*
59 * @tc.name: sign_provider_test_001
60 * @tc.desc: This function tests success for interface Sign
61 * @tc.type: FUNC
62 * @tc.require:
63 */
64HWTEST_F(SignProviderTest, sign_provider_test_001, testing::ext::TestSize.Level1)
65{
66    SIGNATURE_TOOLS_LOGI("hello world !!!");
67    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
68    std::shared_ptr<Options> params = std::make_shared<Options>();
69
70    std::string mode = "localSign";
71    std::string keyAlias = "oh-app1-key-v1";
72    std::string signAlg = "SHA256withECDSA";
73    std::string signCode = "0";
74    std::string appCertFile = "./hapSign/app-release1.pem";
75    std::string profileFile = "./hapSign/signed-profile.p7b";
76    std::string profileSigned = "1";
77    std::string inFile = "./hapSign/phone-default-unsigned-test.hap";
78    std::string keystoreFile = "./hapSign/ohtest.p12";
79    std::string outFile = "./hapSign/phone-default-unsigned-test.hap";
80    char keyPwd[] = "123456";
81    char keystorePwd[] = "123456";
82
83    (*params)["mode"] = mode;
84    (*params)["keyAlias"] = keyAlias;
85    (*params)["signAlg"] = signAlg;
86    (*params)["signCode"] = signCode;
87    (*params)["appCertFile"] = appCertFile;
88    (*params)["profileFile"] = profileFile;
89    (*params)["profileSigned"] = profileSigned;
90    (*params)["inFile"] = inFile;
91    (*params)["keystoreFile"] = keystoreFile;
92    (*params)["outFile"] = outFile;
93    (*params)["keyPwd"] = keyPwd;
94    (*params)["keystorePwd"] = keystorePwd;
95
96    bool ret = signProvider->Sign(params.get());
97    EXPECT_EQ(ret, true);
98}
99/*
100 * @tc.name: sign_provider_test_002
101 * @tc.desc: This function tests failure for interface Sign due to parameter compatibleVersion is not int
102 * @tc.type: FUNC
103 * @tc.require:
104 */
105HWTEST_F(SignProviderTest, sign_provider_test_002, testing::ext::TestSize.Level1)
106{
107    SIGNATURE_TOOLS_LOGI("hello world !!!");
108    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
109    std::shared_ptr<Options> params = std::make_shared<Options>();
110
111    std::string mode = "localSign";
112    std::string keyAlias = "oh-app1-key-v1";
113    std::string signAlg = "SHA256withECDSA";
114    std::string signCode = "1";
115    std::string appCertFile = "./hapSign/app-release1.pem";
116    std::string profileFile = "./hapSign/signed-profile.p7b";
117    std::string profileSigned = "1";
118    std::string inFile = "./hapSign/phone-default-unsigned.hap";
119    std::string keystoreFile = "./hapSign/ohtest.p12";
120    std::string outFile = "./hapSign/phone-default-signed.hap";
121    char keyPwd[] = "123456";
122    char keystorePwd[] = "123456";
123
124    (*params)["mode"] = mode;
125    (*params)["keyAlias"] = keyAlias;
126    (*params)["signAlg"] = signAlg;
127    (*params)["signCode"] = signCode;
128    (*params)["appCertFile"] = appCertFile;
129    (*params)["profileFile"] = profileFile;
130    (*params)["profileSigned"] = profileSigned;
131    (*params)["inFile"] = inFile;
132    (*params)["keystoreFile"] = keystoreFile;
133    (*params)["outFile"] = outFile;
134    (*params)["keyPwd"] = keyPwd;
135    (*params)["keystorePwd"] = keystorePwd;
136
137    (*params)["compatibleVersion"] = std::string("a");
138    bool ret = signProvider->Sign(params.get());
139    EXPECT_EQ(ret, false);
140}
141
142/*
143 * @tc.name: sign_provider_test_003
144 * @tc.desc: This function tests failure for interface Sign due to parameter inFile format error
145 * @tc.type: FUNC
146 * @tc.require:
147 */
148HWTEST_F(SignProviderTest, sign_provider_test_003, testing::ext::TestSize.Level1)
149{
150    SIGNATURE_TOOLS_LOGI("hello world !!!");
151    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
152    std::shared_ptr<Options> params = std::make_shared<Options>();
153
154    std::string mode = "localSign";
155    std::string keyAlias = "oh-app1-key-v1";
156    std::string signAlg = "SHA256withECDSA";
157    std::string signCode = "1";
158    std::string appCertFile = "./hapSign/app-release1.pem";
159    std::string profileFile = "./hapSign/signed-profile.p7b";
160    std::string inFile = "./hapSign/phone-default-unsigned";
161    std::string keystoreFile = "./hapSign/ohtest.p12";
162    std::string outFile = "./hapSign/phone-default-signed.hap";
163    char keyPwd[] = "123456";
164    char keystorePwd[] = "123456";
165
166    (*params)["mode"] = mode;
167    (*params)["keyAlias"] = keyAlias;
168    (*params)["signAlg"] = signAlg;
169    (*params)["signCode"] = signCode;
170    (*params)["appCertFile"] = appCertFile;
171    (*params)["profileFile"] = profileFile;
172    (*params)["inFile"] = inFile;
173    (*params)["keystoreFile"] = keystoreFile;
174    (*params)["outFile"] = outFile;
175    (*params)["keyPwd"] = keyPwd;
176    (*params)["keystorePwd"] = keystorePwd;
177
178    bool ret = signProvider->Sign(params.get());
179    EXPECT_EQ(ret, false);
180}
181
182/*
183 * @tc.name: sign_provider_test_004
184 * @tc.desc: This function tests failure for interface Sign due to parameter compatibleVersion is not int
185 * @tc.type: FUNC
186 * @tc.require:
187 */
188HWTEST_F(SignProviderTest, sign_provider_test_004, testing::ext::TestSize.Level1)
189{
190    SIGNATURE_TOOLS_LOGI("hello world !!!");
191    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
192    std::shared_ptr<Options> params = std::make_shared<Options>();
193
194    std::string mode = "localSign";
195    std::string keyAlias = "oh-app1-key-v1";
196    std::string signAlg = "SHA256withECDSA";
197    std::string signCode = "1";
198    std::string appCertFile = "./hapSign/app-release1.pem";
199    std::string profileFile = "./hapSign/signed-profile.p7b";
200    std::string inFile = "./hapSign/phone-default-unsigned.hap";
201    std::string keystoreFile = "./hapSign/ohtest.p12";
202    std::string outFile = "./hapSign/phone-default-signed.hap";
203    char keyPwd[] = "123456";
204    char keystorePwd[] = "123456";
205    std::string compatibleVersion = "a";
206
207    (*params)["mode"] = mode;
208    (*params)["keyAlias"] = keyAlias;
209    (*params)["signAlg"] = signAlg;
210    (*params)["signCode"] = signCode;
211    (*params)["appCertFile"] = appCertFile;
212    (*params)["profileFile"] = profileFile;
213    (*params)["inFile"] = inFile;
214    (*params)["keystoreFile"] = keystoreFile;
215    (*params)["outFile"] = outFile;
216    (*params)["keyPwd"] = keyPwd;
217    (*params)["keystorePwd"] = keystorePwd;
218    (*params)["compatibleVersion"] = compatibleVersion;
219
220    bool ret = signProvider->Sign(params.get());
221    EXPECT_EQ(ret, false);
222}
223
224/*
225 * @tc.name: sign_provider_test_005
226 * @tc.desc: This function tests failure for interface Sign due to parameter compatibleVersion is not int
227 * @tc.type: FUNC
228 * @tc.require:
229 */
230HWTEST_F(SignProviderTest, sign_provider_test_005, testing::ext::TestSize.Level1)
231{
232    SIGNATURE_TOOLS_LOGI("hello world !!!");
233    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
234    std::shared_ptr<Options> params = std::make_shared<Options>();
235
236    std::string mode = "localSign";
237    std::string keyAlias = "oh-app1-key-v1";
238    std::string signAlg = "SHA256withECDSA";
239    std::string signCode = "1";
240    std::string appCertFile = "./hapSign/app-release1.pem";
241    std::string profileFile = "./hapSign/signed-profile.p7b";
242    std::string inFile = "./hapSign/phone-default-unsigned.hap";
243    std::string keystoreFile = "./hapSign/ohtest.p12";
244    std::string outFile = "./hapSign/phone-default-signed.hap";
245    char keyPwd[] = "123456";
246    char keystorePwd[] = "123456";
247    std::string property = "./hapSign/signed-profile.p7b";
248    std::string proof = "./hapSign/signed-profile.p7b";
249
250    (*params)["mode"] = mode;
251    (*params)["keyAlias"] = keyAlias;
252    (*params)["signAlg"] = signAlg;
253    (*params)["signCode"] = signCode;
254    (*params)["appCertFile"] = appCertFile;
255    (*params)["profileFile"] = profileFile;
256    (*params)["inFile"] = inFile;
257    (*params)["keystoreFile"] = keystoreFile;
258    (*params)["outFile"] = outFile;
259    (*params)["keyPwd"] = keyPwd;
260    (*params)["keystorePwd"] = keystorePwd;
261    (*params)["property"] = property;
262    (*params)["proof"] = proof;
263
264    bool ret = signProvider->Sign(params.get());
265    EXPECT_EQ(ret, true);
266}
267
268/*
269 * @tc.name: sign_provider_test_006
270 * @tc.desc: This function tests failure for interface Sign due to parameter property is not exist
271 * @tc.type: FUNC
272 * @tc.require:
273 */
274HWTEST_F(SignProviderTest, sign_provider_test_006, testing::ext::TestSize.Level1)
275{
276    SIGNATURE_TOOLS_LOGI("hello world !!!");
277    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
278    std::shared_ptr<Options> params = std::make_shared<Options>();
279
280    std::string mode = "localSign";
281    std::string keyAlias = "oh-app1-key-v1";
282    std::string signAlg = "SHA256withECDSA";
283    std::string signCode = "1";
284    std::string appCertFile = "./hapSign/app-release1.pem";
285    std::string profileFile = "./hapSign/signed-profile.p7b";
286    std::string inFile = "./hapSign/phone-default-unsigned.hap";
287    std::string keystoreFile = "./hapSign/ohtest.p12";
288    std::string outFile = "./hapSign/phone-default-signed.hap";
289    char keyPwd[] = "123456";
290    char keystorePwd[] = "123456";
291    std::string property = "./hapSign/signed-nohavaprofile.p7b";
292    std::string proof = "./hapSign/signed-profile.p7b";
293
294    (*params)["mode"] = mode;
295    (*params)["keyAlias"] = keyAlias;
296    (*params)["signAlg"] = signAlg;
297    (*params)["signCode"] = signCode;
298    (*params)["appCertFile"] = appCertFile;
299    (*params)["profileFile"] = profileFile;
300    (*params)["inFile"] = inFile;
301    (*params)["keystoreFile"] = keystoreFile;
302    (*params)["outFile"] = outFile;
303    (*params)["keyPwd"] = keyPwd;
304    (*params)["keystorePwd"] = keystorePwd;
305    (*params)["property"] = property;
306    (*params)["proof"] = proof;
307
308    bool ret = signProvider->Sign(params.get());
309    EXPECT_EQ(ret, false);
310}
311
312/*
313 * @tc.name: sign_provider_test_007
314 * @tc.desc: This function tests failure for interface Sign due to parameter property is not exist
315 * @tc.type: FUNC
316 * @tc.require:
317 */
318HWTEST_F(SignProviderTest, sign_provider_test_007, testing::ext::TestSize.Level1)
319{
320    SIGNATURE_TOOLS_LOGI("hello world !!!");
321    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
322    std::shared_ptr<Options> params = std::make_shared<Options>();
323
324    std::string mode = "localSign";
325    std::string keyAlias = "oh-app1-key-v1";
326    std::string signAlg = "SHA256withECDSA";
327    std::string signCode = "1";
328    std::string appCertFile = "./hapSign/app-release1.pem";
329    std::string profileFile = "./hapSign/signed-nohaveprofile.p7b";
330    std::string inFile = "./hapSign/phone-default-unsigned.hap";
331    std::string keystoreFile = "./hapSign/ohtest.p12";
332    std::string outFile = "./hapSign/phone-default-signed.hap";
333    char keyPwd[] = "123456";
334    char keystorePwd[] = "123456";
335    std::string property = "./hapSign/signed-profile.p7b";
336    std::string proof = "./hapSign/signed-profile.p7b";
337
338    (*params)["mode"] = mode;
339    (*params)["keyAlias"] = keyAlias;
340    (*params)["signAlg"] = signAlg;
341    (*params)["signCode"] = signCode;
342    (*params)["appCertFile"] = appCertFile;
343    (*params)["profileFile"] = profileFile;
344    (*params)["inFile"] = inFile;
345    (*params)["keystoreFile"] = keystoreFile;
346    (*params)["outFile"] = outFile;
347    (*params)["keyPwd"] = keyPwd;
348    (*params)["keystorePwd"] = keystorePwd;
349    (*params)["property"] = property;
350    (*params)["proof"] = proof;
351
352    bool ret = signProvider->Sign(params.get());
353    EXPECT_EQ(ret, false);
354}
355
356/*
357 * @tc.name: sign_provider_test_008
358 * @tc.desc: This function tests failure for interface Sign due to parameter proof is not exist
359 * @tc.type: FUNC
360 * @tc.require:
361 */
362HWTEST_F(SignProviderTest, sign_provider_test_008, testing::ext::TestSize.Level1)
363{
364    SIGNATURE_TOOLS_LOGI("hello world !!!");
365    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
366    std::shared_ptr<Options> params = std::make_shared<Options>();
367
368    std::string mode = "localSign";
369    std::string keyAlias = "oh-app1-key-v1";
370    std::string signAlg = "SHA256withECDSA";
371    std::string signCode = "1";
372    std::string appCertFile = "./hapSign/app-release1.pem";
373    std::string profileFile = "./hapSign/signed-profile.p7b";
374    std::string inFile = "./hapSign/phone-default-unsigned.hap";
375    std::string keystoreFile = "./hapSign/ohtest.p12";
376    std::string outFile = "./hapSign/phone-default-signed.hap";
377    char keyPwd[] = "123456";
378    char keystorePwd[] = "123456";
379    std::string property = "./hapSign/signed-profile.p7b";
380    std::string proof = "./hapSign/signed-nohaveprofile.p7b";
381
382    (*params)["mode"] = mode;
383    (*params)["keyAlias"] = keyAlias;
384    (*params)["signAlg"] = signAlg;
385    (*params)["signCode"] = signCode;
386    (*params)["appCertFile"] = appCertFile;
387    (*params)["profileFile"] = profileFile;
388    (*params)["inFile"] = inFile;
389    (*params)["keystoreFile"] = keystoreFile;
390    (*params)["outFile"] = outFile;
391    (*params)["keyPwd"] = keyPwd;
392    (*params)["keystorePwd"] = keystorePwd;
393    (*params)["property"] = property;
394    (*params)["proof"] = proof;
395
396    bool ret = signProvider->Sign(params.get());
397    EXPECT_EQ(ret, true);
398}
399
400/*
401 * @tc.name: sign_provider_test_009
402 * @tc.desc: This function tests failure for interface Sign due to parameter inFile is not exist
403 * @tc.type: FUNC
404 * @tc.require:
405 */
406HWTEST_F(SignProviderTest, sign_provider_test_009, testing::ext::TestSize.Level1)
407{
408    SIGNATURE_TOOLS_LOGI("hello world !!!");
409    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
410    std::shared_ptr<Options> params = std::make_shared<Options>();
411
412    std::string mode = "localSign";
413    std::string keyAlias = "oh-app1-key-v1";
414    std::string signAlg = "SHA256withECDSA";
415    std::string signCode = "1";
416    std::string appCertFile = "./hapSign/app-release1.pem";
417    std::string profileFile = "./hapSign/signed-profile.p7b";
418    std::string inFile = "./hapSign_test/phone-default-unsigned.hap";
419    std::string keystoreFile = "./hapSign/ohtest.p12";
420    std::string outFile = "./hapSign/phone-default-signed.hap";
421    char keyPwd[] = "123456";
422    char keystorePwd[] = "123456";
423
424    (*params)["mode"] = mode;
425    (*params)["keyAlias"] = keyAlias;
426    (*params)["signAlg"] = signAlg;
427    (*params)["signCode"] = signCode;
428    (*params)["appCertFile"] = appCertFile;
429    (*params)["profileFile"] = profileFile;
430    (*params)["inFile"] = inFile;
431    (*params)["keystoreFile"] = keystoreFile;
432    (*params)["outFile"] = outFile;
433    (*params)["keyPwd"] = keyPwd;
434    (*params)["keystorePwd"] = keystorePwd;
435
436    bool ret = signProvider->Sign(params.get());
437    EXPECT_EQ(ret, false);
438}
439
440/*
441 * @tc.name: sign_provider_test_010
442 * @tc.desc: This function tests failure for interface Sign due to parameter inFile is not exist
443 * @tc.type: FUNC
444 * @tc.require:
445 */
446HWTEST_F(SignProviderTest, sign_provider_test_010, testing::ext::TestSize.Level1)
447{
448    SIGNATURE_TOOLS_LOGI("hello world !!!");
449    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
450    std::shared_ptr<Options> params = std::make_shared<Options>();
451
452    std::string mode = "localSign";
453    std::string keyAlias = "oh-app1-key-v1";
454    std::string signAlg = "SHA256withECDSA";
455    std::string signCode = "1";
456    std::string appCertFile = "./hapSign/app-release1.pem";
457    std::string profileFile = "./hapSign/signed-profile.p7b";
458    std::string inFile = "./hapSign";
459    std::string keystoreFile = "./hapSign/ohtest.p12";
460    std::string outFile = "./hapSign/phone-default-signed.hap";
461    char keyPwd[] = "123456";
462    char keystorePwd[] = "123456";
463
464    (*params)["mode"] = mode;
465    (*params)["keyAlias"] = keyAlias;
466    (*params)["signAlg"] = signAlg;
467    (*params)["signCode"] = signCode;
468    (*params)["appCertFile"] = appCertFile;
469    (*params)["profileFile"] = profileFile;
470    (*params)["inFile"] = inFile;
471    (*params)["keystoreFile"] = keystoreFile;
472    (*params)["outFile"] = outFile;
473    (*params)["keyPwd"] = keyPwd;
474    (*params)["keystorePwd"] = keystorePwd;
475
476    bool ret = signProvider->Sign(params.get());
477    EXPECT_EQ(ret, false);
478}
479
480/*
481 * @tc.name: sign_provider_test_011
482 * @tc.desc: This function tests failure for interface Sign due to parameter inFile is not exist
483 * @tc.type: FUNC
484 * @tc.require:
485 */
486HWTEST_F(SignProviderTest, sign_provider_test_011, testing::ext::TestSize.Level1)
487{
488    SIGNATURE_TOOLS_LOGI("hello world !!!");
489    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
490    std::shared_ptr<Options> params = std::make_shared<Options>();
491
492    std::string mode = "localSign";
493    std::string keyAlias = "oh-app1-key-v1";
494    std::string signAlg = "SHA256withECDSA";
495    std::string signCode = "1";
496    std::string appCertFile = "./hapSign/app-release1.pem";
497    std::string profileFile = "./hapSign/signed-profile.p7b";
498    std::string inFile = "";
499    std::string keystoreFile = "./hapSign/ohtest.p12";
500    std::string outFile = "./hapSign/phone-default-signed.hap";
501    char keyPwd[] = "123456";
502    char keystorePwd[] = "123456";
503
504    (*params)["mode"] = mode;
505    (*params)["keyAlias"] = keyAlias;
506    (*params)["signAlg"] = signAlg;
507    (*params)["signCode"] = signCode;
508    (*params)["appCertFile"] = appCertFile;
509    (*params)["profileFile"] = profileFile;
510    (*params)["inFile"] = inFile;
511    (*params)["keystoreFile"] = keystoreFile;
512    (*params)["outFile"] = outFile;
513    (*params)["keyPwd"] = keyPwd;
514    (*params)["keystorePwd"] = keystorePwd;
515
516    bool ret = signProvider->Sign(params.get());
517    EXPECT_EQ(ret, false);
518}
519
520/*
521 * @tc.name: sign_provider_test_012
522 * @tc.desc: This function tests failure for interface Sign due to parameter profileFile is not exist
523 * @tc.type: FUNC
524 * @tc.require:
525 */
526HWTEST_F(SignProviderTest, sign_provider_test_012, testing::ext::TestSize.Level1)
527{
528    SIGNATURE_TOOLS_LOGI("hello world !!!");
529    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
530    std::shared_ptr<Options> params = std::make_shared<Options>();
531
532    std::string mode = "localSign";
533    std::string keyAlias = "oh-app1-key-v1";
534    std::string signAlg = "SHA256withECDSA";
535    std::string signCode = "1";
536    std::string appCertFile = "./hapSign/app-release1.pem";
537    std::string profileFile = "./hapSign/signed-nohava-profile.p7b";
538    std::string inFile = "./hapSign_test/phone-default-unsigned.hap";
539    std::string keystoreFile = "./hapSign/ohtest.p12";
540    std::string outFile = "./hapSign/phone-default-signed.hap";
541    char keyPwd[] = "123456";
542    char keystorePwd[] = "123456";
543
544    (*params)["mode"] = mode;
545    (*params)["keyAlias"] = keyAlias;
546    (*params)["signAlg"] = signAlg;
547    (*params)["signCode"] = signCode;
548    (*params)["appCertFile"] = appCertFile;
549    (*params)["profileFile"] = profileFile;
550    (*params)["inFile"] = inFile;
551    (*params)["keystoreFile"] = keystoreFile;
552    (*params)["outFile"] = outFile;
553    (*params)["keyPwd"] = keyPwd;
554    (*params)["keystorePwd"] = keystorePwd;
555
556    bool ret = signProvider->Sign(params.get());
557    EXPECT_EQ(ret, false);
558}
559
560/*
561 * @tc.name: sign_provider_test_013
562 * @tc.desc: This function tests failure for interface Sign due to parameter compatibleVersion is not int
563 * @tc.type: FUNC
564 * @tc.require:
565 */
566HWTEST_F(SignProviderTest, sign_provider_test_013, testing::ext::TestSize.Level1)
567{
568    SIGNATURE_TOOLS_LOGI("hello world !!!");
569    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
570    std::shared_ptr<Options> params = std::make_shared<Options>();
571
572    std::string mode = "localSign";
573    std::string keyAlias = "oh-app1-key-v1";
574    std::string signAlg = "SHA256withECDSA";
575    std::string signCode = "0";
576    std::string appCertFile = "./hapSign/app-release1.pem";
577    std::string profileFile = "./hapSign/signed-profile.p7b";
578    std::string inFile = "./hapSign/phone-default-unsigned.hap";
579    std::string keystoreFile = "./hapSign/ohtest.p12";
580    std::string outFile = "./hapSign/phone-default-signed.hap";
581    char keyPwd[] = "123456";
582    char keystorePwd[] = "123456";
583    std::string compatibleVersion = "a";
584
585    (*params)["mode"] = mode;
586    (*params)["keyAlias"] = keyAlias;
587    (*params)["signAlg"] = signAlg;
588    (*params)["signCode"] = signCode;
589    (*params)["appCertFile"] = appCertFile;
590    (*params)["profileFile"] = profileFile;
591    (*params)["inFile"] = inFile;
592    (*params)["keystoreFile"] = keystoreFile;
593    (*params)["outFile"] = outFile;
594    (*params)["keyPwd"] = keyPwd;
595    (*params)["keystorePwd"] = keystorePwd;
596    (*params)["compatibleVersion"] = compatibleVersion;
597
598    bool ret = signProvider->Sign(params.get());
599    EXPECT_EQ(ret, false);
600}
601
602/*
603 * @tc.name: sign_provider_test_014
604 * @tc.desc: This function tests failure for interface Sign due to parameter inFile is not exist
605 * @tc.type: FUNC
606 * @tc.require:
607 */
608HWTEST_F(SignProviderTest, sign_provider_test_014, testing::ext::TestSize.Level1)
609{
610    SIGNATURE_TOOLS_LOGI("hello world !!!");
611    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
612    std::shared_ptr<Options> params = std::make_shared<Options>();
613
614    std::string mode = "localSign";
615    std::string keyAlias = "oh-app1-key-v1";
616    std::string signAlg = "SHA256withECDSA";
617    std::string signCode = "0";
618    std::string appCertFile = "./hapSign/app-release1.pem";
619    std::string profileFile = "./hapSign/signed-profile.p7b";
620    std::string inFile = "./hapSign/phone-default-unsigned";
621    std::string keystoreFile = "./hapSign/ohtest.p12";
622    std::string outFile = "./hapSign/phone-default-signed.hap";
623    char keyPwd[] = "123456";
624    char keystorePwd[] = "123456";
625
626    (*params)["mode"] = mode;
627    (*params)["keyAlias"] = keyAlias;
628    (*params)["signAlg"] = signAlg;
629    (*params)["signCode"] = signCode;
630    (*params)["appCertFile"] = appCertFile;
631    (*params)["profileFile"] = profileFile;
632    (*params)["inFile"] = inFile;
633    (*params)["keystoreFile"] = keystoreFile;
634    (*params)["outFile"] = outFile;
635    (*params)["keyPwd"] = keyPwd;
636    (*params)["keystorePwd"] = keystorePwd;
637
638    bool ret = signProvider->Sign(params.get());
639    EXPECT_EQ(ret, false);
640}
641
642/*
643 * @tc.name: sign_provider_test_015
644 * @tc.desc: This function tests failure for interface Sign due to parameter signAlg is not support
645 * @tc.type: FUNC
646 * @tc.require:
647 */
648HWTEST_F(SignProviderTest, sign_provider_test_015, testing::ext::TestSize.Level1)
649{
650    SIGNATURE_TOOLS_LOGI("hello world !!!");
651    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
652    std::shared_ptr<Options> params = std::make_shared<Options>();
653
654    std::string mode = "localSign";
655    std::string keyAlias = "oh-app1-key-v1";
656    std::string signAlg = "SHA512withECDSA";
657    std::string signCode = "0";
658    std::string appCertFile = "./hapSign/app-release1.pem";
659    std::string profileFile = "./hapSign/signed-profile.p7b";
660    std::string inFile = "./hapSign/phone-default-unsigned.hap";
661    std::string keystoreFile = "./hapSign/ohtest.p12";
662    std::string outFile = "./hapSign/phone-default-signed.hap";
663    char keyPwd[] = "123456";
664    char keystorePwd[] = "123456";
665
666    (*params)["mode"] = mode;
667    (*params)["keyAlias"] = keyAlias;
668    (*params)["signAlg"] = signAlg;
669    (*params)["signCode"] = signCode;
670    (*params)["appCertFile"] = appCertFile;
671    (*params)["profileFile"] = profileFile;
672    (*params)["inFile"] = inFile;
673    (*params)["keystoreFile"] = keystoreFile;
674    (*params)["outFile"] = outFile;
675    (*params)["keyPwd"] = keyPwd;
676    (*params)["keystorePwd"] = keystorePwd;
677
678    bool ret = signProvider->Sign(params.get());
679    EXPECT_EQ(ret, false);
680}
681
682/*
683 * @tc.name: sign_provider_test_016
684 * @tc.desc: This function tests failure for interface Sign due to parameter profileSigned error
685 * @tc.type: FUNC
686 * @tc.require:
687 */
688HWTEST_F(SignProviderTest, sign_provider_test_016, testing::ext::TestSize.Level1)
689{
690    SIGNATURE_TOOLS_LOGI("hello world !!!");
691    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
692    std::shared_ptr<Options> params = std::make_shared<Options>();
693
694    std::string mode = "localSign";
695    std::string keyAlias = "oh-app1-key-v1";
696    std::string signAlg = "SHA256withECDSA";
697    std::string signCode = "0";
698    std::string appCertFile = "./hapSign/app-release1.pem";
699    std::string profileFile = "./hapSign/signed-profile-nohave.p7b";
700    std::string profileSigned = "1";
701    std::string inFile = "./hapSign/phone-default-unsigned-test.hap";
702    std::string keystoreFile = "./hapSign/ohtest.p12";
703    std::string outFile = "./hapSign/phone-default-signed-test.hap";
704    char keyPwd[] = "123456";
705    char keystorePwd[] = "123456";
706
707    (*params)["mode"] = mode;
708    (*params)["keyAlias"] = keyAlias;
709    (*params)["signAlg"] = signAlg;
710    (*params)["signCode"] = signCode;
711    (*params)["appCertFile"] = appCertFile;
712    (*params)["profileFile"] = profileFile;
713    (*params)["profileSigned"] = profileSigned;
714    (*params)["inFile"] = inFile;
715    (*params)["keystoreFile"] = keystoreFile;
716    (*params)["outFile"] = outFile;
717    (*params)["keyPwd"] = keyPwd;
718    (*params)["keystorePwd"] = keystorePwd;
719
720    bool ret = signProvider->Sign(params.get());
721    EXPECT_EQ(ret, false);
722}
723
724/*
725 * @tc.name: sign_provider_test_017
726 * @tc.desc: This function tests failure for interface Sign due to parameter signAlg is not support
727 * @tc.type: FUNC
728 * @tc.require:
729 */
730HWTEST_F(SignProviderTest, sign_provider_test_017, testing::ext::TestSize.Level1)
731{
732    SIGNATURE_TOOLS_LOGI("hello world !!!");
733    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
734    std::shared_ptr<Options> params = std::make_shared<Options>();
735
736    std::string mode = "localSign";
737    std::string keyAlias = "oh-app1-key-v1";
738    std::string signAlg = "SHA256withECDSA-nohave";
739    std::string signCode = "0";
740    std::string appCertFile = "./hapSign/app-release1.pem";
741    std::string profileFile = "./hapSign/signed-profile.p7b";
742    std::string profileSigned = "1";
743    std::string inFile = "./hapSign/phone-default-unsigned-test.hap";
744    std::string keystoreFile = "./hapSign/ohtest.p12";
745    std::string outFile = "./hapSign/phone-default-signed-test.hap";
746    char keyPwd[] = "123456";
747    char keystorePwd[] = "123456";
748
749    (*params)["mode"] = mode;
750    (*params)["keyAlias"] = keyAlias;
751    (*params)["signAlg"] = signAlg;
752    (*params)["signCode"] = signCode;
753    (*params)["appCertFile"] = appCertFile;
754    (*params)["profileFile"] = profileFile;
755    (*params)["profileSigned"] = profileSigned;
756    (*params)["inFile"] = inFile;
757    (*params)["keystoreFile"] = keystoreFile;
758    (*params)["outFile"] = outFile;
759    (*params)["keyPwd"] = keyPwd;
760    (*params)["keystorePwd"] = keystorePwd;
761
762    bool ret = signProvider->Sign(params.get());
763    EXPECT_EQ(ret, false);
764}
765
766/*
767 * @tc.name: sign_provider_test_018
768 * @tc.desc: This function tests failure for interface Sign due to parameter signCode is 3
769 * @tc.type: FUNC
770 * @tc.require:
771 */
772HWTEST_F(SignProviderTest, sign_provider_test_018, testing::ext::TestSize.Level1)
773{
774    SIGNATURE_TOOLS_LOGI("hello world !!!");
775    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
776    std::shared_ptr<Options> params = std::make_shared<Options>();
777
778    std::string mode = "localSign";
779    std::string keyAlias = "oh-app1-key-v1";
780    std::string signAlg = "SHA256withECDSA";
781    std::string signCode = "3";
782    std::string appCertFile = "./hapSign/app-release1.pem";
783    std::string profileFile = "./hapSign/signed-profile.p7b";
784    std::string inFile = "./hapSign/phone-default-unsigned.hap";
785    std::string keystoreFile = "./hapSign/ohtest.p12";
786    std::string outFile = "./hapSign/phone-default-signed.hap";
787    char keyPwd[] = "123456";
788    char keystorePwd[] = "123456";
789
790    (*params)["mode"] = mode;
791    (*params)["keyAlias"] = keyAlias;
792    (*params)["signAlg"] = signAlg;
793    (*params)["signCode"] = signCode;
794    (*params)["appCertFile"] = appCertFile;
795    (*params)["profileFile"] = profileFile;
796    (*params)["inFile"] = inFile;
797    (*params)["keystoreFile"] = keystoreFile;
798    (*params)["outFile"] = outFile;
799    (*params)["keyPwd"] = keyPwd;
800    (*params)["keystorePwd"] = keystorePwd;
801
802    bool ret = signProvider->Sign(params.get());
803    EXPECT_EQ(ret, false);
804}
805
806/*
807 * @tc.name: sign_provider_test_019
808 * @tc.desc: This function tests failure for interface Sign due to parameter signAlg is empty
809 * @tc.type: FUNC
810 * @tc.require:
811 */
812HWTEST_F(SignProviderTest, sign_provider_test_019, testing::ext::TestSize.Level1)
813{
814    SIGNATURE_TOOLS_LOGI("hello world !!!");
815    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
816    std::shared_ptr<Options> params = std::make_shared<Options>();
817
818    std::string mode = "localSign";
819    std::string keyAlias = "oh-app1-key-v1";
820    std::string signAlg = "";
821    std::string signCode = "1";
822    std::string appCertFile = "./hapSign/app-release1.pem";
823    std::string profileFile = "./hapSign/signed-profile.p7b";
824    std::string inFile = "./hapSign/phone-default-unsigned.hap";
825    std::string keystoreFile = "./hapSign/ohtest.p12";
826    std::string outFile = "./hapSign/phone-default-signed.hap";
827    char keyPwd[] = "123456";
828    char keystorePwd[] = "123456";
829
830    (*params)["mode"] = mode;
831    (*params)["keyAlias"] = keyAlias;
832    (*params)["signAlg"] = signAlg;
833    (*params)["signCode"] = signCode;
834    (*params)["appCertFile"] = appCertFile;
835    (*params)["profileFile"] = profileFile;
836    (*params)["inFile"] = inFile;
837    (*params)["keystoreFile"] = keystoreFile;
838    (*params)["outFile"] = outFile;
839    (*params)["keyPwd"] = keyPwd;
840    (*params)["keystorePwd"] = keystorePwd;
841
842    bool ret = signProvider->Sign(params.get());
843    EXPECT_EQ(ret, false);
844}
845
846/*
847 * @tc.name: sign_provider_test_020
848 * @tc.desc: This function tests failure for interface Sign due to parameter profileFile is empty
849 * @tc.type: FUNC
850 * @tc.require:
851 */
852HWTEST_F(SignProviderTest, sign_provider_test_020, testing::ext::TestSize.Level1)
853{
854    SIGNATURE_TOOLS_LOGI("hello world !!!");
855    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
856    std::shared_ptr<Options> params = std::make_shared<Options>();
857
858    std::string mode = "localSign";
859    std::string keyAlias = "oh-app1-key-v1";
860    std::string signAlg = "SHA256withECDSA";
861    std::string signCode = "1";
862    std::string appCertFile = "./hapSign/app-release1.pem";
863    std::string profileFile = "";
864    std::string inFile = "./hapSign/phone-default-unsigned.hap";
865    std::string keystoreFile = "./hapSign/ohtest.p12";
866    std::string outFile = "./hapSign/phone-default-signed.hap";
867    char keyPwd[] = "123456";
868    char keystorePwd[] = "123456";
869
870    (*params)["mode"] = mode;
871    (*params)["keyAlias"] = keyAlias;
872    (*params)["signAlg"] = signAlg;
873    (*params)["signCode"] = signCode;
874    (*params)["appCertFile"] = appCertFile;
875    (*params)["profileFile"] = profileFile;
876    (*params)["inFile"] = inFile;
877    (*params)["keystoreFile"] = keystoreFile;
878    (*params)["outFile"] = outFile;
879    (*params)["keyPwd"] = keyPwd;
880    (*params)["keystorePwd"] = keystorePwd;
881
882    bool ret = signProvider->Sign(params.get());
883    EXPECT_EQ(ret, false);
884}
885
886/*
887 * @tc.name: sign_provider_test_021
888 * @tc.desc: This function tests failure for interface Sign due to parameter appCertFile is empty
889 * @tc.type: FUNC
890 * @tc.require:
891 */
892HWTEST_F(SignProviderTest, sign_provider_test_021, testing::ext::TestSize.Level1)
893{
894    SIGNATURE_TOOLS_LOGI("hello world !!!");
895    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
896    std::shared_ptr<Options> params = std::make_shared<Options>();
897
898    std::string mode = "localSign";
899    std::string keyAlias = "oh-app1-key-v1";
900    std::string signAlg = "SHA256withECDSA";
901    std::string signCode = "0";
902    std::string appCertFile = "";
903    std::string profileFile = "./hapSign/signed-profile.p7b";
904    std::string profileSigned = "1";
905    std::string inFile = "./hapSign/phone-default-unsigned-test.hap";
906    std::string keystoreFile = "./hapSign/ohtest.p12";
907    std::string outFile = "./hapSign/phone-default-signed-test.hap";
908    char keyPwd[] = "123456";
909    char keystorePwd[] = "123456";
910
911    (*params)["mode"] = mode;
912    (*params)["keyAlias"] = keyAlias;
913    (*params)["signAlg"] = signAlg;
914    (*params)["signCode"] = signCode;
915    (*params)["appCertFile"] = appCertFile;
916    (*params)["profileFile"] = profileFile;
917    (*params)["profileSigned"] = profileSigned;
918    (*params)["inFile"] = inFile;
919    (*params)["keystoreFile"] = keystoreFile;
920    (*params)["outFile"] = outFile;
921    (*params)["keyPwd"] = keyPwd;
922    (*params)["keystorePwd"] = keystorePwd;
923
924    bool ret = signProvider->Sign(params.get());
925    EXPECT_EQ(ret, false);
926}
927
928/*
929 * @tc.name: SignElf_001
930 * @tc.desc: Test function result of SignElf_001 will be SUCCESS.
931 * @tc.type: FUNC
932 * @tc.require:
933 */
934HWTEST_F(SignProviderTest, SignElf_001, testing::ext::TestSize.Level1)
935{
936    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
937    std::shared_ptr<Options> params = std::make_shared<Options>();
938
939    std::string mode = "localSign";
940    std::string keyAlias = "oh-app1-key-v1";
941    std::string signAlg = "SHA256withECDSA";
942    std::string signCode = "1";
943    std::string appCertFile = "./hapSign/app-release1.pem";
944    std::string profileFile = "./hapSign/signed-profile.p7b";
945    std::string inFile = "./codeSigning/unsigned-file.hap";
946    std::string keystoreFile = "./hapSign/ohtest.p12";
947    std::string outFile = "./hapSign/entry-default-signed.elf";
948    std::string inForm = "elf";
949    char keyPwd[] = "123456";
950    char keystorePwd[] = "123456";
951
952    (*params)["mode"] = mode;
953    (*params)["keyAlias"] = keyAlias;
954    (*params)["signAlg"] = signAlg;
955    (*params)["signCode"] = signCode;
956    (*params)["appCertFile"] = appCertFile;
957    (*params)["profileFile"] = profileFile;
958    (*params)["inFile"] = inFile;
959    (*params)["keystoreFile"] = keystoreFile;
960    (*params)["outFile"] = outFile;
961    (*params)["inForm"] = inForm;
962    (*params)["keyPwd"] = keyPwd;
963    (*params)["keystorePwd"] = keystorePwd;
964    bool ret = signProvider->SignElf(params.get());
965
966    EXPECT_NE(ret, -1);
967}
968
969/*
970 * @tc.name: SignElf_002
971 * @tc.desc: The return will be false, because the profileFile is null.
972 * @tc.type: FUNC
973 * @tc.require:
974 */
975HWTEST_F(SignProviderTest, SignElf_002, testing::ext::TestSize.Level1)
976{
977    // profileFile:p7b is null
978    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
979    std::shared_ptr<Options> params = std::make_shared<Options>();
980
981    std::string mode = "localSign";
982    std::string keyAlias = "oh-app1-key-v1";
983    std::string signAlg = "SHA256withECDSA";
984    std::string signCode = "1";
985    std::string appCertFile = "./hapSign/app-release1.pem";
986    std::string inFile = "./codeSigning/unsigned-file.hap";
987    std::string keystoreFile = "./hapSign/ohtest.p12";
988    std::string outFile = "./hapSign/entry-default-signed.elf";
989    std::string inForm = "elf";
990    char keyPwd[] = "123456";
991    char keystorePwd[] = "123456";
992
993    (*params)["mode"] = mode;
994    (*params)["keyAlias"] = keyAlias;
995    (*params)["signAlg"] = signAlg;
996    (*params)["signCode"] = signCode;
997    (*params)["appCertFile"] = appCertFile;
998    (*params)["inFile"] = inFile;
999    (*params)["keystoreFile"] = keystoreFile;
1000    (*params)["outFile"] = outFile;
1001    (*params)["inForm"] = inForm;
1002    (*params)["keyPwd"] = keyPwd;
1003    (*params)["keystorePwd"] = keystorePwd;
1004    bool ret = signProvider->SignElf(params.get());
1005    EXPECT_NE(ret, -1);
1006}
1007
1008/*
1009 * @tc.name: SignElf_003
1010 * @tc.desc: The return will be false, because the compatibleVersion is null.
1011 * @tc.type: FUNC
1012 * @tc.require:
1013 */
1014HWTEST_F(SignProviderTest, SignElf_003, testing::ext::TestSize.Level1)
1015{
1016    // compatibleVersion is null
1017    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
1018    std::shared_ptr<Options> params = std::make_shared<Options>();
1019
1020    std::string mode = "localSign";
1021    std::string keyAlias = "oh-app1-key-v1";
1022    std::string signAlg = "SHA256withECDSA";
1023    std::string signCode = "1";
1024    std::string appCertFile = "./hapSign/app-release1.pem";
1025    std::string profileFile = "./hapSign/signed-profile.p7b";
1026    std::string inFile = "./codeSigning/unsigned-file.hap";
1027    std::string keystoreFile = "./hapSign/ohtest.p12";
1028    std::string outFile = "./hapSign/entry-default-signed.elf";
1029    std::string inForm = "elf";
1030    char keyPwd[] = "123456";
1031    char keystorePwd[] = "123456";
1032    std::string compatibleVersion = "";
1033
1034    (*params)["mode"] = mode;
1035    (*params)["keyAlias"] = keyAlias;
1036    (*params)["signAlg"] = signAlg;
1037    (*params)["signCode"] = signCode;
1038    (*params)["appCertFile"] = appCertFile;
1039    (*params)["profileFile"] = profileFile;
1040    (*params)["inFile"] = inFile;
1041    (*params)["keystoreFile"] = keystoreFile;
1042    (*params)["outFile"] = outFile;
1043    (*params)["inForm"] = inForm;
1044    (*params)["keyPwd"] = keyPwd;
1045    (*params)["keystorePwd"] = keystorePwd;
1046    (*params)["compatibleVersion"] = compatibleVersion;
1047    bool ret = signProvider->SignElf(params.get());
1048    EXPECT_EQ(ret, false);
1049}
1050
1051/*
1052 * @tc.name: SignElf_004
1053 * @tc.desc: The return will be false, because the inFile is null.
1054 * @tc.type: FUNC
1055 * @tc.require:
1056 */
1057HWTEST_F(SignProviderTest, SignElf_004, testing::ext::TestSize.Level1)
1058{
1059    // inFile is null
1060    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
1061    std::shared_ptr<Options> params = std::make_shared<Options>();
1062
1063    std::string mode = "localSign";
1064    std::string keyAlias = "oh-app1-key-v1";
1065    std::string signAlg = "SHA256withECDSA";
1066    std::string signCode = "1";
1067    std::string appCertFile = "./hapSign/app-release1.pem";
1068    std::string profileFile = "./hapSign/signed-profile.p7b";
1069    std::string inFile = "";
1070    std::string keystoreFile = "./hapSign/ohtest.p12";
1071    std::string outFile = "./hapSign/entry-default-signed.elf";
1072    std::string inForm = "elf";
1073    char keyPwd[] = "123456";
1074    char keystorePwd[] = "123456";
1075
1076    (*params)["mode"] = mode;
1077    (*params)["keyAlias"] = keyAlias;
1078    (*params)["signAlg"] = signAlg;
1079    (*params)["signCode"] = signCode;
1080    (*params)["appCertFile"] = appCertFile;
1081    (*params)["profileFile"] = profileFile;
1082    (*params)["inFile"] = inFile;
1083    (*params)["keystoreFile"] = keystoreFile;
1084    (*params)["outFile"] = outFile;
1085    (*params)["inForm"] = inForm;
1086    (*params)["keyPwd"] = keyPwd;
1087    (*params)["keystorePwd"] = keystorePwd;
1088
1089    bool ret = signProvider->SignElf(params.get());
1090    EXPECT_EQ(ret, false);
1091}
1092
1093/*
1094 * @tc.name: SignElf_005
1095 * @tc.desc: The return will be false, because the inFile path is error.
1096 * @tc.type: FUNC
1097 * @tc.require:
1098 */
1099HWTEST_F(SignProviderTest, SignElf_005, testing::ext::TestSize.Level1)
1100{
1101    // inFile path is false
1102    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
1103    std::shared_ptr<Options> params = std::make_shared<Options>();
1104
1105    std::string mode = "localSign";
1106    std::string keyAlias = "oh-app1-key-v1";
1107    std::string signAlg = "SHA256withECDSA";
1108    std::string signCode = "1";
1109    std::string appCertFile = "./hapSign/app-release1.pem";
1110    std::string profileFile = "./hapSign/signed-profile.p7b";
1111    std::string inFile = "./hapSign_test/unsigned-file.hap";
1112    std::string keystoreFile = "./hapSign/ohtest.p12";
1113    std::string outFile = "./hapSign/entry-default-signed.elf";
1114    std::string inForm = "elf";
1115    char keyPwd[] = "123456";
1116    char keystorePwd[] = "123456";
1117
1118    (*params)["mode"] = mode;
1119    (*params)["keyAlias"] = keyAlias;
1120    (*params)["signAlg"] = signAlg;
1121    (*params)["signCode"] = signCode;
1122    (*params)["appCertFile"] = appCertFile;
1123    (*params)["profileFile"] = profileFile;
1124    (*params)["inFile"] = inFile;
1125    (*params)["keystoreFile"] = keystoreFile;
1126    (*params)["outFile"] = outFile;
1127    (*params)["inForm"] = inForm;
1128    (*params)["keyPwd"] = keyPwd;
1129    (*params)["keystorePwd"] = keystorePwd;
1130    bool ret = signProvider->SignElf(params.get());
1131    EXPECT_EQ(ret, false);
1132}
1133
1134/*
1135 * @tc.name: SignElf_006
1136 * @tc.desc: The return will be false, because the signAlg format does not support.
1137 * @tc.type: FUNC
1138 * @tc.require:
1139 */
1140HWTEST_F(SignProviderTest, SignElf_006, testing::ext::TestSize.Level1)
1141{
1142    // signAlg format is false
1143    std::unique_ptr<SignProvider> signProvider = std::make_unique<LocalSignProvider>();
1144    std::shared_ptr<Options> params = std::make_shared<Options>();
1145
1146    std::string mode = "localSign";
1147    std::string keyAlias = "oh-app1-key-v1";
1148    std::string signAlg = "SHA512withECDSA";
1149    std::string signCode = "1";
1150    std::string appCertFile = "./hapSign/app-release1.pem";
1151    std::string profileFile = "./hapSign/signed-profile.p7b";
1152    std::string inFile = "./codeSigning/unsigned-file.hap";
1153    std::string keystoreFile = "./hapSign/ohtest.p12";
1154    std::string outFile = "./hapSign/entry-default-signed.elf";
1155    std::string inForm = "elf";
1156    char keyPwd[] = "123456";
1157    char keystorePwd[] = "123456";
1158
1159    (*params)["mode"] = mode;
1160    (*params)["keyAlias"] = keyAlias;
1161    (*params)["signAlg"] = signAlg;
1162    (*params)["signCode"] = signCode;
1163    (*params)["appCertFile"] = appCertFile;
1164    (*params)["profileFile"] = profileFile;
1165    (*params)["inFile"] = inFile;
1166    (*params)["keystoreFile"] = keystoreFile;
1167    (*params)["outFile"] = outFile;
1168    (*params)["inForm"] = inForm;
1169    (*params)["keyPwd"] = keyPwd;
1170    (*params)["keystorePwd"] = keystorePwd;
1171    bool ret = signProvider->SignElf(params.get());
1172    EXPECT_EQ(ret, false);
1173}
1174} // namespace SignatureTools
1175} // namespace OHOS
1176