OpenHarmony定制系统签名

OpenHarmony实战开发-Hap包签名工具指导 1.该工具基于Gradle 7.1编译构建,请确认环境已安装配置Gradle环境,并且版本高于或等于7.1。 阅读详情
AI摘要

文章介绍了OpenHarmony应用签名的重要性和过程,重点讲解了使用hap-sign-tool.jar工具生成私有签名、Profile证书及应用证书的步骤。内容涉及非对称密钥对生成、CSR文件制作、证书链构建以及如何在系统中配置这些签名以确保应用的安全发布与调试。

参考资料:
OpenHarmony应用签名 - 厂商私有签名
OpenHarmony应用签名 - 系统应用签名
OpenHarmony应用签名 - 厂商私有签名的配置和使用
Hap包签名工具
DevEco Studio使用指南(HarmonyOS)应用/服务发布

开发环境

开发平台:Win10
开发板:RK3568
系统版本:OpenHarmony 3.2 Release
DevEco Studio 版本:3.1.0.200
full SDK 版本:3.2.11.9

签名简介

为了保证OpenHarmony应用的完整性和来源可靠,在应用构建时需要对应用进行签名。经过签名的应用才能在真机设备上安装、运行、和调试。developtools_hapsigner仓提供了签名工具的源码,包含密钥对生成、CSR文件生成、证书生成、Profile文件签名、Hap包签名等功能。

OpenHarmony系统中有一套默认签名信息,用于应用的开发和调试。当系统厂商正式发布系统时,需要新增或替换私有签名信息,本篇文档将介绍如何生成私有签名并在系统中进行配置。本文档需准备Java和Gradle编译环境。

概念说明

  • 非对称密钥对:数据签名/验签的基础,应用签名工具实现了标准的非对称密钥对生成功能(支持的密钥对类型包括ECC P384/256、RSA2048/3072/4096)
  • CSR:Certificate Signing Request 证书签发请求是生成证书的前提,他包括证书的公钥、证书主题和私钥签名,在申请证书之前,需要先基于密钥对生成CSR,然后提交给CA签发证书。
  • 证书:OpenHarmony采用RFC5280标准构建X509证书信任体系。用于应用签名的OpenHarmony证书共有三级,分为:根CA证书、中间CA证书、最终实体证书,其中最终实体证书分为应用签名证书和profile签名证书。应用签名证书表示应用开发者的身份,可保证系统上安装的应用来源可追溯,profile签名证书实现对profile文件的签名进行验签,保证profile文件的完整性。
  • HAP:OpenHarmony Ability Package 是Ability的部署包,OpenHarmony应用代码围绕Ability组件展开,它是由一个或者多个Ability组成。
  • Profile文件:HarmonyAppProvision 配置文件,hap包中的描述文件,该描述文件描述了已授权的证书权限和设备ID信息等信息。

开发者通过IDE进行应用签名时,可在SDK中会获得如下签名相关文件:

签名密钥库文件:OpenHarmony.p12
Profile签名证书:OpenHarmonyProfileRelease.pem、OpenHarmonyProfileDebug.pem
Profile模板文件:UnsgnedReleasedProfileTemplate.json、UnsgnedDebugProfileTemplate.json
签名工具:hap-sign-tool.jar

上述文件的使用场景如下图所示。
Profile签名场景:
Profile签名
应用签名场景:
应用签名场景

准备工作

  • Hap签名工具源码:developtools\hapsigner
  • 待签名hap包:entry-default-unsigned.hap
  • Profile模板文件:Sdk\9\toolchains\lib\UnsgnedReleasedProfileTemplate.json

Hap包签名工具

Hap包签名工具基于Java语言开发,需要在Java8以上Java环境运行 (附:一键签名等脚本文件基于Python语言开发,使用需配置环境python3.x)。
签名工具位于源码路径:developtools\hapsigner

developtools\hapsigner

├── autosign                # 一键签名脚本
├── dist                    # SDK预置文件
├── hapsigntool             # 主代码
      ├──hap_sign_tool      # 主程序入口,完成输入参数的基础校验
      ├──hap_sign_tool_lib  # 签名工具库,解析命令字和参数列表,实现各模块逻辑功能
├── tools                   # 自动化测试脚本

仓库地址:https://gitee.com/openharmony/developtools_hapsigner.git

编译构建

若未安装gradle参考:Linux安装Gradle

#进入签名工具所在路径
$ cd developtools/hapsigner/hapsigntool/

#签名工具基于Gradle 7.1编译构建,确认环境已安装配置Gradle环境,并且版本正确
$ gradle -v
Gradle 7.1

#执行gradle build 或者 gradle jar命令编译打包
$ gradle build

BUILD SUCCESSFUL in 22s
14 actionable tasks: 14 executed

#编译完成后得到:developtools\hapsigner\hapsigntool\hap_sign_tool\build\libs\hap-sign-tool.jar

hap-sign-tool.jar接口说明

  • 生成密钥对
generate-keypair : 生成密钥对
     ├── -keyAlias          # 密钥别名,必填项
     ├── -keyPwd            # 密钥口令,可选项
     ├── -keyAlg            # 密钥算法,必填项,包括RSA/ECC
     ├── -keySize           # 密钥长度,必填项,RSA算法的长度为2048/3072/4096,ECC算法的长度NIST-P-256/NIST-P-384
     ├── -keystoreFile      # 密钥库文件,必填项,JKS或P12格式
     ├── -keystorePwd       # 密钥库口令,可选项
  • 生成证书签名请求
generate-csr : 生成证书签名请求
     ├── -keyAlias          # 密钥别名,必填项
     ├── -keyPwd            # 密钥口令,可选项
     ├── -subject           # 证书主题,必填项
     ├── -signAlg           # 签名算法,必填项,包括SHA256withRSA / SHA384withRSA / SHA256withECDSA / SHA384withECDSA
     ├── -keystoreFile      # 密钥库文件,必填项,JKS或P12格式
     ├── -keystorePwd       # 密钥库口令,可选项
     ├── -outFile           # 输出文件,可选项,如果不填,则直接输出到控制台
  • 生成根CA/中间CA证书
generate-ca : 生成根CA/中间CA证书,如果密钥不存在,一起生成密钥
     ├── -keyAlias                        # 密钥别名,必填项
     ├── -keyPwd                          # 密钥口令,可选项
     ├── -keyAlg                          # 密钥算法,必填项,包括RSA/ECC
     ├── -keySize                         # 密钥长度,必填项,RSA算法的长度为2048/3072/4096,ECC算法的长度NIST-P-256/NIST-P-384
     ├── -issuer                          # 颁发者的主题,可选项,如果不填,表示根CA
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,可选项,如果不填,表示根CA
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,可选项
     ├── -subject                         # 证书主题,必填项
     ├── -validity                        # 证书有效期,可选项,默认为3650天
     ├── -signAlg                         # 签名算法,必填项,包括SHA256withRSA / SHA384withRSA / SHA256withECDSA / SHA384withECDSA
     ├── -basicConstraintsPathLen         # 路径长度,可选项,默认为0
     ├── -issuerKeystoreFile              # 签发者密钥库文件,可选项,JKS或P12格式
     ├── -issuerKeystorePwd               # 签发者密钥库口令,可选项
     ├── -keystoreFile                    # 密钥库文件,必填项,JKS或P12格式
     ├── -keystorePwd                     # 密钥库口令,可选项
     ├── -outFile                         # 输出文件,可选项,如果不填,则直接输出到控制台
  • 生成应用调试/发布证书
generate-app-cert : 生成应用调试/发布证书
     ├── -keyAlias                        # 密钥别名,必填项
     ├── -keyPwd                          # 密钥口令,可选项
     ├── -issuer                          # 颁发者的主题,必填项
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,必填项
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,可选项
     ├── -subject                         # 证书主题,必填项
     ├── -validity                        # 证书有效期,可选项,默认为3650天
     ├── -signAlg                         # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA;
     ├── -keystoreFile                    # 密钥库文件,必填项,JKS或P12格式
     ├── -keystorePwd                     # 密钥库口令,可选项
     ├── -issuerKeystoreFile              # 签发者密钥库文件,可选项,JKS或P12格式
     ├── -issuerKeystorePwd               # 签发者密钥库口令,可选项
     ├── -outForm                         # 输出证书文件的格式,包括 cert / certChain,可选项,默认为certChain
     ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件
     ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件
     ├── -outFile                         #  输出证书文件(证书或证书链),可选项,如果不填,则直接输出到控制台
  • 生成profile调试/发布证书
generate-profile-cert : 生成profile调试/发布证书
     ├── -keyAlias                        # 密钥别名,必填项
     ├── -keyPwd                          # 密钥口令,可选项
     ├── -issuer                          # 颁发者的主题,必填项
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,必填项
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,可选项
     ├── -subject                         # 证书主题,必填项
     ├── -validity                        # 证书有效期,可选项,默认为3650天
     ├── -signAlg                         # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA;
     ├── -keystoreFile                    # 密钥库文件,必填项,JKS或P12格式
     ├── -keystorePwd                     # 密钥库口令,可选项
     ├── -issuerKeystoreFile              # 签发者密钥库文件,可选项,JKS或P12格式
     ├── -issuerKeystorePwd               # 签发者密钥库口令,可选项
     ├── -outForm                         # 输出证书文件的格式,包括 cert / certChain,可选项,默认为certChain
     ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件
     ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件
     ├── -outFile                         #  输出证书文件(证书或证书链),可选项,如果不填,则直接输出到控制台
  • 通用证书生成,可以生成自定义证书
generate-cert : 通用证书生成,可以生成自定义证书
      ├── -keyAlias                          # 密钥别名,必填项
      ├── -keyPwd                            # 密钥口令,可选项
      ├── -issuer                            # 颁发者的主题,必填项
      ├── -issuerKeyAlias                    # 颁发者的密钥别名,必填项
      ├── -issuerKeyPwd                      # 颁发者的密钥口令,可选项
      ├── -subject                           # 证书主题,必填项
      ├── -validity                          # 证书有效期,可选项,默认为1095天
      ├── -keyUsage                          # 密钥用法,必选项,包括digitalSignature, nonRepudiation, keyEncipherment,
      ├                                        dataEncipherment, keyAgreement, certificateSignature, crlSignature,
      ├                                        encipherOnly和decipherOnly,如果证书包括多个密钥用法,用逗号分隔
      ├── -keyUsageCritical                  # keyUsage是否为关键项,可选项,默认为是
      ├── -extKeyUsage                       # 扩展密钥用法,可选项,包括clientAuthentication,serverAuthentication,
      ├                                        codeSignature,emailProtection,smartCardLogin,timestamp,ocspSignature
      ├── -extKeyUsageCritical               # extKeyUsage是否为关键项,可选项,默认为否
      ├── -signAlg                           # 签名算法,必填项,包括SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA 
      ├── -basicConstraints                  # 是否包含basicConstraints,可选项,默认为否
      ├── -basicConstraintsCritical          # basicConstraints是否包含为关键项,可选项,默认为否
      ├── -basicConstraintsCa                # 是否为CA,可选项,默认为否
      ├── -basicConstraintsPathLen           # 路径长度,可选项,默认为0
      ├── -issuerKeystoreFile                # 签发者密钥库文件,可选项,JKS或P12格式
      ├── -issuerKeystorePwd                 # 签发者密钥库口令,可选项
      ├── -keystoreFile                      # 密钥库文件,必填项,JKS或P12格式
      ├── -keystorePwd                       # 密钥库口令,可选项
      ├── -outFile                           # 输出证书文件,可选项,如果不填,则直接输出到控制台
  • ProvisionProfile文件签名
