]> git.ipfire.org Git - people/sennis/libloc.git/commitdiff
Log the signature in debug mode
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 12 Dec 2019 12:47:28 +0000 (12:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 12 Dec 2019 12:47:28 +0000 (12:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/loc/private.h
src/writer.c

index 77c9ebd232e59a2d755ae591ab05857b7a5550d3..8c85d28d10ef326659704b19b1c91f3893b3f062 100644 (file)
@@ -539,6 +539,9 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) {
                r = 1;
        }
 
+       // Dump signature
+       hexdump(db->ctx, db->signature, db->signature_length);
+
        clock_t end = clock();
        DEBUG(db->ctx, "Signature checked in %.4fms\n",
                (double)(end - start) / CLOCKS_PER_SEC * 1000);
index 70cdbb9d960ccfce4c7f701d3d9e85222f8dae5e..6d857952e1d59880d78d711dfbb4fd6386be1611 100644 (file)
@@ -78,5 +78,47 @@ static inline void in6_addr_set_bit(struct in6_addr* address, unsigned int i, un
        address->s6_addr[i / 8] ^= (-val ^ address->s6_addr[i / 8]) & (1 << (7 - (i % 8)));
 }
 
+static inline void hexdump(struct loc_ctx* ctx, const void* addr, size_t len) {
+       char buffer_hex[16 * 3 + 6];
+       char buffer_ascii[17];
+
+       unsigned int i = 0;
+       unsigned char* p = (unsigned char*)addr;
+
+       // Process every byte in the data
+       for (i = 0; i < len; i++) {
+               // Multiple of 16 means new line (with line offset)
+               if ((i % 16) == 0) {
+                       // Just don't print ASCII for the zeroth line
+                       if (i != 0)
+                               DEBUG(ctx, "  %s %s\n", buffer_hex, buffer_ascii);
+
+                       // Output the offset.
+                       sprintf(buffer_hex, "%04x ", i);
+               }
+
+               // Now the hex code for the specific character
+               sprintf(buffer_hex + 5 + ((i % 16) * 3), " %02x", p[i]);
+
+               // And store a printable ASCII character for later
+               if ((p[i] < 0x20) || (p[i] > 0x7e))
+                       buffer_ascii[i % 16] = '.';
+               else
+                       buffer_ascii[i % 16] = p[i];
+
+               // Terminate string
+               buffer_ascii[(i % 16) + 1] = '\0';
+       }
+
+       // Pad out last line if not exactly 16 characters
+       while ((i % 16) != 0) {
+               sprintf(buffer_hex + 5 + ((i % 16) * 3), "   ");
+               i++;
+       }
+
+       // And print the final bit
+       DEBUG(ctx, "  %s %s\n", buffer_hex, buffer_ascii);
+}
+
 #endif
 #endif
index 0a4c4087e0d94c22c3ca466d85470da146de034b..26d5c32f3eb96c2266b700d88e8bc2757d4b6e89 100644 (file)
@@ -578,9 +578,13 @@ static int loc_writer_create_signature(struct loc_writer* writer,
        // Save length of the signature
        header->signature_length = htobe32(signature_length);
 
-       DEBUG(writer->ctx, "Successfully generated signature\n");
+       DEBUG(writer->ctx, "Successfully generated signature of %lu bytes\n",
+               signature_length);
        r = 0;
 
+       // Dump signature
+       hexdump(writer->ctx, header->signature, signature_length);
+
 END:
        EVP_MD_CTX_free(mdctx);