]> git.ipfire.org Git - pakfire.git/commitdiff
key: Store the timestamp of the signature if wanted
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Jul 2021 17:05:32 +0000 (17:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Jul 2021 17:05:32 +0000 (17:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c
src/libpakfire/include/pakfire/key.h
src/libpakfire/key.c

index 9ab071567f3c55078d5f9a4bc98b0d08779ab595..0cfb49ddaf984453ebe448e63eb7be836ce0d153 100644 (file)
@@ -1427,7 +1427,7 @@ PAKFIRE_EXPORT const char* pakfire_archive_verify_strerror(pakfire_archive_verif
 }
 
 static int pakfire_archive_create_signature(struct pakfire_archive* archive,
-               struct pakfire_key* key, char** signature, size_t signature_length) {
+               struct pakfire_key* key, char** signature, size_t* signature_length, time_t* timestamp) {
        char* buffer = NULL;
        size_t length = 0;
 
@@ -1437,7 +1437,7 @@ static int pakfire_archive_create_signature(struct pakfire_archive* archive,
                goto ERROR;
 
        // Use the key to sign the buffer
-       r = pakfire_key_sign(key, buffer, length, signature, signature_length);
+       r = pakfire_key_sign(key, buffer, length, signature, signature_length, timestamp);
        if (r)
                goto ERROR;
 
@@ -1455,9 +1455,11 @@ PAKFIRE_EXPORT int pakfire_archive_sign(struct pakfire_archive* archive, struct
 
        char* signature = NULL;
        size_t signature_length = 0;
+       time_t timestamp = 0;
 
        // Create the signature
-       r = pakfire_archive_create_signature(archive, key, &signature, &signature_length);
+       r = pakfire_archive_create_signature(archive, key,
+               &signature, &signature_length, &timestamp);
        if (r)
                return r;
 
index 57f4a198c3db7c2b06741cbd8c84fb032081af63..32e9befbc9200480494bba540ac4bf25485bc9cb 100644 (file)
@@ -66,7 +66,7 @@ char* pakfire_key_dump(struct pakfire_key* key);
 int pakfire_key_create(struct pakfire_key** key, struct pakfire* pakfire, gpgme_key_t gpgkey);
 
 int pakfire_key_sign(struct pakfire_key* key, const char* buffer, const size_t buffer_length,
-       char** signature, size_t* signature_length);
+       char** signature, size_t* signature_length, time_t* timestamp);
 
 #endif
 
index 5d6b205c4dfa827d577d6a1d2f224095a10054d7..6aeea64a942cc2372a5768cf22644120bb6fa683 100644 (file)
@@ -577,7 +577,7 @@ PAKFIRE_EXPORT char* pakfire_key_dump(struct pakfire_key* key) {
 }
 
 int pakfire_key_sign(struct pakfire_key* key, const char* buffer, const size_t buffer_length,
-               char** signature, size_t* signature_length) {
+               char** signature, size_t* signature_length, time_t* timestamp) {
        // Fetch GPGME context
        gpgme_ctx_t gpgctx = pakfire_get_gpgctx(key->pakfire);
        if (!gpgctx)
@@ -631,7 +631,6 @@ int pakfire_key_sign(struct pakfire_key* key, const char* buffer, const size_t b
                        goto ERROR;
        }
 
-#ifdef ENABLE_DEBUG
        // Print some status details
        gpgme_sign_result_t result = gpgme_op_sign_result(gpgctx);
        if (result) {
@@ -641,11 +640,14 @@ int pakfire_key_sign(struct pakfire_key* key, const char* buffer, const size_t b
                        DEBUG(key->pakfire, "  Algorithm : %s\n", gpgme_pubkey_algo_name(s->pubkey_algo));
                        DEBUG(key->pakfire, "  Hash      : %s\n", gpgme_hash_algo_name(s->hash_algo));
                        DEBUG(key->pakfire, "  Timestamp : %ld\n", s->timestamp);
+
+                       // Store timestamp
+                       if (timestamp)
+                               *timestamp = s->timestamp;
                }
 
                gpgme_result_unref(result);
        }
-#endif
 
        // Extract the signature
        __signature = gpgme_data_release_and_get_mem(sign, signature_length);