Skip to content

Commit b8bc68c

Browse files
committed
Add support for multiple OpenPGP signatures per package, part 2/2
Add a tag extension for RPMTAG_OPENPGP (on top of the concrete tag) to handle compatibility with v3/v4 signatures: the extension collects all legacy signatures under the same umbrella so users don't need to query multiple different tags, you just query for RPMTAG_OPENPGP to get all them at once. Extend :pgpsig tag format to handle the new string array/base64 variant. Update --info/-i query to use the extension and output all existing signatures, one per line. The no-signature case of "Signature : (none)" is preserved as-is to help backwards compatibility with scripts parsing the output. Related: #3385
1 parent ebd3884 commit b8bc68c

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

lib/formats.cc

+21-3
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,12 @@ static char *jsonFormat(rpmtd td, char **emsg)
419419
}
420420

421421
/* signature fingerprint and time formatting */
422-
static char * pgpsigFormat(rpmtd td, char **emsg)
422+
static char * pgpsigFormatOne(uint8_t *pkt, size_t pktlen, char **emsg)
423423
{
424424
char * val = NULL;
425425
pgpDigParams sigp = NULL;
426426

427-
if (pgpPrtParams((uint8_t*)td->data, td->count, PGPTAG_SIGNATURE, &sigp)) {
427+
if (pgpPrtParams(pkt, pktlen, PGPTAG_SIGNATURE, &sigp)) {
428428
*emsg = xstrdup(_("(not an OpenPGP signature)"));
429429
} else {
430430
char dbuf[BUFSIZ];
@@ -451,6 +451,24 @@ static char * pgpsigFormat(rpmtd td, char **emsg)
451451
return val;
452452
}
453453

454+
static char * pgpsigFormat(rpmtd td, char **emsg)
455+
{
456+
char *val = NULL;
457+
if (rpmtdType(td) == RPM_BIN_TYPE) {
458+
val = pgpsigFormatOne((uint8_t *)td->data, td->count, emsg);
459+
} else if (rpmtdType(td) == RPM_STRING_ARRAY_TYPE) {
460+
uint8_t *pkt = NULL;
461+
size_t pktlen = 0;
462+
if (rpmBase64Decode(rpmtdGetString(td), (void **)&pkt, &pktlen) == 0) {
463+
val = pgpsigFormatOne(pkt, pktlen, emsg);
464+
free(pkt);
465+
}
466+
} else {
467+
*emsg = xstrdup(_("(invalid type)"));
468+
}
469+
return val;
470+
}
471+
454472
/* dependency flags formatting */
455473
static char * depflagsFormat(rpmtd td, char **emsg)
456474
{
@@ -581,7 +599,7 @@ static const struct headerFmt_s rpmHeaderFormats[] = {
581599
{ RPMTD_FORMAT_BASE64, "base64",
582600
RPM_BINARY_CLASS, base64Format },
583601
{ RPMTD_FORMAT_PGPSIG, "pgpsig",
584-
RPM_BINARY_CLASS, pgpsigFormat },
602+
RPM_NULL_CLASS, pgpsigFormat },
585603
{ RPMTD_FORMAT_DEPFLAGS, "depflags",
586604
RPM_NUMERIC_CLASS, depflagsFormat },
587605
{ RPMTD_FORMAT_DEPTYPE, "deptype",

lib/tagexts.cc

+34
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,39 @@ static int sysusersTag(Header h, rpmtd td, headerGetFlags hgflags)
10521052
return (td->count > 0);
10531053
}
10541054

1055+
static void trySigTag(Header h, rpmTagVal tag, ARGV_t *sigs)
1056+
{
1057+
struct rpmtd_s td;
1058+
if (headerGet(h, tag, &td, HEADERGET_ALLOC)) {
1059+
char *b64 = rpmBase64Encode((uint8_t *)td.data, td.count, 0);
1060+
if (b64) {
1061+
argvAdd(sigs, b64);
1062+
free(b64);
1063+
}
1064+
rpmtdFreeData(&td);
1065+
}
1066+
}
1067+
1068+
static int openpgpTag(Header h, rpmtd td, headerGetFlags hgflags)
1069+
{
1070+
if (headerGet(h, RPMTAG_OPENPGP, td, HEADERGET_ALLOC))
1071+
return 1;
1072+
1073+
ARGV_t sigs = NULL;
1074+
trySigTag(h, RPMTAG_RSAHEADER, &sigs);
1075+
trySigTag(h, RPMTAG_DSAHEADER, &sigs);
1076+
trySigTag(h, RPMTAG_SIGPGP, &sigs);
1077+
trySigTag(h, RPMTAG_SIGGPG, &sigs);
1078+
1079+
if (sigs) {
1080+
td->data = sigs;
1081+
td->count = argvCount(sigs);
1082+
td->type = RPM_STRING_ARRAY_TYPE;
1083+
td->flags = RPMTD_ALLOCED|RPMTD_PTR_ALLOCED;
1084+
}
1085+
return td->count != 0;
1086+
}
1087+
10551088
static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
10561089
{ RPMTAG_GROUP, groupTag },
10571090
{ RPMTAG_DESCRIPTION, descriptionTag },
@@ -1093,6 +1126,7 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
10931126
{ RPMTAG_FILENLINKS, filenlinksTag },
10941127
{ RPMTAG_SYSUSERS, sysusersTag },
10951128
{ RPMTAG_FILEMIMES, filemimesTag },
1129+
{ RPMTAG_OPENPGP, openpgpTag },
10961130
{ 0, NULL }
10971131
};
10981132

rpmpopt.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Install Date: %|INSTALLTIME?{%{INSTALLTIME:date}}:{(not installed)}|\n\
9696
Group : %{GROUP}\n\
9797
Size : %{LONGSIZE}\n\
9898
%|LICENSE?{License : %{LICENSE}}|\n\
99-
Signature : %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|\n\
99+
Signature :%|OPENPGP?{[\n %{OPENPGP:pgpsig}]}:{ (none)}|\n\
100100
Source RPM : %{SOURCERPM}\n\
101101
Build Date : %{BUILDTIME:date}\n\
102102
Build Host : %{BUILDHOST}\n\

tests/rpmquery.at

+41
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,18 @@ rpm \
420420
[RSA/SHA256, Thu Apr 6 13:02:33 2017, Key ID 4344591e1964c5fc],
421421
[warning: /data/RPMS/hello-2.0-1.x86_64-signed.rpm: Header OpenPGP V4 RSA/SHA256 signature, key ID 4344591e1964c5fc: NOKEY
422422
])
423+
424+
RPMTEST_CHECK([[
425+
runroot rpm \
426+
--nosignature \
427+
--qf "[%{openpgp:pgpsig}\n]" \
428+
-qp /data/RPMS/hello-2.0-1.x86_64-signed.rpm
429+
]],
430+
[0],
431+
[RSA/SHA256, Thu Apr 6 13:02:33 2017, Key ID 4344591e1964c5fc
432+
RSA/SHA256, Thu Apr 6 13:02:32 2017, Key ID 4344591e1964c5fc
433+
],
434+
[])
423435
RPMTEST_CLEANUP
424436

425437
# ------------------------------
@@ -1396,3 +1408,32 @@ runroot rpm -qp --filemime /build/RPMS/noarch/filetypes-1.0-1.noarch.rpm | sed -
13961408
],
13971409
[])
13981410
RPMTEST_CLEANUP
1411+
1412+
AT_SETUP([info query output])
1413+
AT_KEYWORDS([query signature])
1414+
RPMTEST_CHECK([
1415+
runroot rpm -qi --nosignature /data/RPMS/hello-2.0-1.x86_64-signed.rpm
1416+
],
1417+
[0],
1418+
[[Name : hello
1419+
Version : 2.0
1420+
Release : 1
1421+
Architecture: x86_64
1422+
Install Date: (not installed)
1423+
Group : Testing
1424+
Size : 7243
1425+
License : GPL
1426+
Signature :
1427+
RSA/SHA256, Thu Apr 6 13:02:33 2017, Key ID 4344591e1964c5fc
1428+
RSA/SHA256, Thu Apr 6 13:02:32 2017, Key ID 4344591e1964c5fc
1429+
Source RPM : hello-2.0-1.src.rpm
1430+
Build Date : Sat Nov 22 12:00:00 2008
1431+
Build Host : localhost
1432+
Relocations : /usr
1433+
Summary : hello -- hello, world rpm
1434+
Description :
1435+
Simple rpm demonstration.
1436+
]],
1437+
[])
1438+
RPMTEST_CLEANUP
1439+

0 commit comments

Comments
 (0)