Skip to content

Commit 085c51a

Browse files
pmatilaidmnks
authored andcommitted
Support OpenPGP v6 signature pre-salting
OpenPGP v6 signature salt is a random per-signature thing that we need to feed into the digest before the actual data. For that we need rpm-sequoia support, the first version to have it is 1.9.0. The tests for this are already written, just need to be adjusted a bit and uncommented, so do that. Kudos to Jakub for covering this part via PR #3844 (squashed into this commit)! Co-authored-by: Jakub Jelen <jjelen@redhat.com> Fixes: #3846
1 parent 28e4f05 commit 085c51a

7 files changed

Lines changed: 44 additions & 42 deletions

File tree

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The scdoc manual page generator, available from
4242
https://git.sr.ht/~sircmpwn/scdoc
4343

4444
You will need a cryptographic library to support digests and an OpenPGP
45-
implementation to support signatures. rpm-sequoia (>= 1.3.0 required) is
45+
implementation to support signatures. rpm-sequoia (>= 1.9.0 required) is
4646
the most complete option, covering both, and also the default:
4747
https://github.com/rpm-software-management/rpm-sequoia
4848

include/rpm/rpmpgp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ int pgpDigParamsVersion(pgpDigParams digp);
489489
*/
490490
uint32_t pgpDigParamsCreationTime(pgpDigParams digp);
491491

492+
int pgpDigParamsSalt(pgpDigParams digp, const uint8_t **datap, size_t *lenp);
493+
492494
/** \ingroup rpmpgp
493495
* Destroy parsed OpenPGP packet parameter(s).
494496
* @param digp parameter container

lib/rpmvs.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,18 @@ void rpmvsInitRange(struct rpmvs_s *sis, int range)
457457
for (int i = 0; i < sis->nsigs; i++) {
458458
struct rpmsinfo_s *sinfo = &sis->sigs[i];
459459
if (sinfo->range & range) {
460-
if (sinfo->rc == RPMRC_OK)
461-
rpmDigestBundleAddID(sis->bundle, sinfo->hashalgo, sinfo->id, 0);
460+
if (sinfo->rc != RPMRC_OK)
461+
continue;
462+
463+
rpmDigestBundleAddID(sis->bundle, sinfo->hashalgo, sinfo->id, 0);
464+
/* OpenPGP v6 signatures need a grain of salt to go */
465+
if (sinfo->sig) {
466+
const uint8_t *salt = NULL;
467+
size_t slen = 0;
468+
if (pgpDigParamsSalt(sinfo->sig, &salt, &slen) == 0 && salt) {
469+
rpmDigestBundleUpdateID(sis->bundle, sinfo->id, salt, slen);
470+
}
471+
}
462472
}
463473
}
464474
}

rpmio/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/rpmio/rpmpgp_legacy/CMakeLists.txt)
2222
endif()
2323

2424
if (WITH_SEQUOIA)
25-
pkg_check_modules(RPMSEQUOIA REQUIRED IMPORTED_TARGET rpm-sequoia>=1.8.0)
25+
pkg_check_modules(RPMSEQUOIA REQUIRED IMPORTED_TARGET rpm-sequoia>=1.9.0)
2626
target_sources(librpmio PRIVATE rpmpgp_sequoia.cc)
2727
target_link_libraries(librpmio PRIVATE PkgConfig::RPMSEQUOIA)
2828
else()

rpmio/rpmpgp_sequoia.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ W(const uint8_t *, pgpDigParamsSignID, (pgpDigParams digp), (digp))
3737
W(const char *, pgpDigParamsUserID, (pgpDigParams digp), (digp))
3838
W(int, pgpDigParamsVersion, (pgpDigParams digp), (digp))
3939
W(uint32_t, pgpDigParamsCreationTime, (pgpDigParams digp), (digp))
40+
W(int, pgpDigParamsSalt,
41+
(pgpDigParams digp, const uint8_t **datap, size_t *lenp),
42+
(digp, datap, lenp))
4043
W(rpmRC, pgpVerifySignature,
4144
(pgpDigParams key, pgpDigParams sig, DIGEST_CTX hashctx),
4245
(key, sig, hashctx))

tests/Dockerfile.fedora

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ RUN dnf -y install \
6060
# Incapacitate IMA, needed until #3234 lands in fedora
6161
RUN rm -f /usr/lib/rpm/macros.d/macros.transaction_ima
6262
# If updates to specific packages are needed, do it here
63-
RUN dnf -y --enablerepo=rawhide install "sequoia-sq >= 1.3" "rpm-sequoia >= 1.8" "crypto-policies >= 20250402"
63+
RUN dnf -y --enablerepo=rawhide install "sequoia-sq >= 1.3" "rpm-sequoia >= 1.9" "crypto-policies >= 20250402"
6464
RUN dnf clean all
6565

