Skip to content

Commit

Permalink
Sanitize rpmsign --addsign/--delsign output
Browse files Browse the repository at this point in the history
--addsign and --delsign used to emit output like below, which makes
you expect some additional output, where there will be none:

	/some/path.rpm:

Make sure all the error messages give a path you can relate to,
only emit the file name in INFO level in case of success.
No news is good news, right? So on success you now only get the
following IFF operation succeeds and -v was specified:

	/some/path.rpm

This also means we don't need to filter out these meaningless messages
all over the place in the test-suite, remove now unndecessary /dev/null
redirects and add -v to one case of both --addsign and --delsign to
cover that case.
  • Loading branch information
pmatilai committed Nov 6, 2024
1 parent 7df36ba commit 1d53115
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
14 changes: 8 additions & 6 deletions sign/rpmgensig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static rpmtd makeGPGSignature(Header sigh, int ishdr, sigTarget sigt)

if (stat(sigfile, &st)) {
/* External command failed to write signature */
rpmlog(RPMLOG_ERR, _("failed to write signature\n"));
rpmlog(RPMLOG_ERR, _("failed to write signature: %s\n"), sigfile);
goto exit;
}

Expand All @@ -357,7 +357,8 @@ static rpmtd makeGPGSignature(Header sigh, int ishdr, sigTarget sigt)
(void) Fclose(fd);
}
if (rc != pktlen) {
rpmlog(RPMLOG_ERR, _("unable to read the signature\n"));
rpmlog(RPMLOG_ERR, _("unable to read the signature: %s\n"),
sigfile);
goto exit;
}
}
Expand Down Expand Up @@ -595,8 +596,6 @@ static int rpmSign(const char *rpm, int deleting, int flags)
int insSig = 0;
rpmTagVal reserveTag = RPMSIGTAG_RESERVEDSPACE;

fprintf(stdout, "%s:\n", rpm);

if (manageFile(&fd, rpm, O_RDWR))
goto exit;

Expand Down Expand Up @@ -626,7 +625,7 @@ static int rpmSign(const char *rpm, int deleting, int flags)
}

if (!headerIsEntry(h, RPMTAG_HEADERIMMUTABLE)) {
rpmlog(RPMLOG_ERR, _("Cannot sign RPM v3 packages\n"));
rpmlog(RPMLOG_ERR, _("Cannot sign RPM v3 packages: %s\n"), rpm);
goto exit;
}

Expand Down Expand Up @@ -725,7 +724,7 @@ static int rpmSign(const char *rpm, int deleting, int flags)
rasprintf(&trpm, "%s.XXXXXX", rpm);
ofd = rpmMkTemp(trpm);
if (ofd == NULL || Ferror(ofd)) {
rpmlog(RPMLOG_ERR, _("rpmMkTemp failed\n"));
rpmlog(RPMLOG_ERR, _("rpmMkTemp failed: %s\n"), trpm);
goto exit;
}

Expand Down Expand Up @@ -768,6 +767,9 @@ static int rpmSign(const char *rpm, int deleting, int flags)
}
}

if (res == 0)
rpmlog(RPMLOG_INFO, "%s\n", rpm);

exit:
if (fd) (void) closeFile(&fd);
if (ofd) (void) closeFile(&ofd);
Expand Down
44 changes: 24 additions & 20 deletions tests/rpmsigdig.at
Original file line number Diff line number Diff line change
Expand Up @@ -1137,13 +1137,13 @@ RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --key-id 4344591E1964C5FC --rpmv3 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id 4344591E1964C5FC --rpmv3 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
runroot rpmkeys --import /data/keys/rpm.org-rsa-2048-test.pub
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64.rpm
echo POST-DELSIGN
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
],
Expand All @@ -1166,13 +1166,13 @@ RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --key-id 4344591E1964C5FC --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id 4344591E1964C5FC --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
runroot rpmkeys --import /data/keys/rpm.org-rsa-2048-test.pub
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64.rpm
echo POST-DELSIGN
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
],
Expand All @@ -1196,9 +1196,9 @@ ORIG="/data/RPMS/hello-2.0-1.x86_64.rpm"
NEW="/tmp/hello-2.0-1.x86_64.rpm"

runroot_other cp ${ORIG} /tmp/
runroot rpmsign --key-id 4344591E1964C5FC --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id 4344591E1964C5FC --addsign ${NEW}
runroot_other cmp -s ${ORIG} ${NEW}; echo $?
runroot rpmsign --delsign ${NEW} > /dev/null
runroot rpmsign --delsign ${NEW}
runroot_other cmp -s ${ORIG} ${NEW}; echo $?
],
[ignore],
Expand All @@ -1208,15 +1208,15 @@ runroot_other cmp -s ${ORIG} ${NEW}; echo $?
[])

