gpg-interface: move parse_gpg_output() to where it should be
Earlier, ffb6d7d5
(Move commit GPG signature verification to
commit.c, 2013-03-31) moved this helper that used to be in pretty.c
(i.e. the output code path) to commit.c for better reusability.
It was a good first step in the right direction, but still suffers
from a myopic view that commits will be the only thing we would ever
want to sign---we would actually want to be able to reuse it even
wider.
The function interprets what GPG said; gpg-interface is obviously a
better place. Move it there.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
36
commit.c
36
commit.c
@ -1220,42 +1220,6 @@ free_return:
|
|||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
|
||||||
char result;
|
|
||||||
const char *check;
|
|
||||||
} sigcheck_gpg_status[] = {
|
|
||||||
{ 'G', "\n[GNUPG:] GOODSIG " },
|
|
||||||
{ 'B', "\n[GNUPG:] BADSIG " },
|
|
||||||
{ 'U', "\n[GNUPG:] TRUST_NEVER" },
|
|
||||||
{ 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
|
|
||||||
};
|
|
||||||
|
|
||||||
static void parse_gpg_output(struct signature_check *sigc)
|
|
||||||
{
|
|
||||||
const char *buf = sigc->gpg_status;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Iterate over all search strings */
|
|
||||||
for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
|
|
||||||
const char *found, *next;
|
|
||||||
|
|
||||||
if (!skip_prefix(buf, sigcheck_gpg_status[i].check + 1, &found)) {
|
|
||||||
found = strstr(buf, sigcheck_gpg_status[i].check);
|
|
||||||
if (!found)
|
|
||||||
continue;
|
|
||||||
found += strlen(sigcheck_gpg_status[i].check);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
found += 17;
|
|
||||||
next = strchrnul(found, '\n');
|
|
||||||
sigc->signer = xmemdupz(found, next - found);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void check_commit_signature(const struct commit* commit, struct signature_check *sigc)
|
void check_commit_signature(const struct commit* commit, struct signature_check *sigc)
|
||||||
{
|
{
|
||||||
struct strbuf payload = STRBUF_INIT;
|
struct strbuf payload = STRBUF_INIT;
|
||||||
|
@ -21,6 +21,42 @@ void signature_check_clear(struct signature_check *sigc)
|
|||||||
sigc->key = NULL;
|
sigc->key = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
char result;
|
||||||
|
const char *check;
|
||||||
|
} sigcheck_gpg_status[] = {
|
||||||
|
{ 'G', "\n[GNUPG:] GOODSIG " },
|
||||||
|
{ 'B', "\n[GNUPG:] BADSIG " },
|
||||||
|
{ 'U', "\n[GNUPG:] TRUST_NEVER" },
|
||||||
|
{ 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
|
||||||
|
};
|
||||||
|
|
||||||
|
void parse_gpg_output(struct signature_check *sigc)
|
||||||
|
{
|
||||||
|
const char *buf = sigc->gpg_status;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Iterate over all search strings */
|
||||||
|
for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
|
||||||
|
const char *found, *next;
|
||||||
|
|
||||||
|
if (!skip_prefix(buf, sigcheck_gpg_status[i].check + 1, &found)) {
|
||||||
|
found = strstr(buf, sigcheck_gpg_status[i].check);
|
||||||
|
if (!found)
|
||||||
|
continue;
|
||||||
|
found += strlen(sigcheck_gpg_status[i].check);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
found += 17;
|
||||||
|
next = strchrnul(found, '\n');
|
||||||
|
sigc->signer = xmemdupz(found, next - found);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void set_signing_key(const char *key)
|
void set_signing_key(const char *key)
|
||||||
{
|
{
|
||||||
free(configured_signing_key);
|
free(configured_signing_key);
|
||||||
|
@ -5,16 +5,22 @@ struct signature_check {
|
|||||||
char *payload;
|
char *payload;
|
||||||
char *gpg_output;
|
char *gpg_output;
|
||||||
char *gpg_status;
|
char *gpg_status;
|
||||||
char result; /* 0 (not checked),
|
|
||||||
* N (checked but no further result),
|
/*
|
||||||
* U (untrusted good),
|
* possible "result":
|
||||||
|
* 0 (not checked)
|
||||||
|
* N (checked but no further result)
|
||||||
|
* U (untrusted good)
|
||||||
* G (good)
|
* G (good)
|
||||||
* B (bad) */
|
* B (bad)
|
||||||
|
*/
|
||||||
|
char result;
|
||||||
char *signer;
|
char *signer;
|
||||||
char *key;
|
char *key;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void signature_check_clear(struct signature_check *sigc);
|
extern void signature_check_clear(struct signature_check *sigc);
|
||||||
|
extern void parse_gpg_output(struct signature_check *);
|
||||||
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
|
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
|
||||||
extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);
|
extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);
|
||||||
extern int git_gpg_config(const char *, const char *, void *);
|
extern int git_gpg_config(const char *, const char *, void *);
|
||||||
|
Reference in New Issue
Block a user