Open
签名问题解决方案 #1
guozejunAdd on  4 days ago
guozejun
guozejunCollaborators
4 days ago Create

尝试使用离线签名工具

  1. 获取签名工具和签名需要的资源文件 https://gitcode.com/openharmony/developtools_hapsigner/tree/master/dist
  2. 修改UnsgnedReleasedProfileTempate.json中的 bundle-name为自己包的名称
  3. 生成profile文件(app1-profile.p7b)
    java -jar hap-sign-tool.jar sign-profile -keyAlias "openharmony application profile release" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "OpenHarmonyProfileRelease.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -keystoreFile "OpenHarmony.p12" -outFile "app1-profile.p7b" -keyPwd "123456" -keystorePwd "123456"
  4. 对hap包进行签名(使用OpenHarmony证书)需要替换 entry-default-unsigned.hap app1-signed.hap为需要的产物名
    java -jar hap-sign-tool.jar sign-app -keyAlias "openharmony application release" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "OpenHarmonyApplication.pem" -profileFile "app1-profile.p7b" -inFile "entry-default-unsigned.hap" -keystoreFile "OpenHarmony.p12" -outFile "app1-signed.hap" -keyPwd "123456" -keystorePwd "123456"
  5. 从IDE中获取 hap-sign-tool.jar 然后使用如下命令验证签名的是否存在问题 java -jar hap-sign-tool.jar verify-app -outCertChain "out.cer" -outProfile "out.p7b" -inFile "XXX.hap"
likedislike
guozejun
guozejunCollaborators
4 days ago Comments:

实测结论(2026-11-16)

配方本身健全——签名链全绿、rk3568 真机安装/启动/运行全通;但模拟器(x86_64_virt 日构建镜像)装不上的根因与签名方式无关,是镜像平台缺陷。

落地修正(按本 issue 步骤执行时必踩)

  • dist 模板 UnsgnedReleasedProfileTemplate.json 的 validity 已过期(not-after=1689473258 ≈ 2023-07),直接用会挂在 profile validity;须续期 + 改 bundle-name + 刷新 uuid。
  • 材料已拉到 D:/rk3568/signing/hapsigner-dist/;jar 用 DevEco SDK 自带的即可(dist 的 jar 走 API 拉不完整)。

验证结果

步骤 结果
sign-profile(release 链)/ sign-app / verify-app 全部 success
rk3568 板安装 + aa start + 进程存活 ✅ 全通(且 release profile 不钉 UDID,跨设备通用,优于 debug 流程——已并入 sign_hap.py --mode release)
x86_64_virt 模拟器安装 ❌ 同样 9568393 verify code signature failed,失败点与 debug 签名完全相同(-256)

模拟器阻断的定性证据(与签名内容无关)

  1. Debug 级 hilog 显示 hap-sign-tool 本就产出了完整代码签名块(version:1 / block_size:4096 / sig 2147B / Merkle 数据),不是缺块;
  2. 静态 statx 探针(gcc -static 编译后推入 guest 直跑):内核 statx 在全路径 × 全 mask(含 STATX_ALL)全部正常,内核 fs/stat.c 为原版;
  3. 同一路径 dummy 文件、同一 syscall 参数,shell 上下文 OK——EINVAL 仅发生在 installd 进程上下文;
  4. debug / release 两种签名同一失败位置。

→ 已按证据链向 openharmony 上游提 issue(链接见后续评论)。

likedislike
guozejun
guozejunCollaborators
4 days ago Comments:

上游 issue 已提交:https://gitcode.com/openharmony/security_code_signature/issues/328 (x86_64_virt 模拟器镜像安装任意 hap 均失败:installd 进程上下文 statx EINVAL,附完整复现与排查证据)。

likedislike
guozejun
guozejunCollaborators
4 days ago Comments:

安装失败关键日志(2026-11-16 复现抓取)

环境:x86_64_virt 日构建模拟器(2026-11-12 构建,OpenHarmony 7.1.0.25,内核 6.6.101,QEMU q35/TCG);被装 hap = 按本 issue 配方 release 离线签名的 grid-ph(verify-app 通过)。
命令:hdc install entry-release-signed.hap(hilog 先 -b D 开 Debug 级再复现)。

