• Home
Name Date Size #Lines LOC

..--

autosign/12-May-2024-791601

dist/12-May-2024-221211

figures/12-May-2024-

hapsigntool/12-May-2024-14,1487,979

tools/12-May-2024-1,1501,042

.gitignoreD12-May-202469 97

BUILD.gnD12-May-20241.1 KiB3229

LICENSED12-May-202411.1 KiB203169

NOTICED12-May-202422.8 KiB433362

OAT.xmlD12-May-20243.5 KiB6245

README.mdD12-May-202420.6 KiB292226

README_ZH.mdD12-May-202418.6 KiB301235

README.md

1# hapsigner
2
3#### Introduction
4
5To ensure the integrity and secure source of OpenHarmony applications, the applications must be signed during the build process. Only signed applications can be installed, run, and debugged on real devices. This repository provides the source code of the HAP signing tool - hapsigner. This tool can be used to generate key pairs, certificate signing requests (CSRs), certificates, profile signatures, and HAP signatures.
6
7
8#### Directory Structure
9
10    developtools_hapsigner
11
12    ├── autosign                # One-click signature script.
13	├── dist                    # SDK preconfigured file.
14    ├── hapsigntool             # Master code.
15          ├──hap_sign_tool      # Application entry, used to verify input parameters.
16          ├──hap_sign_tool_lib  # Signing tool lib, used to parse command words and parameter lists to implement logic of modules.
17    ├── tools                   # Auto-test script.
18
19
20
21#### Constraints
22hapsigner is developed in Java and must run in JRE 8.0 or later.
23The scripts, such as the one-click signature script, are developed in Python, and must run on Python 3.x.
24#### Build
25
26 1. Check that Gradle 7.1 has been installed.
27
28        gradle -v
29
30 2. Download the code, open the file directory **developtools_hapsigner/hapsigntool**, and run the following command to build the code:
31
32        gradle build or gradle jar
33
34 3. Check that **hap-sign-tool.jar** (binary files) is generated in the **./hap_sign_tool/build/libs** directory.
35
36****
37#### Usage
38##### Usage of Signature-related Files
39
40When signing an application using the IDE, you will obtain the following files from the SDK:
41
42```
43KeyStore (KS) file: OpenHarmony.p12
44Profile signing certificates: OpenHarmonyProfileRelease.pem and OpenHarmonyProfileDebug.pem
45Profile templates: UnsgnedReleasedProfileTemplate.json and UnsgnedDebugProfileTemplate.json
46Signature tool: hap-sign-tool.jar
47```
48The figures below illustrate how these files are used.
49
50**Signing a Profile**
51
52![signprofile.png](figures/signprofile_en.png)
53
54**Signing an App**
55
56![signapp.png](figures/signapp_en.png)
57##### Note
58
59In the following, the JAR package used is the binary files generated during the build process.
60
611. Command line signatures
62   Command line signatures include profile signatures and HAP signatures.
63
64   (1) Sign a profile.
65
66
67```shell
68java -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"
69```
70The parameters in the command are described as follows:
71
72    sign-profile: Sign a provisioning profile.
73         ├── -mode              # Signing mode, which can be localSign or remoteSign. It is mandatory.
74         ├── -keyAlias          # Key alias. It is mandatory.
75         ├── -keyPwd            # Key password. It is optional.
76         ├── -profileCertFile   # Profile signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
77         ├── -inFile            # Raw provisioning profile. It is mandatory.
78         ├── -signAlg           # Signature algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
79         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
80         ├── -keystorePwd       # KS password. It is optional.
81         ├── -outFile           # Signed provisioning profile to generate, in p7b format. It is mandatory.
82
83
84
85(2) Sign a HAP.
86
87
88```shell
89java -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"
90```
91The parameters in the command are described as follows:
92
93    sign-app: Sign a HAP.
94         ├── -mode              # Signing mode, which can be localSign or remoteSign. It is mandatory.
95         ├── -keyAlias          # Key alias. It is mandatory.
96         ├── -keyPwd            # Key password. It is optional.
97         ├── -appCertFile       # Application signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
98         ├── -profileFile       # Singed provisioning profile, in p7b format. It is mandatory.
99         ├── -profileSigned     # Whether the profile is signed. The value 1 means signed, and value 0 means unsigned. The default value is 1. It is optional.
100         ├── -inForm            # Raw file, in .zip (default) or .bin format. It is optional.
101         ├── -inFile            # Raw application package, in .zip or .bin format. It is mandatory.
102         ├── -signAlg           # Signature algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
103         ├── -keystoreFile      # KeyStore (KS) file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
104         ├── -keystorePwd       # KS password. It is optional.
105         ├── -outFile           # Signed HAP file to generate. It is mandatory.
106
107
1082. One-click signature
109
110
111To improve development efficiency, this project also provides one-click signature scripts based on the hapsigner tool. You can use these scripts to easily generate key pairs and end-entity certificates and sign profiles and HAPs, instead of entering complex commands.
112The scripts and configuration files are located in the **autosign** directory.
113
114 - create_root.sh/create_root.bat
115 - create_appcert_sign_profile.sh/create_appcert_sign_profile.bat
116 - sign_hap.sh/sign_hap.bat
117 - createAppCertAndProfile.config
118 - createRootAndSubCert.config
119 - signHap.config
120
121Procedure:
1221. Ensure that Python 3.5 or later has been installed.
1232. Prepare **hap-sign-tool.jar**. For details, see section **Build**.
1243. Prepare the HAP to be signed and the provisioning profile template file.
1254. Use the text editor to open the **createAppCertAndProfile.config** file and **signHap.config** file and change the values of **common.keyPwd** and **common.issuerKeyPwd** to match your case.
1265. Run **create_appcert_sign_profile.sh** in Linux or **create_appcert_sign_profile.bat** in Windows to generate files required for signature.
1276. Run **sign_hap.sh** in Linux or **sign_hap.bat** in Windows to sign the HAP.
128
129 > Note: To generate the KS file, root CA certificate, intermediate CA certificate, and profile signing certificate, perform the following steps:
130 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.
131 2. Run **create_root.sh** in Linux or run **create_root.bat** in Windows to generate the required KS file, root CA certificate, intermediate CA certificate, and profile signing certificate.
132
133
134****
135##### Common Operations
1361.Generate a key pair.
137
138     generate-keypair: Generate a key pair.
139         ├── -keyAlias          # Key alias. It is mandatory.
140         ├── -keyPwd            # Key password. It is optional.
141         ├── -keyAlg            # Key algorithm, which can be RSA or ECC. It is mandatory.
142         ├── -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.
143         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory.
144         ├── -keystorePwd       # KS password. It is optional.
145
1462.Generate a CSR.
147
148    generate-csr: Generate a CSR.
149         ├── -keyAlias          # Key alias. It is mandatory.
150         ├── -keyPwd            # Key password. It is optional.
151         ├── -subject           # Certificate subject. It is mandatory.
152         ├── -signAlg           # Signature algorithm, which can be SHA256withRSA, SHA384withRSA, SHA256withECDSA, or SHA384withECDSA. It is mandatory.
153         ├── -keystoreFile      # KS file, in JKS or P12 format. It is mandatory.
154         ├── -keystorePwd       # KS password. It is optional.
155         ├── -outFile           # CSR to generate. It is optional. If you do not specify this parameter, the CSR is output to the console.
156
1573.Generate a root CA or intermediate CA certificate.
158
159    generate-ca: Generate a root CA or intermediate CA certificate. If the key does not exist, generate a key together with the certificate.
160         ├── -keyAlias                        # Key alias. It is mandatory.
161         ├── -keyPwd                          # Key password. It is optional.
162         ├── -keyAlg                          # Key algorithm, which can be RSA or ECC. It is mandatory.
163         ├── -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.
164         ├── -issuer                          # Issuer of the certificate. It is optional. It indicates a root CA certificate if not specified.
165         ├── -issuerKeyAlias                  # Key alias of the issuer. It is optional. It indicates a root CA certificate if not specified.
166         ├── -issuerKeyPwd                    # Key password of the issuer. It is optional.
167         ├── -subject                         # Certificate subject. It is mandatory.
168         ├── -validity                        # Validity period of the certificate. It is optional. The default value is 3650 days.
169         ├── -signAlg                         # Signature algorithm, which can be SHA256withRSA, SHA384withRSA,  SHA256withECDSA, or SHA384withECDSA. It is mandatory.
170         ├── -basicConstraintsPathLen         # Path length. It is optional. The default value is 0.
171         ├── -issuerKeystoreFile              # KS file of the issuer, in JKS or P12 format. It is optional.
172         ├── -issuerKeystorePwd               # KS password of the issuer. It is optional.
173         ├── -keystoreFile                    # KS file, in JKS or P12 format. It is mandatory.
174         ├── -keystorePwd                     # KS password. It is optional.
175         ├── -outFile                         # File to generate. It is optional. The file is output to the console if this parameter is not specified.
176
1774.Generate an application debug or release certificate.
178
179    generate-app-cert: Generate an application debug or release certificate.
180         ├── -keyAlias                        # Key alias. It is mandatory.
181         ├── -keyPwd                          # Key password. It is optional.
182         ├── -issuer                          # Issuer of the certificate. It is mandatory.
183         ├── -issuerKeyAlias                  # Key alias of the issuer. It is mandatory.
184         ├── -issuerKeyPwd                    # Key password of the issuer. It is optional.
185         ├── -subject                         # Certificate subject. It is mandatory.
186         ├── -validity                        # Validity period of the certificate. It is optional. The default value is 3650 days.
187         ├── -signAlg                         # Signature algoritym, which can be SHA256withECDSA or SHA384withECDSA.
188         ├── -keystoreFile                    # KS file, in JKS or P12 format. It is mandatory.
189         ├── -keystorePwd                     # KS password. It is optional.
190         ├── -issuerKeystoreFile              # KS file of the issuer, in JKS or P12 format. It is optional.
191         ├── -issuerKeystorePwd               # KS password of the issuer. It is optional.
192         ├── -outForm                         # Format of the certificate to generate. It is optional. The value can be cert or certChain. The default value is certChain.
193         ├── -rootCaCertFile                  # Root CA certificate, which is mandatory when outForm is certChain.
194         ├── -subCaCertFile                   # Intermediate CA certificate file, which is mandatory when outForm is certChain.
195         ├── -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.
196
1975.Generate a profile debug or release certificate.
198
199    generate-profile-cert: Generate a profile debug or release certificate.
200         ├── -keyAlias                        # Key alias. It is mandatory.
201         ├── -keyPwd                          # Key password. It is optional.
202         ├── -issuer                          # Issuer of the certificate. It is mandatory.
203         ├── -issuerKeyAlias                  # Key alias of the issuer. It is mandatory.
204         ├── -issuerKeyPwd                    # Key password of the issuer. It is optional.
205         ├── -subject                         # Certificate subject. It is mandatory.
206         ├── -validity                        # Validity period of the certificate. It is optional. The default value is 3650 days.
207         ├── -signAlg                         # Signature algoritym, which can be SHA256withECDSA or SHA384withECDSA.
208         ├── -keystoreFile                    # KS file, in JKS or P12 format. It is mandatory.
209         ├── -keystorePwd                     # KS password. It is optional.
210         ├── -issuerKeystoreFile              # KS file of the issuer, in JKS or P12 format. It is optional.
211         ├── -issuerKeystorePwd               # KS password of the issuer. It is optional.
212         ├── -outForm                         # Format of the certificate to generate. It is optional. The value can be cert or certChain. The default value is certChain.
213         ├── -rootCaCertFile                  # Root CA certificate, which is mandatory when outForm is certChain.
214         ├── -subCaCertFile                   # Intermediate CA certificate file, which is mandatory when outForm is certChain.
215         ├── -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.
216
2176.Generate a common certificate, which can be used to generate a custom certificate.
218
219    generate-cert: Generate a common certificate, which can be used to generate a custom certificate.
220          ├── -keyAlias                        # Key alias. It is mandatory.
221          ├── -keyPwd                          # Key password. It is optional.
222          ├── -issuer                          # Issuer of the certificate. It is mandatory.
223          ├── -issuerKeyAlias                  # Key alias of the issuer. It is mandatory.
224          ├── -issuerKeyPwd                    # Key password of the issuer. It is optional.
225          ├── -subject                         # Certificate subject. It is mandatory.
226          ├── -validity                        # Validity period of the certificate. It is optional. The default value is 1095 days.
227          ├── -keyUsage                        # Usages of the key. It is mandatory. The key usages include digitalSignature, nonRepudiation, keyEncipherment,
228          ├                                      dataEncipherment, keyAgreement, certificateSignature, crlSignature, encipherOnly, and decipherOnly.
229          ├                                      Use a comma (,) to separate multiple values.
230          ├── -keyUsageCritical                # Whether keyUsage is a critical option. It is optional. The default value is true.
231          ├── -extKeyUsage                     # Extended key usages. It is optional. The extended key usages include clientAuthentication, serverAuthentication,
232          ├                                      codeSignature, emailProtection, smartCardLogin, timestamp, and ocspSignature.
233          ├── -extKeyUsageCritical             # Whether extKeyUsage is a critical option. It is optional. The default value is false.
234          ├── -signAlg                         # Signature algorithm, which can be SHA256withRSA, SHA384withRSA,  SHA256withECDSA, or SHA384withECDSA. It is mandatory.
235          ├── -basicConstraints                # Whether basicConstraints is contained. It is optional. The default value is false.
236          ├── -basicConstraintsCritical        # Whether basicConstraints is a critical option. It is optional. The default value is false.
237          ├── -basicConstraintsCa              # Whether it is CA. It is optional. The default value is false.
238          ├── -basicConstraintsPathLen         # Path length. It is optional. The default value is 0.
239          ├── -issuerKeystoreFile              # KS file of the issuer, in JKS or P12 format. It is optional.
240          ├── -issuerKeystorePwd               # KS password of the issuer. It is optional.
241          ├── -keystoreFile                    # KS file, in JKS or P12 format. It is mandatory.
242          ├── -keystorePwd                     # KS password. It is optional.
243          ├── -outFile                         # Certificate file to generate. It is optional. The file is output to the console if this parameter is not specified.
244
2457.Sign a provisioning profile.
246
247    sign-profile: Sign a provisioning profile.
248          ├── -mode            # Signing mode, which can be localSign or remoteSign. It is mandatory.
249          ├── -keyAlias        # Key alias. It is mandatory.
250          ├── -keyPwd          # Key password. It is optional.
251          ├── -profileCertFile # Profile signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
252          ├── -inFile          # Raw provisioning profile. It is mandatory.
253          ├── -signAlg         # Signature algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
254          ├── -keystoreFile    # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
255          ├── -keystorePwd     # KS password. It is optional.
256          ├── -outFile         # Signed provisioning profile to generate, in p7b format. It is mandatory.
257
2588.Verify the provisioning profile signature.
259
260     verify-profile: Verify the provisioning profile signature.
261           ├── -inFile        # Signed provisioning profile, in p7b format. It is mandatory.
262           ├── -outFile       # Verification result file (including the verification result and profile content), in json format. It is optional. The file is output to the console if this parameter is not specified.
263
2649.Sign a HAP.
265
266     sign-app: Sign a HAP
267          ├── -mode          # Signing mode, which can be localSign, remoteSign, or remoteResign. It is mandatory.
268          ├── -keyAlias      # Key alias. It is mandatory.
269          ├── -keyPwd        # Key password. It is optional.
270          ├── -appCertFile   # Application signing certificate (certificate chain, in the end-entity certificate, intermediate CA certificate, and root certificate order). It is mandatory.
271          ├── -profileFile   # Name of the signed provisioning profile. The profile is in p7b format if profileSigned is 1 and in json format if profileSigned is 0. It is mandatory.
272          ├── -profileSigned # Whether the profile is signed. The value 1 means signed, and value 0 means unsigned. The default value is 1. It is optional.
273          ├── -inForm        # Raw file, in .zip (default) or .bin format. It is optional.
274          ├── -inFile        # Raw application package, in .zip or .bin format. It is mandatory.
275          ├── -signAlg       # Signature algorithm, which can be SHA256withECDSA or SHA384withECDSA. It is mandatory.
276          ├── -keystoreFile  # KS file, in JKS or P12 format. It is mandatory if the signing mode is localSign.
277          ├── -keystorePwd   # KS password. It is optional.
278          ├── -outFile       # Signed HAP file to generate. It is mandatory.
279
28010.Verify the HAP Signature.
281
282      verify-app: Verify the HAP signature.
283         ├── -inFile          # Signed application file, in .zip or .bin format. It is mandatory.
284         ├── -outCertChain    # Signed certificate chain file. It is mandatory.
285         ├── -outProfile      # Profile of the application. It is mandatory.
286
287
288
289
290#### Repositories Involved
291   N/A
292

README_ZH.md

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