summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-09-29 10:48:59 +0300
committerPanu Matilainen <pmatilai@redhat.com>2010-09-29 10:55:38 +0300
commit8422a94ca990ccc3c60459687b3c3f25e43502b8 (patch)
treee80c5d5586ef500b974be2302a04e2eb5f75150e
parent825691afb2a8e2c0b3c6a031950f3c7855dc4c6e (diff)
downloadlibrpm-tizen-8422a94ca990ccc3c60459687b3c3f25e43502b8.tar.gz
librpm-tizen-8422a94ca990ccc3c60459687b3c3f25e43502b8.tar.bz2
librpm-tizen-8422a94ca990ccc3c60459687b3c3f25e43502b8.zip
Split signature and digest generation to separate functions
- Similar in spirit to commit 825691afb2a8e2c0b3c6a031950f3c7855dc4c6e, these have fairly little in common really. - Change the function names to force breakage on users (these are exported in ABI but not in public headers so "users" are internal uses in practise): the automatically generated bits in signature header are not signatures, but digests (even size is a checksum of sorts) ... and fix the couple of internal uses.
-rw-r--r--build/pack.c4
-rw-r--r--lib/rpmgensig.c6
-rw-r--r--lib/signature.c49
-rw-r--r--lib/signature.h11
4 files changed, 47 insertions, 23 deletions
diff --git a/build/pack.c b/build/pack.c
index 0b57613fe..ea49ec660 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -450,8 +450,8 @@ static rpmRC writeRPM(Header *hdrp, unsigned char ** pkgidp, const char *fileNam
sizetag = RPMSIGTAG_LONGSIZE;
payloadtag = RPMSIGTAG_LONGARCHIVESIZE;
}
- (void) rpmAddSignature(sig, sigtarget, sizetag, NULL);
- (void) rpmAddSignature(sig, sigtarget, RPMSIGTAG_MD5, NULL);
+ (void) rpmGenDigest(sig, sigtarget, sizetag);
+ (void) rpmGenDigest(sig, sigtarget, RPMSIGTAG_MD5);
if (SHA1) {
/* XXX can't use rpmtdFromFoo() on RPMSIGTAG_* items */
diff --git a/lib/rpmgensig.c b/lib/rpmgensig.c
index 4426164f1..75cd24f9a 100644
--- a/lib/rpmgensig.c
+++ b/lib/rpmgensig.c
@@ -173,13 +173,13 @@ static int replaceSignature(Header sigh, const char *sigtarget,
deleteSigs(sigh);
/*
- * rpmAddSignature() internals parse the actual signing result and
+ * rpmGenSignature() internals parse the actual signing result and
* use appropriate DSA/RSA tags regardless of what we pass from here.
* RPMSIGTAG_GPG is only used to signal its an actual signature
* and not just a digest we're adding, and says nothing
* about the actual tags that gets created.
*/
- if (rpmAddSignature(sigh, sigtarget, RPMSIGTAG_GPG, passPhrase) == 0) {
+ if (rpmGenSignature(sigh, sigtarget, RPMSIGTAG_GPG, passPhrase) == 0) {
/* Lets see what we got and whether its the same signature as before */
rpmSigTag sigtag = headerIsEntry(sigh, RPMSIGTAG_DSA) ?
RPMSIGTAG_DSA : RPMSIGTAG_RSA;
@@ -295,7 +295,7 @@ static int rpmSign(const char *rpm, int deleting, const char *passPhrase)
int nsigs = sizeof(sigs) / sizeof(rpmSigTag);
for (int i = 0; i < nsigs; i++) {
(void) headerDel(sigh, sigs[i]);
- if (rpmAddSignature(sigh, sigtarget, sigs[i], passPhrase))
+ if (rpmGenDigest(sigh, sigtarget, sigs[i]))
goto exit;
}
}
diff --git a/lib/signature.c b/lib/signature.c
index 7aa8f8cdf..e5142f075 100644
--- a/lib/signature.c
+++ b/lib/signature.c
@@ -500,6 +500,37 @@ exit:
return ret;
}
+int rpmGenSignature(Header sigh, const char * file, rpmSigTag sigTag,
+ const char * passPhrase)
+{
+ uint8_t * pkt = NULL;
+ size_t pktlen;
+ int ret = -1; /* assume failure. */
+
+ switch (sigTag) {
+ case RPMSIGTAG_PGP5: /* XXX legacy */
+ case RPMSIGTAG_PGP:
+ case RPMSIGTAG_GPG: {
+ rpmSigTag hdrtag;
+ if (makeGPGSignature(file, &sigTag, &pkt, &pktlen, passPhrase)
+ || !sighdrPut(sigh, sigTag, RPM_BIN_TYPE, pkt, pktlen))
+ break;
+ /* XXX Piggyback a header-only DSA/RSA signature as well. */
+ hdrtag = (sigTag == RPMSIGTAG_GPG) ? RPMSIGTAG_DSA : RPMSIGTAG_RSA;
+ ret = makeHDRSignature(sigh, file, hdrtag, passPhrase);
+ } break;
+ case RPMSIGTAG_RSA:
+ case RPMSIGTAG_DSA:
+ ret = makeHDRSignature(sigh, file, sigTag, passPhrase);
+ break;
+ default:
+ break;
+ }
+ free(pkt);
+
+ return ret;
+}
+
static int makeHDRDigest(Header sigh, const char * file, rpmSigTag sigTag)
{
Header h = NULL;
@@ -556,8 +587,7 @@ exit:
return ret;
}
-int rpmAddSignature(Header sigh, const char * file, rpmSigTag sigTag,
- const char * passPhrase)
+int rpmGenDigest(Header sigh, const char * file, rpmSigTag sigTag)
{
struct stat st;
uint8_t * pkt = NULL;
@@ -591,21 +621,6 @@ int rpmAddSignature(Header sigh, const char * file, rpmSigTag sigTag,
break;
ret = 0;
break;
- case RPMSIGTAG_PGP5: /* XXX legacy */
- case RPMSIGTAG_PGP:
- case RPMSIGTAG_GPG: {
- rpmSigTag hdrtag;
- if (makeGPGSignature(file, &sigTag, &pkt, &pktlen, passPhrase)
- || !sighdrPut(sigh, sigTag, RPM_BIN_TYPE, pkt, pktlen))
- break;
- /* XXX Piggyback a header-only DSA/RSA signature as well. */
- hdrtag = (sigTag == RPMSIGTAG_GPG) ? RPMSIGTAG_DSA : RPMSIGTAG_RSA;
- ret = makeHDRSignature(sigh, file, hdrtag, passPhrase);
- } break;
- case RPMSIGTAG_RSA:
- case RPMSIGTAG_DSA:
- ret = makeHDRSignature(sigh, file, sigTag, passPhrase);
- break;
case RPMSIGTAG_SHA1:
ret = makeHDRDigest(sigh, file, sigTag);
break;
diff --git a/lib/signature.h b/lib/signature.h
index 3f0024560..ebd039281 100644
--- a/lib/signature.h
+++ b/lib/signature.h
@@ -45,6 +45,15 @@ rpmRC rpmReadSignature(FD_t fd, Header *sighp, sigType sig_type, char ** msg);
int rpmWriteSignature(FD_t fd, Header h);
/** \ingroup signature
+ * Generate digest(s) from a header+payload file, save in signature header.
+ * @param sigh signature header
+ * @param file header+payload file name
+ * @param sigTag type of digest(s) to add
+ * @return 0 on success, -1 on failure
+ */
+int rpmGenDigest(Header sigh, const char * file, rpmSigTag sigTag);
+
+/** \ingroup signature
* Generate signature(s) from a header+payload file, save in signature header.
* @param sigh signature header
* @param file header+payload file name
@@ -52,7 +61,7 @@ int rpmWriteSignature(FD_t fd, Header h);
* @param passPhrase private key pass phrase
* @return 0 on success, -1 on failure
*/
-int rpmAddSignature(Header sigh, const char * file,
+int rpmGenSignature(Header sigh, const char * file,
rpmSigTag sigTag, const char * passPhrase);
/** \ingroup signature