Skip to content

Commit

Permalink
Ignore revoked subkeys
Browse files Browse the repository at this point in the history
RPM could not handle revoked subkeys: old versions accepted signatures
made by them, while more recent versions will usually fail to import the
signature.  This ignores such subkeys.

Additionally, require all signatures following a subkey to be subkey
binding or revocation signatures issued by the main key.  Anything else
is most likely an alternate method of revocation that RPM doesn’t
implement, and so importing such a key would be unsafe.
  • Loading branch information
DemiMarie committed Apr 12, 2022
1 parent ae35666 commit 126d896
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 15 deletions.
40 changes: 25 additions & 15 deletions rpmio/rpmpgp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,29 +1090,39 @@ int pgpPrtParamsSubkeys(const uint8_t *pkts, size_t pktlen,
continue;
}

pgpDigParams subkey_sig = NULL;
if (decodePkt(p, pend - p, &pkt) ||
parseSubkeySig(&pkt, 0, &subkey_sig))
{
pgpDigParamsFree(digps[count]);
break;
}
int ignore = 0;
do {
pgpDigParams subkey_sig = NULL;
if (decodePkt(p, pend - p, &pkt) ||
parseSubkeySig(&pkt, 0, &subkey_sig))
{
pgpDigParamsFree(digps[count]);
goto end;
}

/* if this is wrong this will be freed anyway */
digps[count]->saved |= PGPDIG_SIG_HAS_KEY_FLAGS;
digps[count]->key_flags = subkey_sig->key_flags;

/* Is the subkey revoked or incapable of signing? */
int ignore = subkey_sig->sigtype != PGPSIGTYPE_SUBKEY_BINDING ||
!((subkey_sig->saved & PGPDIG_SIG_HAS_KEY_FLAGS) &&
(subkey_sig->key_flags & 0x02));
/* Is the subkey revoked or incapable of signing? */
if (subkey_sig->sigtype != PGPSIGTYPE_SUBKEY_BINDING ||
!((subkey_sig->saved & PGPDIG_SIG_HAS_KEY_FLAGS) &&
(subkey_sig->key_flags & 0x02))) {
ignore = 1;
}
p += (pkt.body - pkt.head) + pkt.blen;
pgpDigParamsFree(subkey_sig);
if (p >= pend || decodePkt(p, pend - p, &pkt))
break; /* next iteration will catch any error */
} while (pkt.tag != PGPTAG_PUBLIC_SUBKEY);
if (ignore) {
pgpDigParamsFree(digps[count]);
} else {
digps[count]->key_flags = subkey_sig->key_flags;
digps[count]->saved |= PGPDIG_SIG_HAS_KEY_FLAGS;
count++;
}
p += (pkt.body - pkt.head) + pkt.blen;
pgpDigParamsFree(subkey_sig);
}
}
end:
rc = (p == pend) ? 0 : -1;