sign-profile : ProvisionProfile文件签名
      ├── -mode            # 签名模式,必填项,包括localSign,remoteSign
      ├── -keyAlias        # 密钥别名,必填项
      ├── -keyPwd          # 密钥口令,可选项
      ├── -profileCertFile # Profile签名证书(证书链,顺序为最终实体证书-中间CA证书-根证书),必填项
      ├── -inFile          # 输入的原始Provision Profile文件,必填项
      ├── -signAlg         # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA
      ├── -keystoreFile    # 密钥库文件,localSign模式时为必填项,JKS或P12格式
      ├── -keystorePwd     # 密钥库口令,可选项
      ├── -outFile         # 输出签名后的Provision Profile文件,p7b格式,必填项
  • hap应用包签名
 sign-app : hap应用包签名 
      ├── -mode          # 签名模式,必填项,包括localSign,remoteSign,remoteResign
      ├── -keyAlias      # 密钥别名,必填项
      ├── -keyPwd        # 密钥口令,可选项
      ├── -appCertFile   # 应用签名证书文件(证书链,顺序为最终实体证书-中间CA证书-根证书),必填项
      ├── -profileFile   # 签名后的Provision Profile文件名,profileSigned为1时为p7b格式,profileSigned为0时为json格式,必填项
      ├── -profileSigned # 指示profile文件是否带有签名,1表示有签名,0表示没有签名,默认为1。可选项
      ├── -inForm        # 输入的原始文件的格式,zip格式或bin格式,默认zip格式,可选项
      ├── -inFile        # 输入的原始APP包文件,zip格式或bin格式,必填项
      ├── -signAlg       # 签名算法,必填项,包括SHA256withECDSA / SHA384withECDSA
      ├── -keystoreFile  # 密钥库文件,localSign模式时为必填项,JKS或P12格式
      ├── -keystorePwd   # 密钥库口令,可选项
      ├── -outFile       # 输出签名后的包文件,必填项
  • ProvisionProfile文件验签
 verify-profile : ProvisionProfile文件验签
       ├── -inFile       # 已签名的Provision Profile文件,p7b格式,必填项
       ├── -outFile       # 验证结果文件(包含验证结果和profile内容),json格式,可选项;如果不填,则直接输出到控制台
  • hap应用包文件验签
  verify-app : hap应用包文件**验签**
     ├── -inFile          # 已签名的应用包文件,zip格式或bin格式,必填项
     ├── -outCertChain    # 签名的证书链文件,必填项
     ├── -outProfile      # 应用包中的profile文件,必填项

命令行签名,生成签名文件

注意:为了方便后续将签名配置导入IDE,在设置密码时需遵守IDE密码规范:

