6 Commits

Author SHA1 Message Date
AndyChen1024
30331f7d89 Merge branch 'dev' into main 2026-09-11 17:30:49 +08:00
AndyChen1024
3ceaa9188b Merge branch 'feature/signing-guard' into dev 2026-09-11 17:30:41 +08:00
AndyChen1024
77ee00070e chore: 忽略本地临时目录 tmp/ 2026-09-11 17:28:43 +08:00
AndyChen1024
a0e0758b6b chore: 新增签名凭据 pre-commit 拦截钩子,防止 signingConfigs 入库 2026-09-11 17:26:33 +08:00
AndyChen1024
84233fa0b8 Merge branch 'dev' into main 2026-09-11 17:08:07 +08:00
AndyChen1024
1c98772253 Merge branch 'dev' into main 2026-09-11 16:54:58 +08:00
4 changed files with 62 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
/node_modules /node_modules
/oh_modules /oh_modules
/tmp
/local.properties /local.properties
/.idea /.idea
**/build **/build

View File

@@ -33,12 +33,38 @@ hvigorw assembleHap --mode module -p product=default -p buildMode=release
## 签名 Signing ## 签名 Signing
`build-profile.json5` 里 `signingConfigs` 目前为**空**,且 `products[].signingConfig` 引用了 `"default"` —— **签名尚未配置**。 ### 现状与原则
- `build-profile.json5` 里 `signingConfigs` 在**仓库中必须保持为空 `[]`**(`products[].signingConfig` 仍引用 `"default"`)——签名是机器相关的,禁止入库。
- 真正的密钥物料(`.p12` / `.cer` / `.p7b`)由 DevEco 生成在 `~/.ohos/config/` 下,**本来就在仓库外**;`build-profile.json5` 里只有「文件路径 + 加密后的密码」,但同样属敏感信息,不得提交。
### 本地配置签名(不入库)
要跑真机/模拟器需先配置签名: 要跑真机/模拟器需先配置签名:
- DevEco Studio → File → Project Structure → Signing Configs → 勾选自动签名(登录华为账号)。 - DevEco Studio → File → Project Structure → Signing Configs → 勾选自动签名(登录华为账号)。
- 或手动配置 `.p12` + `.cer` / `.p7b`。 - 或手动配置 `.p12` + `.cer` / `.p7b`。
> 该文件的签名部分属于 **Agent 禁止修改** 范围(见 `AGENTS.md`)。 DevEco 自动签名会把凭据写进 `build-profile.json5`,这属于**本地未提交状态**,不要 `git add` 它。
### 防泄露:pre-commit 钩子
仓库内置了 pre-commit 钩子 `scripts/git-hooks/pre-commit`:只要暂存区的 `build-profile.json5` 出现 `keyPassword` / `storePassword` / `certpath` 等签名字段,就**拒绝提交**。
每个克隆启用一次:
```bash
git config core.hooksPath scripts/git-hooks
```
验证:临时在 `build-profile.json5` 里塞一个 `"keyPassword"` 再 `git add build-profile.json5 && git commit`,应被拦截。
> 确需临时绕过时用 `git commit --no-verify`(仅应急,不建议)。
### 彻底外部化(可选)
若想连本地也不出现凭据,可走「动态配置签名」:用 `hvigorfile.ts` 从 gitignore 的本地文件或环境变量读取签名注入,让 `build-profile.json5` 始终保持空。参考华为官方《基于动态配置签名的多人协同开发应用签名解决方案》。
> `build-profile.json5` 的签名部分属于 **Agent 禁止修改** 范围(见 `AGENTS.md`)。
## 产品与构建模式 Products & Build Modes ## 产品与构建模式 Products & Build Modes

View File

@@ -96,6 +96,7 @@ git push -u origin hotfix/xxx
2. **PR 合入前过 lint + 相关测试**,见 `docs/testing.md` 的「改动后验证」。 2. **PR 合入前过 lint + 相关测试**,见 `docs/testing.md` 的「改动后验证」。
3. **feature 合并后删除分支**,保持分支列表干净。 3. **feature 合并后删除分支**,保持分支列表干净。
4. **提交信息必须走 Conventional Commits**,不合规的提交在 PR 中 squash 掉。 4. **提交信息必须走 Conventional Commits**,不合规的提交在 PR 中 squash 掉。
5. **签名信息永不入库**——`build-profile.json5` 的 `signingConfigs` 必须保持空 `[]`,已由 pre-commit 钩子兜底,见 `docs/build-deploy.md` 的「签名管理」。
## 仓库设置 Repo Settings(一次性) ## 仓库设置 Repo Settings(一次性)

32
scripts/git-hooks/pre-commit Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# 拦截提交包含签名凭据的 build-profile.json5。
# Block commits that add signing credentials to build-profile.json5.
# 详见 docs/build-deploy.md 的「签名管理」章节。
set -u
FILE="build-profile.json5"
# 仅当本次提交要改动 build-profile.json5 时才检查
if git diff --cached --quiet -- "$FILE"; then
exit 0
fi
# 读取暂存区版本,检测签名敏感字段
if git show ":$FILE" | grep -qE '"(keyPassword|storePassword|certpath|storeFile|keyAlias|signAlg)"'; then
cat >&2 <<'EOF'
❌ 已拦截提交:build-profile.json5 中含签名凭据(keyPassword / storePassword / certpath / …)。
signingConfigs 必须保持为空 [] 才能提交。
处理办法:
- 若只是本地 DevEco 自动签名产生的:先取消暂存,再还原为空
git reset HEAD build-profile.json5
git checkout -- build-profile.json5
- 确需本地跑真机:保持该改动「未提交」即可,不要 git add 它。
如确实要临时绕过(不建议):git commit --no-verify
详见 docs/build-deploy.md 的「签名管理」章节。
EOF
exit 1
fi
exit 0