Unbreak DSA signature trailer handling
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 23 May 2008 13:59:04 +0000 (16:59 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 23 May 2008 14:07:35 +0000 (17:07 +0300)
- RFC 4880 states the following:
V4 signatures also hash in a final trailer of six octets: the
version of the Signature packet, i.e., 0x04; 0xFF; and a four-octet,
big-endian number that is the length of the hashed data from the
Signature packet (note that this number does not include these final
six octets).
  ... but we were using size_t, whose size is  platform dependent, oops :)

lib/signature.c

index cc1d017..b3e7f42 100644 (file)
@@ -1290,14 +1290,14 @@ verifyDSASignature(rpmts ts, char ** msg,
            xx = rpmDigestUpdate(ctx, sigp->hash, sigp->hashlen);
 
        if (sigp->version == 4) {
-           size_t nb = sigp->hashlen;
-           uint8_t *trailer = xmalloc(2+sizeof(nb));
+           /* V4 trailer is six octets long (rfc4880) */
+           uint8_t trailer[6];
+           uint32_t nb = sigp->hashlen;
            nb = htonl(nb);
            trailer[0] = sigp->version;
            trailer[1] = 0xff;
-           memcpy(trailer+2, &nb, sizeof(nb));
+           memcpy(trailer+2, &nb, 4);
            xx = rpmDigestUpdate(ctx, trailer, sizeof(trailer));
-           free(trailer);
        }
        xx = rpmDigestFinal(ctx, (void **)&dig->sha1, &dig->sha1len, 0);
        (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DIGEST), sigp->hashlen);