RPMTEST_CHECK([
runroot rpmsign --define "__gpg_sign_cmd mumble" --key-id 1964C5FC --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --define "__gpg_sign_cmd mumble" --key-id 1964C5FC --addsign /tmp/hello-2.0-1.x86_64.rpm
],
[1],
[],
[error: Invalid sign command: mumble
])

RPMTEST_CHECK([
runroot rpmsign --define "__gpg /gnus/not/here" --key-id 1964C5FC --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --define "__gpg /gnus/not/here" --key-id 1964C5FC --addsign /tmp/hello-2.0-1.x86_64.rpm
],
[1],
[],
Expand Down Expand Up @@ -1248,8 +1248,7 @@ dd if=/dev/zero of="${RPMTEST}"/tmp/${pkg} \
runroot rpmsign --define "_pkgverify_flags 0" --key-id 4344591E1964C5FC --digest-algo sha256 --addsign "/tmp/${pkg}"
],
[1],
[/tmp/hello-2.0-1.x86_64.rpm:
],
[],
[error: not signing corrupt package /tmp/hello-2.0-1.x86_64.rpm: MD5 digest: BAD (Expected 007ca1d8b35cca02a1854ba301c5432e != 137ca1d8b35cca02a1854ba301c5432e)
])

Expand All @@ -1276,8 +1275,7 @@ dd if=/dev/zero of="${RPMTEST}"/tmp/${pkg} \
runroot rpmsign --key-id 1964C5FC --digest-algo sha256 --addsign "/tmp/${pkg}"
],
[1],
[/tmp/hello-2.0-1.x86_64.rpm:
],
[],
[error: not signing corrupt package /tmp/hello-2.0-1.x86_64.rpm: Payload SHA256 digest: BAD (Expected 84a7338287bf19715c4eed0243f5cdb447eeb0ade37b2af718d4060aefca2f7c != bea903609dceac36e1f26a983c493c98064d320fdfeb423034ed63d649b2c8dc)
])

Expand Down Expand Up @@ -1317,23 +1315,29 @@ runroot_other sq key import /data/keys/rpm.org-rsa-2048-test.secret

RPMTEST_CHECK([
cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
echo SIGN
runroot rpmsign --addsign -v /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
runroot rpmkeys --import /data/keys/rpm.org-rsa-2048-test.pub
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
echo DELSIGN
runroot rpmsign --delsign -v /tmp/hello-2.0-1.x86_64.rpm
echo POST-DELSIGN
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
],
[0],
[PRE-IMPORT
[SIGN
/tmp/hello-2.0-1.x86_64.rpm
PRE-IMPORT
/tmp/hello-2.0-1.x86_64.rpm:
Header V4 RSA/SHA512 signature, key ID 4344591e1964c5fc: NOKEY
POST-IMPORT
/tmp/hello-2.0-1.x86_64.rpm:
Header V4 RSA/SHA512 signature, key fingerprint: 771b18d3d7baa28734333c424344591e1964c5fc: OK
DELSIGN
/tmp/hello-2.0-1.x86_64.rpm
POST-DELSIGN
/tmp/hello-2.0-1.x86_64.rpm:
],
Expand All @@ -1352,7 +1356,7 @@ cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64-signed.rpm "${RPMTEST}"/tmp/
echo PRE-DELSIGN
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64-signed.rpm|grep -v digest
echo POST-DELSIGN
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64-signed.rpm > /dev/null
runroot rpmsign --delsign /tmp/hello-2.0-1.x86_64-signed.rpm
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64-signed.rpm|grep -v digest
],
[0],
Expand Down Expand Up @@ -1399,7 +1403,7 @@ RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --key-id B0645AEC757BF69E --digest-algo sha512 --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id B0645AEC757BF69E --digest-algo sha512 --addsign /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
Expand Down Expand Up @@ -1430,7 +1434,7 @@ RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --key-id 7f1c21f95f65bbe8 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id 7f1c21f95f65bbe8 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
Expand Down Expand Up @@ -1461,7 +1465,7 @@ RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --key-id 79cc07f167fee8841829acaa42655a75156b3de0 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id 79cc07f167fee8841829acaa42655a75156b3de0 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
Expand Down Expand Up @@ -1498,7 +1502,7 @@ RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}"/data/RPMS/hello-2.0-1.x86_64.rpm "${RPMTEST}"/tmp/
runroot rpmsign --key-id 94706f8da571389e8642bdfd42655a75156b3de0 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm > /dev/null
runroot rpmsign --key-id 94706f8da571389e8642bdfd42655a75156b3de0 --digest-algo sha256 --addsign /tmp/hello-2.0-1.x86_64.rpm
echo PRE-IMPORT
runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64.rpm|grep -v digest
echo POST-IMPORT
Expand Down

0 comments on commit 1d53115

Please sign in to comment.