密码必须至少包含8个字符,并包括以下任何两项:
1.小写字母:a-z
2.大写字母: A-Z
3.数字: 0-9
4.特殊字符: `~!@#$%^&*()-_=+\|[{}];:'",<.>/?

1、生成密钥对(xxx.p12),keystorePwd为密钥库口令

 generate-keypair : 生成密钥对
     ├── -keyAlias          # 密钥别名,【OpenHarmony-ABC】
     ├── -keyPwd            # 密钥口令,【keypair123】
     ├── -keyAlg            # 密钥算法,【ECC】
     ├── -keySize           # 密钥长度,【NIST-P-256】
     ├── -keystoreFile      # 密钥库文件,【OpenHarmony-ABC.p12】
     ├── -keystorePwd       # 密钥库口令,【keystore123】
     
$ java -jar hap-sign-tool.jar generate-keypair -keyAlias "OpenHarmony-ABC" -keyPwd "keypair123" -keyAlg "ECC" -keySize "NIST-P-256" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123"
#运行成功结果如下
INFO  - Start generate-keypair
INFO  - generate-keypair success

2、​生成RootCA证书,subject为RootCA的证书主题,用于配置trusted_root_ca.json。

generate-ca : 生成根CA证书,如果密钥不存在,一起生成密钥
     ├── -keyAlias                        # 密钥别名,【OpenHarmony-ABC-rootCA】
     ├── -keyPwd                          # 密钥口令,【rootCA123】
     ├── -keyAlg                          # 密钥算法,【ECC】
     ├── -keySize                         # 密钥长度,【NIST-P-256】
     ├── -subject                         # 证书主题,【C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA】
     ├── -validity                        # 证书有效期,【365】(1年)
     ├── -signAlg                         # 签名算法,【SHA256withECDSA】
     ├── -keystoreFile                    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
     ├── -keystorePwd                     # 密钥库口令,【keystore123】
     ├── -outFile                         # 输出文件,【./result/OpenHarmony-ABC-rootCA.cer】

$ java -jar hap-sign-tool.jar generate-ca -keyAlias "OpenHarmony-ABC-rootCA" -keyPwd "rootCA123" -keyAlg "ECC" -keySize "NIST-P-256" -subject "C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA" -validity "365" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/OpenHarmony-ABC-rootCA.cer"

#运行成功结果如下
INFO  - Start generate-ca
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - generate-ca success

3、生成SubCA证书

generate-ca : 生成根CA证书,如果密钥不存在,一起生成密钥
     ├── -keyAlias                        # 密钥别名,【OpenHarmony-ABC-subCA】
     ├── -keyPwd                          # 密钥口令,【subCA123】
     ├── -keyAlg                          # 密钥算法,【ECC】
     ├── -keySize                         # 密钥长度,【NIST-P-256】
     ├── -issuer                          # 颁发者的主题,【C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA】
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,【OpenHarmony-ABC-rootCA】
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,【rootCA123】
     ├── -subject                         # 证书主题,【C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application Sub CA】
     ├── -validity                        # 证书有效期,【365】(1年)
     ├── -signAlg                         # 签名算法,【SHA256withECDSA】
     ├── -keystoreFile                    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
     ├── -keystorePwd                     # 密钥库口令,【keystore123】
     ├── -outFile                         # 输出文件,【./result/OpenHarmony-ABC-subCA.cer】

$ java -jar hap-sign-tool.jar generate-ca -keyAlias "OpenHarmony-ABC-subCA" -keyPwd "subCA123" -keyAlg "ECC" -keySize "NIST-P-256" -issuer "C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA" -issuerKeyAlias "OpenHarmony-ABC-rootCA" -issuerKeyPwd "rootCA123" -subject "C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application Sub CA" -validity "365" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/OpenHarmony-ABC-subCA.cer"

#运行成功结果如下
INFO  - Start generate-ca
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - generate-ca success

4、生成应用调试/发布证书,subject用于配置trusted_apps_sources.json中的app-signing-cert项。

generate-app-cert : 生成应用调试/发布证书
     ├── -keyAlias                        # 密钥别名,【OpenHarmony-ABC-subCA】
     ├── -keyPwd                          # 密钥口令,【subCA123】
     ├── -issuer                          # 颁发者的主题,【C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application Sub CA" -issuerKeyAlias "OpenHarmony-ABC-subCA】
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,【OpenHarmony-ABC-subCA】
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,【subCA123】
     ├── -subject                         # 证书主题,【C=CN, O=OpenHarmony-ABC-app-cert, OU=OpenHarmony-ABC-app-cert Community, CN=OpenHarmony Application Release】
     ├── -validity                        # 证书有效期,【365】
     ├── -signAlg                         # 签名算法,【SHA256withECDSA】
     ├── -keystoreFile                    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
     ├── -keystorePwd                     # 密钥库口令,【keystore123】
     ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件【./result/OpenHarmony-ABC-rootCA.cer】
     ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件【./result/OpenHarmony-ABC-subCA.cer】
     ├── -outFile                         #  输出证书文件(证书或证书链),【./result/OpenHarmony-ABC-app-cert.pem】

$ java -jar hap-sign-tool.jar generate-app-cert -keyAlias "OpenHarmony-ABC-subCA" -keyPwd "subCA123" -issuer "C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application Sub CA" -issuerKeyAlias "OpenHarmony-ABC-subCA" -issuerKeyPwd "subCA123" -subject "C=CN, O=OpenHarmony-ABC-app-cert, OU=OpenHarmony-ABC-app-cert Community, CN=OpenHarmony Application Release" -validity "365" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -rootCaCertFile "./result/OpenHarmony-ABC-rootCA.cer" -outForm "certChain" -subCaCertFile "./result/OpenHarmony-ABC-subCA.cer" -outFile "./result/OpenHarmony-ABC-app-cert.pem"

#运行成功结果如下
INFO  - Start generate-app-cert
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - generate-app-cert success

5、生成ProfileCA证书,subject用于配置trusted_apps_sources.json中的issuer-ca项

generate-ca : 生成ProfileCA证书,如果密钥不存在,一起生成密钥
     ├── -keyAlias                        # 密钥别名,【OpenHarmony-ABC-profileCA】
     ├── -keyPwd                          # 密钥口令,【profileCA123】
     ├── -keyAlg                          # 密钥算法,【ECC】
     ├── -keySize                         # 密钥长度,【NIST-P-256】
     ├── -issuer                          # 颁发者的主题,【C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA】
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,【OpenHarmony-ABC-rootCA】
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,【rootCA123】
     ├── -subject                         # 证书主题,【C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application Sub CA】
     ├── -validity                        # 证书有效期,【365】(1年)
     ├── -signAlg                         # 签名算法,【SHA256withECDSA】
     ├── -keystoreFile                    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
     ├── -keystorePwd                     # 密钥库口令,【keystore123】
     ├── -outFile                         # 输出文件,【./result/OpenHarmony-ABC-profileCA.cer】

$ java -jar hap-sign-tool.jar generate-ca -keyAlias "OpenHarmony-ABC-profileCA" -keyPwd "profileCA123" -keyAlg "ECC" -keySize "NIST-P-256" -issuer "C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA" -issuerKeyAlias "OpenHarmony-ABC-rootCA" -issuerKeyPwd "rootCA123" -subject "C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA" -validity "365" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/OpenHarmony-ABC-profileCA.cer"

#运行成功结果如下
INFO  - Start generate-ca
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - generate-ca success

6、生成应用Release版profile调试/发布证书,subject用于配置trusted_apps_sources.json中的profile-signing-certificate项。

generate-profile-cert : 生成Release版本profile调试/发布证书
     ├── -keyAlias                        # 密钥别名,【OpenHarmony-ABC-profileCA】
     ├── -keyPwd                          # 密钥口令,【profileCA123】
     ├── -issuer                          # 颁发者的主题,【C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA】
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,【OpenHarmony-ABC-profileCA】
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,【profileCA123】
     ├── -subject                         # 证书主题,【C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Release】
     ├── -validity                        # 证书有效期,【365】
     ├── -signAlg                         # 签名算法,【SHA256withECDSA】
     ├── -keystoreFile                    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
     ├── -keystorePwd                     # 密钥库口令,【keystore123】
     ├── -outForm                         # 输出证书文件的格式,包括 cert / certChain,【certChain】
     ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件【./result/OpenHarmony-ABC-rootCA.cer】
     ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件【./result/OpenHarmony-ABC-profileCA.cer】
     ├── -outFile                         #  输出证书文件(证书或证书链),【./result/OpenHarmony-ABC-profile-cert-release.pem】

$ java -jar hap-sign-tool.jar generate-profile-cert -keyAlias "OpenHarmony-ABC-profileCA" -keyPwd "profileCA123" -issuer "C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA" -issuerKeyAlias "OpenHarmony-ABC-profileCA" -issuerKeyPwd "profileCA123" -subject "C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Release" -validity "365" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outForm "certChain" -rootCaCertFile "./result/OpenHarmony-ABC-rootCA.cer" -subCaCertFile "./result/OpenHarmony-ABC-profileCA.cer" -outFile "./result/OpenHarmony-ABC-profile-cert-release.pem"

#运行成功结果如下
INFO  - Start generate-profile-cert
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - generate-profile-cert success

7、生成应用Debug版profile调试/发布证书,subject用于配置trusted_apps_sources.json中的profile-debug-signing-certificate项

generate-profile-cert : 生成Debug版本profile调试/发布证书
     ├── -keyAlias                        # 密钥别名,【OpenHarmony-ABC-profileCA】
     ├── -keyPwd                          # 密钥口令,【profileCA123】
     ├── -issuer                          # 颁发者的主题,【C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA】
     ├── -issuerKeyAlias                  # 颁发者的密钥别名,【OpenHarmony-ABC-profileCA】
     ├── -issuerKeyPwd                    # 颁发者的密钥口令,【profileCA123】
     ├── -subject                         # 证书主题,【C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Debug】
     ├── -validity                        # 证书有效期,【365】
     ├── -signAlg                         # 签名算法,【SHA256withECDSA】
     ├── -keystoreFile                    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
     ├── -keystorePwd                     # 密钥库口令,【keystore123】
     ├── -outForm                         # 输出证书文件的格式,包括 cert / certChain,【certChain】
     ├── -rootCaCertFile                  #  outForm为certChain时必填,根CA证书文件【./result/OpenHarmony-ABC-rootCA.cer】
     ├── -subCaCertFile                   #  outForm为certChain时必填,中间CA证书文件【./result/OpenHarmony-ABC-profileCA.cer】
     ├── -outFile                         #  输出证书文件(证书或证书链),【./result/OpenHarmony-ABC-profile-cert-debug.pem】

$ java -jar hap-sign-tool.jar generate-profile-cert -keyAlias "OpenHarmony-ABC-profileCA" -keyPwd "profileCA123" -issuer "C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA" -issuerKeyAlias "OpenHarmony-ABC-profileCA" -issuerKeyPwd "profileCA123" -subject "C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Debug" -validity "365" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outForm "certChain" -rootCaCertFile "./result/OpenHarmony-ABC-rootCA.cer" -subCaCertFile "./result/OpenHarmony-ABC-profileCA.cer" -outFile "./result/OpenHarmony-ABC-profile-cert-debug.pem"

#运行成功结果如下
INFO  - Start generate-profile-cert
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - generate-profile-cert success

经过以上步骤得到签名文件如下:

$ ls -al result/
OpenHarmony-ABC-app-cert.pem
OpenHarmony-ABC.p12
OpenHarmony-ABC-profileCA.cer
OpenHarmony-ABC-profile-cert-debug.pem
OpenHarmony-ABC-profile-cert-release.pem
OpenHarmony-ABC-rootCA.cer
OpenHarmony-ABC-subCA.cer

8、将OpenHarmony-ABC-app-cert.pem中第一部分的密钥,把回车转换为\n字符,放入UnsgnedReleasedProfileTemplate.json的distribution-certificate中

Profile模板文件:Sdk\9\toolchains\lib\UnsgnedReleasedProfileTemplate.json

-----BEGIN CERTIFICATE-----
MIICZjCCAgygAwIBAgIEXPrigDAKBggqhkjOPQQDAjCBgDELMAkGA1UEBhMCQ04x
HjAcBgNVBAoMFU9wZW5IYXJtb255LUFCQy1zdWJDQTEoMCYGA1UECwwfT3Blbkhh
cm1vbnktQUJDLXN1YkNBIENvbW11bml0eTEnMCUGA1UEAwweT3Blbkhhcm1vbnkg
QXBwbGljYXRpb24gU3ViIENBMB4XDTIzMDYyODA1MjgwMloXDTI0MDYyNzA1Mjgw
MlowgYcxCzAJBgNVBAYTAkNOMSEwHwYDVQQKDBhPcGVuSGFybW9ueS1BQkMtYXBw
LWNlcnQxKzApBgNVBAsMIk9wZW5IYXJtb255LUFCQy1hcHAtY2VydCBDb21tdW5p
dHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTAT
BgcqhkjOPQIBBggqhkjOPQMBBwNCAARvPLo0HPZroleu81PSWDEmB2cGI+EHUM7b
w95BBsaThBfjbtt37oNICJRGaBWSxmCSxbU557Ci7IRE7o/vJaM0o2swaTAdBgNV
HQ4EFgQUUvatlguoLp2hFrlme6a0KrlNF2AwCQYDVR0TBAIwADAOBgNVHQ8BAf8E
BAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwGAYMKwYBBAGPWwKCeAEDBAgwBgIB
AQoBADAKBggqhkjOPQQDAgNIADBFAiAcH26/JhsRiHqDEX7A95Vb2VkIm8xUYJs5
pz2Nzde6yAIhAJrYHxuTVuhdgkJ7IL5WNmU+YwJdp6Li+rIb0JFe2ZmR
-----END CERTIFICATE-----

转换后:

-----BEGIN CERTIFICATE-----\nMIICZjCCAgygAwIBAgIEXPrigDAKBggqhkjOPQQDAjCBgDELMAkGA1UEBhMCQ04x\nHjAcBgNVBAoMFU9wZW5IYXJtb255LUFCQy1zdWJDQTEoMCYGA1UECwwfT3Blbkhh\ncm1vbnktQUJDLXN1YkNBIENvbW11bml0eTEnMCUGA1UEAwweT3Blbkhhcm1vbnkg\nQXBwbGljYXRpb24gU3ViIENBMB4XDTIzMDYyODA1MjgwMloXDTI0MDYyNzA1Mjgw\nMlowgYcxCzAJBgNVBAYTAkNOMSEwHwYDVQQKDBhPcGVuSGFybW9ueS1BQkMtYXBw\nLWNlcnQxKzApBgNVBAsMIk9wZW5IYXJtb255LUFCQy1hcHAtY2VydCBDb21tdW5p\ndHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTAT\nBgcqhkjOPQIBBggqhkjOPQMBBwNCAARvPLo0HPZroleu81PSWDEmB2cGI+EHUM7b\nw95BBsaThBfjbtt37oNICJRGaBWSxmCSxbU557Ci7IRE7o/vJaM0o2swaTAdBgNV\nHQ4EFgQUUvatlguoLp2hFrlme6a0KrlNF2AwCQYDVR0TBAIwADAOBgNVHQ8BAf8E\nBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwGAYMKwYBBAGPWwKCeAEDBAgwBgIB\nAQoBADAKBggqhkjOPQQDAgNIADBFAiAcH26/JhsRiHqDEX7A95Vb2VkIm8xUYJs5\npz2Nzde6yAIhAJrYHxuTVuhdgkJ7IL5WNmU+YwJdp6Li+rIb0JFe2ZmR\n-----END CERTIFICATE-----\n

将转换后的密钥写入UnsgnedReleasedProfileTemplate.json的distribution-certificate中
注意:bundle-name需与应用包名匹配,否则安装时:
error: failed to install bundle. error: verify signature failed.

"bundle-info": {
        "developer-id": "OpenHarmony",
        "distribution-certificate": "-----BEGIN CERTIFICATE-----\nMIICZjCCAgygAwIBAgIEXPrigDAKBggqhkjOPQQDAjCBgDELMAkGA1UEBhMCQ04x\nHjAcBgNVBAoMFU9wZW5IYXJtb255LUFCQy1zdWJDQTEoMCYGA1UECwwfT3Blbkhh\ncm1vbnktQUJDLXN1YkNBIENvbW11bml0eTEnMCUGA1UEAwweT3Blbkhhcm1vbnkg\nQXBwbGljYXRpb24gU3ViIENBMB4XDTIzMDYyODA1MjgwMloXDTI0MDYyNzA1Mjgw\nMlowgYcxCzAJBgNVBAYTAkNOMSEwHwYDVQQKDBhPcGVuSGFybW9ueS1BQkMtYXBw\nLWNlcnQxKzApBgNVBAsMIk9wZW5IYXJtb255LUFCQy1hcHAtY2VydCBDb21tdW5p\ndHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTAT\nBgcqhkjOPQIBBggqhkjOPQMBBwNCAARvPLo0HPZroleu81PSWDEmB2cGI+EHUM7b\nw95BBsaThBfjbtt37oNICJRGaBWSxmCSxbU557Ci7IRE7o/vJaM0o2swaTAdBgNV\nHQ4EFgQUUvatlguoLp2hFrlme6a0KrlNF2AwCQYDVR0TBAIwADAOBgNVHQ8BAf8E\nBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwGAYMKwYBBAGPWwKCeAEDBAgwBgIB\nAQoBADAKBggqhkjOPQQDAgNIADBFAiAcH26/JhsRiHqDEX7A95Vb2VkIm8xUYJs5\npz2Nzde6yAIhAJrYHxuTVuhdgkJ7IL5WNmU+YwJdp6Li+rIb0JFe2ZmR\n-----END CERTIFICATE-----\n",
        "bundle-name": "com.example.mysigndemo",
        "apl": "system_basic",
        "app-feature": "hos_system_app"
    }

9、ProvisionProfile文件签名

sign-profile : ProvisionProfile文件签名
      ├── -mode            # 签名模式,【localSign】
      ├── -keyAlias        # 密钥别名,【OpenHarmony-ABC-profileCA】
      ├── -keyPwd          # 密钥口令,【profileCA123】
      ├── -profileCertFile # Profile签名证书,【./result/OpenHarmony-ABC-profile-cert-release.pem】
      ├── -inFile          # 输入的原始Provision Profile文件,【UnsgnedReleasedProfileTemplate.json】
      ├── -signAlg         # 签名算法,【SHA256withECDSA】
      ├── -keystoreFile    # 密钥库文件,【./result/OpenHarmony-ABC.p12】
      ├── -keystorePwd     # 密钥库口令,【keystore123】
      ├── -outFile         # 输出签名后的Provision Profile文件,p7b格式,【./result/Openharmony-signtest.p7b】

$ java -jar hap-sign-tool.jar sign-profile -mode "localSign" -keyAlias "OpenHarmony-ABC-profileCA" -keyPwd "profileCA123" -profileCertFile "./result/OpenHarmony-ABC-profile-cert-release.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/Openharmony-signtest.p7b"

#运行成功结果如下
INFO  - Start sign-profile
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - sign-profile success

#ProvisionProfile文件验签
 verify-profile : ProvisionProfile文件验签
       ├── -inFile       # 已签名的Provision Profile文件,【】
       ├── -outFile       # 验证结果文件(包含验证结果和profile内容),【】

$ java -jar hap-sign-tool.jar verify-profile -inFile "./result/Openharmony-signtest.p7b" -outFile "./result/Openharmony-verify-profile-result.json"

#运行成功结果如下,详细结果见Openharmony-verify-profile-result.json
INFO  - Start verify-profile
INFO  - verify-profile success

10、hap应用包签名

 sign-app : hap应用包签名 
      ├── -mode          # 签名模式,【localSign】
      ├── -keyAlias      # 密钥别名,【OpenHarmony-ABC-subCA】
      ├── -keyPwd        # 密钥口令,【subCA123】
      ├── -appCertFile   # 应用签名证书文件(证书链,顺序为最终实体证书-中间CA证书-根证书),【./result/OpenHarmony-ABC-app-cert.pem】
      ├── -profileFile   # 签名后的Provision Profile文件名,profileSigned为1时为p7b格式,profileSigned为0时为json格式,【./result/Openharmony-signtest.p7b】
      ├── -inFile        # 输入的原始APP包文件,【entry-default-unsigned.hap】
      ├── -signAlg       # 签名算法,【SHA256withECDSA】
      ├── -keystoreFile  # 密钥库文件,【OpenHarmony-ABC.p12】
      ├── -keystorePwd   # 密钥库口令,【keystore123】
      ├── -outFile       # 输出签名后的包文件,【./result/entry-default-signed.hap】

$ java -jar hap-sign-tool.jar sign-app -mode "localSign" -keyAlias "OpenHarmony-ABC-subCA" -keyPwd "subCA123" -appCertFile "./result/OpenHarmony-ABC-app-cert.pem" -profileFile "./result/Openharmony-signtest.p7b" -signAlg "SHA256withECDSA"  -inFile "entry-default-unsigned.hap" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/entry-default-signed.hap"

#运行成功结果如下
INFO  - Start sign-app
INFO  - certificate in profile: OpenHarmony Application Release
INFO  - ./result/OpenHarmony-ABC.p12 is exist. Try to load it with given passwd
INFO  - Add sign data in sign info list success.
INFO  - Generate signing block success, begin write it to output file
INFO  - Sign Hap success!
INFO  - sign-app success

verify-app : hap应用包文件验签
     ├── -inFile          # 已签名的应用包文件,【./result/entry-default-signed.hap】
     ├── -outCertChain    # 签名的证书链文件,【./result/OpenHarmony-ABC-subCA.cer】
     ├── -outProfile      # 应用包中的profile文件,【Openharmony-signtest.p7b】

$ java -jar hap-sign-tool.jar verify-app -inFile "./result/entry-default-signed.hap" -outCertChain "./result/OpenHarmony-ABC-subCA.cer" -outProfile "Openharmony-signtest.p7b" > ./result/OpenHarmony-verify-app-result.json

#运行成功结果如下,详细结果见OpenHarmony-verify-app-result.json
06-28 16:26:35 WARN  - Missing parameter: outproof

得到Profile签名文件和已签名的hap

Openharmony-signtest.p7b
entry-default-signed.hap

验证定制签名

验证定制签名主要通过

  • hdc安装已签名的hap
  • IDE导入签名配置,编译安装hap

hdc验证

上述步骤生成的entry-default-signed.hap为定制签名的hap,与系统默认签名配置不同,因此直接安装会失败:

> hdc install xxx\ohos_signtest\result\entry-default-signed.hap

[Info]App install path:ohos_signtest\result\entry-default-signed.hap, queuesize:0, msg:error: failed to install bundle. error: fail to verify pkcs7 file.
AppMod finish

因此需要修改默认系统证书配置文件trusted_apps_sources.json和trusted_root_ca.json
设备路径:/etc/security/trusted_apps_sources.json、/etc/security/trusted_root_ca.json
源码路径:base/security/appverify/interfaces/innerkits/appverify/config/OpenHarmony/trusted_apps_sources.json、
base/security/appverify/interfaces/innerkits/appverify/config/OpenHarmony/trusted_root_ca.json

  • trusted_apps_sources.json修改如下:
#兼容则新添加一下配置项,强制则替换默认OpenHarmony apps配置
{
    "name":"OpenHarmony-ABC apps",
    "app-signing-cert":"C=CN, O=OpenHarmony-ABC-app-cert, OU=OpenHarmony-ABC-app-cert Community, CN=OpenHarmony Application Release",
    "profile-signing-certificate":"C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Release",
    "profile-debug-signing-certificate":"C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Debug",
    "issuer-ca":"C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA",
    "max-certs-path":3,
    "critialcal-cert-extension":["keyusage"]
}

其中

name:授信应用群名称,无特殊要求,可自定义
app-signing-cert:应用签名证书主题,与OpenHarmony-ABC-app-cert.pem subject保持一致
profile-signing-certificate:profile Release签名证书主题,与OpenHarmony-ABC-profile-cert-release.pem subject保持一致
profile-debug-signing-certificate:profile Debug签名证书主题,与OpenHarmony-ABC-profile-cert-debug.pem subject保持一致
issuer-ca:profileCA主题,与OpenHarmony-ABC-profileCA.cer subject保持一致

subject中的C、O、OU、CN含义如下:
C:国家/地区代码,如CN
O:组织名称,如HUAWEI
OU:组织单位名称,如HUAWEI IDE
CN:名字与姓氏,建议与别名一致
  • 修改trusted_root_ca.json 文件:
    将 OpenHarmony-ABC-rootCA.cer 密钥信息处理后加入到文件中。
-----BEGIN CERTIFICATE-----
MIICQDCCAeagAwIBAgIFANIukcQwCgYIKoZIzj0EAwIwgYMxCzAJBgNVBAYTAkNO
MR8wHQYDVQQKDBZPcGVuSGFybW9ueS1BQkMtcm9vdENBMSkwJwYDVQQLDCBPcGVu
SGFybW9ueS1BQkMtcm9vdENBIENvbW11bml0eTEoMCYGA1UEAwwfT3Blbkhhcm1v
bnkgQXBwbGljYXRpb24gUm9vdCBDQTAeFw0yMzA2MjgwMzE3NTlaFw0yNDA2Mjcw
MzE3NTlaMIGDMQswCQYDVQQGEwJDTjEfMB0GA1UECgwWT3Blbkhhcm1vbnktQUJD
LXJvb3RDQTEpMCcGA1UECwwgT3Blbkhhcm1vbnktQUJDLXJvb3RDQSBDb21tdW5p
dHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJvb3QgQ0EwWTAT
BgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ/IK5FcvYOsKF8OpuiHRcR6zawSiPmVYp2
AKahLN5CxjMTpVj14t23yG8RScJEOjuKUxh8SAqYr7lB0riOWJodo0UwQzAdBgNV
HQ4EFgQUeb2WbI8s7xczwXlsuk8fo9eqmQUwEgYDVR0TAQH/BAgwBgEB/wIBADAO
BgNVHQ8BAf8EBAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANv5RhH5UtH0SXOh7k7+
AVcBkn3Dqfdbu/LTShclS+APAiBpEe3s49fxpW7pNbGzdMEgaqXafuf5+YTT5VqF
8PYydA==
-----END CERTIFICATE-----

处理后:

-----BEGIN CERTIFICATE-----\nMIICQDCCAeagAwIBAgIFANIukcQwCgYIKoZIzj0EAwIwgYMxCzAJBgNVBAYTAkNO\nMR8wHQYDVQQKDBZPcGVuSGFybW9ueS1BQkMtcm9vdENBMSkwJwYDVQQLDCBPcGVu\nSGFybW9ueS1BQkMtcm9vdENBIENvbW11bml0eTEoMCYGA1UEAwwfT3Blbkhhcm1v\nbnkgQXBwbGljYXRpb24gUm9vdCBDQTAeFw0yMzA2MjgwMzE3NTlaFw0yNDA2Mjcw\nMzE3NTlaMIGDMQswCQYDVQQGEwJDTjEfMB0GA1UECgwWT3Blbkhhcm1vbnktQUJD\nLXJvb3RDQTEpMCcGA1UECwwgT3Blbkhhcm1vbnktQUJDLXJvb3RDQSBDb21tdW5p\ndHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJvb3QgQ0EwWTAT\nBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ/IK5FcvYOsKF8OpuiHRcR6zawSiPmVYp2\nAKahLN5CxjMTpVj14t23yG8RScJEOjuKUxh8SAqYr7lB0riOWJodo0UwQzAdBgNV\nHQ4EFgQUeb2WbI8s7xczwXlsuk8fo9eqmQUwEgYDVR0TAQH/BAgwBgEB/wIBADAO\nBgNVHQ8BAf8EBAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANv5RhH5UtH0SXOh7k7+\nAVcBkn3Dqfdbu/LTShclS+APAiBpEe3s49fxpW7pNbGzdMEgaqXafuf5+YTT5VqF\n8PYydA==\n-----END CERTIFICATE-----\n

写入trusted_root_ca.json

#兼容则新添加一下配置项,强制则替换默认rootCA配置
{
    "C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA":"-----BEGIN CERTIFICATE-----\nMIICQDCCAeagAwIBAgIFANIukcQwCgYIKoZIzj0EAwIwgYMxCzAJBgNVBAYTAkNO\nMR8wHQYDVQQKDBZPcGVuSGFybW9ueS1BQkMtcm9vdENBMSkwJwYDVQQLDCBPcGVu\nSGFybW9ueS1BQkMtcm9vdENBIENvbW11bml0eTEoMCYGA1UEAwwfT3Blbkhhcm1v\nbnkgQXBwbGljYXRpb24gUm9vdCBDQTAeFw0yMzA2MjgwMzE3NTlaFw0yNDA2Mjcw\nMzE3NTlaMIGDMQswCQYDVQQGEwJDTjEfMB0GA1UECgwWT3Blbkhhcm1vbnktQUJD\nLXJvb3RDQTEpMCcGA1UECwwgT3Blbkhhcm1vbnktQUJDLXJvb3RDQSBDb21tdW5p\ndHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJvb3QgQ0EwWTAT\nBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ/IK5FcvYOsKF8OpuiHRcR6zawSiPmVYp2\nAKahLN5CxjMTpVj14t23yG8RScJEOjuKUxh8SAqYr7lB0riOWJodo0UwQzAdBgNV\nHQ4EFgQUeb2WbI8s7xczwXlsuk8fo9eqmQUwEgYDVR0TAQH/BAgwBgEB/wIBADAO\nBgNVHQ8BAf8EBAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANv5RhH5UtH0SXOh7k7+\nAVcBkn3Dqfdbu/LTShclS+APAiBpEe3s49fxpW7pNbGzdMEgaqXafuf5+YTT5VqF\n8PYydA==\n-----END CERTIFICATE-----\n"
}

将更新后的trusted_apps_sources.json和trusted_root_ca.json推送至系统中并重启:

> hdc shell "mount -o remount,rw /"
> hdc file send xxx\test\ohos_signtest\trusted_apps_sources.json /etc/security/trusted_apps_sources.json
FileTransfer finish, Size:2168, File count = 1, time:21ms rate:103.24kB/s
> hdc file send xxx\test\ohos_signtest\trusted_root_ca.json /etc/security/trusted_root_ca.json
FileTransfer finish, Size:1847, File count = 1, time:17ms rate:108.65kB/s
> hdc shell reboot

安装签名应用

> hdc install xxx\test\ohos_signtest\demo\entry-default-signed.hap
[Info]App install path:xxx\test\ohos_signtool\demo\entry-default-signed.hap, queuesize:0, msg:install bundle successfully.
AppMod finish

5、IDE验证

将生成的定制系统签名配置文件导入IDE,使用定制签名对hap进行签名,编译后直接可安装至设备。
打开IDE进行签名配置:
IDE->File->ProjectStructure->Signing Configs
IDE手动签名
其中:

  • Store file(*.p12):密钥库文件,选择OpenHarmony-ABC.p12
  • Store password:密钥库密码,keystore123
  • Key alias:密钥别名,OpenHarmony-ABC-subCA
  • Key password:密钥密码,subCA123
  • Sign alg:签名算法,默认为SHA256withECDSA
  • Profile file(*.p7b):profile签名文件,选择Openharmony-signtest.p7b
  • Certpath file(*.cer):应用调试/发布证书,将OpenHarmony-ABC-app-cert.pem 重命名为OpenHarmony-ABC-app-cert.cer

查看项目build-profile.json5签名配置是否已更新

"signingConfigs": [
      {
        "name": "default",
        "material": {
          "storePassword": "0000001BD38A4D685B71DC9660538FE27BFDFFA31735901B6EF4690690D4AF8E91936D04D6571E60B56376",
          "certpath": "C:/Users/xxx/Desktop/result/OpenHarmony-ABC-app-cert.cer",
          "keyAlias": "OpenHarmony-ABC-subCA",
          "keyPassword": "000000183110ABA8E0FE869D85057E2EADA895DDBE7C2CF30A292A217AFA8239B547506E250FD5F1",
          "profile": "C:/Users/xxx/Desktop/result/Openharmony-signtest.p7b",
          "signAlg": "SHA256withECDSA",
          "storeFile": "C:/Users/xxx/Desktop/result/OpenHarmony-ABC.p12"
        }
      }
    ],

点击编译,编译完成后自动hap自动安装至设备中。

定制签名配置导入源码

详细步骤可参考OpenHarmony应用签名 - 厂商私有签名的配置和使用
参考文档中对于当前版本(3.2 Release)源码中签名配置不完善之处也给出了说明。本文这里以替换源码默认签名配置方式介绍导入定制签名配置的大致步骤,详细过程可以参见上述资料。

准备工作

#相关定制签名配置文件
hap签名工具包:hap-sign-tool.jar
定制签名密钥库:OpenHarmony-ABC.p12
定制签名密钥库密码:keystore123
Key alias密钥别名:OpenHarmony-ABC-subCA
密钥密码:subCA123
应用profile签名文件:OpenHarmony-ABC-app-cert.pem或OpenHarmony-ABC-app-cert.cer
profile签名模板:UnsgnedReleasedProfileTemplate.json

OpenHarmony 3.2 Release源码一份

配置源码私有源签名信息

根据前文【验证定制签名】章节方式修改trusted_apps_sources.json和trusted_root_ca.json文件,替换源码默认私有源签名信息。
base/security/appverify/interfaces/innerkits/appverify/config/OpenHarmony/trusted_apps_sources.json

{
    "name":"OpenHarmony-ABC apps",
    "app-signing-cert":"C=CN, O=OpenHarmony-ABC-app-cert, OU=OpenHarmony-ABC-app-cert Community, CN=OpenHarmony Application Release",
    "profile-signing-certificate":"C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Release",
    "profile-debug-signing-certificate":"C=CN, O=OpenHarmony-ABC-profile-cert, OU=OpenHarmony-ABC-profile-cert Community, CN=OpenHarmony Application Profile Debug",
    "issuer-ca":"C=CN, O=OpenHarmony-ABC-subCA, OU=OpenHarmony-ABC-subCA Community, CN=OpenHarmony Application CA",
    "max-certs-path":3,
    "critialcal-cert-extension":["keyusage"]
}

base/security/appverify/interfaces/innerkits/appverify/config/OpenHarmony/trusted_root_ca.json

{
    "C=CN, O=OpenHarmony-ABC-rootCA, OU=OpenHarmony-ABC-rootCA Community, CN=OpenHarmony Application Root CA":"-----BEGIN CERTIFICATE-----\nMIICQDCCAeagAwIBAgIFANIukcQwCgYIKoZIzj0EAwIwgYMxCzAJBgNVBAYTAkNO\nMR8wHQYDVQQKDBZPcGVuSGFybW9ueS1BQkMtcm9vdENBMSkwJwYDVQQLDCBPcGVu\nSGFybW9ueS1BQkMtcm9vdENBIENvbW11bml0eTEoMCYGA1UEAwwfT3Blbkhhcm1v\nbnkgQXBwbGljYXRpb24gUm9vdCBDQTAeFw0yMzA2MjgwMzE3NTlaFw0yNDA2Mjcw\nMzE3NTlaMIGDMQswCQYDVQQGEwJDTjEfMB0GA1UECgwWT3Blbkhhcm1vbnktQUJD\nLXJvb3RDQTEpMCcGA1UECwwgT3Blbkhhcm1vbnktQUJDLXJvb3RDQSBDb21tdW5p\ndHkxKDAmBgNVBAMMH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJvb3QgQ0EwWTAT\nBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ/IK5FcvYOsKF8OpuiHRcR6zawSiPmVYp2\nAKahLN5CxjMTpVj14t23yG8RScJEOjuKUxh8SAqYr7lB0riOWJodo0UwQzAdBgNV\nHQ4EFgQUeb2WbI8s7xczwXlsuk8fo9eqmQUwEgYDVR0TAQH/BAgwBgEB/wIBADAO\nBgNVHQ8BAf8EBAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIhANv5RhH5UtH0SXOh7k7+\nAVcBkn3Dqfdbu/LTShclS+APAiBpEe3s49fxpW7pNbGzdMEgaqXafuf5+YTT5VqF\n8PYydA==\n-----END CERTIFICATE-----\n"
}

为了确保后续步骤的正确性,这里先进行简单的验证:编译源码,烧录images更新软件。
安装使用定制签名的demo应用,若安装成功则说明上述json文件修改有效,否则需要检查上述json配置文件修改参数或demo应用定制签名配置。

替换源码默认编译签名配置

OpenHarmony-ABC.p12替换developtools\hapsigner\dist\OpenHarmony.p12
OpenHarmony-ABC-app-cert.pem替换developtools\hapsigner\dist\OpenHarmonyApplication.pem
注意:为了方便后续更新应用签名配置,仅更新上述两个签名配置内容,文件名不做更新,仍保留源码默认文件名OpenHarmony.p12和OpenHarmonyApplication.pem。

OpenHarmony 3.2 修改默认编译签名信息
build/ohos_var.gni

default_hap_private_key_path = "OpenHarmony-ABC-subCA"    //更新定制签名密钥别名
default_signature_algorithm = "SHA256withECDSA"
default_key_alias = "subCA123"    //更新定制签名签名密钥密码
default_keystore_password = "keystore123"  //更新定制签名密钥库密码
default_keystore_path = "//developtools/hapsigner/dist/OpenHarmony.p12"
default_hap_certificate_file =
    "//developtools/hapsigner/dist/OpenHarmonyApplication.pem"

OpenHarmony 4.1 修改默认编译签名信息
build/ohos_var.gni

default_hap_private_key_path = "subCA123"    //更新定制签名签名密钥密码
default_signature_algorithm = "SHA256withECDSA"
default_key_alias = "OpenHarmony-ABC-subCA"    //更新定制签名密钥别名
default_keystore_password = "keystore123"  //更新定制签名密钥库密码
default_keystore_path = "//developtools/hapsigner/dist/OpenHarmony.p12"
default_hap_certificate_file =
    "//developtools/hapsigner/dist/OpenHarmonyApplication.pem"

更新系统应用及其定制签名配置文件

到这里源码BUILD.gn编译出的应用为使用定制签名配置签名应用。但源码中部分应用采用直接预置hap的方式,故需要另外使用定制签名配置生成hap后更新hap文件。
需更新hap的应用:

输入法选择框:
base/inputmethod/imf/services/dialog/input_method_choose_dialog.hap
webview应用:
base\web\webview\ohos_nweb\prebuilts\arm64\NWeb.hap
系统默认部分预置应用:
applications\standard\hap\*.hap

这里以更新BUILD.gn编译方式permissionmanager的应用和IDE编译的KikaInput输入法为例。

配置permissionmanager系统应用定制签名

applications\standard\permission_manager\signature
从permissionmanager原始pm.p7b中获取UnsgnedReleasedProfileTemplate.json信息

java -jar hap-sign-tool.jar verify-profile -inFile pm.p7b -outFile PM_UnsgnedReleasedProfileTemplate.json

将PM_UnsgnedReleasedProfileTemplate.json的bundle-name、apl、app-feature、allowed-acls、permissions字段信息更新至用于重新生成pm.p7b的UnsgnedReleasedProfileTemplate.json。
通过文本查看的方式打开pm.p7b将app-privilege-capabilities字段信息填入UnsgnedReleasedProfileTemplate.json。
注意:UnsgnedReleasedProfileTemplate.json字段distribution-certificate需与上文第8小节distribution-certificate保持一致。详细见【8、将OpenHarmony-ABC-app-cert.pem中第一部分的密钥,把回车转换为\n字符,放入UnsgnedReleasedProfileTemplate.json的distribution-certificate中】。

生成新的pm.p7b

java -jar hap-sign-tool.jar sign-profile -mode "localSign" -keyAlias "OpenHarmony-ABC-profileCA" -keyPwd "profileCA123" -profileCertFile "./result/OpenHarmony-ABC-profile-cert-release.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/pm.p7b"

将pm.p7b和UnsgnedReleasedProfileTemplate.json一同更新至
applications\standard\permission_manager\signature
接下来进行验证:
使用hb命令模块编译permissionmanager:

hb build -T applications/standard/permission_manager/permissionmanager:permission_manager
#得到签名hap
out\zp37a\obj\applications\standard\permission_manager\permissionmanager\permission_manager.hap

更新vendor\hihope\rk3568\preinstall-config\install_list_capability.json或vendor\hihope\rk3568\preinstall-config\install_list_permissions.json中permisson_manager的app_signature,简单验证可修改后拷贝至设备/system/etc/app/。
将out\zp37a\obj\applications\standard\permission_manager\permissionmanager\permission_manager.hap替换设备中的/system/app/com.ohos.permissionmanager/permission_manager.hap,删除data/分区后重启设备。
重启后bm dump -a若查看到com.ohos.permissionmanager则说明签名后的permission_manager.hap已验签成功并重新安装。

配置KikaInput系统应用定制签名

同上方式,从
applications\standard\app_samples\CompleteApps\KikaInput原始p7b中获取profile信息,并更新至UnsgnedReleasedProfileTemplate.json。
使用UnsgnedReleasedProfileTemplate.json生成新的kikakeyboard.p7b

java -jar hap-sign-tool.jar sign-profile -mode "localSign" -keyAlias "OpenHarmony-ABC-profileCA" -keyPwd "profileCA123" -profileCertFile "./result/OpenHarmony-ABC-profile-cert-release.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -signAlg "SHA256withECDSA" -keystoreFile "./result/OpenHarmony-ABC.p12" -keystorePwd "keystore123" -outFile "./result/kikakeyboard.p7b"

将applications\standard\app_samples\CompleteApps\KikaInput导入IDE工程,并使用定制签名配置文件OpenHarmony.p12、kikakeyboard.p7b、OpenHarmony-ABC-app-cert.cer
编译生成新的签名hap,替换设备/system/app/com.example.kikakeyboard/kikaInput.hap,更新vendor\hihope\rk3568\preinstall-config\install_list_capability.json或vendor\hihope\rk3568\preinstall-config\install_list_permissions.json中kikakeyboard的app_signature,修改后拷贝至设备/system/etc/app/。
删除data分区后重启设备,重启后bm dump -a若查看到com.example.kikakeyboard则说明签名后的kikaInput.hap已验签成功并重新安装。

总结定制签名导入源码步骤:
1、更新配置源码私有源签名信息文件trusted_apps_sources.json和trusted_root_ca.json
base/security/appverify/interfaces/innerkits/appverify/config/OpenHarmony/trusted_apps_sources.json
base/security/appverify/interfaces/innerkits/appverify/config/OpenHarmony/trusted_root_ca.json
2、替换源码默认编译签名配置
developtools\hapsigner\dist\OpenHarmony.p12
developtools\hapsigner\dist\OpenHarmonyApplication.pem
build/ohos_var.gni
3、更新预置应用p7b签名配置及hap
对于以预置hap方式的应用需收到生成定制签名的hap并将hap更新至源码中。
4、更新应用的app_signature签名指纹信息
vendor\hihope\rk3568\preinstall-config\install_list_capability.json
vendor\hihope\rk3568\preinstall-config\install_list_permissions.json中
5、编译源码验证,bm dump -a查看各应用是否已安装上,各应用运行情况。

hap-sign-tool.jar帮助手册

$ java -jar hap-sign-tool.jar -h
06-27 19:28:02 INFO  - /*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

USAGE:  <generate-keypair|generate-csr|generate-cert|generate-ca|generate-app-cert|generate-profile-cert> [options]
USAGE:  <sign-profile|verify-profile|sign-app|verify-app> [options]

    generate-keypair [options]:
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -keyAlg : key algorithm, required fields, including RSA/ECC;
        -keySize : key size, required fields, the size of the RSA algorithm is 2048/3072/4096, and the size of the ECC algorithm is NIST-P-256/NIST-P-384;
        -keystoreFile : keystore file, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -extCfgFile : Extend Profile, optional fields;

    EXAMPLE:
        generate-keypair -keyAlias "oh-app1-key-v1" -keyPwd ****** -keyAlg ECC -keySize NIST-P-256 -keystoreFile "D:\OH\app-keypair.jks" -keystorePwd ******
        generate-keypair -keyAlias "oh-profile-key-v1" -keyPwd ****** -keyAlg RSA -keySize 2048 -keystoreFile "D:\OH\profile-keypair.jks" -keystorePwd ******

    generate-csr [options]:
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -subject : certificate subject, required fields;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -keystoreFile : keystore file, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -outFile : output file, optional fields, if not filled, it will be directly output to the console;
        -extCfgFile : Extend Profile, optional fields;

    EXAMPLE:
        generate-csr -keyAlias "oh-app1-key-v1" -keyPwd ****** -subject "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release" -signAlg SHA256withECDSA  -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ****** -outFile "D:\OH\oh-app1-key-v1.csr"

    generate-cert [options]:
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -issuer : issuer subject, required fields;
        -issuerKeyAlias : issuer key alias, required fields;
        -issuerKeyPwd : issuer key password, optional fields;
        -subject : certificate subject, required fields;
        -validity : certificate validity, optional fields, the default is 1095 days;
        -keyUsage : key usage, required fields, including digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement, certificateSignature, crlSignature, encipherOnly and decipherOnly, if the certificate includes multiple key usages, separate them with commas;
        -keyUsageCritical : whether keyUsage is a key item, optional fields, the default is true;
        -extKeyUsage : extended key usage, optional fields, including clientAuthentication, serverAuthentication, codeSignature, emailProtection, smartCardLogin, timestamp, ocspSignature;
        -extKeyUsageCritical : whether extKeyUsage is a key item, optional fields, the default is false;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -basicConstraints : whether to include basicConstraints, optional fields, the default is false;
        -basicConstraintsCritical : whether basicConstraints is a key item, optional fields, the default is false;
        -basicConstraintsCa : whether it is CA, optional fields, the default is false;
        -basicConstraintsPathLen : basicConstraints path length, optional fields, the default is 0;
        -keystoreFile : keystore file, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -outFile : output file, optional fields, if not filled, it will be directly output to the console;
        -extCfgFile : Extend Profile, optional fields;
        -issuerKeystoreFile : issuer keystore file, optional fields, JKS or P12 format;
        -issuerKeystorePwd : issuer keystore password, optional fields;

    EXAMPLE:
        generate-cert -keyAlias "oh-app1-key-v1" -keyPwd ****** -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA" -issuerKeyAlias "oh-app-sign-srv-ca-key-v1" -issuerKeyPwd ****** -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release" -validity 365 -keyUsage digitalSignature -extKeyUsage codeSignature -signAlg SHA256withECDSA  -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ****** -outFile "D:\OH\app1.cer"

    generate-ca [options]:
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -keyAlg : key algorithm, required fields, including RSA/ECC;
        -keySize : key size, required fields, the size of the RSA algorithm is 2048/3072/4096, and the size of the ECC algorithm is NIST-P-256/NIST-P-384;
        -issuer : issuer subject, optional fields, if it is empty, it means root CA;
        -issuerKeyAlias : issuer key alias, optional fields, if it is empty, it means root CA;
        -issuerKeyPwd : issuer key password, optional fields;
        -subject : certificate subject, required fields;
        -validity : certificate validity, optional fields, the default is 3650 days;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -basicConstraintsPathLen : basicConstraints path length, optional fields, the default is 0;
        -keystoreFile : keystore file, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -outFile : output file, optional fields, if not filled, it will be directly output to the console;
        -extCfgFile : Extend Profile, optional fields;
        -issuerKeystoreFile : issuer keystore file, optional fields, JKS or P12 format;
        -issuerKeystorePwd : issuer keystore password, optional fields;

    EXAMPLE:
        generate-ca -keyAlias "oh-root-ca-key-v1" -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA" -validity 365 -signAlg SHA384withECDSA  -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ******  -outFile "D:\OH\root-ca.cer" -keyAlg RSA -keySize 2048
        generate-ca -keyAlias "oh-app1-key-v1" -keyAlg RSA -keySize 2048 -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA" -issuerKeyAlias "oh-sub-app-ca-key-v1" -issuerKeyPwd ****** -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA" -validity 365 -signAlg SHA384withECDSA  -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ******  -outFile "D:\OH\sub-app-sign-srv-ca.cer"
        generate-ca -keyAlias "oh-profile-key-v1" -keyAlg RSA -keySize 4096 -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA" -issuerKeyAlias "oh-sub-profile-ca-key-v1" -issuerKeyPwd ****** -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Profile Signature Service CA" -validity 365 -signAlg SHA384withECDSA  -keystoreFile  "D:\OH\profile-keypair.jks" -keystorePwd ******  -outFile "D:\OH\sub-profile-sign-srv-ca.cer"

    generate-app-cert [options]:
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -issuer : issuer subject, required fields;
        -issuerKeyAlias : issuer key alias, required fields;
        -issuerKeyPwd : issuer key password, optional fields;
        -subject : certificate subject, required fields;
        -validity : certificate validity, optional fields, the default is 1095 days;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -keystoreFile : keystore file, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -outForm : the format of the output certificate file, including cert/certChain, optional fields, the default is cert;
        -rootCaCertFile : root CA certificate file, required when outForm is certChain;
        -subCaCertFile : secondary sub-CA certificate file, required when outForm is certChain;
        -outFile : output certificate file (certificate or certificate chain), optional fields, if not filled, it will be directly output to the console;
        -extCfgFile : Extend Profile, optional fields;
        -issuerKeystoreFile : issuer keystore file, optional fields, JKS or P12 format;
        -issuerKeystorePwd : issuer keystore password, optional fields;

    EXAMPLE:
        generate-app-cert -keyAlias "oh-app1-key-v1" -keyPwd ****** -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Debug Signature Service CA" -issuerKeyAlias "oh-app-sign-debug-srv-ca-key-v1" -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Debug" -validity 365 -signAlg SHA256withECDSA -rootCaCertFile "D:\OH\root-ca.cer" -subCaCertFile "D:\OH\sub-app-sign-srv-ca.cer" -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ****** -outForm certChain -outFile "D:\OH\app-debug-cert.cer"
        generate-app-cert -keyAlias "oh-app1-key-v1" -keyPwd ****** -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Release Signature Service CA" -issuerKeyAlias "oh-app-sign-release-srv-ca-key-v1" -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release" -validity 365 -signAlg SHA256withECDSA -rootCaCertFile "D:\OH\root-ca.cer" -subCaCertFile "D:\OH\sub-app-sign-srv-ca.cer" -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ****** -outForm certChain -outFile "D:\OH\app-release-cert.cer"

    generate-profile-cert [options]:
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -issuer : issuer subject, required fields;
        -issuerKeyAlias : issuer key alias, required fields;
        -issuerKeyPwd : issuer key password, optional fields;
        -subject : certificate subject, required fields;
        -validity : certificate validity, optional fields, the default is 1095 days;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -keystoreFile : keystore file, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -outForm : the format of the output certificate file, including cert/certChain, optional fields, the default is cert;
        -rootCaCertFile : root CA certificate file, required when outForm is certChain;
        -subCaCertFile : secondary sub-CA certificate file, required when outForm is certChain;
        -outFile : output file, optional fields, if not filled, it will be directly output to the console;
        -extCfgFile : Extend Profile, optional fields;
        -issuerKeystoreFile : issuer keystore file, optional fields, JKS or P12 format;
        -issuerKeystorePwd : issuer keystore password, optional fields;

    EXAMPLE:
        generate-profile-cert -keyAlias "oh-profile-key-v1" -keyPwd ****** -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Provision Profile Debug Signature Service CA" -issuerKeyAlias "oh-profile-sign-debug-srv-ca-key-v1" -issuerKeyPwd ****** -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Provision Profile Debug" -validity 365 -signAlg SHA256withECDSA  -rootCaCertFile "D:\OH\root-ca.cer" -subCaCertFile "D:\OH\sub-profile-sign-srv-ca.cer" -keystoreFile  "D:\OH\profile-keypair.jks" -keystorePwd ****** -outForm certChain -outFile "D:\OH\provision-profile-debug.cer"
        generate-profile-cert -keyAlias "oh-profile-key-v1" -keyPwd ****** -issuer "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Provision Profile Release Signature Service CA" -issuerKeyAlias "oh-profile-sign-release-srv-ca-key-v1" -issuerKeyPwd ****** -subject  "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Provision Profile Release" -validity 365 -signAlg SHA256withECDSA  -rootCaCertFile "D:\OH\root-ca.cer" -subCaCertFile "D:\OH\sub-profile-sign-srv-ca.cer" -keystoreFile  "D:\OH\profile-keypair.jks" -keystorePwd ****** -outForm certChain -outFile "D:\OH\provision-profile-release.cer"

    sign-profile [options]:
        -mode : signature mode, required fields, including localSign/remoteSign;
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields;
        -profileCertFile : profile signing certificate (certificate chain, the order is three-level-two-root), required fields;
        -inFile : input original Provision Profile file, required fields;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -keystoreFile : keystore file, if signature mode is localSign, required fields, JKS or P12 format;
        -keystorePwd : keystore password, optional fields;
        -outFile : output the signed Provision Profile file, p7b format, required fields;
        -extCfgFile : Extend Profile, optional fields;

    EXAMPLE:
        sign-profile -mode localSign -keyAlias "oh-profile-key-v1" -keyPwd ****** -profileCertFile "D:\OH\provision-profile-release.cer" -inFile "D:\OH\app1-profile-release.json" -signAlg SHA256withECDSA  -keystoreFile  "D:\OH\profile-keypair.jks" -keystorePwd ****** -outFile "D:\OH\signed-profile.p7b"

    verify-profile [options]:
        -inFile : signed Provision Profile file, p7b format, required fields;
        -outFile : Verification result file (including verification result and profile content), json format, optional; if not filled, it will be directly output to the console;
        -extCfgFile : Extend Profile, optional fields;

    EXAMPLE:
        verify-profile -inFile "D:\OH\signed-profile.p7b" -outFile "D:\OH\VerifyResult.json"

    sign-app [options]:
        -mode : signature mode, required fields, including localSign/remoteSign/remoteResign;
        -keyAlias : key alias, required fields;
        -keyPwd : key password, optional fields on localSign mode;
        -appCertFile : application signature certificate file, required fields on localSign mode, optional fields on remoteSign mode;
        -profileFile : signed Provision Profile file, p7b format, required fields;
        -profileSigned : indicates whether the profile file has a signature.The options are as follows: 1:yes; 0:no; default value:1. optional fields;
        -inFile : input original application package file, hap or bin format, required fields;
        -signAlg : signature algorithm, required fields, including SHA256withRSA/SHA384withRSA/SHA256withECDSA/SHA384withECDSA;
        -keystoreFile : keystore file, if signature mode is localSign, required fields on localSign mode, JKS or P12 format;
        -keystorePwd : keystore password, optional fields on localSign mode;
        -outFile : output the signed Provision Profile file, required fields;
        -extCfgFile : Extend Profile, optional fields;
        -inForm : enter the format of the original file, the format is .zip or .bin;
        -compatibleVersion : min compatible api version for running app, required fields while input original application package file format is hap;
        -signServer : remote signer plugin, required fields on remoteSign mode;
        -signerPlugin : remote sign service url, required fields on remoteSign mode;
        -onlineAuthMode : remote sign auth mode, required fields on remoteSign mode, including account;
        -username : user account for online auth, required fields on remoteSign mode with account auth mode;
        -userPwd : user password for online auth, required fields on remoteSign mode with account auth mode;
        -ext : extend parameters for remote signer plugin, optional fields;

    EXAMPLE:
        sign-app -mode localSign -keyAlias "oh-app1-key-v1" -appCertFile "D:\OH\app-release-cert.cer" -profileFile "D:\OH\signed-profile.p7b" -inFile "D:\OH\app1-unsigned.hap" -signAlg SHA256withECDSA  -keystoreFile  "D:\OH\app-keypair.jks" -keystorePwd ****** -outFile "D:\OH\app1-signed.hap -compatibleVersion 8"

    verify-app [options]:
        -inFile : signed application package file, hap or bin format, required fields;
        -outCertChain : signed certificate chain file, required fields;
        -outProfile : profile file in application package, required fields;
        -extCfgFile : Extend Profile, optional fields;

    EXAMPLE:
        verify-app -inFile "D:\OH\app1-signed.hap" -outCertChain "outCertChain.cer" -outProfile "outprofile.p7b"

COMMANDS:
        generate-keypair : generate key pair
        generate-csr : generate certificate signing request
        generate-cert : generate certificate in full, large and complete, any certificate can be generated
        generate-ca : generate root/subject CA certificate, if the key does not exist, generate the key together
        generate-app-cert : generate application debug/release certificate
        generate-profile-cert : generate application debug/release certificate
        sign-profile : Provision Profile file signature
        verify-profile : Provision Profile file verification
        sign-app : application package signature
        verify-app : application package file verification
OpenHarmony实战开发-如何实现一个轻量级输入法 kikainput是一个轻量级的输入法应用,支持在运行OpenHarmony OS的智能终端上。 阅读详情

相关推荐

如何通过OpenHarmony中的定制系统实现生成“私有签名”

为了保证 OpenHarmony 应用的完整性和来源可靠,在应用构建时需要对应用进行签名。经过签名的应用才能在真机设备上安装、运行、和调试。

2401_82546228的博客 1121

DevEco Studio调试时在真机设备上运行应用时报“Failure[INSTALL_FAILED_VERIFY_APP_PKCS7_FAIL]”

检查证书的有效时间,可在AppGallery Connect中,进入HarmonyOS项目,然后点击左侧导航栏最下方的HarmonyOS应用 > HAP Provision Profile管理,查看对应证书的失效时间。如果证书未过期,设备系统日期也正确,则可能是证书链无效,需要重新申请新的证书,可采用DevEco Studio自动化签名方案,重新对应用进行签名。如果证书未过期,请检查运行设备上的日期,确保设备的日期与当前实际日期保持一致。该问题是由于签名证书的有效时间问题导致。

qq_32065891的博客 885

OpenHarmony HAP签名实战:用HapSigner搞定命令行签名与验证

在OpenHarmony应用开发中,HAP安装包的数字签名是系统安全校验的关键环节。数字签名通过非对称加密和摘要算法,为应用包提供来源认证与防篡改能力。HapSigner作为官方命令行签名工具,可在无IDE环境下完成HAP的签名与验证,适用于CI/CD流水线、批量出包及企业级证书管理等自动化工程实践。本文从HAP包结构、签名原理入手,详细讲解密钥库生成、Profile准备、sign-app命令参数及验签流程,并整理常见错误排查技巧,帮助开发者快速构建可复现的OpenHarmony签名流程。

weixin_29597551的博客 310

OpenHarmony应用签名 - 系统应用签名(4.0-Release)

OpenHarmony开源社区提供了标准系统上的部分系统应用,如桌面、SystemUI、设置等,为开发者提供了构建标准系统应用的具体实例,这些应用支持在所有标准系统的设备上使用。本篇文档将介绍如何给这些系统应用进行签名,使它们可以正确的安装和运行在OpenHarmony系统上。

TiZizzz 2988

团结引擎+OpenHarmony实战:如何用Hvigor适配最新SDK并成功打包真机应用

本文详细介绍了如何利用团结引擎与OpenHarmony深度整合,通过Hvigor工具链适配最新SDK并成功打包真机应用。内容涵盖开发环境配置、SDK版本管理、Hvigor构建系统定制以及真机调试等关键环节,特别针对SDK版本冲突问题提供了实用解决方案,助力开发者高效接入鸿蒙生态。

weixin_30566063的博客 431

OpenHarmony-L2标准系统开发实战:从源码下载到应用部署全流程指南

本文详细介绍了OpenHarmony-L2标准系统开发的完整流程,从源码下载、环境配置到应用部署与调试。涵盖DevEco Studio环境搭建、代码下载编译、系统优化及版本烧写等关键步骤,为开发者提供全面的实战指南,助力高效开发智能终端应用。

weixin_30836759的博客 333

应用签名

weixin_59519801的博客 215

Dayu200编译OpenHarmony标准系统全链路指南

OpenHarmony标准系统是面向64位ARM平台的完整操作系统框架,其核心依赖Linux内核、分布式软总线与ArkUI等模块的协同运行。编译原理上需实现Loader-U-Boot-Kernel三层启动链的精准对齐,并完成内核与用户态、构建系统与组件、烧录固件与启动流程的三重解耦。技术价值在于支撑可调试、可裁剪、可量产的硬件适配基线,为HDMI输出、音频驱动、USB WiFi等关键外设提供底层保障。典型应用场景包括RK3568开发板(如Dayu200)上的IoT网关、边缘计算终端及信创设备开发。本文聚焦O

weixin_33428613的博客 359

SHK_openharmony系统内置HAP包步骤(HAP包需要已签名)

3、在vendor/kaihong/khp_rk3588_ic801/preinstall-config/khos/install_list.json文件内进行HAP包配置。2、在vendor/kaihong/khp_rk3588_ic801/app/BUILD.gn文件内进行应用增加。1、把签名好的HAP应用放置于extension/applications/hap下。4、修改完成后编译即可。

csdn_1233的博客 260

OpenHarmony系统定制:实现开机自启动应用与Launcher替换实战

在嵌入式系统与物联网设备开发中,应用自启动与系统启动管理是核心技术需求,尤其在面向专用设备(如工业平板、智能终端)的产品化场景下。其原理通常涉及操作系统启动流程、应用框架的入口管理机制(如Launcher标识与Intent匹配),通过修改系统配置或应用属性来实现特定应用的首屏展示。这项技术的核心价值在于提供“开机即用”的无缝用户体验,提升设备专业性与操作效率,是设备定制化与品牌化的重要环节。应用场景广泛覆盖智能零售终端、教育一体机、工业控制面板等专用设备领域。本文以OpenHarmony 4.1系统与RK3

weixin_42523104的博客 744

HarmonyOS 鸿蒙开发DevEco Studio:编译构建

编译构建是将HarmonyOS应用/服务的源代码、资源、第三方库等,通过编译工具转换为可直接在硬件设备上运行的二进制机器码,然后再将二进制机器码封装为HAP/APP软件包,并为HAP/APP包进行签名的过程。其中,HAP是可以直接运行在模拟器或真机设备中的软件包;APP则是用于应用/服务上架到华为应用市场。

斌擎科技 1316

Flutter与OpenHarmony融合开发教育应用实战

跨平台开发框架Flutter通过其高效的渲染引擎和丰富的组件库,为开发者提供了构建高性能应用的解决方案。当Flutter遇上新兴的OpenHarmony操作系统,这种组合为教育类应用开发带来了新的可能性。通过Dart语言编写的业务逻辑与平台特定代码的分离,开发者可以专注于核心功能实现,同时确保应用在不同平台上的表现一致性。在教育应用场景中,这种技术组合特别适合实现可视化学习管理系统和交互式训练模块。本项目通过TableCalendar组件与自定义事件加载器的结合,展示了如何构建一个集逆向思维训练与学习进度管

weixin_33824385的博客 317

pkcs7.rar_openssl 签名_openssl pkcs7_openssl数字签名_openssl签名_pkcs7签

利用OpenSSL PKCS7进行数字签名的示例代码,仅供参考

Flutter与OpenHarmony融合开发电商App实战

跨平台开发框架Flutter以其高效的渲染性能和丰富的UI组件库,正在成为移动应用开发的重要选择。当Flutter与开源操作系统OpenHarmony结合时,开发者需要解决特殊的环境适配问题,同时保持应用性能。本文以电商App开发为例,详解Flutter在OpenHarmony平台上的定制化集成方案,包括分布式能力调用、原子化服务集成等OpenHarmony特性适配。通过性能优化策略如渲染调优、内存管理,以及瀑布流布局、动效设计等电商典型场景实现,展示了如何构建高性能的跨平台电商应用。对于想要探索Flutt

weixin_42525005的博客 247

LMX2595实战:手把手教你配置JESD204B时钟与SYSREF(含相位同步避坑指南)

本文详细介绍了LMX2595在JESD204B时钟系统中的配置与优化方法,包括时钟系统架构设计、相位同步配置、SYSREF生成技巧以及PCB布局规范。通过实战案例和避坑指南,帮助工程师充分发挥LMX2595的超低相位噪声和抖动性能,确保高速数据转换器系统的稳定性和同步精度。

weixin_29206669的博客 478

优化求解器性能:当分支切割算法中的gap停滞不前时如何应对

本文深入探讨了当分支切割算法求解复杂整数规划问题时,gap停滞不前的根本原因与应对策略。文章指出gap停滞源于上界(找不到更优整数解)或下界(证明过程缓慢)提升受阻,并提供了从模型改写、自定义割平面、调整搜索策略到参数调优等一系列实战方法,帮助优化工程师有效打破求解僵局,推动gap下降。

weixin_29294597的博客 381

OpenHarmony设备到手后必做的10件事:从屏幕旋转到开机动画,用hdc命令一站式定制你的开发板

本文详细介绍了OpenHarmony开发板开箱后的10项必备配置与定制技巧,涵盖从基础连接到深度定制的全流程。重点讲解了如何使用hdc命令进行屏幕旋转设置、开机动画更换、系统应用管理等操作,帮助开发者快速搭建高效的OpenHarmony开发环境。

weixin_33736649的博客 244

UE5.1实战:从零到打包,手把手教你用UMG和蓝图搭建智慧城市数字孪生界面

本文详细介绍了如何使用UE5.1的UMG和蓝图系统从零开始构建智慧城市数字孪生界面。通过环境准备、UMG界面设计、蓝图功能实现、数据绑定到最终打包发布的全流程指导,帮助开发者掌握数字孪生技术的核心应用,提升智慧城市可视化开发效率。

weixin_30251829的博客 619

RK3568平台OpenHarmony 4.0浏览器应用从编译到预集成的全流程实践

本文详细介绍了在RK3568平台上为OpenHarmony 4.0系统集成浏览器应用的全流程实践,包括环境准备、代码编译、系统预集成和性能优化等关键步骤。通过具体配置示例和常见问题解决方案,帮助开发者高效完成浏览器应用的部署与优化,提升在嵌入式设备上的运行效果。

weixin_28745067的博客 386

vcpkg管理OpenCASCADE的5个高效技巧:从多版本共存到离线部署

本文详细介绍了使用vcpkg高效管理OpenCASCADE的5个实用技巧,包括多版本共存、性能优化、团队共享、CI/CD集成和离线部署。通过自动配置和版本控制,vcpkg显著简化了OpenCASCADE的开发环境管理,特别适合工业级CAD开发场景。

rain6的博客 188

DFT知识点扫盲——DFT scan chain

实际在项目中synccell一般直接上ULVT,既然是SDF,就是带Scan接口的DFF,SN (set negtive)是低置位,RP(reset positive)是高复位,既没有SN也没有RP的就是无复位寄存器。1:定义:满足可测试性设计(DFT),将设计中所有的触发器连接到一条或者若干条链上,称为scan chain,将一个复杂的时序电路转换为简单的组合电路进行测试,这一步是在逻辑综合(DC)中实现。当SE=1当SI=1时,电路进入scan状态,当SI=0时,电路工作在normal状态。

笨蛋大乌龟的博客 4938

Flutter在OpenHarmony上的开发实践与优化指南

跨平台开发框架Flutter凭借其高效的开发体验和接近原生的性能表现,正在成为移动应用开发的主流选择。其核心原理是通过Skia渲染引擎实现跨平台UI一致性,配合Dart语言的热重载特性大幅提升开发效率。在分布式操作系统OpenHarmony生态中集成Flutter,开发者可以充分利用单代码库优势,快速构建适配多种设备形态的应用界面。本教程重点演示了从环境配置到打包部署的全流程实践,特别针对OpenHarmony平台特性提供了分布式能力集成和系统UI适配方案,并深入探讨了状态管理、性能优化等工程实践要点,为开

weixin_30536861的博客 237

Reeds-Shepp曲线公式推导及代码实现-第二部分(共三部分)

文章目录2. Reeds-Shepp求解2.1 L+S+L+L^+S^+L^+L+S+L+2.2 L+S+R+L^+S^+R^+L+S+R+2.3 L+R−L+L^+R^-L^+L+R−L+2.4 L+R−L−L^+R^-L^-L+R−L−2.5 L+R+L−L^+R^+L^-L+R+L−2.6 L+Rβ+Lβ−R−L^+R_{\beta}^+L_{\beta}^-R^-L+Rβ+​Lβ−​R−2.7 L+Rβ−Lβ−R+L^+R_{\beta}^-L_{\beta}^-R^+L+Rβ−​Lβ−​R+2.8

jianmo的博客 1213

OpenHarmony 录屏免弹窗踩坑记:从 CUSTOM_SCREEN_RECORDING 到 EXEMPT_CAPTURE_SCREEN_AUTHORIZE

定制系统会裁剪权限定义表。查权限是否真的存在,不是看文档、不是看 API 版本,而是查设备的access_token 权限定义表# 输出为空 = 这个系统里该权限根本不存在,声明了也白搭# 有定义,且关键字段:SYSTEM_GRANT / provisionEnable: true我这台 API 23 的系统,全量定义表(200+ KB)里出现0 次。之前无论怎么配预授权都不弹消失,根因在此——授一个系统里不存在的权限,是不可能成功的。ATM 权限定义表。

qq_44160056的博客 176

16、Cortex-M7处理器:高性能与复杂架构解析

本文深入解析了Cortex-M7处理器的高性能架构与复杂设计,涵盖AHB总线矩阵优化、超标量六阶段双发射流水线、增强型分支预测单元及双精度浮点支持。重点介绍了其独特的内存层次结构,包括指令与数据TCM、片上缓存和AXI-M 64位总线接口,提升系统并行性与执行效率。通过实际测试对比M4与M7性能差异,并演示如何将代码与数据定位到TCM以实现零等待运行。同时阐述了缓存机制的工作原理及其对系统性能的影响,为开发者提供全面的性能优化指导。

a1b2c3d的博客 126

【图像去噪】论文复现:灵感源自MAE!进一步解决BSN的局限性,破坏真实噪声的空间相关性!AMSNet的Pytorch源码复现,跑通源码,原理详解!

论文题目:Asymmetric Mask Scheme for Self-Supervised Real Image Denoising —— 自监督真实图像去噪的非对称掩码方案【图像去噪】论文精读:Asymmetric Mask Scheme for Self-Supervised Real Image Denoising(AMSNet)AMSNet是基于PyTorch Lightning CLI深度学习框架编写的,比较适合复杂的大型任务,复用很方便,但是安装和环境配置问题太多。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 547
上一篇: OpenHarmony开发学习资料
下一篇: OpenHarmony 3.2使用fio进行I/O性能测试
Mart!nHu
博客等级 码龄7年 1万+粉丝 50原创
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值