6666
# Workaround for pkgconf(1)'s unlisted dependency on rpm.

tests/rpmsigdig.at

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,28 +2408,20 @@ runroot rpmsign --addsign --rpmv6 /tmp/hello-2.0-1.x86_64.rpm
24082408
[],
24092409
[])
24102410

2411-
# The test reflects what I *assume* this should return as v6 key ids are the
2412-
# first 64 bits of the fingerprint, but this is very cursory skim through
2413-
# rfc-9580 and might not be right. What we're currently getting as the
2414-
# signer key is the last 64bit as with v4 keys, and when this doesn't match
2415-
# with what we get from the subkey ids, rpm does not find the key.
2416-
# In addition, rpm-sequoia 1.8 doesn't handle the v6 trailer so it's BAD
2417-
# instead of NOKEY.
2418-
# Header OpenPGP V6 Ed25519/SHA512 signature, key ID 0e00df3ed2d7b65e: BAD
2419-
#RPMTEST_CHECK([
2420-
#runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm
2421-
#],
2422-
#[0],
2423-
#[/tmp/hello-2.0-1.x86_64.rpm:
2424-
# Header OpenPGP V6 Ed25519/SHA512 signature, key ID 6118abe481c41473: NOKEY
2425-
# Header OpenPGP RSA signature: NOTFOUND
2426-
# Header OpenPGP DSA signature: NOTFOUND
2427-
# Header SHA256 digest: OK
2428-
# Payload SHA256 digest: OK
2429-
# Legacy OpenPGP RSA signature: NOTFOUND
2430-
# Legacy OpenPGP DSA signature: NOTFOUND
2431-
#],
2432-
#[])
2411+
RPMTEST_CHECK([
2412+
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm
2413+
],
2414+
[1],
2415+
[/tmp/hello-2.0-1.x86_64.rpm:
2416+
Header OpenPGP V6 Ed25519/SHA512 signature, key ID 6118abe481c41473: NOKEY
2417+
Header OpenPGP RSA signature: NOTFOUND
2418+
Header OpenPGP DSA signature: NOTFOUND
2419+
Header SHA256 digest: OK
2420+
Payload SHA256 digest: OK
2421+
Legacy OpenPGP RSA signature: NOTFOUND
2422+
Legacy OpenPGP DSA signature: NOTFOUND
2423+
],
2424+
[])
24332425

24342426
RPMTEST_CHECK([
24352427
runroot rpmkeys --import /data/keys/rpm.org-v6-ed25519-test.asc
@@ -2446,21 +2438,16 @@ runroot rpmkeys --list 036824f0ac60aed6f1a3256f88190469f6d7255e3d8e41c577233aa03
24462438
],
24472439
[])
24482440

2449-
# This is currently failing, see the NOKEY case above
2450-
#RPMTEST_CHECK([
2451-
#runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm
2452-
#],
2453-
#[0],
2454-
#[/tmp/hello-2.0-1.x86_64.rpm:
2455-
# Header OpenPGP V6 Ed25519/SHA512 signature, key fingerprint 036824f0ac60aed6f1a3256f88190469f6d7255e3d8e41c577233aa03e0bb9d3 OK
2456-
# Header OpenPGP RSA signature: NOTFOUND
2457-
# Header OpenPGP DSA signature: NOTFOUND
2458-
# Header SHA256 digest: OK
2459-
# Payload SHA256 digest: OK
2460-
# Legacy OpenPGP RSA signature: NOTFOUND
2461-
# Legacy OpenPGP DSA signature: NOTFOUND
2462-
#],
2463-
#[])
2441+
RPMTEST_CHECK([
2442+
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm
2443+
],
2444+
[0],
2445+
[/tmp/hello-2.0-1.x86_64.rpm:
2446+
Header OpenPGP V6 Ed25519/SHA512 signature, key fingerprint: 036824f0ac60aed6f1a3256f88190469f6d7255e3d8e41c577233aa03e0bb9d3: OK
2447+
Header SHA256 digest: OK
2448+
Payload SHA256 digest: OK
2449+
],
2450+
[])
24642451

24652452
RPMTEST_CHECK([
24662453
runroot rpmkeys --delete 036824f0ac60aed6f1a3256f88190469f6d7255e3d8e41c577233aa03e0bb9d3

0 commit comments

Comments
 (0)