Merge branch 'js/test-git-installed'
[gitweb.git] / gpg-interface.c
index 71618d86b9153a62b1b52b57fea1a5234d35b1f0..8ed274533f87198a74a3660809c25932fa43124a 100644 (file)
@@ -73,6 +73,8 @@ void signature_check_clear(struct signature_check *sigc)
        FREE_AND_NULL(sigc->gpg_status);
        FREE_AND_NULL(sigc->signer);
        FREE_AND_NULL(sigc->key);
+       FREE_AND_NULL(sigc->fingerprint);
+       FREE_AND_NULL(sigc->primary_key_fingerprint);
 }
 
 /* An exclusive status -- only one of them can appear in output */
@@ -81,6 +83,8 @@ void signature_check_clear(struct signature_check *sigc)
 #define GPG_STATUS_KEYID       (1<<1)
 /* The status includes user identifier */
 #define GPG_STATUS_UID         (1<<2)
+/* The status includes key fingerprints */
+#define GPG_STATUS_FINGERPRINT (1<<3)
 
 /* Short-hand for standard exclusive *SIG status with keyid & UID */
 #define GPG_STATUS_STDSIG      (GPG_STATUS_EXCLUSIVE|GPG_STATUS_KEYID|GPG_STATUS_UID)
@@ -98,13 +102,14 @@ static struct {
        { 'X', "EXPSIG ", GPG_STATUS_STDSIG },
        { 'Y', "EXPKEYSIG ", GPG_STATUS_STDSIG },
        { 'R', "REVKEYSIG ", GPG_STATUS_STDSIG },
+       { 0, "VALIDSIG ", GPG_STATUS_FINGERPRINT },
 };
 
 static void parse_gpg_output(struct signature_check *sigc)
 {
        const char *buf = sigc->gpg_status;
        const char *line, *next;
-       int i;
+       int i, j;
        int seen_exclusive_status = 0;
 
        /* Iterate over all lines */
@@ -119,11 +124,12 @@ static void parse_gpg_output(struct signature_check *sigc)
                for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
                        if (skip_prefix(line, sigcheck_gpg_status[i].check, &line)) {
                                if (sigcheck_gpg_status[i].flags & GPG_STATUS_EXCLUSIVE) {
-                                       if (++seen_exclusive_status > 1)
+                                       if (seen_exclusive_status++)
                                                goto found_duplicate_status;
                                }
 
-                               sigc->result = sigcheck_gpg_status[i].result;
+                               if (sigcheck_gpg_status[i].result)
+                                       sigc->result = sigcheck_gpg_status[i].result;
                                /* Do we have key information? */
                                if (sigcheck_gpg_status[i].flags & GPG_STATUS_KEYID) {
                                        next = strchrnul(line, ' ');
@@ -137,6 +143,24 @@ static void parse_gpg_output(struct signature_check *sigc)
                                                sigc->signer = xmemdupz(line, next - line);
                                        }
                                }
+                               /* Do we have fingerprint? */
+                               if (sigcheck_gpg_status[i].flags & GPG_STATUS_FINGERPRINT) {
+                                       next = strchrnul(line, ' ');
+                                       free(sigc->fingerprint);
+                                       sigc->fingerprint = xmemdupz(line, next - line);
+
+                                       /* Skip interim fields */
+                                       for (j = 9; j > 0; j--) {
+                                               if (!*next)
+                                                       break;
+                                               line = next + 1;
+                                               next = strchrnul(line, ' ');
+                                       }
+
+                                       next = strchrnul(line, '\n');
+                                       free(sigc->primary_key_fingerprint);
+                                       sigc->primary_key_fingerprint = xmemdupz(line, next - line);
+                               }
 
                                break;
                        }
@@ -154,6 +178,8 @@ static void parse_gpg_output(struct signature_check *sigc)
         */
        sigc->result = 'E';
        /* Clear partial data to avoid confusion */
+       FREE_AND_NULL(sigc->primary_key_fingerprint);
+       FREE_AND_NULL(sigc->fingerprint);
        FREE_AND_NULL(sigc->signer);
        FREE_AND_NULL(sigc->key);
 }