michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame SOURCES/0008-Eliminate-redundant-signature-length-calculation-fun.patch

45afda
From ff2fb80469e9aa478ea4de3eae5d9c13ca411382 Mon Sep 17 00:00:00 2001
45afda
From: Panu Matilainen <pmatilai@redhat.com>
45afda
Date: Tue, 10 Oct 2017 15:04:38 +0300
45afda
Subject: [PATCH 08/33] Eliminate redundant signature length calculation
45afda
 function
45afda
45afda
The actual signing function knows the length already, we just need to
45afda
return it and then we can insert it if there was anything at all
45afda
to sign.
45afda
---
45afda
 sign/rpmsignfiles.c | 40 ++++++++++++++--------------------------
45afda
 1 file changed, 14 insertions(+), 26 deletions(-)
45afda
45afda
diff --git a/sign/rpmsignfiles.c b/sign/rpmsignfiles.c
45afda
index de7a73cfd..9fe6e6d41 100644
45afda
--- a/sign/rpmsignfiles.c
45afda
+++ b/sign/rpmsignfiles.c
45afda
@@ -33,7 +33,7 @@ static const char *hash_algo_name[] = {
45afda
 #define ARRAY_SIZE(a)  (sizeof(a) / sizeof(a[0]))
45afda
 
45afda
 static char *signFile(const char *algo, const uint8_t *fdigest, int diglen,
45afda
-const char *key, char *keypass)
45afda
+const char *key, char *keypass, uint32_t *siglenp)
45afda
 {
45afda
     char *fsignature;
45afda
     unsigned char digest[diglen];
45afda
@@ -56,32 +56,18 @@ const char *key, char *keypass)
45afda
 	return NULL;
45afda
     }
45afda
 
45afda
+    *siglenp = siglen + 1;
45afda
     /* convert file signature binary to hex */
45afda
     fsignature = pgpHexStr(signature, siglen+1);
45afda
     return fsignature;
45afda
 }
45afda
 
45afda
-static uint32_t signatureLength(const char *algo, int diglen, const char *key,
45afda
-char *keypass)
45afda
-{
45afda
-    unsigned char digest[diglen];
45afda
-    unsigned char signature[MAX_SIGNATURE_LENGTH];
45afda
-
45afda
-    memset(digest, 0, diglen);
45afda
-    memset(signature, 0, MAX_SIGNATURE_LENGTH);
45afda
-    signature[0] = '\x03';
45afda
-
45afda
-    uint32_t siglen = sign_hash(algo, digest, diglen, key, keypass,
45afda
-				signature+1);
45afda
-    return siglen + 1;
45afda
-}
45afda
-
45afda
 rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
45afda
 {
45afda
     struct rpmtd_s td;
45afda
     int algo;
45afda
     int diglen;
45afda
-    uint32_t siglen;
45afda
+    uint32_t siglen = 0;
45afda
     const char *algoname;
45afda
     const uint8_t *digest;
45afda
     char *signature = NULL;
45afda
@@ -108,14 +94,6 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
45afda
 
45afda
     headerDel(sigh, RPMTAG_FILESIGNATURELENGTH);
45afda
     headerDel(sigh, RPMTAG_FILESIGNATURES);
45afda
-    siglen = signatureLength(algoname, diglen, key, keypass);
45afda
-
45afda
-    rpmtdReset(&td);
45afda
-    td.tag = RPMSIGTAG_FILESIGNATURELENGTH;
45afda
-    td.type = RPM_INT32_TYPE;
45afda
-    td.data = &siglen;
45afda
-    td.count = 1;
45afda
-    headerPut(sigh, &td, HEADERPUT_DEFAULT);
45afda
 
45afda
     rpmtdReset(&td);
45afda
     td.tag = RPMSIGTAG_FILESIGNATURES;
45afda
@@ -125,7 +103,7 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
45afda
 
45afda
     while (rpmfiNext(fi) >= 0) {
45afda
 	digest = rpmfiFDigest(fi, NULL, NULL);
45afda
-	signature = signFile(algoname, digest, diglen, key, keypass);
45afda
+	signature = signFile(algoname, digest, diglen, key, keypass, &siglen);
45afda
 	if (!signature) {
45afda
 	    rpmlog(RPMLOG_ERR, _("signFile failed\n"));
45afda
 	    goto exit;
45afda
@@ -137,6 +115,16 @@ rpmRC rpmSignFiles(Header sigh, Header h, const char *key, char *keypass)
45afda
 	}
45afda
 	signature = _free(signature);
45afda
     }
45afda
+
45afda
+    if (siglen > 0) {
45afda
+	rpmtdReset(&td);
45afda
+	td.tag = RPMSIGTAG_FILESIGNATURELENGTH;
45afda
+	td.type = RPM_INT32_TYPE;
45afda
+	td.data = &siglen;
45afda
+	td.count = 1;
45afda
+	headerPut(sigh, &td, HEADERPUT_DEFAULT);
45afda
+    }
45afda
+
45afda
     rc = RPMRC_OK;
45afda
 
45afda
 exit:
45afda
-- 
45afda
2.27.0
45afda