Skip to content

Commit 1be2973

Browse files
committed
Support updating individual IDs in a digest bundle
Up to now, rpm digest bundles have only needed to support data from a single stream - just covering different ranges and algorithms. But OpenPGP v6 signature salt is a random per-signature thing that we need to feed into the digest before the actual data, so we need to be able to update each ID in a bundle individually too. Luckily this is easy to do. Add a small test-program to exercise it, we can't yet actually use it for testing a real-world V6 scenario anyway. Fixes: #3845
1 parent 1a1a05c commit 1be2973

5 files changed

Lines changed: 79 additions & 2 deletions

File tree

include/rpm/rpmcrypto.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ int rpmDigestBundleAddID(rpmDigestBundle bundle, int algo, int id,
144144
*/
145145
int rpmDigestBundleUpdate(rpmDigestBundle bundle, const void *data, size_t len);
146146

147+
/** \ingroup rpmcrypto
148+
* Update context of an individual ID within bundle with next plain text buffer.
149+
* @param bundle digest bundle
150+
* @param id id of digest (arbitrary, must be > 0)
151+
* @param data next data buffer
152+
* @param len no. bytes of data
153+
* @return 0 on success
154+
*/
155+
int rpmDigestBundleUpdateID(rpmDigestBundle bundle, int id,
156+
const void *data, size_t len);
157+
147158
/** \ingroup rpmcrypto
148159
* Return digest from a bundle and destroy context, see rpmDigestFinal().
149160
*

rpmio/digest.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,19 @@ int rpmDigestBundleUpdate(rpmDigestBundle bundle, const void *data, size_t len)
6666
return rc;
6767
}
6868

69+
int rpmDigestBundleUpdateID(rpmDigestBundle bundle, int id,
70+
const void *data, size_t len)
71+
{
72+
int rc = -1;
73+
if (bundle && data && len > 0 && id > 0) {
74+
auto it = bundle->digs.find(id);
75+
if (it != bundle->digs.end())
76+
rc = rpmDigestUpdate(it->second, data, len);
77+
}
78+
return rc;
79+
}
6980
int rpmDigestBundleFinal(rpmDigestBundle bundle, int id,
70-
void ** datap, size_t * lenp, int asAscii)
81+
void ** datap, size_t * lenp, int asAscii)
7182
{
7283
int rc = -1;
7384
if (bundle) {

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ foreach(at ${TESTSUITE_AT})
6262
FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpmtests.at "m4_include([${at}])\n")
6363
endforeach()
6464

65-
set(TESTPROGS rpmpgpcheck rpmpgppubkeyfingerprint readpkgnullts)
65+
set(TESTPROGS rpmpgpcheck rpmpgppubkeyfingerprint readpkgnullts rpmdig)
6666
foreach(prg ${TESTPROGS})
6767
add_executable(${prg} EXCLUDE_FROM_ALL ${prg}.c)
6868
target_link_libraries(${prg} PRIVATE librpm)

tests/rpmdig.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <stddef.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
6+
#include <rpm/rpmcrypto.h>
7+
8+
static void printID(rpmDigestBundle b, int id)
9+
{
10+
char *s = NULL;
11+
if (rpmDigestBundleFinal(b, id, (void **)&s, NULL, 1) == 0) {
12+
printf("%d: %s\n", id, s);
13+
free(s);
14+
}
15+
}
16+
17+
int main(int argc, char *argv[])
18+
{
19+
const char *AAA = "AAA";
20+
const char *BBB = "BBB";
21+
22+
if (rpmInitCrypto())
23+
return EXIT_FAILURE;
24+
25+
rpmDigestBundle b = rpmDigestBundleNew();
26+
rpmDigestBundleAddID(b, RPM_HASH_SHA256, 1, 0);
27+
rpmDigestBundleAddID(b, RPM_HASH_SHA256, 2, 0);
28+
rpmDigestBundleAddID(b, RPM_HASH_SHA256, 3, 0);
29+
rpmDigestBundleAddID(b, RPM_HASH_SHA512, 4, 0);
30+
31+
rpmDigestBundleUpdateID(b, 2, BBB, strlen(BBB));
32+
rpmDigestBundleUpdate(b, AAA, strlen(AAA));
33+
34+
for (int i = 1; i < 5; ++i)
35+
printID(b, i);
36+
37+
rpmDigestBundleFree(b);
38+
rpmFreeCrypto();
39+
return 0;
40+
}

tests/rpmsigdig.at

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ m4_define([RPMOUTPUT_SEQUOIA], [m4_if(RPM_PGP, [sequoia], [$1
77
m4_define([RPMOUTPUT_LEGACY], [m4_if(RPM_PGP, [legacy], [$1
88
])])
99

10+
RPMTEST_SETUP([Digest bundle])
11+
AT_KEYWORDS([digest])
12+
RPMTEST_CHECK([
13+
rpmdig
14+
],
15+
[0],
16+
[1: cb1ad2119d8fafb69566510ee712661f9f14b83385006ef92aec47f523a38358
17+
2: e6c9f16ad216ab08c2511d9e67b450dbef6e0522a735ae2b0a61cef453fbcaa2
18+
3: cb1ad2119d8fafb69566510ee712661f9f14b83385006ef92aec47f523a38358
19+
4: 8d708d18b54df3962d696f069ad42dad7762b5d4d3c97ee5fa2dae0673ed46545164c078b8db3d59c4b96020e4316f17bb3d91bf1f6bc0896bbe75416eb8c385
20+
],
21+
[])
22+
RPMTEST_CLEANUP
23+
1024
RPMTEST_SETUP([seen signer id tracking])
1125
AT_KEYWORDS([query signature])
1226
RPMTEST_CHECK([
@@ -2455,3 +2469,4 @@ runroot rpmkeys --delete 036824f0ac60aed6f1a3256f88190469f6d7255e3d8e41c577233aa
24552469
[],
24562470
[])
24572471
RPMTEST_CLEANUP
2472+

0 commit comments

Comments
 (0)