2011-09-08 04:19:47 +00:00
|
|
|
#ifndef GPG_INTERFACE_H
|
|
|
|
#define GPG_INTERFACE_H
|
|
|
|
|
2018-08-15 17:54:05 +00:00
|
|
|
struct strbuf;
|
|
|
|
|
2017-01-17 23:37:18 +00:00
|
|
|
#define GPG_VERIFY_VERBOSE 1
|
|
|
|
#define GPG_VERIFY_RAW 2
|
|
|
|
#define GPG_VERIFY_OMIT_STATUS 4
|
2015-06-21 23:14:41 +00:00
|
|
|
|
gpg-interface: add minTrustLevel as a configuration option
Previously, signature verification for merge and pull operations checked
if the key had a trust-level of either TRUST_NEVER or TRUST_UNDEFINED in
verify_merge_signature(). If that was the case, the process die()d.
The other code paths that did signature verification relied entirely on
the return code from check_commit_signature(). And signatures made with
a good key, irregardless of its trust level, was considered valid by
check_commit_signature().
This difference in behavior might induce users to erroneously assume
that the trust level of a key in their keyring is always considered by
Git, even for operations where it is not (e.g. during a verify-commit or
verify-tag).
The way it worked was by gpg-interface.c storing the result from the
key/signature status *and* the lowest-two trust levels in the `result`
member of the signature_check structure (the last of these status lines
that were encountered got written to `result`). These are documented in
GPG under the subsection `General status codes` and `Key related`,
respectively [1].
The GPG documentation says the following on the TRUST_ status codes [1]:
"""
These are several similar status codes:
- TRUST_UNDEFINED <error_token>
- TRUST_NEVER <error_token>
- TRUST_MARGINAL [0 [<validation_model>]]
- TRUST_FULLY [0 [<validation_model>]]
- TRUST_ULTIMATE [0 [<validation_model>]]
For good signatures one of these status lines are emitted to
indicate the validity of the key used to create the signature.
The error token values are currently only emitted by gpgsm.
"""
My interpretation is that the trust level is conceptionally different
from the validity of the key and/or signature. That seems to also have
been the assumption of the old code in check_signature() where a result
of 'G' (as in GOODSIG) and 'U' (as in TRUST_NEVER or TRUST_UNDEFINED)
were both considered a success.
The two cases where a result of 'U' had special meaning were in
verify_merge_signature() (where this caused git to die()) and in
format_commit_one() (where it affected the output of the %G? format
specifier).
I think it makes sense to refactor the processing of TRUST_ status lines
such that users can configure a minimum trust level that is enforced
globally, rather than have individual parts of git (e.g. merge) do it
themselves (except for a grace period with backward compatibility).
I also think it makes sense to not store the trust level in the same
struct member as the key/signature status. While the presence of a
TRUST_ status code does imply that the signature is good (see the first
paragraph in the included snippet above), as far as I can tell, the
order of the status lines from GPG isn't well-defined; thus it would
seem plausible that the trust level could be overwritten with the
key/signature status if they were stored in the same member of the
signature_check structure.
This patch introduces a new configuration option: gpg.minTrustLevel. It
consolidates trust-level verification to gpg-interface.c and adds a new
`trust_level` member to the signature_check structure.
Backward-compatibility is maintained by introducing a special case in
verify_merge_signature() such that if no user-configurable
gpg.minTrustLevel is set, then the old behavior of rejecting
TRUST_UNDEFINED and TRUST_NEVER is enforced. If, on the other hand,
gpg.minTrustLevel is set, then that value overrides the old behavior.
Similarly, the %G? format specifier will continue show 'U' for
signatures made with a key that has a trust level of TRUST_UNDEFINED or
TRUST_NEVER, even though the 'U' character no longer exist in the
`result` member of the signature_check structure. A new format
specifier, %GT, is also introduced for users that want to show all
possible trust levels for a signature.
Another approach would have been to simply drop the trust-level
requirement in verify_merge_signature(). This would also have made the
behavior consistent with other parts of git that perform signature
verification. However, requiring a minimum trust level for signing keys
does seem to have a real-world use-case. For example, the build system
used by the Qubes OS project currently parses the raw output from
verify-tag in order to assert a minimum trust level for keys used to
sign git tags [2].
[1] https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=doc/doc/DETAILS;h=bd00006e933ac56719b1edd2478ecd79273eae72;hb=refs/heads/master
[2] https://github.com/QubesOS/qubes-builder/blob/9674c1991deef45b1a1b1c71fddfab14ba50dccf/scripts/verify-git-tag#L43
Signed-off-by: Hans Jerry Illikainen <hji@dyntopia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-12-27 13:55:57 +00:00
|
|
|
enum signature_trust_level {
|
|
|
|
TRUST_UNDEFINED,
|
|
|
|
TRUST_NEVER,
|
|
|
|
TRUST_MARGINAL,
|
|
|
|
TRUST_FULLY,
|
|
|
|
TRUST_ULTIMATE,
|
|
|
|
};
|
|
|
|
|
2021-12-09 08:52:45 +00:00
|
|
|
enum payload_type {
|
|
|
|
SIGNATURE_PAYLOAD_UNDEFINED,
|
|
|
|
SIGNATURE_PAYLOAD_COMMIT,
|
|
|
|
SIGNATURE_PAYLOAD_TAG,
|
|
|
|
SIGNATURE_PAYLOAD_PUSH_CERT,
|
|
|
|
};
|
|
|
|
|
2013-03-31 16:00:14 +00:00
|
|
|
struct signature_check {
|
2014-06-23 07:05:48 +00:00
|
|
|
char *payload;
|
2021-12-09 08:52:43 +00:00
|
|
|
size_t payload_len;
|
2021-12-09 08:52:45 +00:00
|
|
|
enum payload_type payload_type;
|
|
|
|
timestamp_t payload_timestamp;
|
2021-09-10 20:07:34 +00:00
|
|
|
char *output;
|
2013-03-31 16:00:14 +00:00
|
|
|
char *gpg_status;
|
2014-08-14 22:31:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* possible "result":
|
|
|
|
* 0 (not checked)
|
|
|
|
* N (checked but no further result)
|
|
|
|
* G (good)
|
|
|
|
* B (bad)
|
|
|
|
*/
|
|
|
|
char result;
|
2013-03-31 16:00:14 +00:00
|
|
|
char *signer;
|
|
|
|
char *key;
|
2018-10-22 16:38:20 +00:00
|
|
|
char *fingerprint;
|
2018-10-22 16:38:21 +00:00
|
|
|
char *primary_key_fingerprint;
|
gpg-interface: add minTrustLevel as a configuration option
Previously, signature verification for merge and pull operations checked
if the key had a trust-level of either TRUST_NEVER or TRUST_UNDEFINED in
verify_merge_signature(). If that was the case, the process die()d.
The other code paths that did signature verification relied entirely on
the return code from check_commit_signature(). And signatures made with
a good key, irregardless of its trust level, was considered valid by
check_commit_signature().
This difference in behavior might induce users to erroneously assume
that the trust level of a key in their keyring is always considered by
Git, even for operations where it is not (e.g. during a verify-commit or
verify-tag).
The way it worked was by gpg-interface.c storing the result from the
key/signature status *and* the lowest-two trust levels in the `result`
member of the signature_check structure (the last of these status lines
that were encountered got written to `result`). These are documented in
GPG under the subsection `General status codes` and `Key related`,
respectively [1].
The GPG documentation says the following on the TRUST_ status codes [1]:
"""
These are several similar status codes:
- TRUST_UNDEFINED <error_token>
- TRUST_NEVER <error_token>
- TRUST_MARGINAL [0 [<validation_model>]]
- TRUST_FULLY [0 [<validation_model>]]
- TRUST_ULTIMATE [0 [<validation_model>]]
For good signatures one of these status lines are emitted to
indicate the validity of the key used to create the signature.
The error token values are currently only emitted by gpgsm.
"""
My interpretation is that the trust level is conceptionally different
from the validity of the key and/or signature. That seems to also have
been the assumption of the old code in check_signature() where a result
of 'G' (as in GOODSIG) and 'U' (as in TRUST_NEVER or TRUST_UNDEFINED)
were both considered a success.
The two cases where a result of 'U' had special meaning were in
verify_merge_signature() (where this caused git to die()) and in
format_commit_one() (where it affected the output of the %G? format
specifier).
I think it makes sense to refactor the processing of TRUST_ status lines
such that users can configure a minimum trust level that is enforced
globally, rather than have individual parts of git (e.g. merge) do it
themselves (except for a grace period with backward compatibility).
I also think it makes sense to not store the trust level in the same
struct member as the key/signature status. While the presence of a
TRUST_ status code does imply that the signature is good (see the first
paragraph in the included snippet above), as far as I can tell, the
order of the status lines from GPG isn't well-defined; thus it would
seem plausible that the trust level could be overwritten with the
key/signature status if they were stored in the same member of the
signature_check structure.
This patch introduces a new configuration option: gpg.minTrustLevel. It
consolidates trust-level verification to gpg-interface.c and adds a new
`trust_level` member to the signature_check structure.
Backward-compatibility is maintained by introducing a special case in
verify_merge_signature() such that if no user-configurable
gpg.minTrustLevel is set, then the old behavior of rejecting
TRUST_UNDEFINED and TRUST_NEVER is enforced. If, on the other hand,
gpg.minTrustLevel is set, then that value overrides the old behavior.
Similarly, the %G? format specifier will continue show 'U' for
signatures made with a key that has a trust level of TRUST_UNDEFINED or
TRUST_NEVER, even though the 'U' character no longer exist in the
`result` member of the signature_check structure. A new format
specifier, %GT, is also introduced for users that want to show all
possible trust levels for a signature.
Another approach would have been to simply drop the trust-level
requirement in verify_merge_signature(). This would also have made the
behavior consistent with other parts of git that perform signature
verification. However, requiring a minimum trust level for signing keys
does seem to have a real-world use-case. For example, the build system
used by the Qubes OS project currently parses the raw output from
verify-tag in order to assert a minimum trust level for keys used to
sign git tags [2].
[1] https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=doc/doc/DETAILS;h=bd00006e933ac56719b1edd2478ecd79273eae72;hb=refs/heads/master
[2] https://github.com/QubesOS/qubes-builder/blob/9674c1991deef45b1a1b1c71fddfab14ba50dccf/scripts/verify-git-tag#L43
Signed-off-by: Hans Jerry Illikainen <hji@dyntopia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-12-27 13:55:57 +00:00
|
|
|
enum signature_trust_level trust_level;
|
2013-03-31 16:00:14 +00:00
|
|
|
};
|
|
|
|
|
2018-04-13 21:18:31 +00:00
|
|
|
void signature_check_clear(struct signature_check *sigc);
|
|
|
|
|
2021-02-11 02:08:03 +00:00
|
|
|
/*
|
|
|
|
* Look at a GPG signed tag object. If such a signature exists, store it in
|
|
|
|
* signature and the signed content in payload. Return 1 if a signature was
|
|
|
|
* found, and 0 otherwise.
|
|
|
|
*/
|
|
|
|
int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct strbuf *signature);
|
|
|
|
|
2018-04-13 21:18:31 +00:00
|
|
|
/*
|
|
|
|
* Look at GPG signed content (e.g. a signed tag object), whose
|
|
|
|
* payload is followed by a detached signature on it. Return the
|
|
|
|
* offset where the embedded detached signature begins, or the end of
|
|
|
|
* the data when there is no such signature.
|
|
|
|
*/
|
2021-02-11 02:08:03 +00:00
|
|
|
size_t parse_signed_buffer(const char *buf, size_t size);
|
2018-04-13 21:18:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a detached signature for the contents of "buffer" and append
|
|
|
|
* it after "signature"; "buffer" and "signature" can be the same
|
|
|
|
* strbuf instance, which would cause the detached signature appended
|
2024-02-07 18:46:54 +00:00
|
|
|
* at the end. Returns 0 on success, non-zero on failure.
|
2018-04-13 21:18:31 +00:00
|
|
|
*/
|
|
|
|
int sign_buffer(struct strbuf *buffer, struct strbuf *signature,
|
|
|
|
const char *signing_key);
|
|
|
|
|
2022-07-11 05:00:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns corresponding string in lowercase for a given member of
|
|
|
|
* enum signature_trust_level. For example, `TRUST_ULTIMATE` will
|
|
|
|
* return "ultimate".
|
|
|
|
*/
|
|
|
|
const char *gpg_trust_level_to_str(enum signature_trust_level level);
|
|
|
|
|
2018-04-13 21:18:31 +00:00
|
|
|
void set_signing_key(const char *);
|
|
|
|
const char *get_signing_key(void);
|
2021-09-10 20:07:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a textual unique representation of the signing key in use
|
|
|
|
* Either a GPG KeyID or a SSH Key Fingerprint
|
|
|
|
*/
|
|
|
|
const char *get_signing_key_id(void);
|
2021-12-09 08:52:43 +00:00
|
|
|
int check_signature(struct signature_check *sigc,
|
|
|
|
const char *signature, size_t slen);
|
2018-04-13 21:18:31 +00:00
|
|
|
void print_signature_buffer(const struct signature_check *sigc,
|
|
|
|
unsigned flags);
|
2011-09-08 04:19:47 +00:00
|
|
|
|
|
|
|
#endif
|