• Home
Name Date Size #Lines LOC

..--

autosign/12-May-2024-882664

dist/12-May-2024-221211

figures/12-May-2024-

hapsigntool/12-May-2024-22,91112,935

tools/12-May-2024-1,2811,175

.gitignoreD12-May-202469 97

BUILD.gnD12-May-20241.1 KiB3229

LICENSED12-May-202411.1 KiB203169

NOTICED12-May-202437.2 KiB726601

OAT.xmlD12-May-20243.8 KiB6548

README.mdD12-May-202422.8 KiB330255

README_ZH.mdD12-May-202420.1 KiB305242

README.md

1# hapsigner
2
3## Introduction
4
5To ensure that all apps and binary tools (such as lldb-server) come from a known and approved source and have not been tampered with, OpenHarmony requires that all executable code be signed. Only signed apps and binary tools can be installed, run, and debugged on real devices.
6
7The repository provides the source code of the signing tool named hapsigner, which provides the functions such as generating a key pair, a certificate signing request (CSR), or a certificate, and signing a profile, a Harmony Ability Package (HAP), or a binary tool.
8The mandatory code signing mechanism provides validity check and integrity protection for apps in runtime, eliminating execution of malicious code on devices and malicious tampering of app code by attackers.
9
10Code signing is enabled by default for hapsigner. If you do not need the mandatory code signing feature, you can disable it as required. Currently, hapsigner supports code signing only for apps in hap format and binary tools.
11
12
13## Directory Structure
14
15    developtools_hapsigner
16
17    ├── autosign                # Script for one-click signing.
18    ├── dist                    # SDK preconfigured file.
19    ├── hapsigntool             # Code of the hapsigner tool.
20          ├──hap_sign_tool      # Entry of the hapsigner tool, used to verify input parameters.
21          ├──hap_sign_tool_lib  # Lib of the hapsigner tool, used to parse command words and parameter lists to implement logic of modules.
22    ├── tools                   # Auto-test script.
23
24
25
26## Constraints
27- The hapsigner tool is developed in Java and must run in JRE 8.0 or later.
28- The scripts, such as the one-click signing script, are developed in Python, and must run on Python 3.5 or later.
29
30## Build
31
32 1. Check that Gradle 7.1 has been installed.
33
34        gradle -v
35
36 2. Download the code, open the directory **developtools_hapsigner/hapsigntool**, and run the following command to build the code:
37
38        gradle build or gradle jar
39
40 3. Check that **hap-sign-tool.jar** (binary files) is generated in the **./hap_sign_tool/build/libs** directory.
41
42
43## Usage
44### Files Related to Signing
45
46When signing an app using the IDE, you will obtain the following files from the SDK:
47
48```
49KeyStore (KS) file: OpenHarmony.p12
50Profile signing certificates: OpenHarmonyProfileRelease.pem and OpenHarmonyProfileDebug.pem
51Profile templates: UnsgnedReleasedProfileTemplate.json and UnsgnedDebugProfileTemplate.json
52Signing tool: hap-sign-tool.jar
53```
54The figures below illustrate how these files are used.
55
56**Signing a Profile**
57
58![signprofile.png](figures/signprofile_en.png)
59
60**Signing an App**
61
62![signapp.png](figures/signapp_en.png)
63### Usage Guidelines
64
65In the following, the .jar package is the binary files built.
66
67#### Using Commands
68You can use commands to sign a profile and a HAP or binary tool.
69
701. Sign a profile.
71
72
73```shell
74java -jar hap-sign-tool.jar  sign-profile -keyAlias "oh-profile1-key-v1" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "result\profile1.pem" -inFile "app1-profile-release.json" -keystoreFile "result\ohtest.jks" -outFile "result\app1-profile.p7b" -keyPwd "123456" -keystorePwd "123456"
75```
76The parameters in the command are described as follows:
77
78    sign-profile: Sign a provisioning profile.
79         ├── -mode              # Signing mode, which can be localSign or remoteSign. It is mandatory.
80         ├── -keyAlias          # Key alias. It is mandatory.
81         ├── -keyPwd            # Key password. It is optional.
82         ├── -profileCertFile   # Profile signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
83         ├── -inFile            # Provisioning profile to be signed. It is mandatory.
84         ├── -signAlg           # Signing algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
85         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
86         ├── -keystorePwd       # KS password. It is optional.
87         ├── -outFile           # Signed provisioning profile to generate, in p7b format. It is mandatory.
88
89
90
912. Sign a HAP or binary tool.
92
93
94```shell
95java -jar hap-sign-tool.jar sign-app -keyAlias "oh-app1-key-v1" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "result\app1.pem" -profileFile "result\app1-profile.p7b" -inFile "app1-unsigned.zip" -keystoreFile "result\ohtest.jks" -outFile "result\app1-unsigned.hap" -keyPwd "123456" -keystorePwd "123456" -signCode "1"
96```
97The parameters in the command are described as follows:
98
99    sign-app: sign a HAP or binary tool
100         ├── -mode              # Signing mode, which can be localSign or remoteSign. It is mandatory.
101         ├── -keyAlias          # Key alias. It is mandatory.
102         ├── -keyPwd            # Key password. It is optional.
103         ├── -appCertFile       # App signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
104         ├── -profileFile       # Signed provisioning profile in p7b format. This parameter is mandatory for a HAP and optional for a binary tool.
105         ├── -profileSigned     # Whether the profile is signed. The value 1 means the profile is signed, and the value 0 means the opposite. The default value is 1. This parameter is optional.
106         ├── -inForm            # Format of the file to be signed. The value can be zip, elf, or bin. It is zip for a HAP, elf for a binary tool, and bin for a program running on the small system. In case of code signing, it can be zip or elf. The default value is zip. This parameter is optional.
107         ├── -inFile            # File to be signed, which can be a HAP or an ELF or bin file. This parameter is mandatory.
108         ├── -signAlg           # Signing algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
109         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
110         ├── -keystorePwd       # KS password. It is optional.
111         ├── -outFile           # Signed HAP to generate. It is mandatory.
112         ├── -signCode          # Whether to enable code signing. The value 1 means to enable code signing; the value 0 means the opposite. The default value is 1. This parameter is optional.
113
114#### Performing One-Click Signing
115
116
117To improve development efficiency, this project also provides scripts for one-click signing. You can use the scripts to easily generate a key pair or an end-entity certificate and sign a profile, HAP, or binary tool without entering complex commands.
118The following scripts and configuration files are located in the **autosign** directory:
119
120 - create_root.sh/create_root.bat
121 - create_appcert_sign_profile.sh/create_appcert_sign_profile.bat
122 - sign_hap.sh/sign_hap.bat
123 - sign_elf.sh/sign_elf.bat
124 - createAppCertAndProfile.config
125 - createRootAndSubCert.config
126 - signHap.config
127 - signElf.config
128
129**Procedure**
1301. Check that Python 3.5 or later is available.
1312. Obtain **hap-sign-tool.jar**. For details, see section **Build**.
1323. Check that the HAP, binary tool, or provisioning profile to be signed is available.
1334. Use the text editor to open **createAppCertAndProfile.config**, **signElf.config**, and **signHap.config** and change the values of **common.keyPwd** and **common.issuerKeyPwd** to match your case.
1345. Run **create_appcert_sign_profile.sh** on Linux or **create_appcert_sign_profile.bat** on Windows to generate the files required for signing.
1356. Run **sign_hap.sh** on Linux or **sign_hap.bat** on Windows to sign the HAP. Run **sign_elf.sh** on Linux or **sign_elf.bat** on Windows to sign the binary tool.
136
137 > **NOTE**
138 >
139 > To generate a KS file, root CA certificate, intermediate CA certificate, and profile signing certificate, perform the following steps:
140 1. Use the text editor to open the **createRootAndSubCert.config** file and change the values of **common.keyPwd** and **common.issuerKeyPwd** to match your case.
141 2. Run **create_root.sh** on Linux or run **create_root.bat** on Windows to generate the required KS file, root CA certificate, intermediate CA certificate, and profile signing certificate.
142
143****
144### Common Operations
1451. Generate a key pair.
146
147     ```
148     generate-keypair: Generate a key pair.
149         ├── -keyAlias          # Key alias. It is mandatory.
150         ├── -keyPwd            # Key password. It is optional.
151         ├── -keyAlg            # Key algorithm, which can be RSA or ECC. It is mandatory.
152         ├── -keySize           # Key length. It is mandatory. The key length is 2048, 3072, or 4096 bits if RSA is used and is NIST-P-256 or NIST-P-384 if ECC is used.
153         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory.
154         ├── -keystorePwd       # KS password. It is optional.
155     ```
156
157
1582. Generate a CSR.
159
160    ```
161    generate-csr: Generate a CSR.
162         ├── -keyAlias          # Key alias. It is mandatory.
163         ├── -keyPwd            # Key password. It is optional.
164         ├── -subject           # Certificate subject. It is mandatory.
165         ├── -signAlg           # Signing algorithm, which can be SHA256withRSA, SHA384withRSA, SHA256withECDSA, or SHA384withECDSA. It is mandatory.
166         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory.
167         ├── -keystorePwd       # KS password. It is optional.
168         ├── -outFile           # CSR to generate. It is optional. If you do not specify this parameter, the CSR is output to the console.
169    ```
170
171
1723. Generate a root CA or intermediate CA certificate.
173
174    ```
175    generate-ca: Generate a root CA or intermediate CA certificate. If the key does not exist, generate a key together with the certificate.
176         ├── -keyAlias                  # Key alias. It is mandatory.
177         ├── -keyPwd                    # Key password. It is optional.
178         ├── -keyAlg                    # Key algorithm, which can be RSA or ECC. It is mandatory.
179         ├── -keySize                   # Key length. It is mandatory. The key length is 2048, 3072, or 4096 bits if RSA is used and is NIST-P-256 or NIST-P-384 if ECC is used.
180         ├── -issuer                    # Issuer of the certificate. It is optional. It indicates a root CA certificate if not specified.
181         ├── -issuerKeyAlias            # Key alias of the issuer. It is optional. It indicates a root CA certificate if not specified.
182         ├── -issuerKeyPwd              # Key password of the issuer. It is optional.
183         ├── -subject                   # Certificate subject. It is mandatory.
184         ├── -validity                  # Validity period of the certificate. It is optional. The default value is 3650 days.
185         ├── -signAlg                   # Signing algorithm, which can be SHA256withRSA, SHA384withRSA,  SHA256withECDSA, or SHA384withECDSA. It is mandatory.
186         ├── -basicConstraintsPathLen   # Path length. It is optional. The default value is 0.
187         ├── -issuerKeystoreFile        # KS file of the issuer, in JKS or P12 format. It is optional.
188         ├── -issuerKeystorePwd         # KS password of the issuer. It is optional.
189         ├── -keystoreFile              # KS file, in JKS or P12 format. It is mandatory.
190         ├── -keystorePwd               # KS password. It is optional.
191         ├── -outFile                   # File to generate. It is optional. The file is output to the console if this parameter is not specified.
192    ```
193
194
1954. Generate an app debug or release certificate.
196
197    ```
198    generate-app-cert: Generate an app debug or release certificate.
199         ├── -keyAlias                        # Key alias. It is mandatory.
200         ├── -keyPwd                          # Key password. It is optional.
201         ├── -issuer                          # Issuer of the certificate. It is mandatory.
202         ├── -issuerKeyAlias                  # Key alias of the issuer. It is mandatory.
203         ├── -issuerKeyPwd                    # Key password of the issuer. It is optional.
204         ├── -subject                         # Certificate subject. It is mandatory.
205         ├── -validity                        # Validity period of the certificate. It is optional. The default value is 3650 days.
206         ├── -signAlg                         # Signing algorithm, which can be SHA256withECDSA or SHA384withECDSA.
207         ├── -keystoreFile                    # KS file, in JKS or P12 format. It is mandatory.
208         ├── -keystorePwd                     # KS password. It is optional.
209         ├── -issuerKeystoreFile              # KS file of the issuer, in JKS or P12 format. It is optional.
210         ├── -issuerKeystorePwd               # KS password of the issuer. It is optional.
211         ├── -outForm                         # Format of the certificate to generate. It is optional. The value can be cert or certChain. The default value is certChain.
212         ├── -rootCaCertFile                  # Root CA certificate, which is mandatory when outForm is certChain.
213         ├── -subCaCertFile                   # Intermediate CA certificate file, which is mandatory when outForm is certChain.
214         ├── -outFile                         # Certificate file (certificate or certificate chain) to generate. It is optional. The file is output to the console if this parameter is not specified.
215    ```
216
217
2185. Generate a profile debug or release certificate.
219
220    ```
221    generate-profile-cert: Generate a profile debug or release certificate.
222         ├── -keyAlias                        # Key alias. It is mandatory.
223         ├── -keyPwd                          # Key password. It is optional.
224         ├── -issuer                          # Issuer of the certificate. It is mandatory.
225         ├── -issuerKeyAlias                  # Key alias of the issuer. It is mandatory.
226         ├── -issuerKeyPwd                    # Key password of the issuer. It is optional.
227         ├── -subject                         # Certificate subject. It is mandatory.
228         ├── -validity                        # Validity period of the certificate. It is optional. The default value is 3650 days.
229         ├── -signAlg                         # Signing algorithm, which can be SHA256withECDSA or SHA384withECDSA.
230         ├── -keystoreFile                    # KS file, in JKS or P12 format. It is mandatory.
231         ├── -keystorePwd                     # KS password. It is optional.
232         ├── -issuerKeystoreFile              # KS file of the issuer, in JKS or P12 format. It is optional.
233         ├── -issuerKeystorePwd               # KS password of the issuer. It is optional.
234         ├── -outForm                         # Format of the certificate to generate. It is optional. The value can be cert or certChain. The default value is certChain.
235         ├── -rootCaCertFile                  # Root CA certificate, which is mandatory when outForm is certChain.
236         ├── -subCaCertFile                   # Intermediate CA certificate file, which is mandatory when outForm is certChain.
237         ├── -outFile                         # Certificate file (certificate or certificate chain) to generate. It is optional. The file is output to the console if this parameter is not specified.
238    ```
239
240
2416. Generate a common certificate, which can be used to generate a custom certificate.
242
243    ```
244    generate-cert: Generate a common certificate, which can be used to generate a custom certificate.
245          ├── -keyAlias                         # Key alias. It is mandatory.
246          ├── -keyPwd                           # Key password. It is optional.
247          ├── -issuer                           # Issuer of the certificate. It is mandatory.
248          ├── -issuerKeyAlias                   # Key alias of the issuer. It is mandatory.
249          ├── -issuerKeyPwd                     # Key password of the issuer. It is optional.
250          ├── -subject                          # Certificate subject. It is mandatory.
251          ├── -validity                         # Validity period of the certificate. It is optional. The default value is 1095 days.
252          ├── -keyUsage                         # Usages of the key. It is mandatory. The key usages include digitalSignature, nonRepudiation, keyEncipherment,
253          ├                                        dataEncipherment, keyAgreement, certificateSignature, crlSignature,
254          ├                                        encipherOnly, and decipherOnly. Use a comma (,) to separate multiple values.
255          ├── -keyUsageCritical                 # Whether keyUsage is a critical option. It is optional. The default value is true.
256          ├── -extKeyUsage                      # Extended key usages. It is optional. The extended key usages include clientAuthentication, serverAuthentication,
257          ├                                        codeSignature, emailProtection, smartCardLogin, timestamp, and ocspSignature.
258          ├── -extKeyUsageCritical              # Whether extKeyUsage is a critical option. It is optional. The default value is false.
259          ├── -signAlg                          # Signing algorithm, which can be SHA256withRSA, SHA384withRSA,  SHA256withECDSA, or SHA384withECDSA. It is mandatory.
260          ├── -basicConstraints                 # Whether basicConstraints is contained. It is optional. The default value is false.
261          ├── -basicConstraintsCritical         # Whether basicConstraints is a critical option. It is optional. The default value is false.
262          ├── -basicConstraintsCa               # Whether it is a CA. It is optional. The default value is false.
263          ├── -basicConstraintsPathLen          # Path length. It is optional. The default value is 0.
264          ├── -issuerKeystoreFile               # KS file of the issuer, in JKS or P12 format. It is optional.
265          ├── -issuerKeystorePwd                # KS password of the issuer. It is optional.
266          ├── -keystoreFile                     # KS file, in JKS or P12 format. It is mandatory.
267          ├── -keystorePwd                      # KS password. It is optional.
268          ├── -outFile                          # Certificate file to generate. It is optional. The file is output to the console if this parameter is not specified.
269    ```
270
271
2727. Sign a provisioning profile.
273
274    ```
275    sign-profile: Sign a provisioning profile.
276          ├── -mode            # Signing mode, which can be localSign or remoteSign. It is mandatory.
277          ├── -keyAlias        # Key alias. It is mandatory.
278          ├── -keyPwd          # Key password. It is optional.
279          ├── -profileCertFile # Profile signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
280          ├── -inFile          # Provisioning profile to be signed. It is mandatory.
281          ├── -signAlg         # Signing algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
282          ├── -keystoreFile    # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
283          ├── -keystorePwd     # KS password. It is optional.
284          ├── -outFile         # Signed provisioning profile to generate, in p7b format. It is mandatory.
285    ```
286
287
2888. Verify the provisioning profile signature.
289
290     ```
291     verify-profile: Verify the provisioning profile signature.
292           ├── -inFile       # Signed provisioning profile, in p7b format. It is mandatory.
293           ├── -outFile      # Verification result file (including the verification result and profile content), in json format. It is optional. The verification result is output to the console if this parameter is not specified.
294     ```
295
296
2979. Sign a HAP or binary tool
298
299     ```
300     sign-app: sign a HAP or binary tool
301          ├── -mode          # Signing mode, which can be localSign, remoteSign, or remoteResign. It is mandatory.
302          ├── -keyAlias      # Key alias. It is mandatory.
303          ├── -keyPwd        # Key password. It is optional.
304          ├── -appCertFile   # App signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
305          ├── -profileFile   # Name of the signed provisioning profile. When profileSigned is 1, the file is in p7b format. When profileSigned is 0, the file is in JSON format. This parameter is mandatory for a HAP and optional for a binary tool.
306          ├── -profileSigned # Whether the profile is signed. The value 1 means the profile is signed, and the value 0 means the opposite. The default value is 1. This parameter is optional.
307          ├── -inForm        # Format of the file to be signed. The value can be zip, elf, or bin. It is zip for a HAP, elf for a binary tool, and bin for a program running on the small system. In case of code signing, it can be zip or elf. The default value is zip. This parameter is optional.
308          ├── -inFile        # File to be signed, which can be a HAP or an ELF or bin file. This parameter is mandatory.
309          ├── -signAlg       # Signing algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
310          ├── -keystoreFile  # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
311          ├── -keystorePwd   # KS password. It is optional.
312          ├── -outFile       # Signed HAP to generate. It is mandatory.
313          ├── -signCode      # Whether to enable code signing. The value 1 means to enable code signing; the value 0 means the opposite. The default value is 1. This parameter is optional.
314     ```
315
316
31710. Verify the signature of a HAP or a binary tool.
318
319    ```
320      verify-app: verify the signature of a HAP or a binary tool.
321         ├── -inFile          # Signed file, which can be a HAP, an ELF file, or a bin file. This parameter is mandatory.
322         ├── -outCertchain    # Signed certificate chain file. It is mandatory.
323         ├── -outProfile      # Profile of the app. It is mandatory.
324         ├── -inForm          # Format of the file to be signed. The value can be zip, elf, or bin. It is zip for a HAP, elf for a binary tool, and bin for a program running on the small system. In case of code signing, it can be zip or elf. The default value is zip. This parameter is optional.
325    ```
326
327
328## Repositories Involved
329   N/A
330

