TL; DR:RPM签名不起作用,并且它正在以各种疯狂和不稳定的方式工作,具体取决于确切的GPG密钥大小和格式,甚至是生成它的位置,当rpm -qa显示密钥时会产生NOKEY错误gpg- *存在;在具有相同密钥的同一台计算机上签名的RPM上出现BAD签名错误;密钥上的密码短语错误,gpg直接接受密码短语而没有问题;等等
我已经使用4096,2048和1024位RSA密钥以及2048位DSA密钥进行了测试,在同一个CentOS 5.10 VM上进行签名和验证.行为因密钥类型和大小而异,但我还没有找到任何实际可行的东西.
使用XXX屏蔽名称,电子邮件和RPM文件名但不进行其他编辑,例如,DSA 2048密钥:
$rpm --version RPM version 4.4.2.3 $gpg --list-secret 92fb1e62 sec 2048D/92FB1E62 2014-08-29 [expires: 2015-08-29] uid XXX <XXX@XXX.com> ssb 2048g/2E0F0A24 2014-08-29 [expires: 2015-08-29] $gpg -a --export 92fb1e62 > /tmp/packagers $sudo rpm --import /tmp/packagers $rpm -qa gpg* gpg-pubkey-92fb1e62-54001945 $rpmsign --define '%_gpg_name XXX@XXX.com' --resign test.el5.x86_64.rpm Enter pass phrase: Pass phrase is good. test.el5.x86_64.rpm: gpg: WARNING: standard input reopened gpg: WARNING: standard input reopened $rpm -v -K test.el5.x86_64.rpm test.el5.x86_64.rpm: Header V3 DSA signature: NOKEY,key ID 92fb1e62 Header SHA1 digest: OK (47271f9fa8ac0ce03b980ff75a37f10d3b78ee7c) MD5 digest: OK (f453985ee4331d36cb82d2c4f6009509) V3 DSA signature: NOKEY,key ID 92fb1e62
NOKEY?这有什么用呢?
我正常使用rpm –import导入密钥.它导入没有错误.它列在RPM DB中.然而RPM的验证命令却看不到它.
我在CentOS 5上看到4096位RSA密钥存在同样的问题.
(在Fedora 20上,它失败了:
$rpmsign --define '%_gpg_name XXX@XXX.com' --resign test.x86_64.rpm Enter pass phrase: Pass phrase is good. test.x86_64.rpm: error: Unsupported PGP signature
……至少在签约时失败了,而不是以后.)
如果我在CentOS 5上使用2048或1024位RSA密钥,我会在验证签名时报告BAD签名,尽管事实上我只是使用该密钥签署了RPM:
$gpg --import /mnt/repo/packaging-key-secret-1024 gpg: key 1FC138CC: secret key imported gpg: key 1FC138CC: public key "XXX <XXX@XXX.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) gpg: secret keys read: 1 gpg: secret keys imported: 1 $gpg -a --export XXX@XXX.com > /tmp/packagers $sudo rpm --import /tmp/packagers $rpm --define '%_gpg_name XXX@XXX.com' --resign test.x86_64.rpm Enter pass phrase: Pass phrase is good. test.x86_64.rpm: gpg: WARNING: standard input reopened gpg: WARNING: standard input reopened $$rpm -v -K test.x86_64.rpm test.x86_64.rpm: Header V3 RSA/SHA1 signature: BAD,key ID 1fc138cc Header SHA1 digest: OK (1befc128ddd02a79d1b1098bc16aff4532b5af6c) V3 RSA/SHA1 signature: BAD,key ID 1fc138cc MD5 digest: OK (2aaacbe1db08a2c63c94f2f705693c7d)
认真. W.T.F?我正处于一种令人沮丧的头脑中,并且正在向Stack Exchange的怜悯投掷自己. RPM包装商,请分享你的秘密签名伏都教.
It doesn’t seem to be do to with the warnings about stdin being re-opened.
(我很乐意不支持EL5,但是我坚持支持它一段时间,以及更新和更健全的发行版).
其他相关信息:
$gpg --version gpg (GnuPG) 1.4.5 ...blahcopyrightblah... Supported algorithms: Pubkey: RSA,RSA-E,RSA-S,ELG-E,DSA Cipher: 3DES,CAST5,BLOWFISH,AES,AES192,AES256,TWOFISH Hash: MD5,SHA1,RIPEMD160,SHA256,SHA384,SHA512,SHA224 $cat /etc/redhat-release CentOS release 5.10 (Final)
哦,对于奖励WTF积分,我直接在CentOS盒子上生成一个一次性的新密钥,密码为“fred”.我可以用它来签名:
$gpg -q -a -b --sign -u XXX@XXX.com testfile You need a passphrase to unlock the secret key for user: "XXX <XXX@XXX.com>" 1024-bit DSA key,ID 99188B9C,created 2014-08-29
并验证它:
$gpg -v testfile.asc gpg: armor header: Version: GnuPG v1.4.5 (GNU/Linux) gpg: assuming signed data in `testfile.asc' gpg: Signature made Fri 29 Aug 2014 08:02:47 AM UTC using DSA key ID 99188B9C gpg: Good signature from "XXX <XXX@XXX.com>" gpg: binary signature,digest algorithm SHA1
但是rpmsign更加疯狂.使用完全相同的密码,它拒绝它:
$rpmsign --define '%_gpg_name XXX@XXX.com' --resign test.el5.x86_64.rpm Enter pass phrase: Pass phrase check Failed
是打字还是复制&粘贴.使用rpm作为包装而不是直接使用rpmsign没有任何区别.
更新:对于新的奖励疯狂点,在使用2048位DSA密钥的CentOS 6.5上,使用在CentOS 6.5目标模拟环境中使用mock编译的test.rpm(即具有匹配的RPM版本):
$rpmsign --define '%_gpg_name 92FB1E62' --resign test.rpm Enter pass phrase: Pass phrase is good. test.rpm: $rpm -v -K test.rpm error: skipping package test.rpm with unverifiable V4 signature
是的 – rpmsign只签了包,然后拒绝了自己的签名.
显然大多数人都没有这些问题.我错过了什么?
解决方法
This lifesaving blog entry by Jacob Helwig,as pointed out by a colleague,covers the issues:
登录/为RHEL / CentOS 5或6登录时,您必须强制GnuPG使用v3签名.
%__gpg_sign_cmd %{__gpg} \ gpg --force-v3-sigs --digest-algo=sha1 --batch --no-verbose --no-armor \ --passphrase-fd 3 --no-secmem-warning -u "%{_gpg_name}" \ -sbo %{__signature_filename} %{__plaintext_filename}
因为RPM在签名后不检查sigversion或验证签名包,并且这些发行版包含默认为v4签名的GPG版本.
您还必须生成一个2048位仅有签名的RSA密钥,不带子密钥.
一些相关的错误:
> RPM seems unable to find (GPG) RSA keys for verifying signatures
> rpm –sign with 4096bit or 2048bit RSA key creates broken signature