在公司环境中使用 x509 证书签署 git 提交
Sign git commit with x509 certificate in corporate environment
我从文档中了解到可以签署 git 标签和提交。
git config --global user.signingkey 0A46826A
文档:https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work
这适用于 GPG。有人用 X509 用户证书做过这样的事情吗?
看起来 GPG 与 x509 pki 证书不兼容或不可互换。由于这是在企业环境中,GPG 不是一个选项。
如果有人可以分享想法或经验如何使用 x509 证书来完成,那就太好了?实现这样的东西需要什么?
使用 Git 2.19(2018 年第 3 季度)应该更容易,因为“git tag -s
”等现在有一些配置变量(gpg.format
可以设置为“openpgp
”或“x509
”,以及用于指定使用什么程序来处理格式的 gpg.<format>.program
)以通过“gpgsm
允许使用 CMS 的 x.509 证书" 代替
openpgp 通过“gnupg
”.
参见 commit 53fc999 (20 Jul 2018), commit 1e7adb9, commit b02f51b, commit 42149d7, commit 58af57e, commit 57a8dd7 (17 Jul 2018), and commit 1865a64 (18 Jul 2018) by Henning Schild (henning-schild
)。
(由 Junio C Hamano -- gitster
-- in commit 3ec5ebe 合并,2018 年 8 月 15 日)
这涉及如下更改:
gpg-interface
: add new config to select how to sign a commit
Add "gpg.format
" where the user can specify which type of signature to
use for commits.
gpg-interface
: introduce an abstraction for multiple gpg formats
Create a struct that holds the format details for the supported formats.
This commit prepares for the introduction of more formats, that might use other programs and match other signatures.
gpg-interface: do not hardcode the key string len anymore
gnupg
does print the keyid followed by a space and the signer comes next.
The same pattern is also used in gpgsm
, but there the key length would be 40 instead of 16.
Instead of hardcoding the expected length, find the first space and calculate it.
Input that does not match the expected format will be ignored now, before we jumped to found+17 which might have been behind the end of an unexpected string.
GitHub 在 Windows 和 Mac 上提供了一些关于 specifying signing keys including how to sign using X.509 certificates using smimesign
的有用说明。
对于 Git 版本 2.19 和更高版本
$ git config --global gpg.x509.program smimesign
$ git config --global gpg.format x509
对于 Git 版本 2.18 及更早版本
$ git config --global gpg.program smimesign
在 Linux 上,您可以改用 gpgme
。使用 gpgme --import cert.p12
添加您的证书。在 gpgme
允许您签署任何内容之前,您可能还需要导入根证书和任何中间证书。
我从文档中了解到可以签署 git 标签和提交。
git config --global user.signingkey 0A46826A
文档:https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work
这适用于 GPG。有人用 X509 用户证书做过这样的事情吗?
看起来 GPG 与 x509 pki 证书不兼容或不可互换。由于这是在企业环境中,GPG 不是一个选项。
如果有人可以分享想法或经验如何使用 x509 证书来完成,那就太好了?实现这样的东西需要什么?
使用 Git 2.19(2018 年第 3 季度)应该更容易,因为“git tag -s
”等现在有一些配置变量(gpg.format
可以设置为“openpgp
”或“x509
”,以及用于指定使用什么程序来处理格式的 gpg.<format>.program
)以通过“gpgsm
允许使用 CMS 的 x.509 证书" 代替
openpgp 通过“gnupg
”.
参见 commit 53fc999 (20 Jul 2018), commit 1e7adb9, commit b02f51b, commit 42149d7, commit 58af57e, commit 57a8dd7 (17 Jul 2018), and commit 1865a64 (18 Jul 2018) by Henning Schild (henning-schild
)。
(由 Junio C Hamano -- gitster
-- in commit 3ec5ebe 合并,2018 年 8 月 15 日)
这涉及如下更改:
gpg-interface
: add new config to select how to sign a commitAdd "
gpg.format
" where the user can specify which type of signature to use for commits.
gpg-interface
: introduce an abstraction for multiple gpg formatsCreate a struct that holds the format details for the supported formats.
This commit prepares for the introduction of more formats, that might use other programs and match other signatures.gpg-interface: do not hardcode the key string len anymore
gnupg
does print the keyid followed by a space and the signer comes next. The same pattern is also used ingpgsm
, but there the key length would be 40 instead of 16.Instead of hardcoding the expected length, find the first space and calculate it.
Input that does not match the expected format will be ignored now, before we jumped to found+17 which might have been behind the end of an unexpected string.
GitHub 在 Windows 和 Mac 上提供了一些关于 specifying signing keys including how to sign using X.509 certificates using smimesign
的有用说明。
对于 Git 版本 2.19 和更高版本
$ git config --global gpg.x509.program smimesign
$ git config --global gpg.format x509
对于 Git 版本 2.18 及更早版本
$ git config --global gpg.program smimesign
在 Linux 上,您可以改用 gpgme
。使用 gpgme --import cert.p12
添加您的证书。在 gpgme
允许您签署任何内容之前,您可能还需要导入根证书和任何中间证书。