README_ZH.md

1# Hap包签名工具
2
3* 简介
4* 目录
5* 约束
6* 编译构建
7* 说明
8  * 签名相关文件用法说明
9  * 使用说明
10  * 接口说明
11* 相关仓
12
13#### 简介
14
15为了保证OpenHarmony应用和二进制工具(如:lldb-server)的完整性和来源可靠,需要对应用和二进制工具进行签名。经过签名的应用和二进制工具才能在真机设备上安装、运行和调试。本仓提供了签名工具的源码,包含密钥对生成、CSR文件生成、证书生成、Profile文件签名、Hap包签名、二进制工具签名等功能。
16在支持强制代码签名机制的设备上,该机制可以为应用提供运行时的合法性校验以及完整性保护,杜绝未经审核的恶意代码在端侧任意执行,或应用代码被攻击者恶意篡改。
17签名工具默认开启代码签名,若用户确定不需要强制执行代码签名,可参考以下说明,关闭代码签名功能。签名工具当前仅支持对hap格式应用和二进制工具执行代码签名。
18
19
20#### 目录
21
22    developtools_hapsigner
23
24    ├── autosign                # 一键签名脚本
25	├── dist                    # SDK预置文件
26    ├── hapsigntool             # 主代码
27          ├──hap_sign_tool      # 主程序入口,完成输入参数的基础校验
28          ├──hap_sign_tool_lib  # 签名工具库,解析命令字和参数列表,实现各模块逻辑功能
29    ├── tools                   # 自动化测试脚本
30
31
32
33#### 约束
34- Hap包签名工具基于Java语言开发,需要在Java8以上Java环境运行。
35- 一键签名等脚本文件基于Python语言开发,使用需配置环境python3.5及以上。
36#### 编译构建
37
38 1. 该工具基于Gradle 7.1编译构建,请确认环境已安装配置Gradle环境,并且版本正确
39
40        gradle -v
41
42 2. 下载代码,命令行打开文件目录至developtools_hapsigner/hapsigntool,执行命令进行编译打包
43
44        gradle build 或者 gradle jar
45
46 3. 编译后得到二进制文件,目录为: ./hap_sign_tool/build/libs/hap-sign-tool.jar
47
48****
49#### 说明
50##### 签名相关文件用法说明
51
52开发者通过IDE进行应用签名时,可在SDK中会获得如下签名相关文件:
53
54```
55签名密钥库文件:OpenHarmony.p12
56Profile签名证书:OpenHarmonyProfileRelease.pemOpenHarmonyProfileDebug.pem
57Profile模板文件:UnsgnedReleasedProfileTemplate.jsonUnsgnedDebugProfileTemplate.json
58签名工具:hap-sign-tool.jar
59```
60上述文件的使用场景如下图所示。
61
62**Profile签名场景:**
63
64![signprofile.png](figures/signprofile_zh.png)
65
66**应用签名场景:**
67
68![signapp.png](figures/signapp_zh.png)
69##### 使用说明
70
71以下说明中使用jar包为编译构建中生成的二进制文件
72
731.命令行签名
74   命令行签名分为profile文件签名和hap包或二进制工具签名。
75
76   (1)签名profile文件的命令实例如下:
77
78
79```shell
80java -jar hap-sign-tool.jar  sign-profile -keyAlias "oh-profile1-key-v1" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "result\profile1.pem" -inFile "app1-profile-release.json" -keystoreFile "result\ohtest.jks" -outFile "result\app1-profile.p7b" -keyPwd "123456" -keystorePwd "123456"
81```
82该命令的参数说明如下:
83
84    sign-profile : ProvisionProfile文件签名
85         ├── -mode              #签名模式,必填项,包括localSign,remoteSign
86         ├── -keyAlias          #密钥别名,必填项
87         ├── -keyPwd            #密钥口令,可选项
88         ├── -profileCertFile   #Profile签名证书(证书链,顺序为实体证书-中间CA证书-根证书),必填项
89         ├── -inFile            #输入的原始Provision Profile文件,必填项
90         ├── -signAlg           #签名算法,必填项,包括 SHA256withECDSA / SHA384withECDSA
91         ├── -keystoreFile      #密钥库文件,localSign模式时为必填项,JKS或P12格式
92         ├── -keystorePwd       #密钥库口令,可选项
93         ├── -outFile           #输出签名后的Provision Profile文件,p7b格式,必填项
94
95
96
97(2)签名Hap包或二进制工具的命令实例如下:
98
99
100```shell
101java -jar hap-sign-tool.jar sign-app -keyAlias "oh-app1-key-v1" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "result\app1.pem" -profileFile "result\app1-profile.p7b" -inFile "app1-unsigned.zip" -keystoreFile "result\ohtest.jks" -outFile "result\app1-unsigned.hap" -keyPwd "123456" -keystorePwd "123456" -signCode "1"
102```
103该命令的参数说明如下:
104
105    sign-app : hap应用包和二进制工具签名
106         ├── -mode              #签名模式,必填项,包括localSign,remoteSign
107         ├── -keyAlias          #密钥别名,必填项
108         ├── -keyPwd            #密钥口令,可选项
109         ├── -appCertFile       #应用签名证书文件(证书链,顺序为实体证书-中间CA证书-根证书),必填项
110         ├── -profileFile       #签名后的Provision Profile文件名,p7b格式,应用包签名必填项,二进制工具签名选填
111         ├── -profileSigned     #指示profile文件是否带有签名,1表示有签名,0表示没有签名,默认为1。可选项
112         ├── -inForm            #输入的原始文件的格式,枚举值:zip、elf或bin;zip和elf支持代码签名,hap 应用包对应zip,二进制工具对应elf,默认zip;可选项
113         ├── -inFile            #输入的原始文件,hap应用、elf或bin文件,必填项
114         ├── -signAlg           #签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA
115         ├── -keystoreFile      #密钥库文件,localSign模式时为必填项,JKS或P12格式
116         ├── -keystorePwd       #密钥库口令,可选项
117         ├── -outFile           #输出签名后的包文件,必填项
118         ├── -signCode          #是否启用代码签名,1表示开启代码签名,0表示关闭代码签名,默认为1。可选项
119
1202.一键签名
121
122
123为降低学习成本,提高开发效率,本项目还将基于应用签名工具提供一键签名脚本,免于输入繁杂的参数命令,脚本内容包括生成密钥对、实体证书、签名profile包、签名hap包和二进制工具的命令。
124脚本以及配置文件位于目录 autosign 下:
125
126 - create_root.sh/create_root.bat
127 - create_appcert_sign_profile.sh/create_appcert_sign_profile.bat
128 - sign_hap.sh/sign_hap.bat
129 - sign_elf.sh/sign_elf.bat
130 - createAppCertAndProfile.config
131 - createRootAndSubCert.config
132 - signHap.config
133 - signElf.config
134
135使用指导:
1361. 准备依赖环境 python3.5 以上
1372. 准备签名工具jar包:hap-sign-tool.jar(参照上文编译生成的产物)
1383. 准备待签名的应用hap包、二进制工具和 Provision profile 模板文件
1394. 使用文本编辑器编辑 createAppCertAndProfile.configsignElf.configsignHap.config,修改配置文件中的配置信息:common.keyPwdcommon.issuerKeyPwd 参数值改成自己定义的口令信息
1405. Linux运行 create_appcert_sign_profile.sh、Windows运行 create_appcert_sign_profile.bat 生成签名所需文件
1416. Linux运行 sign_hap.sh、Windows运行 sign_hap.bat 对hap包进行签名;Linux运行 sign_elf.sh、Windows运行 sign_elf.bat 对二进制工具进行签名
142
143 > 说明:如需自定义生成密钥库文件,根CA,中间CA证书,profile签名证书,可执行以下步骤
144 1.使用文本编辑器编辑 createRootAndSubCert.config 修改配置文件中的配置信息:common.keyPwdcommon.issuerKeyPwd 参数值改成自己定义的口令信息
145 2.Linux运行 create_root.sh、Windows运行 create_root.bat 生成所需密钥库文件,根CA,中间CA证书,profile签名证书
146
147
148****
149##### 接口说明
1501.生成密钥对
151
152     generate-keypair : 生成密钥对
153         ├── -keyAlias          # 密钥别名,必填项
154         ├── -keyPwd            # 密钥口令,可选项
155         ├── -keyAlg            # 密钥算法,必填项,包括RSA/ECC
156         ├── -keySize           # 密钥长度,必填项,RSA算法的长度为2048/3072/4096,ECC算法的长度NIST-P-256/NIST-P-384
157         ├── -keystoreFile      # 密钥库文件,必填项,JKS或P12格式
158         ├── -keystorePwd       # 密钥库口令,可选项
159
1602.生成证书签名请求
161
162    generate-csr : 生成证书签名请求
163         ├── -keyAlias          # 密钥别名,必填项
164         ├── -keyPwd            # 密钥口令,可选项
165         ├── -subject           # 证书主题,必填项
166         ├── -signAlg           # 签名算法,必填项,包括SHA256withRSA / SHA384withRSA / SHA256withECDSA / SHA384withECDSA
167         ├── -keystoreFile      # 密钥库文件,必填项,JKS或P12格式
168         ├── -keystorePwd       # 密钥库口令,可选项
169         ├── -outFile           # 输出文件,可选项,如果不填,则直接输出到控制台
170
1713.生成根CA/中间CA证书
172
173    generate-ca : 生成根CA/中间CA证书,如果密钥不存在,一起生成密钥
174         ├── -keyAlias                        # 密钥别名,必填项
175         ├── -keyPwd                          # 密钥口令,可选项
176         ├── -keyAlg                          # 密钥算法,必填项,包括RSA/ECC
177         ├── -keySize                         # 密钥长度,必填项,RSA算法的长度为2048/3072/4096,ECC算法的长度NIST-P-256/NIST-P-384
178         ├── -issuer                          # 颁发者的主题,可选项,如果不填,表示根CA
179         ├── -issuerKeyAlias                  # 颁发者的密钥别名,可选项,如果不填,表示根CA
180         ├── -issuerKeyPwd                    # 颁发者的密钥口令,可选项
181         ├── -subject                         # 证书主题,必填项
182         ├── -validity                        # 证书有效期,可选项,默认为3650天
183         ├── -signAlg                         # 签名算法,必填项,包括SHA256withRSA / SHA384withRSA / SHA256withECDSA / SHA384withECDSA
184         ├── -basicConstraintsPathLen         # 路径长度,可选项,默认为0
185         ├── -issuerKeystoreFile              # 签发者密钥库文件,可选项,JKS或P12格式
186         ├── -issuerKeystorePwd               # 签发者密钥库口令,可选项
187         ├── -keystoreFile                    # 密钥库文件,必填项,JKS或P12格式
188         ├── -keystorePwd                     # 密钥库口令,可选项
189         ├── -outFile                         # 输出文件,可选项,如果不填,则直接输出到控制台
190
1914.生成应用调试/发布证书
192
193    generate-app-cert : 生成应用调试/发布证书
194         ├── -keyAlias                        # 密钥别名,必填项
195         ├── -keyPwd                          # 密钥口令,可选项
196         ├── -issuer                          # 颁发者的主题,必填项
197         ├── -issuerKeyAlias                  # 颁发者的密钥别名,必填项
198         ├── -issuerKeyPwd                    # 颁发者的密钥口令,可选项
199         ├── -subject                         # 证书主题,必填项
200         ├── -validity                        # 证书有效期,可选项,默认为3650天
201         ├── -signAlg                         # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA;
202         ├── -keystoreFile                    # 密钥库文件,必填项,JKS或P12格式
203         ├── -keystorePwd                     # 密钥库口令,可选项
204         ├── -issuerKeystoreFile              # 签发者密钥库文件,可选项,JKS或P12格式
205         ├── -issuerKeystorePwd               # 签发者密钥库口令,可选项
206         ├── -outForm                         # 输出证书文件的格式,包括 cert / certChain,可选项,默认为certChain
207         ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件
208         ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件
209         ├── -outFile                         #  输出证书文件(证书或证书链),可选项,如果不填,则直接输出到控制台
210
2115.生成profile调试/发布证书
212
213    generate-profile-cert : 生成profile调试/发布证书
214         ├── -keyAlias                        # 密钥别名,必填项
215         ├── -keyPwd                          # 密钥口令,可选项
216         ├── -issuer                          # 颁发者的主题,必填项
217         ├── -issuerKeyAlias                  # 颁发者的密钥别名,必填项
218         ├── -issuerKeyPwd                    # 颁发者的密钥口令,可选项
219         ├── -subject                         # 证书主题,必填项
220         ├── -validity                        # 证书有效期,可选项,默认为3650天
221         ├── -signAlg                         # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA;
222         ├── -keystoreFile                    # 密钥库文件,必填项,JKS或P12格式
223         ├── -keystorePwd                     # 密钥库口令,可选项
224         ├── -issuerKeystoreFile              # 签发者密钥库文件,可选项,JKS或P12格式
225         ├── -issuerKeystorePwd               # 签发者密钥库口令,可选项
226         ├── -outForm                         # 输出证书文件的格式,包括 cert / certChain,可选项,默认为certChain
227         ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件
228         ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件
229         ├── -outFile                         #  输出证书文件(证书或证书链),可选项,如果不填,则直接输出到控制台
230
2316.通用证书生成,可以生成自定义证书
232
233    generate-cert : 通用证书生成,可以生成自定义证书
234          ├── -keyAlias                          # 密钥别名,必填项
235          ├── -keyPwd                            # 密钥口令,可选项
236          ├── -issuer                            # 颁发者的主题,必填项
237          ├── -issuerKeyAlias                    # 颁发者的密钥别名,必填项
238          ├── -issuerKeyPwd                      # 颁发者的密钥口令,可选项
239          ├── -subject                           # 证书主题,必填项
240          ├── -validity                          # 证书有效期,可选项,默认为1095天
241          ├── -keyUsage                          # 密钥用法,必选项,包括digitalSignature, nonRepudiation, keyEncipherment,
242          ├                                        dataEncipherment, keyAgreement, certificateSignature, crlSignature,
243          ├                                        encipherOnly和decipherOnly,如果证书包括多个密钥用法,用逗号分隔
244          ├── -keyUsageCritical                  # keyUsage是否为关键项,可选项,默认为是
245          ├── -extKeyUsage                       # 扩展密钥用法,可选项,包括clientAuthentication,serverAuthentication,
246          ├                                        codeSignature,emailProtection,smartCardLogin,timestamp,ocspSignature
247          ├── -extKeyUsageCritical               # extKeyUsage是否为关键项,可选项,默认为否
248          ├── -signAlg                           # 签名算法,必填项,包括SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA
249          ├── -basicConstraints                  # 是否包含basicConstraints,可选项,默认为否
250          ├── -basicConstraintsCritical          # basicConstraints是否包含为关键项,可选项,默认为否
251          ├── -basicConstraintsCa                # 是否为CA,可选项,默认为否
252          ├── -basicConstraintsPathLen           # 路径长度,可选项,默认为0
253          ├── -issuerKeystoreFile                # 签发者密钥库文件,可选项,JKS或P12格式
254          ├── -issuerKeystorePwd                 # 签发者密钥库口令,可选项
255          ├── -keystoreFile                      # 密钥库文件,必填项,JKS或P12格式
256          ├── -keystorePwd                       # 密钥库口令,可选项
257          ├── -outFile                           # 输出证书文件,可选项,如果不填,则直接输出到控制台
258
2597.ProvisionProfile文件签名
260
261    sign-profile : ProvisionProfile文件签名
262          ├── -mode            # 签名模式,必填项,包括localSign,remoteSign
263          ├── -keyAlias        # 密钥别名,必填项
264          ├── -keyPwd          # 密钥口令,可选项
265          ├── -profileCertFile # Profile签名证书(证书链,顺序为实体证书-中间CA证书-根证书),必填项
266          ├── -inFile          # 输入的原始Provision Profile文件,必填项
267          ├── -signAlg         # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA
268          ├── -keystoreFile    # 密钥库文件,localSign模式时为必填项,JKS或P12格式
269          ├── -keystorePwd     # 密钥库口令,可选项
270          ├── -outFile         # 输出签名后的Provision Profile文件,p7b格式,必填项
271
2728.ProvisionProfile文件验签
273
274     verify-profile : ProvisionProfile文件验签
275           ├── -inFile       # 已签名的Provision Profile文件,p7b格式,必填项
276           ├── -outFile      # 验证结果文件(包含验证结果和profile内容),json格式,可选项;如果不填,则直接输出到控制台
277
2789.hap应用包和二进制工具签名
279
280     sign-app : hap应用包和二进制工具签名
281          ├── -mode          # 签名模式,必填项,包括localSign,remoteSign,remoteResign
282          ├── -keyAlias      # 密钥别名,必填项
283          ├── -keyPwd        # 密钥口令,可选项
284          ├── -appCertFile   # 应用签名证书文件(证书链,顺序为实体证书-中间CA证书-根证书),必填项
285          ├── -profileFile   # 签名后的Provision Profile文件名,profileSigned为1时为p7b格式,profileSigned为0时为json格式,应用包签名必填项,二进制工具签名选填
286          ├── -profileSigned # 指示profile文件是否带有签名,1表示有签名,0表示没有签名,默认为1。可选项
287          ├── -inForm        # 输入的原始文件的格式,枚举值:zip、elf或bin;zip和elf支持代码签名,hap 应用包对应zip,二进制工具对应elf,默认zip;可选项
288          ├── -inFile        # 输入的原始文件,hap应用、elf或bin文件,必填项
289          ├── -signAlg       # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA
290          ├── -keystoreFile  # 密钥库文件,localSign模式时为必填项,JKS或P12格式
291          ├── -keystorePwd   # 密钥库口令,可选项
292          ├── -outFile       # 输出签名后的包文件,必填项
293          ├── -signCode      # 是否启用代码签名,1表示开启代码签名,0表示关闭代码签名,默认为1。可选项
294
29510.hap应用包和二进制工具文件验签
296
297      verify-app : hap应用包和二进制工具文件验签
298         ├── -inFile          # 已签名的文件,hap应用、elf或bin文件,必填项
299         ├── -outCertChain    # 签名的证书链文件,必填项
300         ├── -outProfile      # 应用包中的profile文件,必填项
301         ├── -inForm          # 输入的原始文件的格式,枚举值:zip、elf或bin;zip和elf支持代码签名,hap 应用包对应zip,二进制工具对应elf,默认zip;可选项
302
303
304#### 相关仓
305   不涉及