editorconfig: provide editor settings for Git developers
[gitweb.git] / gpg-interface.c
index a02db765807dfdcd14054b3641040e0e77256516..db17d65f8ac977ddc5204130cb0af6a7565ae04b 100644 (file)
@@ -24,11 +24,23 @@ static const char *openpgp_sigs[] = {
        NULL
 };
 
+static const char *x509_verify_args[] = {
+       NULL
+};
+static const char *x509_sigs[] = {
+       "-----BEGIN SIGNED MESSAGE-----",
+       NULL
+};
+
 static struct gpg_format gpg_format[] = {
        { .name = "openpgp", .program = "gpg",
          .verify_args = openpgp_verify_args,
          .sigs = openpgp_sigs
        },
+       { .name = "x509", .program = "gpgsm",
+         .verify_args = x509_verify_args,
+         .sigs = x509_sigs
+       },
 };
 
 static struct gpg_format *use_format = &gpg_format[0];
@@ -95,10 +107,11 @@ static void parse_gpg_output(struct signature_check *sigc)
                sigc->result = sigcheck_gpg_status[i].result;
                /* The trust messages are not followed by key/signer information */
                if (sigc->result != 'U') {
-                       sigc->key = xmemdupz(found, 16);
+                       next = strchrnul(found, ' ');
+                       sigc->key = xmemdupz(found, next - found);
                        /* The ERRSIG message is not followed by signer information */
-                       if (sigc-> result != 'E') {
-                               found += 17;
+                       if (*next && sigc-> result != 'E') {
+                               found = next + 1;
                                next = strchrnul(found, '\n');
                                sigc->signer = xmemdupz(found, next - found);
                        }
@@ -123,12 +136,13 @@ int check_signature(const char *payload, size_t plen, const char *signature,
        sigc->gpg_output = strbuf_detach(&gpg_output, NULL);
        sigc->gpg_status = strbuf_detach(&gpg_status, NULL);
        parse_gpg_output(sigc);
+       status |= sigc->result != 'G' && sigc->result != 'U';
 
  out:
        strbuf_release(&gpg_status);
        strbuf_release(&gpg_output);
 
-       return sigc->result != 'G' && sigc->result != 'U';
+       return !!status;
 }
 
 void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
@@ -188,9 +202,12 @@ int git_gpg_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       if (!strcmp(var, "gpg.program"))
+       if (!strcmp(var, "gpg.program") || !strcmp(var, "gpg.openpgp.program"))
                fmtname = "openpgp";
 
+       if (!strcmp(var, "gpg.x509.program"))
+               fmtname = "x509";
+
        if (fmtname) {
                fmt = get_format_by_name(fmtname);
                return git_config_string(&fmt->program, var, value);