if (rc == 0) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ EXTRA_DIST += data/SOURCES/hello.c
EXTRA_DIST += data/SPECS/hello-attr-buildid.spec
EXTRA_DIST += data/SPECS/hello-config-buildid.spec
EXTRA_DIST += data/SPECS/hello-cd.spec
EXTRA_DIST += data/keys/rpm.org-ed25519-subkey-test.pub
EXTRA_DIST += data/keys/rpm.org-ed25519-subkey-2-test.pub
EXTRA_DIST += data/keys/first-signing-key-revoked.asc
EXTRA_DIST += data/keys/rpm.org-rsa-2048-test.pub
EXTRA_DIST += data/keys/rpm.org-rsa-2048-test.secret
EXTRA_DIST += data/keys/CVE-2021-3521-badbind.asc
Expand Down
26 changes: 26 additions & 0 deletions tests/data/keys/first-signing-key-revoked.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mDMEYj+PQhYJKwYBBAHaRw8BAQdAP4QSxJCz09EVaKH6BUHYfWrZNlworVRa0W8H
UQsp2AG0J0Fub3RoZXIgY29tcGxleCB0ZXN0IGtleSA8dGVzdEBycG0ub3JnPoia
BBMWCgBCFiEEyeRYWl0CAamgd85g0RW+m+vd0mQFAmI/j0ICGwMFCQPCZwAFCwkI
BwIDIgIBBhUKCQgLAgQWAgMBAh4HAheAAAoJENEVvpvr3dJkjjEBAMhVviHU9uTY
6Qzk4MDNCk0Okz96j+tFHd9R/dCJu6jRAP4s3WRnv3QtRqfZNZY6UsAp/n+Fv8MP
8fdQfN6la/V6CrgzBGI/j1sWCSsGAQQB2kcPAQEHQHv8VulNMB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519-subkey-2-test.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mDMEYj9egBYJKwYBBAHaRw8BAQdAqeaD3Smr6MJd1fzczVHdNcVnpGNO6fXPQ1W3
Bir40C60eXRlc3QgcnBtLm9yZyBlZDI1NTE5IGtleSB3aXRoIHZhbGlkIHNpZ25p
bmcgYW5kIGVuY3J5cHRpb24gc3Via2V5cyBhbmQgYSByZXZva2VkIHNpZ25pbmcg
c3Via2V5IDxjb21wbGV4LWVkMjU1MTlAcnBtLm9yZz6ImgQTFgoAQhYhBHsyy8MN
NCMWJzLdhZ3W8Dmg4MHHBQJiP2F3AhsDBQkDwmcABQsJCAcCAyICAQYVCgkICwIE
FgIDAQIeBwIXgAAKCRCd1vA5oODBx1y0AQCC14V8ULAoBdQsoanET2beUJgkIdT6
LBdncZx8loRLiAD+LEWLpAGBMEq+iblPTAHjApsik02eDawLdl66Yi69Xgi4OARi
P16AEgorBgEEAZdVAQUBAQdAeHhEFfY5qU6cpSMQ/LgzayG+8Q/VBbO5X8B3R433
zi4DAQgHiLYEKBYKAF4WIQR7MsvDDTQjFicy3YWd1vA5oODBxwUCYj+JTUAdAVJl
dm9rZWQgdG8gdGVzdCBob3cgUlBNIGhhbmRsZXMgdGhlIGZpcnN0IHN1YmtleSBi
ZWluZyByZXZva2VkAAoJEJ3W8Dmg4MHHL78A/2LHlQiy8DUaH0J9XobkuEGNQYfE
e23oEZ388bqKsKDGAQDA7M0RyiM+7PskRSYTKEU36o4wqh0ePJkdcW6KQDhGBYh4
BBgWCgAgAhsMFiEEezLLww00IxYnMt2FndbwOaDgwccFAmI/iMUACgkQndbwOaDg
wcd/RwD9HAZ8Jsvwthz+f10SsZAuNSP7x89VLO7mNVu1IF96VxQBAJodLZqehAsa
HDw71wkAdLgnpPTpdQLf5MfjwKgPxC0NuDMEYj9enhYJKwYBBAHaRw8BAQdAioo3
y5vRSJzPkTtTKiex1agJT0ETOzCPTU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umvq4znkCl6rp/d4XlnT
MbnC4Y9EifHzsD9DxKYnJnhvn7LnrfKnbs0bxb+0eWKhxSXeRwDFg4Hw4pQND7oc
p21jVGlFRFmGl9RdRe/GEOZSD64CrCafkaMtnUWrVHF3IM2r1Jtpr9GKULJiwTJB
ZbMIMcTuMLHzz9zDOV4zbizLT8zPAvVVPamK/RA22Y0eiSVsRffU4j3ljr0vuEeg
oBWc4aAKZByzdCHuvYzfqQru46W53xM2fTvEJxmS446S21R+n1xWZLXLLDiDF/CV
qNPP6dUgK/RV38xtYnN5e16btMAmILmQSZcQSkJPZL4Fp59L7XHnbF4XpMMLQhst
sHZ3ZUVB4r6PEqLnld+oteNjQBUmIKZ+uzafpfN9RFQDoJLuStdf4yS3fOzqNxte
zvrH1w0AEQEAAYh4BBgWCgAgFiEEezLLww00IxYnMt2FndbwOaDgwccFAmI/X2kC
GwwACgkQndbwOaDgwcex0AD+K1FEH6u0I9zfDGQ/KxydAYWzaSLDS4Mb5bp/0lbo
2iEBAM0cwefyPleuBRb1WbOIhWCW78KVxqYmbOml8UQWjhcP
=GmPE
-----END PGP PUBLIC KEY BLOCK-----
41 changes: 41 additions & 0 deletions tests/data/keys/rpm.org-ed25519-subkey-test.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mDMEYj9egBYJKwYBBAHaRw8BAQdAqeaD3Smr6MJd1fzczVHdNcVnpGNO6fXPQ1W3
Bir40C60eXRlc3QgcnBtLm9yZyBlZDI1NTE5IGtleSB3aXRoIHZhbGlkIHNpZ25p
bmcgYW5kIGVuY3J5cHRpb24gc3Via2V5cyBhbmQgYSByZXZva2VkIHNpZ25pbmcg
c3Via2V5IDxjb21wbGV4LWVkMjU1MTlAcnBtLm9yZz6ImgQTFgoAQhYhBHsyy8MN
NCMWJzLdhZ3W8Dmg4MHHBQJiP2F3AhsDBQkDwmcABQsJCAcCAyICAQYVCgkICwIE
FgIDAQIeBwIXgAAKCRC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OaDgwcd2IAQZFgoAHRYhBE7ao2AiDuxZOQu+Ntv4gI97qxB6BQJiP162AAoJENv4
gI97qxB6Lm0A/ilFgqZC8s1b0LsxROrhNr/ZTRPL5uUPHxPe1m6LkpbzAQCWA2wc
3YC6ysipXUH7YykeHPQa7CMT+D4blywQFqITBjKcAP99Xo0dx06PrT4scOU4W1GE
2O7VCEoDq2K4M2AfZJjx6QEAl6n2BYN9Z9ZAOQxokkVhTTgudIKgV0Ro+CdY7YB+
RAK5AY0EYj9faQEMAK/LykZKhjMBtVWQur3hi++FKDbwthKDjQb9KsI0GTKbpAoz
I4G6b21dBiR0MCuDPNS9Hwb+k5leb43DSlnYgDgzrWNK6hkcNewjc/u6a+rjOeQK
Xqun93heWdMxucLhj0SJ8fOwP0PEpicmeG+fsuet8qduzRvFv7R5YqHFJd5HAMWD
gfDilA0PuhynbWNUaUVEWYaX1F1F78YQ5lIPrgKsJp+Roy2dRatUcXcgzavUm2mv
0YpQsmLBMkFlswgxxO4wsfPP3MM5XjNuLMtPzM8C9VU9qYr9EDbZjR6JJWxF99Ti
PeWOvS+4R6CgFZzhoApkHLN0Ie69jN+pCu7jpbnfEzZ9O8QnGZLjjpLbVH6fXFZk
tcssOIMX8JWo08/p1SAr9FXfzG1ic3l7Xpu0wCYguZBJlxBKQk9kvgWnn0vtceds
XhekwwtCGy2wdndlRUHivo8SoueV36i142NAFSYgpn67Np+l831EVAOgku5K11/j
JLd87Oo3G17O+sfXDQARAQABiHgEGBYKACAWIQR7MsvDDTQjFicy3YWd1vA5oODB
xwUCYj9faQIbDAAKCRCd1vA5oODBx7HQAP4rUUQfq7Qj3N8MZD8rHJ0BhbNpIsNL
gxvlun/SVujaIQEAzRzB5/I+V64FFvVZs4iFYJbvwpXGpiZs6aXxRBaOFw8=
=rm2D
-----END PGP PUBLIC KEY BLOCK-----
Loading

0 comments on commit 126d896

Please sign in to comment.