如何对 Travis-CI 构建的文件进行 GPG 签名

How to GPG sign a file that is built by Travis-CI

我看到 Travis 有一个加密文件的工作流程,here

我的用例稍微简单一些,我只想为已经在 Travis-CI 上构建的文件生成签名。 说:

hello-0.0.1-a.bin.asc
hello-0.0.1-a.bin
pubkey.gpg 
<or> hello-0.0.1-a.pub

在这种情况下,hello-0.0.1-a.bin 由 Travis 构建创建,并将作为发布推送到 Github。 同样,签名也必须作为发布推送到 Github(即在同一标签下)。

我不太关心(即不是交易破坏者)private/public 密钥对是否是该版本所独有的。 但如果 private/public 密钥对在构建之间共享,那将是理想的。

欣赏并提示技巧或咒语。

基本上可以归结为几个步骤。

  1. 从您的 gpg 密钥环中导出密钥 gpg --export-secret-keys > all.gpg
  2. 使用 travis ruby gem 到 encrypt-file gpg 密钥环(例如 all.gpg
  3. all.gpg.enc 添加到您的存储库(不是未加密的 all.gpg
  4. 确保存储库可以访问安全变量
  5. 将此行添加到您的 .travis.yml 文件以解密您的加密私人签名密钥

    openssl aes-256-cbc -K $encrypted_0a6446eb3ae3_key -iv $encrypted_0a6446eb3ae3_key -in all.gpg.enc -out all.gpg -d

  6. 导入 gpg 密钥 gpg --import all.gpg

  7. 为你的形象签名 gpg --output hello.bin.asc --sign hello.bin
$ travis encrypt-file all.gpg --add
encrypting all.gpg for rkh/travis-encrypt-file-example
storing result as all.gpg.enc
storing secure env variables for decryption

Make sure to add all.gpg.enc to the git repository.
Make sure not to add all.gpg to the git repository.
Commit all changes to your .travis.yml.