我可以用 keybase.io 签署 git 提交吗?

Can I sign git commits with keybase.io?

我正在设置一台新机器,并且更愿意将密钥库用于各种 pgp 活动,例如签署提交。我可以 运行 像

这样的命令
$ keybase pgp sign -m foo > x
$ gpg --verify x 2>&1 | grep -oF 'Good signature'
Good signature

我可以直接用 gpg 签名,但是让 keybase 管理这个东西很方便。那么我可以通过某种方式让 git 使用 keybase 吗?

Git configuration 似乎无法自定义用于签署提交的 gpg 命令。您所能做的就是提供密钥。有什么办法吗?

这里有一份关于如何操作的文档(github)https://github.com/pstadler/keybase-gpg-github

感谢 中的 link 我了解到我可以使用 gpg.program 配置覆盖 gpg 程序:

git config --global gpg.program /path/to/something

所以我可以用它来围绕 keybase 编写一个包装器。

但事实证明,git 对 something 是什么非常挑剔。 Git expects to partially parse the output that results from the --fd-status flag, which causes gpg to output special status codes 在备用文件句柄上。

幸运的是,至少在我的第一遍中,git 没有解析 gpg 生成的所有内容,所以我能够模拟它。 Here's a gist with a functional wrapper,这是它的主要内容:

# Copy the commit message from stdin to a file. 
d=$(mktmp -d "${TMPDIR:-/tmp}/gitsig.XXXXXXXXX")
cat > "$d/commit.msg"

# Have Keybase write the signature to another file.
keybase pgp sign --detached \
                 --key "" \
                 --infile "$d/commit.msg" \
                 --outfile "$d/commit.sig"

# Have gpg verify the signature right away.
# Capture its status in a file.
gpg --verify --status-fd=2 \
    "$d/commit.sig" "$d/commit.msg" \
    > /dev/null 2> "$d/gpgstatus.txt"

# Copy the KEY_CONSIDERED lines to stderr. Git wants that.
grep '^\[GNUPG:\] KEY_CONSIDERED' "$d/gpgstatus.txt" >&2

# Produce a minimal SIG_CREATED line to stderr. Git also wants that.
printf '[GNUPG:] SIG_CREATED ' >&2