Junio C Hamano | 2f47eae | 2011-09-07 21:19:47 -0700 | [diff] [blame] | 1 | #ifndef GPG_INTERFACE_H |
| 2 | #define GPG_INTERFACE_H |
| 3 | |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 4 | struct strbuf; |
| 5 | |
Lukas Puehringer | 94240b9 | 2017-01-17 18:37:18 -0500 | [diff] [blame] | 6 | #define GPG_VERIFY_VERBOSE 1 |
| 7 | #define GPG_VERIFY_RAW 2 |
| 8 | #define GPG_VERIFY_OMIT_STATUS 4 |
brian m. carlson | ca194d5 | 2015-06-21 23:14:41 +0000 | [diff] [blame] | 9 | |
Hans Jerry Illikainen | 54887b4 | 2019-12-27 13:55:57 +0000 | [diff] [blame] | 10 | enum signature_trust_level { |
| 11 | TRUST_UNDEFINED, |
| 12 | TRUST_NEVER, |
| 13 | TRUST_MARGINAL, |
| 14 | TRUST_FULLY, |
| 15 | TRUST_ULTIMATE, |
| 16 | }; |
| 17 | |
Fabian Stelzer | 6393c95 | 2021-12-09 09:52:45 +0100 | [diff] [blame] | 18 | enum payload_type { |
| 19 | SIGNATURE_PAYLOAD_UNDEFINED, |
| 20 | SIGNATURE_PAYLOAD_COMMIT, |
| 21 | SIGNATURE_PAYLOAD_TAG, |
| 22 | SIGNATURE_PAYLOAD_PUSH_CERT, |
| 23 | }; |
| 24 | |
Sebastian Götte | ffb6d7d | 2013-03-31 18:00:14 +0200 | [diff] [blame] | 25 | struct signature_check { |
Michael J Gruber | 71c214c | 2014-06-23 09:05:48 +0200 | [diff] [blame] | 26 | char *payload; |
Fabian Stelzer | 0276943 | 2021-12-09 09:52:43 +0100 | [diff] [blame] | 27 | size_t payload_len; |
Fabian Stelzer | 6393c95 | 2021-12-09 09:52:45 +0100 | [diff] [blame] | 28 | enum payload_type payload_type; |
| 29 | timestamp_t payload_timestamp; |
Fabian Stelzer | b5726a5 | 2021-09-10 20:07:34 +0000 | [diff] [blame] | 30 | char *output; |
Sebastian Götte | ffb6d7d | 2013-03-31 18:00:14 +0200 | [diff] [blame] | 31 | char *gpg_status; |
Junio C Hamano | a50e7ca | 2014-08-14 15:31:13 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * possible "result": |
| 35 | * 0 (not checked) |
| 36 | * N (checked but no further result) |
Junio C Hamano | a50e7ca | 2014-08-14 15:31:13 -0700 | [diff] [blame] | 37 | * G (good) |
| 38 | * B (bad) |
| 39 | */ |
| 40 | char result; |
Sebastian Götte | ffb6d7d | 2013-03-31 18:00:14 +0200 | [diff] [blame] | 41 | char *signer; |
| 42 | char *key; |
Michał Górny | 3daaaab | 2018-10-22 18:38:20 +0200 | [diff] [blame] | 43 | char *fingerprint; |
Michał Górny | 4de9394 | 2018-10-22 18:38:21 +0200 | [diff] [blame] | 44 | char *primary_key_fingerprint; |
Hans Jerry Illikainen | 54887b4 | 2019-12-27 13:55:57 +0000 | [diff] [blame] | 45 | enum signature_trust_level trust_level; |
Sebastian Götte | ffb6d7d | 2013-03-31 18:00:14 +0200 | [diff] [blame] | 46 | }; |
| 47 | |
Jeff King | f80bee2 | 2018-04-13 15:18:31 -0600 | [diff] [blame] | 48 | void signature_check_clear(struct signature_check *sigc); |
| 49 | |
| 50 | /* |
brian m. carlson | 482c119 | 2021-02-11 02:08:03 +0000 | [diff] [blame] | 51 | * Look at a GPG signed tag object. If such a signature exists, store it in |
| 52 | * signature and the signed content in payload. Return 1 if a signature was |
| 53 | * found, and 0 otherwise. |
| 54 | */ |
| 55 | int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct strbuf *signature); |
| 56 | |
| 57 | /* |
Jeff King | f80bee2 | 2018-04-13 15:18:31 -0600 | [diff] [blame] | 58 | * Look at GPG signed content (e.g. a signed tag object), whose |
| 59 | * payload is followed by a detached signature on it. Return the |
| 60 | * offset where the embedded detached signature begins, or the end of |
| 61 | * the data when there is no such signature. |
| 62 | */ |
brian m. carlson | 482c119 | 2021-02-11 02:08:03 +0000 | [diff] [blame] | 63 | size_t parse_signed_buffer(const char *buf, size_t size); |
Jeff King | f80bee2 | 2018-04-13 15:18:31 -0600 | [diff] [blame] | 64 | |
Jeff King | f80bee2 | 2018-04-13 15:18:31 -0600 | [diff] [blame] | 65 | /* |
| 66 | * Create a detached signature for the contents of "buffer" and append |
| 67 | * it after "signature"; "buffer" and "signature" can be the same |
| 68 | * strbuf instance, which would cause the detached signature appended |
| 69 | * at the end. |
| 70 | */ |
| 71 | int sign_buffer(struct strbuf *buffer, struct strbuf *signature, |
| 72 | const char *signing_key); |
| 73 | |
Jeff King | f80bee2 | 2018-04-13 15:18:31 -0600 | [diff] [blame] | 74 | int git_gpg_config(const char *, const char *, void *); |
| 75 | void set_signing_key(const char *); |
| 76 | const char *get_signing_key(void); |
Fabian Stelzer | 4838f62 | 2021-09-10 20:07:38 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Returns a textual unique representation of the signing key in use |
| 80 | * Either a GPG KeyID or a SSH Key Fingerprint |
| 81 | */ |
| 82 | const char *get_signing_key_id(void); |
Fabian Stelzer | 0276943 | 2021-12-09 09:52:43 +0100 | [diff] [blame] | 83 | int check_signature(struct signature_check *sigc, |
| 84 | const char *signature, size_t slen); |
Jeff King | f80bee2 | 2018-04-13 15:18:31 -0600 | [diff] [blame] | 85 | void print_signature_buffer(const struct signature_check *sigc, |
| 86 | unsigned flags); |
Junio C Hamano | 2f47eae | 2011-09-07 21:19:47 -0700 | [diff] [blame] | 87 | |
| 88 | #endif |