① 安装命令返回

[Info]App install path:C:\...\entry-release-signed.hap msg:error: failed to install bundle. code:9568393 error: verify code signature failed.
AppMod finish

② hap 代码签名块解析成功(证明签名块完好,不是缺块/格式问题)

11-16 16:25:14.840 7067 7071 D BMSInstalld: installd_host_impl.cpp:VerifyCodeSignatureForHap:4045 Verify code signature for non-enterprise bundle
11-16 16:25:14.840 7067 7071 I CODE_SIGN: [EnforceCodeSignForAppWithPluginId]:Start to enforce codesign FileType:0, entryPathMap size:0, path = /data/app/el1/bundle/public/com.ohoscowork.gridph/entry/entry.hap
11-16 16:25:14.841 7067 7071 I CODE_SIGN: [CodeSignEnableMultiTask]:Tasks init.
11-16 16:25:14.855 7067 7071 D CODE_SIGN: [GetOneFileAndCodeSignInfo]:flag = 0, extensionNum = 1, signInfo->extensionNum = 2
11-16 16:25:14.855 7067 7071 D CODE_SIGN: [ShowCodeSignInfo]:{ file:/data/app/el1/bundle/public/com.ohoscowork.gridph/entry/entry.hap version:1 hash_algorithm:1 block_size:4096 sig_size:2147 data_size:151552 salt_size:0 flags:1 tree_offset:294912 root_hash:[38, 16, 170, ...] }

③ 失败点:IsSupportFsVerity 的 statx 在 installd 进程返回 EINVAL(重试一次同样失败)→ -256

11-16 16:25:14.856 7067 7071 E CODE_SIGN: [IsSupportFsVerity]:Get attributes failed, errno = <22, Invalid argument>
11-16 16:25:14.856 7067 7071 I CODE_SIGN: [~CodeSignEnableMultiTask]:Tasks finish.
11-16 16:25:14.861 7067 7071 I CODE_SIGN: [CodeSignEnableMultiTask]:Tasks init.          ← 框架内重试
11-16 16:25:14.874 7067 7071 E CODE_SIGN: [IsSupportFsVerity]:Get attributes failed, errno = <22, Invalid argument>
11-16 16:25:14.879 7067 7071 I CODE_SIGN: [EnforceCodeSignForAppWithPluginId]:Enforcing done, ret = -256     ← CS_ERR_FILE_INVALID
11-16 16:25:14.879 7067 7071 E BMSInstalld: installd_host_impl.cpp:VerifyCodeSignatureForHap:4055 hap or hsp code signature failed due to -256
11-16 16:25:14.880 378  7062 E BMSInstalld: installd_proxy.cpp:VerifyCodeSignatureForHap:1590 TransactInstalldCmd failed

④ 回滚与最终结果

11-16 16:25:14.880 378 7062 D BMSInstaller: base_bundle_installer.cpp:RollBack:2367 start rollback due to install failed
11-16 16:25:14.971 378 7062 D BMS: [status_receiver_proxy.cpp(TransformResult:955)]result transformed is 9568393, [MSG_ERR_INSTALL_CODE_SIGNATURE_FAILED]
11-16 16:25:14.982 7056 7060 I BMSTool: [status_receiver_impl.cpp(OnFinished:43)]on finished result is 9568393

对照:同一 hap 在 rk3568(5.10 内核)上同位置日志为 [EnableCodeSignForFile]:Enforcing file complete, ret = 0,安装成功。
完整原始日志(Debug 级,2565 行)留档:runs/emul-20261113/install-fail-hilog.txt(本机仓 runs/ 留档区,不进 git)。上游跟踪:https://gitcode.com/openharmony/security_code_signature/issues/328

likedislike
guozejun
guozejunCollaborators
4 days ago Comments:
guozejun
guozejunCollaborators
4 days ago Comments:

勘误:上评提到「rk3568(5.10 内核)」有误——实测 uname,板与模拟器同为 6.6.101(板 aarch64 / 模拟器 x86_64 -gc0c10d57367a-dirty)。差异在 arch/内核 config 而非版本,已在上游 issue 追加勘误与排查方向建议。

likedislike