ssh signing: verify key lifetime
v2 cover ssh signing: verify key lifetime
This series adds key lifetime validity checks by parsing commit/tag dates from the paylod and passing them to the ssh-keygen operations.
changes since v1:
- struct signature_check is now used to input payload data into check_function
- payload metadata parsing is completely internal to check_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removed payload_signer parameter. since we now use the struct we can extend this later.
Since the last 3 patches now only contain a minimal code change and the tests for the seperate callers we could merge them together. I don't mind either way.
Fabian Stelzer (6):
ssh signing: use sigc struct to pass payload ssh signing: add key lifetime test prereqs ssh signing: make verify-commit consider key lifetime ssh signing: make git log verify key lifetime ssh signing: make verify-tag consider key lifetime ssh signing: make fmt-merge-msg consider key lifetime
Documentation/config/gpg.txt | 5 ++ builtin/receive-pack.c | 6 ++- commit.c | 6 ++- fmt-merge-msg.c | 5 +- gpg-interface.c | 87 ++++++++++++++++++++++++-------- gpg-interface.h | 15 ++++-- log-tree.c | 10 ++-- t/lib-gpg.sh | 19 ++++++- t/t4202-log.sh | 43 ++++++++++++++++ t/t6200-fmt-merge-msg.sh | 54 ++++++++++++++++++++ t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++ t/t7528-signed-commit-ssh.sh | 42 +++++++++++++++ tag.c | 5 +- 13 files changed, 303 insertions(+), 36 deletions(-)
base-commit: e9e5ba39a78c8f5057262d49e261b42a8660d5b9
Signature · 1 line
2.31.1
PATCH v2 1/6 ssh signing: use sigc struct to pass payload
To be able to extend the payload metadata with things like its creation timestamp or the creators ident we remove the payload parameters to check_signature() and use the already existing sigc->payload field instead, only adding the length field to the struct. This also allows us to get rid of the xmemdupz() calls in the verify functions. Since sigc is now used to input data as well as output the result move it to the front of the function list.
- Add payload_length to struct signature_check
- Populate sigc.payload/payload_len on all call sites
- Remove payload parameters to check_signature()
- Remove payload parameters to internal verify_* functions and use sigc instead
- Remove xmemdupz() used for verbose output since payload is now already populated.
--- builtin/receive-pack.c | 6 ++++-- commit.c | 5 +++-- fmt-merge-msg.c | 4 ++-- gpg-interface.c | 37 +++++++++++++++++-------------------- gpg-interface.h | 6 +++--- log-tree.c | 8 ++++---- tag.c | 4 ++-- 7 files changed, 35 insertions(+), 35 deletions(-)
builtin/receive-pack.c +4 -2
@@ -769,8 +769,10 @@ static void prepare_push_cert_sha1(struct child_process *proc)memset (&sigcheck,'\0' ,sizeof (sigcheck)); bogs =parse_signed_buffer (push_cert.buf, push_cert.len); -check_signature (push_cert.buf, bogs, push_cert.buf + bogs, - push_cert.len - bogs, &sigcheck); + sigcheck.payload =xmemdupz (push_cert.buf, bogs); + sigcheck.payload_len = bogs; +check_signature (&sigcheck, push_cert.buf + bogs, + push_cert.len - bogs); nonce_status =check_nonce (push_cert.buf, bogs); }
commit.c +3 -2
@@ -1212,8 +1212,9 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, sigc); + + sigc->payload =strbuf_detach (&payload, &sigc->payload_len); + ret =check_signature (sigc, signature.buf, signature.len); out:strbuf_release (&payload);
fmt-merge-msg.c +2 -2
@@ -533,8 +533,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; -if (check_signature (payload.buf, payload.len, sig.buf, - sig.len, &sigc) && + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); +if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)strbuf_addstr (&sig,"gpg verification failed.\n" );else
gpg-interface.c +17 -20
@@ -19,8 +19,8 @@ struct gpg_format {const char **verify_args;const char **sigs;int (*verify_signed_buffer)(struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);int (*sign_buffer)(struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -53,12 +53,12 @@ static const char *ssh_sigs[] = { };static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int sign_buffer_gpg (struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -314,8 +314,8 @@ static void parse_gpg_output(struct signature_check *sigc) }static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process gpg =CHILD_PROCESS_INIT ;
@@ -343,14 +343,13 @@ static int verify_gpg_signed_buffer(struct signature_check *sigc, NULL);sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&gpg, payload, payload_size, &gpg_stdout,0 , + ret =pipe_command (&gpg, sigc->payload, sigc->payload_len, &gpg_stdout,0 , &gpg_stderr,0 );sigchain_pop (SIGPIPE );delete_tempfile (&temp); ret |= !strstr (gpg_stdout.buf,"\n[GNUPG:] GOODSIG " ); - sigc->payload =xmemdupz (payload, payload_size); sigc->output =strbuf_detach (&gpg_stderr,NULL ); sigc->gpg_status =strbuf_detach (&gpg_stdout,NULL );
@@ -424,8 +423,8 @@ static void parse_ssh_output(struct signature_check *sigc) }static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process ssh_keygen =CHILD_PROCESS_INIT ;
@@ -478,7 +477,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,"-n" ,"git" ,"-s" , buffer_file->filename.buf, NULL); -pipe_command (&ssh_keygen, payload, payload_size, +pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );/*
@@ -524,7 +523,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, }sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&ssh_keygen, payload, payload_size, + ret =pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );sigchain_pop (SIGPIPE );
@@ -538,7 +537,6 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, } } - sigc->payload =xmemdupz (payload, payload_size);strbuf_stripspace (&ssh_keygen_out,0 );strbuf_stripspace (&ssh_keygen_err,0 );/* Add stderr outputs to show the user actual ssh-keygen errors */
@@ -560,8 +558,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,return ret; } -int check_signature (const char *payload,size_t plen,const char *signature, -size_t slen,struct signature_check *sigc) +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen) {struct gpg_format *fmt;int status;
@@ -573,8 +571,7 @@ int check_signature(const char *payload, size_t plen, const char *signature,if (!fmt)die (_ ("bad/incompatible signature '%s'" ), signature); - status = fmt->verify_signed_buffer (sigc, fmt, payload, plen, signature, - slen); + status = fmt->verify_signed_buffer (sigc, fmt, signature, slen);if (status && !sigc->output)return !!status;
@@ -591,7 +588,7 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags) sigc->output;if (flags &GPG_VERIFY_VERBOSE && sigc->payload) -fputs (sigc->payload, stdout); +fwrite (sigc->payload,1 , sigc->payload_len, stdout);if (output)fputs (output, stderr);
gpg-interface.h +3 -3
@@ -17,6 +17,7 @@ enum signature_trust_level {struct signature_check {char *payload; +size_t payload_len;char *output;char *gpg_status;
@@ -70,9 +71,8 @@ const char *get_signing_key(void);* Either a GPG KeyID or a SSH Key Fingerprint */ const char *get_signing_key_id (void ); -int check_signature (const char *payload,size_t plen, -const char *signature,size_t slen, -struct signature_check *sigc); +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen);void print_signature_buffer (const struct signature_check *sigc,unsigned flags);
log-tree.c +4 -4
@@ -513,8 +513,8 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - status =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)show_sig_lines (opt, status,"No signature\n" );else
@@ -583,8 +583,8 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ - status =check_signature (payload.buf, payload.len, - signature.buf, signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)strbuf_addstr (&verify_message, sigc.output);else
tag.c +2 -2
@@ -25,8 +25,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + ret =check_signature (&sigc, signature.buf, signature.len);if (!(flags &GPG_VERIFY_OMIT_STATUS ))print_signature_buffer (&sigc, flags);
Signature · 1 line
2.31.1
PATCH v2 2/6 ssh signing: add key lifetime test prereqs
In reply to Fabian Stelzerif ssh-keygen supports -Overify-time, add test keys marked as expired, not yet valid and valid both within the test_tick timeframe and outside of it.
--- t/lib-gpg.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
t/lib-gpg.sh +18 -1
@@ -90,6 +90,10 @@ test_lazy_prereq RFC1991 ' GPGSSH_KEY_PRIMARY="${GNUPGHOME}/ed25519_ssh_signing_key" GPGSSH_KEY_SECONDARY="${GNUPGHOME}/rsa_2048_ssh_signing_key" GPGSSH_KEY_UNTRUSTED="${GNUPGHOME}/untrusted_ssh_signing_key" +GPGSSH_KEY_EXPIRED="${GNUPGHOME}/expired_ssh_signing_key" +GPGSSH_KEY_NOTYETVALID="${GNUPGHOME}/notyetvalid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDVALID="${GNUPGHOME}/timeboxed_valid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDINVALID="${GNUPGHOME}/timeboxed_invalid_ssh_signing_key" GPGSSH_KEY_WITH_PASSPHRASE="${GNUPGHOME}/protected_ssh_signing_key" GPGSSH_KEY_PASSPHRASE="super_secret" GPGSSH_ALLOWED_SIGNERS="${GNUPGHOME}/ssh.all_valid.allowedSignersFile"
@@ -112,7 +116,20 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null +' + +test_lazy_prereq GPGSSH_VERIFYTIME ' + # Check if ssh-keygen has a verify-time option by passing an invalid date to it + ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && + echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && + echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && + echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && + echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v2 3/6 ssh signing: make verify-commit consider key lifetime
In reply to Fabian StelzerIf valid-before/after dates are configured for this signatures key in the allowedSigners file then the verification should check if the key was valid at the time the commit was made. This allows for graceful key rollover and revoking keys without invalidating all previous commits.
This feature needs openssh > 8.8. Older ssh-keygen versions will simply ignore this flag and use the current time.
Strictly speaking this feature is available in 8.7, but since 8.7 has a bug that makes it unusable in another needed call we require 8.8.
Timestamp information is present on most invocations of check_signature. However signer ident is not. We will need the signer email / name to be able to implement "Trust on first use" functionality later.
Since the payload contains all necessary information we can parse it from there. The caller only needs to provide us some info about the payload by setting payload_type in the signature_check struct.
- Add payload_type field & enum and payload_timestamp to struct signature_check
- Populate the timestamp when not already set if we know about the payload type
- Pass -Overify-time={payload_timestamp} in the users timezone to all ssh-keygen verification calls
- Set the payload type when verifying commits
- Add tests for expired, not yet valid and keys having a commit date outside of key validity as well as within
--- Documentation/config/gpg.txt | 5 ++++ commit.c | 1 + gpg-interface.c | 50 ++++++++++++++++++++++++++++++++++++ gpg-interface.h | 9 +++++++ t/t7528-signed-commit-ssh.sh | 42 ++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+)
Documentation/config/gpg.txt +5 -0
@@ -64,6 +64,11 @@ A repository that only allows signed commits can store the file in the repository itself using a path relative to the top-level of the working tree. This way only committers with an already valid key can add or change keys in the keyring. + +Since OpensSSH 8.8 this file allows specifying a key lifetime using valid-after & +valid-before options. Git will mark signatures as valid if the signing key was +valid at the time of the signatures creation. This allows users to change a +signing key without invalidating all previously made signatures. ++ Using a SSH CA key with the cert-authority option (see ssh-keygen(1) "CERTIFICATES") is also valid.
commit.c +1 -0
@@ -1213,6 +1213,7 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc->payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc->payload =strbuf_detach (&payload, &sigc->payload_len); ret =check_signature (sigc, signature.buf, signature.len);
gpg-interface.c +50 -0
95 lines not on this page · raw message
gpg-interface.h +9 -0
@@ -15,9 +15,18 @@ enum signature_trust_level { TRUST_ULTIMATE, }; +enum payload_type { +SIGNATURE_PAYLOAD_UNDEFINED , +SIGNATURE_PAYLOAD_COMMIT , +SIGNATURE_PAYLOAD_TAG , +SIGNATURE_PAYLOAD_PUSH_CERT , +}; +struct signature_check {char *payload;size_t payload_len; +enum payload_type payload_type; +timestamp_t payload_timestamp;char *output;char *gpg_status;
t/t7528-signed-commit-ssh.sh +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v2 3/6] ssh signing: make verify-commit consider key lifetime
Quoted 8 lines · Fabian Stelzer
gpg-interface.c +8
-0+static int parse_payload_metadata (struct signature_check *sigc) +{ +const char *ident_line =NULL ; +size_t ident_len; +struct ident_split ident; +const char *signer_header; + +switch (sigc->payload_type) {
gpg-interface.c static int verify_ssh_signed_buffer(struct signature_check *sigc, · line 593
Quoted 10 lines
gpg-interface.c +10
-0+case SIGNATURE_PAYLOAD_COMMIT : + signer_header ="committer" ; +break ; +case SIGNATURE_PAYLOAD_TAG : + signer_header ="tagger" ; +break ; +default : +/* Ignore unknown payload types */ +return 0 ; + }
The case arms should be indented to the same level as opening switch(). Have SP between keyword "switch" and the expression the statement switches on.
More importantly, can you explain why it is necessary to allow callers to call this function with a random value in payload_type and have it silently succeed? Isn't it a programming error that deserves a call to BUG("...")?
Thanks.
Re: [PATCH v2 3/6] ssh signing: make verify-commit consider key lifetime
Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Fabian Stelzer
gpg-interface.c +14
-0+static int parse_payload_metadata (struct signature_check *sigc) +{ +const char *ident_line =NULL ; +size_t ident_len; +struct ident_split ident; +const char *signer_header; + +switch (sigc->payload_type) { +case SIGNATURE_PAYLOAD_COMMIT : + signer_header ="committer" ; +break ; +case SIGNATURE_PAYLOAD_TAG : + signer_header ="tagger" ; +break ;
Quoted 9 lines
gpg-interface.c static int verify_ssh_signed_buffer(struct signature_check *sigc, · line 593
Quoted 4 lines
gpg-interface.c +4
-0+default : +/* Ignore unknown payload types */ +return 0 ; + }The case arms should be indented to the same level as opening
switch(). Have SP between keyword "switch" and the expression the statement switches on.
Thanks, will fix.
Quoted 7 lines
More importantly, can you explain why it is necessary to allow callers to call this function with a random value in
payload_typeand have it silently succeed? Isn't it a programming error that deserves a call toBUG("...")?Thanks.
Not really. I will add a BUG() to the default case and only ignore the known cases that we don't want to handle.
Thanks
v3 cover ssh signing: verify key lifetime
In reply to Junio C Hamanochanges since v2:
- fix swich/case indentation
- BUG() on unknown payload types
- improve test prereq by actually validating ssh-keygen functionality
changes since v1:
- struct signature_check is now used to input payload data into check_function
- payload metadata parsing is completely internal to check_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removed payload_signer parameter. since we now use the struct we can extend this later.
Fabian Stelzer (7):
ssh signing: use sigc struct to pass payload ssh signing: add key lifetime test prereqs ssh signing: make verify-commit consider key lifetime ssh signing: make git log verify key lifetime ssh signing: make verify-tag consider key lifetime ssh signing: make fmt-merge-msg consider key lifetime ssh signing: verify ssh-keygen in test prereq
Documentation/config/gpg.txt | 5 ++ builtin/receive-pack.c | 6 ++- commit.c | 6 ++- fmt-merge-msg.c | 5 +- gpg-interface.c | 90 +++++++++++++++++++++++++------- gpg-interface.h | 15 ++++-- log-tree.c | 10 ++-- t/lib-gpg.sh | 36 ++++++++++--- t/t4202-log.sh | 43 +++++++++++++++ t/t6200-fmt-merge-msg.sh | 54 +++++++++++++++++++ t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++ t/t7528-signed-commit-ssh.sh | 42 +++++++++++++++ tag.c | 5 +- 13 files changed, 318 insertions(+), 41 deletions(-)
Range-diff against v2:
1: 11d275b53f = 1: 9f71fd8639 ssh signing: use sigc struct to pass payload
2: 35ee285887 = 2: 5ee143bc38 ssh signing: add key lifetime test prereqs
3: ccfba23934 ! 3: 3183e84e2e ssh signing: make verify-commit consider key lifetime
@@ gpg-interface.c: static int verify_ssh_signed_buffer(struct signature_check *sig
+ struct ident_split ident;
+ const char *signer_header;
+
-+ switch(sigc->payload_type) {
-+ case SIGNATURE_PAYLOAD_COMMIT:
-+ signer_header = "committer";
-+ break;
-+ case SIGNATURE_PAYLOAD_TAG:
-+ signer_header = "tagger";
-+ break;
-+ default:
-+ /* Ignore unknown payload types */
-+ return 0;
++ switch (sigc->payload_type) {
++ case SIGNATURE_PAYLOAD_COMMIT:
++ signer_header = "committer";
++ break;
++ case SIGNATURE_PAYLOAD_TAG:
++ signer_header = "tagger";
++ break;
++ case SIGNATURE_PAYLOAD_UNDEFINED:
++ case SIGNATURE_PAYLOAD_PUSH_CERT:
++ /* Ignore payloads we don't want to parse */
++ return 0;
++ default:
++ BUG("invalid value for sigc->payload_type");
+ }
+
+ ident_line = find_commit_header(sigc->payload, signer_header, &ident_len);
4: ef8178f88b = 4: e35515867c ssh signing: make git log verify key lifetime
5: c12457020e = 5: e20177d950 ssh signing: make verify-tag consider key lifetime
6: fe17c60276 = 6: 2af2b6d098 ssh signing: make fmt-merge-msg consider key lifetime
-: ---------- > 7: e6e2236a52 ssh signing: verify ssh-keygen in test prereqbase-commit: cd3e606211bb1cf8bc57f7d76bab98cc17a150bc
Signature · 1 line
2.31.1
PATCH v3 1/7 ssh signing: use sigc struct to pass payload
To be able to extend the payload metadata with things like its creation timestamp or the creators ident we remove the payload parameters to check_signature() and use the already existing sigc->payload field instead, only adding the length field to the struct. This also allows us to get rid of the xmemdupz() calls in the verify functions. Since sigc is now used to input data as well as output the result move it to the front of the function list.
- Add payload_length to struct signature_check
- Populate sigc.payload/payload_len on all call sites
- Remove payload parameters to check_signature()
- Remove payload parameters to internal verify_* functions and use sigc instead
- Remove xmemdupz() used for verbose output since payload is now already populated.
--- builtin/receive-pack.c | 6 ++++-- commit.c | 5 +++-- fmt-merge-msg.c | 4 ++-- gpg-interface.c | 37 +++++++++++++++++-------------------- gpg-interface.h | 6 +++--- log-tree.c | 8 ++++---- tag.c | 4 ++-- 7 files changed, 35 insertions(+), 35 deletions(-)
builtin/receive-pack.c +4 -2
@@ -769,8 +769,10 @@ static void prepare_push_cert_sha1(struct child_process *proc)memset (&sigcheck,'\0' ,sizeof (sigcheck)); bogs =parse_signed_buffer (push_cert.buf, push_cert.len); -check_signature (push_cert.buf, bogs, push_cert.buf + bogs, - push_cert.len - bogs, &sigcheck); + sigcheck.payload =xmemdupz (push_cert.buf, bogs); + sigcheck.payload_len = bogs; +check_signature (&sigcheck, push_cert.buf + bogs, + push_cert.len - bogs); nonce_status =check_nonce (push_cert.buf, bogs); }
commit.c +3 -2
@@ -1212,8 +1212,9 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, sigc); + + sigc->payload =strbuf_detach (&payload, &sigc->payload_len); + ret =check_signature (sigc, signature.buf, signature.len); out:strbuf_release (&payload);
fmt-merge-msg.c +2 -2
@@ -533,8 +533,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; -if (check_signature (payload.buf, payload.len, sig.buf, - sig.len, &sigc) && + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); +if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)strbuf_addstr (&sig,"gpg verification failed.\n" );else
gpg-interface.c +17 -20
@@ -19,8 +19,8 @@ struct gpg_format {const char **verify_args;const char **sigs;int (*verify_signed_buffer)(struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);int (*sign_buffer)(struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -53,12 +53,12 @@ static const char *ssh_sigs[] = { };static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int sign_buffer_gpg (struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -314,8 +314,8 @@ static void parse_gpg_output(struct signature_check *sigc) }static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process gpg =CHILD_PROCESS_INIT ;
@@ -343,14 +343,13 @@ static int verify_gpg_signed_buffer(struct signature_check *sigc, NULL);sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&gpg, payload, payload_size, &gpg_stdout,0 , + ret =pipe_command (&gpg, sigc->payload, sigc->payload_len, &gpg_stdout,0 , &gpg_stderr,0 );sigchain_pop (SIGPIPE );delete_tempfile (&temp); ret |= !strstr (gpg_stdout.buf,"\n[GNUPG:] GOODSIG " ); - sigc->payload =xmemdupz (payload, payload_size); sigc->output =strbuf_detach (&gpg_stderr,NULL ); sigc->gpg_status =strbuf_detach (&gpg_stdout,NULL );
@@ -426,8 +425,8 @@ static void parse_ssh_output(struct signature_check *sigc) }static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process ssh_keygen =CHILD_PROCESS_INIT ;
@@ -480,7 +479,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,"-n" ,"git" ,"-s" , buffer_file->filename.buf, NULL); -pipe_command (&ssh_keygen, payload, payload_size, +pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );/*
@@ -526,7 +525,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, }sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&ssh_keygen, payload, payload_size, + ret =pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );sigchain_pop (SIGPIPE );
@@ -540,7 +539,6 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, } } - sigc->payload =xmemdupz (payload, payload_size);strbuf_stripspace (&ssh_keygen_out,0 );strbuf_stripspace (&ssh_keygen_err,0 );/* Add stderr outputs to show the user actual ssh-keygen errors */
@@ -562,8 +560,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,return ret; } -int check_signature (const char *payload,size_t plen,const char *signature, -size_t slen,struct signature_check *sigc) +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen) {struct gpg_format *fmt;int status;
@@ -575,8 +573,7 @@ int check_signature(const char *payload, size_t plen, const char *signature,if (!fmt)die (_ ("bad/incompatible signature '%s'" ), signature); - status = fmt->verify_signed_buffer (sigc, fmt, payload, plen, signature, - slen); + status = fmt->verify_signed_buffer (sigc, fmt, signature, slen);if (status && !sigc->output)return !!status;
@@ -593,7 +590,7 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags) sigc->output;if (flags &GPG_VERIFY_VERBOSE && sigc->payload) -fputs (sigc->payload, stdout); +fwrite (sigc->payload,1 , sigc->payload_len, stdout);if (output)fputs (output, stderr);
gpg-interface.h +3 -3
@@ -17,6 +17,7 @@ enum signature_trust_level {struct signature_check {char *payload; +size_t payload_len;char *output;char *gpg_status;
@@ -70,9 +71,8 @@ const char *get_signing_key(void);* Either a GPG KeyID or a SSH Key Fingerprint */ const char *get_signing_key_id (void ); -int check_signature (const char *payload,size_t plen, -const char *signature,size_t slen, -struct signature_check *sigc); +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen);void print_signature_buffer (const struct signature_check *sigc,unsigned flags);
log-tree.c +4 -4
@@ -513,8 +513,8 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - status =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)show_sig_lines (opt, status,"No signature\n" );else
@@ -583,8 +583,8 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ - status =check_signature (payload.buf, payload.len, - signature.buf, signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)strbuf_addstr (&verify_message, sigc.output);else
tag.c +2 -2
@@ -25,8 +25,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + ret =check_signature (&sigc, signature.buf, signature.len);if (!(flags &GPG_VERIFY_OMIT_STATUS ))print_signature_buffer (&sigc, flags);
Signature · 1 line
2.31.1
PATCH v3 2/7 ssh signing: add key lifetime test prereqs
In reply to Fabian Stelzerif ssh-keygen supports -Overify-time, add test keys marked as expired, not yet valid and valid both within the test_tick timeframe and outside of it.
--- t/lib-gpg.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
t/lib-gpg.sh +18 -1
@@ -90,6 +90,10 @@ test_lazy_prereq RFC1991 ' GPGSSH_KEY_PRIMARY="${GNUPGHOME}/ed25519_ssh_signing_key" GPGSSH_KEY_SECONDARY="${GNUPGHOME}/rsa_2048_ssh_signing_key" GPGSSH_KEY_UNTRUSTED="${GNUPGHOME}/untrusted_ssh_signing_key" +GPGSSH_KEY_EXPIRED="${GNUPGHOME}/expired_ssh_signing_key" +GPGSSH_KEY_NOTYETVALID="${GNUPGHOME}/notyetvalid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDVALID="${GNUPGHOME}/timeboxed_valid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDINVALID="${GNUPGHOME}/timeboxed_invalid_ssh_signing_key" GPGSSH_KEY_WITH_PASSPHRASE="${GNUPGHOME}/protected_ssh_signing_key" GPGSSH_KEY_PASSPHRASE="super_secret" GPGSSH_ALLOWED_SIGNERS="${GNUPGHOME}/ssh.all_valid.allowedSignersFile"
@@ -119,7 +123,20 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null +' + +test_lazy_prereq GPGSSH_VERIFYTIME ' + # Check if ssh-keygen has a verify-time option by passing an invalid date to it + ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && + echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && + echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && + echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && + echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v3 3/7 ssh signing: make verify-commit consider key lifetime
In reply to Fabian StelzerIf valid-before/after dates are configured for this signatures key in the allowedSigners file then the verification should check if the key was valid at the time the commit was made. This allows for graceful key rollover and revoking keys without invalidating all previous commits.
This feature needs openssh > 8.8. Older ssh-keygen versions will simply ignore this flag and use the current time.
Strictly speaking this feature is available in 8.7, but since 8.7 has a bug that makes it unusable in another needed call we require 8.8.
Timestamp information is present on most invocations of check_signature. However signer ident is not. We will need the signer email / name to be able to implement "Trust on first use" functionality later.
Since the payload contains all necessary information we can parse it from there. The caller only needs to provide us some info about the payload by setting payload_type in the signature_check struct.
- Add payload_type field & enum and payload_timestamp to struct signature_check
- Populate the timestamp when not already set if we know about the payload type
- Pass -Overify-time={payload_timestamp} in the users timezone to all ssh-keygen verification calls
- Set the payload type when verifying commits
- Add tests for expired, not yet valid and keys having a commit date outside of key validity as well as within
--- Documentation/config/gpg.txt | 5 ++++ commit.c | 1 + gpg-interface.c | 53 ++++++++++++++++++++++++++++++++++++ gpg-interface.h | 9 ++++++ t/t7528-signed-commit-ssh.sh | 42 ++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+)
Documentation/config/gpg.txt +5 -0
@@ -64,6 +64,11 @@ A repository that only allows signed commits can store the file in the repository itself using a path relative to the top-level of the working tree. This way only committers with an already valid key can add or change keys in the keyring. + +Since OpensSSH 8.8 this file allows specifying a key lifetime using valid-after & +valid-before options. Git will mark signatures as valid if the signing key was +valid at the time of the signatures creation. This allows users to change a +signing key without invalidating all previously made signatures. ++ Using a SSH CA key with the cert-authority option (see ssh-keygen(1) "CERTIFICATES") is also valid.
commit.c +1 -0
@@ -1213,6 +1213,7 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc->payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc->payload =strbuf_detach (&payload, &sigc->payload_len); ret =check_signature (sigc, signature.buf, signature.len);
gpg-interface.c +53 -0
98 lines not on this page · raw message
gpg-interface.h +9 -0
@@ -15,9 +15,18 @@ enum signature_trust_level { TRUST_ULTIMATE, }; +enum payload_type { +SIGNATURE_PAYLOAD_UNDEFINED , +SIGNATURE_PAYLOAD_COMMIT , +SIGNATURE_PAYLOAD_TAG , +SIGNATURE_PAYLOAD_PUSH_CERT , +}; +struct signature_check {char *payload;size_t payload_len; +enum payload_type payload_type; +timestamp_t payload_timestamp;char *output;char *gpg_status;
t/t7528-signed-commit-ssh.sh +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 4/7 ssh signing: make git log verify key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling git log. Implements the same tests as for verify-commit.
--- log-tree.c | 2 ++ t/t4202-log.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
log-tree.c +2 -0
@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc.payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)
@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)
t/t4202-log.sh +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 5/7 ssh signing: make verify-tag consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling verify-tag. Implements the same tests as for verify-commit.
--- t/t7031-verify-tag-signed-ssh.sh | 42 ++++++++++++++++++++++++++++++++ tag.c | 1 + 2 files changed, 43 insertions(+)
t/t7031-verify-tag-signed-ssh.sh +42 -0
@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' ' git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' + test_when_finished "test_unconfig commit.gpgsign" && + test_config gpg.format ssh && + + echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && + git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && + + echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && + git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && + + echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && + + echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed +' + test_expect_success GPGSSH 'verify and show ssh signatures' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && (
@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' ' ) ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag expired-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag notyetvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git verify-tag timeboxedvalid-signed 2>actual && + grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && + ! grep "${GPGSSH_BAD_SIGNATURE}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag timeboxedinvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + test_expect_success GPGSSH 'detect fudged ssh signature' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git cat-file tag seventh-signed >raw &&
tag.c +1 -0
@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); ret =check_signature (&sigc, signature.buf, signature.len);
Signature · 1 line
2.31.1
PATCH v3 6/7 ssh signing: make fmt-merge-msg consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when generating merge messages to verify merged tags signatures key lifetimes.
Implements the same tests as for verify-commit.
--- fmt-merge-msg.c | 1 + t/t6200-fmt-merge-msg.sh | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
fmt-merge-msg.c +1 -0
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len);if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)
t/t6200-fmt-merge-msg.sh +54 -0
66 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 7/7 ssh signing: verify ssh-keygen in test prereq
In reply to Fabian StelzerDo a full ssh signing, find-principals and verify operation in the test prereq's to make sure ssh-keygen works as expected. Only generating the keys and verifying its presence is not sufficient in some situations. One example was ssh-keygen creating unusable ssh keys in cygwin because of unsafe default permissions for the key files. The other a broken openssh 8.7 that segfaulted on any find-principals operation. This extended prereq check avoids future test breakages in case ssh-keygen or any environment behaviour changes.
--- t/lib-gpg.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
t/lib-gpg.sh +13 -6
@@ -109,11 +109,7 @@ test_lazy_prereq GPGSSH ' echo $ssh_version | grep -q "find-principals:missing signature file" test $? = 0 || exit 1; - # some broken versions of ssh-keygen segfault on find-principals; - # avoid testing with them. - ssh-keygen -Y find-principals -f /dev/null -s /dev/null - test $? = 139 && exit 1 - + # Setup some keys and an allowed signers file mkdir -p "${GNUPGHOME}" && chmod 0700 "${GNUPGHOME}" && (setfacl -k "${GNUPGHOME}" 2>/dev/null || true) &&
@@ -123,12 +119,19 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && + + # Verify if at least one key and ssh-keygen works as expected + echo "testpayload" | ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_PRIMARY}" > gpgssh_prereq.sig && + ssh-keygen -Y find-principals -f "${GPGSSH_ALLOWED_SIGNERS}" -s gpgssh_prereq.sig && + echo "testpayload" | ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with number 1" -s gpgssh_prereq.sig ' test_lazy_prereq GPGSSH_VERIFYTIME ' # Check if ssh-keygen has a verify-time option by passing an invalid date to it ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + + # Set up keys with key lifetimes ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null &&
@@ -137,6 +140,10 @@ test_lazy_prereq GPGSSH_VERIFYTIME ' echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" + + # and verify ssh-keygen verifies the key lifetime + echo "testpayload" | ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_EXPIRED}" > gpgssh_verifytime_prereq.sig && + ! (ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with expired key" -s gpgssh_verifytime_prereq.sig) ' sanitize_pgp() {
Signature · 1 line
2.31.1
Re: [PATCH v3 7/7] ssh signing: verify ssh-keygen in test prereq
t/lib-gpg.sh test_lazy_prereq GPGSSH ' · line 125
Quoted 9 lines · Fabian Stelzer
t/lib-gpg.sh +4
-1@@ -123,12 +119,19 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && + + # Verify if at least one key and ssh-keygen works as expected + echo "testpayload" | ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_PRIMARY}" > gpgssh_prereq.sig &&
Style:
. Avoid overlong line by breaking the line after pipe. . No SP between redirection operator '>' and redirection target.
echo "testpayload" |
ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_PRIMARY}" >gpgssh_prereq.sig &&Also I wonder if preparation of GPGSSH_ALLOWED_SIGNERS file can be simplified and made easier to read. Instead of adding one line at a time like this:
t/lib-gpg.sh test_lazy_prereq GPGSSH_VERIFYTIME ' · line 142
Quoted 1 line
t/lib-gpg.sh +0
-0echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}"
if you define variables with meaningful name and used here document, e.g.
ts2005a=200504070000 ts2005b=200504100000 &&
key_timeboxedvalid=$(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub") &&
ts2999=299901010000 &&
key_notyetvalid=$(cat "${GPGSSH_KEY_NOTYETVALID}.pub") &&
cat >"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF &&
"principal with not yet valid key" valid-after="$ts2999" $key_notyetvalid
"timeboxed valid key" valid-after="$ts2005a",valid-before="$ts2005b" $key_timeboxedvalid
...
EOFv4 cover ssh signing: verify key lifetime
In reply to Fabian Stelzerchanges since v3:
- improve readability of prereq setup code by using heredoc and some variables
changes since v2:
- fix swich/case indentation
- BUG() on unknown payload types
- improve test prereq by actually validating ssh-keygen functionality
changes since v1:
- struct signature_check is now used to input payload data into check_function
- payload metadata parsing is completely internal to check_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removed payload_signer parameter. since we now use the struct we can extend
this later.
Fabian Stelzer (7):
ssh signing: use sigc struct to pass payload ssh signing: add key lifetime test prereqs ssh signing: make verify-commit consider key lifetime ssh signing: make git log verify key lifetime ssh signing: make verify-tag consider key lifetime ssh signing: make fmt-merge-msg consider key lifetime ssh signing: verify ssh-keygen in test prereq
Documentation/config/gpg.txt | 5 ++ builtin/receive-pack.c | 6 ++- commit.c | 6 ++- fmt-merge-msg.c | 5 +- gpg-interface.c | 90 +++++++++++++++++++++++++------- gpg-interface.h | 15 ++++-- log-tree.c | 10 ++-- t/lib-gpg.sh | 62 ++++++++++++++++++---- t/t4202-log.sh | 43 +++++++++++++++ t/t6200-fmt-merge-msg.sh | 54 +++++++++++++++++++ t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++ t/t7528-signed-commit-ssh.sh | 42 +++++++++++++++ tag.c | 5 +- 13 files changed, 341 insertions(+), 44 deletions(-)
Range-diff against v3:
1: 9f71fd8639 = 1: c4447d30f2 ssh signing: use sigc struct to pass payload 2: 5ee143bc38 = 2: 0bb1617529 ssh signing: add key lifetime test prereqs 3: 3183e84e2e = 3: f60bd1efd0 ssh signing: make verify-commit consider key lifetime 4: e35515867c = 4: 5fc0ad5c37 ssh signing: make git log verify key lifetime 5: e20177d950 = 5: f1c225871f ssh signing: make verify-tag consider key lifetime 6: 2af2b6d098 = 6: 1cbd4dbb6b ssh signing: make fmt-merge-msg consider key lifetime 7: e6e2236a52 < -: ---------- ssh signing: verify ssh-keygen in test prereq -: ---------- > 7: d60f4ec82c ssh signing: verify ssh-keygen in test prereq
base-commit: abe6bb3905392d5eb6b01fa6e54d7e784e0522aa
Signature · 1 line
2.31.1
PATCH v4 1/7 ssh signing: use sigc struct to pass payload
To be able to extend the payload metadata with things like its creation timestamp or the creators ident we remove the payload parameters to check_signature() and use the already existing sigc->payload field instead, only adding the length field to the struct. This also allows us to get rid of the xmemdupz() calls in the verify functions. Since sigc is now used to input data as well as output the result move it to the front of the function list.
- Add payload_length to struct signature_check
- Populate sigc.payload/payload_len on all call sites
- Remove payload parameters to check_signature()
- Remove payload parameters to internal verify_* functions and use sigc instead
- Remove xmemdupz() used for verbose output since payload is now already populated.
--- builtin/receive-pack.c | 6 ++++-- commit.c | 5 +++-- fmt-merge-msg.c | 4 ++-- gpg-interface.c | 37 +++++++++++++++++-------------------- gpg-interface.h | 6 +++--- log-tree.c | 8 ++++---- tag.c | 4 ++-- 7 files changed, 35 insertions(+), 35 deletions(-)
builtin/receive-pack.c +4 -2
@@ -769,8 +769,10 @@ static void prepare_push_cert_sha1(struct child_process *proc)memset (&sigcheck,'\0' ,sizeof (sigcheck)); bogs =parse_signed_buffer (push_cert.buf, push_cert.len); -check_signature (push_cert.buf, bogs, push_cert.buf + bogs, - push_cert.len - bogs, &sigcheck); + sigcheck.payload =xmemdupz (push_cert.buf, bogs); + sigcheck.payload_len = bogs; +check_signature (&sigcheck, push_cert.buf + bogs, + push_cert.len - bogs); nonce_status =check_nonce (push_cert.buf, bogs); }
commit.c +3 -2
@@ -1212,8 +1212,9 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, sigc); + + sigc->payload =strbuf_detach (&payload, &sigc->payload_len); + ret =check_signature (sigc, signature.buf, signature.len); out:strbuf_release (&payload);
fmt-merge-msg.c +2 -2
@@ -533,8 +533,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; -if (check_signature (payload.buf, payload.len, sig.buf, - sig.len, &sigc) && + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); +if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)strbuf_addstr (&sig,"gpg verification failed.\n" );else
gpg-interface.c +17 -20
@@ -19,8 +19,8 @@ struct gpg_format {const char **verify_args;const char **sigs;int (*verify_signed_buffer)(struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);int (*sign_buffer)(struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -53,12 +53,12 @@ static const char *ssh_sigs[] = { };static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int sign_buffer_gpg (struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -314,8 +314,8 @@ static void parse_gpg_output(struct signature_check *sigc) }static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process gpg =CHILD_PROCESS_INIT ;
@@ -343,14 +343,13 @@ static int verify_gpg_signed_buffer(struct signature_check *sigc, NULL);sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&gpg, payload, payload_size, &gpg_stdout,0 , + ret =pipe_command (&gpg, sigc->payload, sigc->payload_len, &gpg_stdout,0 , &gpg_stderr,0 );sigchain_pop (SIGPIPE );delete_tempfile (&temp); ret |= !strstr (gpg_stdout.buf,"\n[GNUPG:] GOODSIG " ); - sigc->payload =xmemdupz (payload, payload_size); sigc->output =strbuf_detach (&gpg_stderr,NULL ); sigc->gpg_status =strbuf_detach (&gpg_stdout,NULL );
@@ -426,8 +425,8 @@ static void parse_ssh_output(struct signature_check *sigc) }static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process ssh_keygen =CHILD_PROCESS_INIT ;
@@ -480,7 +479,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,"-n" ,"git" ,"-s" , buffer_file->filename.buf, NULL); -pipe_command (&ssh_keygen, payload, payload_size, +pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );/*
@@ -526,7 +525,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, }sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&ssh_keygen, payload, payload_size, + ret =pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );sigchain_pop (SIGPIPE );
@@ -540,7 +539,6 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, } } - sigc->payload =xmemdupz (payload, payload_size);strbuf_stripspace (&ssh_keygen_out,0 );strbuf_stripspace (&ssh_keygen_err,0 );/* Add stderr outputs to show the user actual ssh-keygen errors */
@@ -562,8 +560,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,return ret; } -int check_signature (const char *payload,size_t plen,const char *signature, -size_t slen,struct signature_check *sigc) +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen) {struct gpg_format *fmt;int status;
@@ -575,8 +573,7 @@ int check_signature(const char *payload, size_t plen, const char *signature,if (!fmt)die (_ ("bad/incompatible signature '%s'" ), signature); - status = fmt->verify_signed_buffer (sigc, fmt, payload, plen, signature, - slen); + status = fmt->verify_signed_buffer (sigc, fmt, signature, slen);if (status && !sigc->output)return !!status;
@@ -593,7 +590,7 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags) sigc->output;if (flags &GPG_VERIFY_VERBOSE && sigc->payload) -fputs (sigc->payload, stdout); +fwrite (sigc->payload,1 , sigc->payload_len, stdout);if (output)fputs (output, stderr);
gpg-interface.h +3 -3
@@ -17,6 +17,7 @@ enum signature_trust_level {struct signature_check {char *payload; +size_t payload_len;char *output;char *gpg_status;
@@ -70,9 +71,8 @@ const char *get_signing_key(void);* Either a GPG KeyID or a SSH Key Fingerprint */ const char *get_signing_key_id (void ); -int check_signature (const char *payload,size_t plen, -const char *signature,size_t slen, -struct signature_check *sigc); +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen);void print_signature_buffer (const struct signature_check *sigc,unsigned flags);
log-tree.c +4 -4
@@ -513,8 +513,8 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - status =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)show_sig_lines (opt, status,"No signature\n" );else
@@ -583,8 +583,8 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ - status =check_signature (payload.buf, payload.len, - signature.buf, signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)strbuf_addstr (&verify_message, sigc.output);else
tag.c +2 -2
@@ -25,8 +25,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + ret =check_signature (&sigc, signature.buf, signature.len);if (!(flags &GPG_VERIFY_OMIT_STATUS ))print_signature_buffer (&sigc, flags);
Signature · 1 line
2.31.1
PATCH v4 2/7 ssh signing: add key lifetime test prereqs
In reply to Fabian Stelzerif ssh-keygen supports -Overify-time, add test keys marked as expired, not yet valid and valid both within the test_tick timeframe and outside of it.
--- t/lib-gpg.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
t/lib-gpg.sh +18 -1
@@ -90,6 +90,10 @@ test_lazy_prereq RFC1991 ' GPGSSH_KEY_PRIMARY="${GNUPGHOME}/ed25519_ssh_signing_key" GPGSSH_KEY_SECONDARY="${GNUPGHOME}/rsa_2048_ssh_signing_key" GPGSSH_KEY_UNTRUSTED="${GNUPGHOME}/untrusted_ssh_signing_key" +GPGSSH_KEY_EXPIRED="${GNUPGHOME}/expired_ssh_signing_key" +GPGSSH_KEY_NOTYETVALID="${GNUPGHOME}/notyetvalid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDVALID="${GNUPGHOME}/timeboxed_valid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDINVALID="${GNUPGHOME}/timeboxed_invalid_ssh_signing_key" GPGSSH_KEY_WITH_PASSPHRASE="${GNUPGHOME}/protected_ssh_signing_key" GPGSSH_KEY_PASSPHRASE="super_secret" GPGSSH_ALLOWED_SIGNERS="${GNUPGHOME}/ssh.all_valid.allowedSignersFile"
@@ -119,7 +123,20 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null +' + +test_lazy_prereq GPGSSH_VERIFYTIME ' + # Check if ssh-keygen has a verify-time option by passing an invalid date to it + ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && + echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && + echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && + echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && + echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v4 3/7 ssh signing: make verify-commit consider key lifetime
In reply to Fabian StelzerIf valid-before/after dates are configured for this signatures key in the allowedSigners file then the verification should check if the key was valid at the time the commit was made. This allows for graceful key rollover and revoking keys without invalidating all previous commits.
This feature needs openssh > 8.8. Older ssh-keygen versions will simply ignore this flag and use the current time.
Strictly speaking this feature is available in 8.7, but since 8.7 has a bug that makes it unusable in another needed call we require 8.8.
Timestamp information is present on most invocations of check_signature. However signer ident is not. We will need the signer email / name to be able to implement "Trust on first use" functionality later.
Since the payload contains all necessary information we can parse it from there. The caller only needs to provide us some info about the payload by setting payload_type in the signature_check struct.
- Add payload_type field & enum and payload_timestamp to struct signature_check
- Populate the timestamp when not already set if we know about the payload type
- Pass -Overify-time={payload_timestamp} in the users timezone to all ssh-keygen verification calls
- Set the payload type when verifying commits
- Add tests for expired, not yet valid and keys having a commit date outside of key validity as well as within
--- Documentation/config/gpg.txt | 5 ++++ commit.c | 1 + gpg-interface.c | 53 ++++++++++++++++++++++++++++++++++++ gpg-interface.h | 9 ++++++ t/t7528-signed-commit-ssh.sh | 42 ++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+)
Documentation/config/gpg.txt +5 -0
@@ -64,6 +64,11 @@ A repository that only allows signed commits can store the file in the repository itself using a path relative to the top-level of the working tree. This way only committers with an already valid key can add or change keys in the keyring. + +Since OpensSSH 8.8 this file allows specifying a key lifetime using valid-after & +valid-before options. Git will mark signatures as valid if the signing key was +valid at the time of the signatures creation. This allows users to change a +signing key without invalidating all previously made signatures. ++ Using a SSH CA key with the cert-authority option (see ssh-keygen(1) "CERTIFICATES") is also valid.
commit.c +1 -0
@@ -1213,6 +1213,7 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc->payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc->payload =strbuf_detach (&payload, &sigc->payload_len); ret =check_signature (sigc, signature.buf, signature.len);
gpg-interface.c +53 -0
98 lines not on this page · raw message
gpg-interface.h +9 -0
@@ -15,9 +15,18 @@ enum signature_trust_level { TRUST_ULTIMATE, }; +enum payload_type { +SIGNATURE_PAYLOAD_UNDEFINED , +SIGNATURE_PAYLOAD_COMMIT , +SIGNATURE_PAYLOAD_TAG , +SIGNATURE_PAYLOAD_PUSH_CERT , +}; +struct signature_check {char *payload;size_t payload_len; +enum payload_type payload_type; +timestamp_t payload_timestamp;char *output;char *gpg_status;
t/t7528-signed-commit-ssh.sh +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v4 4/7 ssh signing: make git log verify key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling git log. Implements the same tests as for verify-commit.
--- log-tree.c | 2 ++ t/t4202-log.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
log-tree.c +2 -0
@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc.payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)
@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)
t/t4202-log.sh +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v4 5/7 ssh signing: make verify-tag consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling verify-tag. Implements the same tests as for verify-commit.
--- t/t7031-verify-tag-signed-ssh.sh | 42 ++++++++++++++++++++++++++++++++ tag.c | 1 + 2 files changed, 43 insertions(+)
t/t7031-verify-tag-signed-ssh.sh +42 -0
@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' ' git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' + test_when_finished "test_unconfig commit.gpgsign" && + test_config gpg.format ssh && + + echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && + git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && + + echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && + git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && + + echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && + + echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed +' + test_expect_success GPGSSH 'verify and show ssh signatures' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && (
@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' ' ) ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag expired-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag notyetvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git verify-tag timeboxedvalid-signed 2>actual && + grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && + ! grep "${GPGSSH_BAD_SIGNATURE}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag timeboxedinvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + test_expect_success GPGSSH 'detect fudged ssh signature' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git cat-file tag seventh-signed >raw &&
tag.c +1 -0
@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); ret =check_signature (&sigc, signature.buf, signature.len);
Signature · 1 line
2.31.1
PATCH v4 6/7 ssh signing: make fmt-merge-msg consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when generating merge messages to verify merged tags signatures key lifetimes.
Implements the same tests as for verify-commit.
--- fmt-merge-msg.c | 1 + t/t6200-fmt-merge-msg.sh | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
fmt-merge-msg.c +1 -0
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len);if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)
t/t6200-fmt-merge-msg.sh +54 -0
66 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v4 6/7] ssh signing: make fmt-merge-msg consider key lifetime
Quoted 32 lines · Fabian Stelzer
t/t6200-fmt-merge-msg.sh +20
-0@@ -91,6 +91,26 @@ test_expect_success GPGSSH 'created ssh signed commit and tag' ' git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' + test_when_finished "test_unconfig commit.gpgsign" && + test_config gpg.format ssh && + git checkout -b signed-expiry-ssh && + touch file && + git add file && + + echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && + git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && + + echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && + git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && + + echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && + + echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed +' + test_expect_success 'message for merging local branch' ' echo "Merge branch ${apos}left${apos}" >expected &&
t/t6200-fmt-merge-msg.sh test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh · line 166
Quoted 10 lines
t/t6200-fmt-merge-msg.sh +7
-0@@ -137,6 +157,40 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh ! grep "${GPGSSH_BAD_SIGNATURE}" actual && grep "${GPGSSH_KEY_NOT_TRUSTED}" actual ' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git checkout main && + git fetch . expired-signed && + git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
Are these messages supposed to go to standard output or error? If it's the former, then please drop the unnecessary (and confusing) '2>&1' redirection, but if it's the latter, then save and 'grep' only stderr.
Quoted 33 lines
t/t6200-fmt-merge-msg.sh +27
-0+' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git checkout main && + git fetch . notyetvalid-signed && + git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git checkout main && + git fetch . timeboxedvalid-signed && + git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && + ! grep "${GPGSSH_BAD_SIGNATURE}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git checkout main && + git fetch . timeboxedinvalid-signed && + git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + test_expect_success 'message for merging external branch' ' echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&Signature · 1 line
2.31.1
Re: [PATCH v4 6/7] ssh signing: make fmt-merge-msg consider key lifetime
Quoted 14 lines · SZEDER Gábor
t/t6200-fmt-merge-msg.sh test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh · line 166
Quoted 7 lines · Fabian Stelzer
t/t6200-fmt-merge-msg.sh +7
-0+ +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git checkout main && + git fetch . expired-signed && + git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actualAre these messages supposed to go to standard output or error? If it's the former, then please drop the unnecessary (and confusing) '2>&1' redirection, but if it's the latter, then save and 'grep' only stderr.
You are right, these are not correct. I copied the fmt-merge-msg calls from the GPG tests a bit above which grep for the merged tag name and for gpg signature output (i assume those two things go to stdout/err respectively). I will check and create a new patch series for fixing up all of these.
Thanks
PATCH v4 7/7 ssh signing: verify ssh-keygen in test prereq
In reply to Fabian StelzerDo a full ssh signing, find-principals and verify operation in the test prereq's to make sure ssh-keygen works as expected. Only generating the keys and verifying its presence is not sufficient in some situations. One example was ssh-keygen creating unusable ssh keys in cygwin because of unsafe default permissions for the key files. The other a broken openssh 8.7 that segfaulted on any find-principals operation. This extended prereq check avoids future test breakages in case ssh-keygen or any environment behaviour changes.
--- t/lib-gpg.sh | 53 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-)
t/lib-gpg.sh +40 -13
@@ -109,34 +109,61 @@ test_lazy_prereq GPGSSH ' echo $ssh_version | grep -q "find-principals:missing signature file" test $? = 0 || exit 1; - # some broken versions of ssh-keygen segfault on find-principals; - # avoid testing with them. - ssh-keygen -Y find-principals -f /dev/null -s /dev/null - test $? = 139 && exit 1 - + # Setup some keys and an allowed signers file mkdir -p "${GNUPGHOME}" && chmod 0700 "${GNUPGHOME}" && (setfacl -k "${GNUPGHOME}" 2>/dev/null || true) && ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null && - echo "\"principal with number 1\" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null && - echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && + + cat >"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && + "principal with number 1" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" + "principal with number 2" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" + "principal with number 3" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" + EOF + + # Verify if at least one key and ssh-keygen works as expected + echo "testpayload" | + ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_PRIMARY}" >gpgssh_prereq.sig && + ssh-keygen -Y find-principals -f "${GPGSSH_ALLOWED_SIGNERS}" -s gpgssh_prereq.sig && + echo "testpayload" | + ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with number 1" -s gpgssh_prereq.sig ' test_lazy_prereq GPGSSH_VERIFYTIME ' # Check if ssh-keygen has a verify-time option by passing an invalid date to it ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + + # Set up keys with key lifetimes ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && - echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_valid=$(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub") && ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && - echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_invalid=$(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub") && ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && - echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_expired=$(cat "${GPGSSH_KEY_EXPIRED}.pub") && ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && - echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" + key_notyetvalid=$(cat "${GPGSSH_KEY_NOTYETVALID}.pub") && + + # Timestamps outside of test_tick span + ts2005a=20050401000000 ts2005b=200504020000 && + # Timestamps within test_tick span + ts2005c=20050407000000 ts2005d=200504100000 && + # Definitely not yet valid / expired timestamps + ts2000=20000101000000 ts2999=29990101000000 && + + cat >>"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && + "timeboxed valid key" valid-after="$ts2005c",valid-before="$ts2005d" $key_valid" + "timeboxed invalid key" valid-after="$ts2005a",valid-before="$ts2005b" $key_invalid" + "principal with expired key" valid-before="$ts2000" $key_expired" + "principal with not yet valid key" valid-after="$ts2999" $key_notyetvalid" + EOF + + # and verify ssh-keygen verifies the key lifetime + echo "testpayload" | + ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_EXPIRED}" >gpgssh_verifytime_prereq.sig && + ! (ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with expired key" -s gpgssh_verifytime_prereq.sig) ' sanitize_pgp() {
Signature · 1 line
2.31.1
Re: [PATCH v4 7/7] ssh signing: verify ssh-keygen in test prereq
Quoted 11 lines · Fabian Stelzer
Do a full ssh signing, find-principals and verify operation in the test prereq's to make sure ssh-keygen works as expected. Only generating the keys and verifying its presence is not sufficient in some situations. One example was ssh-keygen creating unusable ssh keys in cygwin because of unsafe default permissions for the key files. The other a broken openssh 8.7 that segfaulted on any find-principals operation. This extended prereq check avoids future test breakages in case ssh-keygen or any environment behaviour changes.
Signed-off-by Fabian Stelzer <[email protected]>---
The way keys are set-up has become much easier to follow.
This unfortunately interacts with the old way of adding a test key done in <[email protected]> 350a2518 (ssh
signing: support non ssh-* keytypes, 2021-11-19)
Here is my attempt (which is in 'seen') to resolve the inevitable merge conflicts between the topics.
Thanks.
commit fa6c2973744b419c95b5eaf6a697c795ab7823fa
Merge: 2a8505f6a0 3b4b5a793a
Author: Junio C Hamano <[email protected]>
Date: Wed Dec 1 16:01:54 2021 -0800
Merge branch 'fs/ssh-signing-other-keytypes' into jch
* fs/ssh-signing-other-keytypes:
ssh signing: make sign/amend test more resilient ssh signing: support non ssh-* keytypes
t/lib-gpg.sh +2 -10
@@ -117,13 +117,14 @@ test_lazy_prereq GPGSSH ' ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null && ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && -<<<<<<< 2a8505f6a0 (Merge branch 'fs/ssh-signing-key-lifetime' into jch) + ssh-keygen -t ecdsa -N "" -f "${GPGSSH_KEY_ECDSA}" >/dev/null && ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && cat >"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && "principal with number 1" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" "principal with number 2" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" "principal with number 3" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" + "principal with number 4" $(cat "${GPGSSH_KEY_ECDSA}.pub")" EOF # Verify if at least one key and ssh-keygen works as expected
@@ -166,15 +167,6 @@ test_lazy_prereq GPGSSH_VERIFYTIME ' echo "testpayload" | ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_EXPIRED}" >gpgssh_verifytime_prereq.sig && ! (ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with expired key" -s gpgssh_verifytime_prereq.sig) -||||||| cd3e606211 - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null -======= - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ecdsa -N "" -f "${GPGSSH_KEY_ECDSA}" >/dev/null - echo "\"principal with number 4\" $(cat "${GPGSSH_KEY_ECDSA}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null ->>>>>>> 3b4b5a793a (ssh signing: make sign/amend test more resilient) ' sanitize_pgp() {
Re: [PATCH v4 7/7] ssh signing: verify ssh-keygen in test prereq
Quoted 14 lines · Junio C Hamano
Quoted 11 lines · Fabian Stelzer
Do a full ssh signing, find-principals and verify operation in the test prereq's to make sure ssh-keygen works as expected. Only generating the keys and verifying its presence is not sufficient in some situations. One example was ssh-keygen creating unusable ssh keys in cygwin because of unsafe default permissions for the key files. The other a broken openssh 8.7 that segfaulted on any find-principals operation. This extended prereq check avoids future test breakages in case ssh-keygen or any environment behaviour changes.
Signed-off-by Fabian Stelzer <[email protected]>---
Quoted 8 lines
The way keys are set-up has become much easier to follow.
This unfortunately interacts with the old way of adding a test key done in <[email protected]>
350a2518(ssh
signing: support non ssh-* keytypes, 2021-11-19)Here is my attempt (which is in 'seen') to resolve the inevitable merge conflicts between the topics.
Yes, that looks good. In this case the conflict is rather trivial, but how could i prevent this / make it easier for you to merge these?
Especially since in this case the conflict only arose after a reroll when both topics were already in seen. For a new topic i can of course make them as "on top of XXX". Should I in the future rebase the "support non ssh-* keytypes" topic on top of this series and mark it as such? Or whats a good way to deal with things like this? (besides avoiding merge conflicts altogether :D)
Thanks
Quoted 50 lines
Thanks.
commit
fa6c2973744b419c95b5eaf6a697c795ab7823fa
Merge:2a8505f6a03b4b5a793a
Author: Junio C Hamano <[email protected]>
Date: Wed Dec 1 16:01:54 2021 -0800Merge branch '
fs/ssh-signing-other-keytypes' into jch*
fs/ssh-signing-other-keytypes:
ssh signing: make sign/amend test more resilient ssh signing: support non ssh-* keytypest/lib-gpg.sh +2
-10@@ -117,13 +117,14 @@ test_lazy_prereq GPGSSH ' ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null && ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && -<<<<<<< 2a8505f6a0 (Merge branch 'fs/ssh-signing-key-lifetime' into jch) + ssh-keygen -t ecdsa -N "" -f "${GPGSSH_KEY_ECDSA}" >/dev/null && ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && cat >"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && "principal with number 1" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" "principal with number 2" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" "principal with number 3" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" + "principal with number 4" $(cat "${GPGSSH_KEY_ECDSA}.pub")" EOF # Verify if at least one key and ssh-keygen works as expected@@ -166,15 +167,6 @@ test_lazy_prereq GPGSSH_VERIFYTIME ' echo "testpayload" | ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_EXPIRED}" >gpgssh_verifytime_prereq.sig && ! (ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with expired key" -s gpgssh_verifytime_prereq.sig) -||||||| cd3e606211 - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null -======= - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ecdsa -N "" -f "${GPGSSH_KEY_ECDSA}" >/dev/null - echo "\"principal with number 4\" $(cat "${GPGSSH_KEY_ECDSA}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null ->>>>>>> 3b4b5a793a (ssh signing: make sign/amend test more resilient)'
sanitize_pgp(){
Re: [PATCH v4 7/7] ssh signing: verify ssh-keygen in test prereq
Quoted 8 lines · Fabian Stelzer
Yes, that looks good. In this case the conflict is rather trivial, but how could i prevent this / make it easier for you to merge these? Especially since in this case the conflict only arose after a reroll when both topics were already in seen. For a new topic i can of course make them as "on top of XXX". Should I in the future rebase the "support non ssh-* keytypes" topic on top of this series and mark it as such? Or whats a good way to deal with things like this? (besides avoiding merge conflicts altogether :D)
For this particular one, my rerere database already knows how the conflict and its resolution should look like, so there is nothing that is urgently needed.
If the other topic were to be rerolled, since either has hit 'next', basing it on top of the other, essentially making the result into a single series, may be the easiest (and that is basically avoiding conflicts altogether ;-).
Thanks.
Re: [PATCH v4 7/7] ssh signing: verify ssh-keygen in test prereq
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Fabian Stelzer
Yes, that looks good. In this case the conflict is rather trivial, but how could i prevent this / make it easier for you to merge these? Especially since in this case the conflict only arose after a reroll when both topics were already in seen. For a new topic i can of course make them as "on top of XXX". Should I in the future rebase the "support non ssh-* keytypes" topic on top of this series and mark it as such? Or whats a good way to deal with things like this? (besides avoiding merge conflicts altogether :D)
Quoted 8 lines
For this particular one, my rerere database already knows how the conflict and its resolution should look like, so there is nothing that is urgently needed.
If the other topic were to be rerolled, since either has hit 'next', basing it on top of the other, essentially making the result into a single series, may be the easiest (and that is basically avoiding conflicts altogether ;-).
...but to answer a bit of Fabian's question: Just as someone giving these two topics a brief look it's not clear to me why the existing GPGSSH prerequisite needs an adjustment at the same time as adding a test that uses it (in addition to existing tests).
I.e. was it that it was always wrong, in that case I'd expect a patch that fixes the prereq and doesn't make any other test changes in the same commit as [1] does.
Or does it need to be more strict to cater to one new test being added in the same commit, but that strictness doesn't apply to existing tests?
Then maybe it should be a new GPGSSH_THAT_NEW_REQUIRED_FEATURE, which can in turn depend on the GPGSSH prerequisite.
Which, incidentally would help with any textual conflict, but more importantly makes for clearer end-state, and maps prerequisites to those existing tests that need those specific things, and not a more stricter & recent requirement.
I don't know/think that any of this needs re-rolling, just my 0.02.
Re: [PATCH v4 7/7] ssh signing: verify ssh-keygen in test prereq
Quoted 32 lines · Ævar Arnfjörð Bjarmason
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Fabian Stelzer
Yes, that looks good. In this case the conflict is rather trivial, but how could i prevent this / make it easier for you to merge these? Especially since in this case the conflict only arose after a reroll when both topics were already in seen. For a new topic i can of course make them as "on top of XXX". Should I in the future rebase the "support non ssh-* keytypes" topic on top of this series and mark it as such? Or whats a good way to deal with things like this? (besides avoiding merge conflicts altogether :D)
Quoted 8 lines
For this particular one, my rerere database already knows how the conflict and its resolution should look like, so there is nothing that is urgently needed.
If the other topic were to be rerolled, since either has hit 'next', basing it on top of the other, essentially making the result into a single series, may be the easiest (and that is basically avoiding conflicts altogether ;-).
...but to answer a bit of Fabian's question: Just as someone giving these two topics a brief look it's not clear to me why the existing GPGSSH prerequisite needs an adjustment at the same time as adding a test that uses it (in addition to existing tests).
I.e. was it that it was always wrong, in that case I'd expect a patch that fixes the prereq and doesn't make any other test changes in the same commit as [1] does.
Quoted 6 lines
Or does it need to be more strict to cater to one new test being added in the same commit, but that strictness doesn't apply to existing tests?
Then maybe it should be a new
GPGSSH_THAT_NEW_REQUIRED_FEATURE, which can in turn depend on the GPGSSH prerequisite.
What [1] needed was another keytype set up for some tests to run. I could have done this in the test itself or in a separate setup function. But since all the other keys are set up in the prereq and we might want to reuse this new ecdsa key in other tests as well this seemed like the better place for it. A new prereq depending on GPGSSH feels kinda wrong to me when it would just create the key and always succeed otherwise. I guess this is a side effect of using the prereq to do setup as well (something that we discussed in https://lore.kernel.org/git/[email protected]/ ).
Quoted 5 lines
Which, incidentally would help with any textual conflict, but more importantly makes for clearer end-state, and maps prerequisites to those existing tests that need those specific things, and not a more stricter & recent requirement.
The problem here was just that I also refactored the existing GPGSSH prereq to be more readable while doing the same for the new one. Only refactoring the new one while leaving the older one just above it untouched would have avoided the conflict but would have needed a follow up series. In the future I would probably do that or leave the code as is and refactor both in a follow up.
Quoted 3 lines
I don't know/think that any of this needs re-rolling, just my 0.02.
Always glad for your input.
Thanks
Re: [PATCH v4 7/7] ssh signing: verify ssh-keygen in test prereq
In reply to Junio C HamanoQuoted 11 lines · Junio C Hamano
Quoted 8 lines · Fabian Stelzer
Yes, that looks good. In this case the conflict is rather trivial, but how could i prevent this / make it easier for you to merge these? Especially since in this case the conflict only arose after a reroll when both topics were already in seen. For a new topic i can of course make them as "on top of XXX". Should I in the future rebase the "support non ssh-* keytypes" topic on top of this series and mark it as such? Or whats a good way to deal with things like this? (besides avoiding merge conflicts altogether :D)
Quoted 5 lines
For this particular one, my rerere database already knows how the conflict and its resolution should look like, so there is nothing that is urgently needed.
If the other topic were to be rerolled, since either has hit 'next',
Sorry, "since neither has hit 'next' yet," was what I meant to type. Not being in 'next' allows us to replace the series without having to do "oops, that earlier one was wrong, and here is a band-aid".
Thanks.
Quoted 5 lines
basing it on top of the other, essentially making the result into a single series, may be the easiest (and that is basically avoiding conflicts altogether ;-).
Thanks.
v5 cover ssh signing: verify key lifetime
In reply to Fabian Stelzerchanges since v4:
- removed unneccessary io redir in merge-msg tests
- added grep for merged tag to gpgssh merge-msg tests
changes since v3:
- improve readability of prereq setup code by using heredoc and some variables
changes since v2:
- fix swich/case indentation
- BUG() on unknown payload types
- improve test prereq by actually validating ssh-keygen functionality
changes since v1:
- struct signature_check is now used to input payload data into check_function
- payload metadata parsing is completely internal to check_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removed payload_signer parameter. since we now use the struct we can extend
this later.
Fabian Stelzer (8):
ssh signing: use sigc struct to pass payload ssh signing: add key lifetime test prereqs ssh signing: make verify-commit consider key lifetime ssh signing: make git log verify key lifetime ssh signing: make verify-tag consider key lifetime ssh signing: make fmt-merge-msg consider key lifetime ssh signing: verify ssh-keygen in test prereq t/fmt-merge-msg: make gpg/ssh tests more specific
Documentation/config/gpg.txt | 5 ++ builtin/receive-pack.c | 6 ++- commit.c | 6 ++- fmt-merge-msg.c | 5 +- gpg-interface.c | 90 +++++++++++++++++++++++++------- gpg-interface.h | 15 ++++-- log-tree.c | 10 ++-- t/lib-gpg.sh | 62 ++++++++++++++++++---- t/t4202-log.sh | 43 +++++++++++++++ t/t6200-fmt-merge-msg.sh | 67 ++++++++++++++++++++++-- t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++ t/t7528-signed-commit-ssh.sh | 42 +++++++++++++++ tag.c | 5 +- 13 files changed, 350 insertions(+), 48 deletions(-)
Range-diff against v4:
1: c4447d30f2 = 1: c4447d30f2 ssh signing: use sigc struct to pass payload 2: 0bb1617529 = 2: 0bb1617529 ssh signing: add key lifetime test prereqs 3: f60bd1efd0 = 3: f60bd1efd0 ssh signing: make verify-commit consider key lifetime 4: 5fc0ad5c37 = 4: 5fc0ad5c37 ssh signing: make git log verify key lifetime 5: f1c225871f = 5: f1c225871f ssh signing: make verify-tag consider key lifetime 6: 1cbd4dbb6b = 6: 1cbd4dbb6b ssh signing: make fmt-merge-msg consider key lifetime 7: d60f4ec82c = 7: d60f4ec82c ssh signing: verify ssh-keygen in test prereq -: ---------- > 8: 679a02d1fe t/fmt-merge-msg: make gpg/ssh tests more specific
Signature · 1 line
2.31.1
PATCH v5 1/8 ssh signing: use sigc struct to pass payload
To be able to extend the payload metadata with things like its creation timestamp or the creators ident we remove the payload parameters to check_signature() and use the already existing sigc->payload field instead, only adding the length field to the struct. This also allows us to get rid of the xmemdupz() calls in the verify functions. Since sigc is now used to input data as well as output the result move it to the front of the function list.
- Add payload_length to struct signature_check
- Populate sigc.payload/payload_len on all call sites
- Remove payload parameters to check_signature()
- Remove payload parameters to internal verify_* functions and use sigc instead
- Remove xmemdupz() used for verbose output since payload is now already populated.
--- builtin/receive-pack.c | 6 ++++-- commit.c | 5 +++-- fmt-merge-msg.c | 4 ++-- gpg-interface.c | 37 +++++++++++++++++-------------------- gpg-interface.h | 6 +++--- log-tree.c | 8 ++++---- tag.c | 4 ++-- 7 files changed, 35 insertions(+), 35 deletions(-)
builtin/receive-pack.c +4 -2
@@ -769,8 +769,10 @@ static void prepare_push_cert_sha1(struct child_process *proc)memset (&sigcheck,'\0' ,sizeof (sigcheck)); bogs =parse_signed_buffer (push_cert.buf, push_cert.len); -check_signature (push_cert.buf, bogs, push_cert.buf + bogs, - push_cert.len - bogs, &sigcheck); + sigcheck.payload =xmemdupz (push_cert.buf, bogs); + sigcheck.payload_len = bogs; +check_signature (&sigcheck, push_cert.buf + bogs, + push_cert.len - bogs); nonce_status =check_nonce (push_cert.buf, bogs); }
commit.c +3 -2
@@ -1212,8 +1212,9 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, sigc); + + sigc->payload =strbuf_detach (&payload, &sigc->payload_len); + ret =check_signature (sigc, signature.buf, signature.len); out:strbuf_release (&payload);
fmt-merge-msg.c +2 -2
@@ -533,8 +533,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; -if (check_signature (payload.buf, payload.len, sig.buf, - sig.len, &sigc) && + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); +if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)strbuf_addstr (&sig,"gpg verification failed.\n" );else
gpg-interface.c +17 -20
@@ -19,8 +19,8 @@ struct gpg_format {const char **verify_args;const char **sigs;int (*verify_signed_buffer)(struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);int (*sign_buffer)(struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -53,12 +53,12 @@ static const char *ssh_sigs[] = { };static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int sign_buffer_gpg (struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -314,8 +314,8 @@ static void parse_gpg_output(struct signature_check *sigc) }static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process gpg =CHILD_PROCESS_INIT ;
@@ -343,14 +343,13 @@ static int verify_gpg_signed_buffer(struct signature_check *sigc, NULL);sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&gpg, payload, payload_size, &gpg_stdout,0 , + ret =pipe_command (&gpg, sigc->payload, sigc->payload_len, &gpg_stdout,0 , &gpg_stderr,0 );sigchain_pop (SIGPIPE );delete_tempfile (&temp); ret |= !strstr (gpg_stdout.buf,"\n[GNUPG:] GOODSIG " ); - sigc->payload =xmemdupz (payload, payload_size); sigc->output =strbuf_detach (&gpg_stderr,NULL ); sigc->gpg_status =strbuf_detach (&gpg_stdout,NULL );
@@ -426,8 +425,8 @@ static void parse_ssh_output(struct signature_check *sigc) }static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process ssh_keygen =CHILD_PROCESS_INIT ;
@@ -480,7 +479,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,"-n" ,"git" ,"-s" , buffer_file->filename.buf, NULL); -pipe_command (&ssh_keygen, payload, payload_size, +pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );/*
@@ -526,7 +525,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, }sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&ssh_keygen, payload, payload_size, + ret =pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );sigchain_pop (SIGPIPE );
@@ -540,7 +539,6 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, } } - sigc->payload =xmemdupz (payload, payload_size);strbuf_stripspace (&ssh_keygen_out,0 );strbuf_stripspace (&ssh_keygen_err,0 );/* Add stderr outputs to show the user actual ssh-keygen errors */
@@ -562,8 +560,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,return ret; } -int check_signature (const char *payload,size_t plen,const char *signature, -size_t slen,struct signature_check *sigc) +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen) {struct gpg_format *fmt;int status;
@@ -575,8 +573,7 @@ int check_signature(const char *payload, size_t plen, const char *signature,if (!fmt)die (_ ("bad/incompatible signature '%s'" ), signature); - status = fmt->verify_signed_buffer (sigc, fmt, payload, plen, signature, - slen); + status = fmt->verify_signed_buffer (sigc, fmt, signature, slen);if (status && !sigc->output)return !!status;
@@ -593,7 +590,7 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags) sigc->output;if (flags &GPG_VERIFY_VERBOSE && sigc->payload) -fputs (sigc->payload, stdout); +fwrite (sigc->payload,1 , sigc->payload_len, stdout);if (output)fputs (output, stderr);
gpg-interface.h +3 -3
@@ -17,6 +17,7 @@ enum signature_trust_level {struct signature_check {char *payload; +size_t payload_len;char *output;char *gpg_status;
@@ -70,9 +71,8 @@ const char *get_signing_key(void);* Either a GPG KeyID or a SSH Key Fingerprint */ const char *get_signing_key_id (void ); -int check_signature (const char *payload,size_t plen, -const char *signature,size_t slen, -struct signature_check *sigc); +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen);void print_signature_buffer (const struct signature_check *sigc,unsigned flags);
log-tree.c +4 -4
@@ -513,8 +513,8 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - status =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)show_sig_lines (opt, status,"No signature\n" );else
@@ -583,8 +583,8 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ - status =check_signature (payload.buf, payload.len, - signature.buf, signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)strbuf_addstr (&verify_message, sigc.output);else
tag.c +2 -2
@@ -25,8 +25,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + ret =check_signature (&sigc, signature.buf, signature.len);if (!(flags &GPG_VERIFY_OMIT_STATUS ))print_signature_buffer (&sigc, flags);
Signature · 1 line
2.31.1
PATCH v5 2/8 ssh signing: add key lifetime test prereqs
In reply to Fabian Stelzerif ssh-keygen supports -Overify-time, add test keys marked as expired, not yet valid and valid both within the test_tick timeframe and outside of it.
--- t/lib-gpg.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
t/lib-gpg.sh +18 -1
@@ -90,6 +90,10 @@ test_lazy_prereq RFC1991 ' GPGSSH_KEY_PRIMARY="${GNUPGHOME}/ed25519_ssh_signing_key" GPGSSH_KEY_SECONDARY="${GNUPGHOME}/rsa_2048_ssh_signing_key" GPGSSH_KEY_UNTRUSTED="${GNUPGHOME}/untrusted_ssh_signing_key" +GPGSSH_KEY_EXPIRED="${GNUPGHOME}/expired_ssh_signing_key" +GPGSSH_KEY_NOTYETVALID="${GNUPGHOME}/notyetvalid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDVALID="${GNUPGHOME}/timeboxed_valid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDINVALID="${GNUPGHOME}/timeboxed_invalid_ssh_signing_key" GPGSSH_KEY_WITH_PASSPHRASE="${GNUPGHOME}/protected_ssh_signing_key" GPGSSH_KEY_PASSPHRASE="super_secret" GPGSSH_ALLOWED_SIGNERS="${GNUPGHOME}/ssh.all_valid.allowedSignersFile"
@@ -119,7 +123,20 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null +' + +test_lazy_prereq GPGSSH_VERIFYTIME ' + # Check if ssh-keygen has a verify-time option by passing an invalid date to it + ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && + echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && + echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && + echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && + echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v5 3/8 ssh signing: make verify-commit consider key lifetime
In reply to Fabian StelzerIf valid-before/after dates are configured for this signatures key in the allowedSigners file then the verification should check if the key was valid at the time the commit was made. This allows for graceful key rollover and revoking keys without invalidating all previous commits.
This feature needs openssh > 8.8. Older ssh-keygen versions will simply ignore this flag and use the current time.
Strictly speaking this feature is available in 8.7, but since 8.7 has a bug that makes it unusable in another needed call we require 8.8.
Timestamp information is present on most invocations of check_signature. However signer ident is not. We will need the signer email / name to be able to implement "Trust on first use" functionality later.
Since the payload contains all necessary information we can parse it from there. The caller only needs to provide us some info about the payload by setting payload_type in the signature_check struct.
- Add payload_type field & enum and payload_timestamp to struct signature_check
- Populate the timestamp when not already set if we know about the payload type
- Pass -Overify-time={payload_timestamp} in the users timezone to all ssh-keygen verification calls
- Set the payload type when verifying commits
- Add tests for expired, not yet valid and keys having a commit date outside of key validity as well as within
--- Documentation/config/gpg.txt | 5 ++++ commit.c | 1 + gpg-interface.c | 53 ++++++++++++++++++++++++++++++++++++ gpg-interface.h | 9 ++++++ t/t7528-signed-commit-ssh.sh | 42 ++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+)
Documentation/config/gpg.txt +5 -0
@@ -64,6 +64,11 @@ A repository that only allows signed commits can store the file in the repository itself using a path relative to the top-level of the working tree. This way only committers with an already valid key can add or change keys in the keyring. + +Since OpensSSH 8.8 this file allows specifying a key lifetime using valid-after & +valid-before options. Git will mark signatures as valid if the signing key was +valid at the time of the signatures creation. This allows users to change a +signing key without invalidating all previously made signatures. ++ Using a SSH CA key with the cert-authority option (see ssh-keygen(1) "CERTIFICATES") is also valid.
commit.c +1 -0
@@ -1213,6 +1213,7 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc->payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc->payload =strbuf_detach (&payload, &sigc->payload_len); ret =check_signature (sigc, signature.buf, signature.len);
gpg-interface.c +53 -0
98 lines not on this page · raw message
gpg-interface.h +9 -0
@@ -15,9 +15,18 @@ enum signature_trust_level { TRUST_ULTIMATE, }; +enum payload_type { +SIGNATURE_PAYLOAD_UNDEFINED , +SIGNATURE_PAYLOAD_COMMIT , +SIGNATURE_PAYLOAD_TAG , +SIGNATURE_PAYLOAD_PUSH_CERT , +}; +struct signature_check {char *payload;size_t payload_len; +enum payload_type payload_type; +timestamp_t payload_timestamp;char *output;char *gpg_status;
t/t7528-signed-commit-ssh.sh +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v5 4/8 ssh signing: make git log verify key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling git log. Implements the same tests as for verify-commit.
--- log-tree.c | 2 ++ t/t4202-log.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
log-tree.c +2 -0
@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc.payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)
@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)
t/t4202-log.sh +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v5 5/8 ssh signing: make verify-tag consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling verify-tag. Implements the same tests as for verify-commit.
--- t/t7031-verify-tag-signed-ssh.sh | 42 ++++++++++++++++++++++++++++++++ tag.c | 1 + 2 files changed, 43 insertions(+)
t/t7031-verify-tag-signed-ssh.sh +42 -0
@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' ' git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' + test_when_finished "test_unconfig commit.gpgsign" && + test_config gpg.format ssh && + + echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && + git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && + + echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && + git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && + + echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && + + echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed +' + test_expect_success GPGSSH 'verify and show ssh signatures' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && (
@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' ' ) ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag expired-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag notyetvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git verify-tag timeboxedvalid-signed 2>actual && + grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && + ! grep "${GPGSSH_BAD_SIGNATURE}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag timeboxedinvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + test_expect_success GPGSSH 'detect fudged ssh signature' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git cat-file tag seventh-signed >raw &&
tag.c +1 -0
@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); ret =check_signature (&sigc, signature.buf, signature.len);
Signature · 1 line
2.31.1
PATCH v5 6/8 ssh signing: make fmt-merge-msg consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when generating merge messages to verify merged tags signatures key lifetimes.
Implements the same tests as for verify-commit.
--- fmt-merge-msg.c | 1 + t/t6200-fmt-merge-msg.sh | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
fmt-merge-msg.c +1 -0
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len);if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)
t/t6200-fmt-merge-msg.sh +54 -0
66 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v5 7/8 ssh signing: verify ssh-keygen in test prereq
In reply to Fabian StelzerDo a full ssh signing, find-principals and verify operation in the test prereq's to make sure ssh-keygen works as expected. Only generating the keys and verifying its presence is not sufficient in some situations. One example was ssh-keygen creating unusable ssh keys in cygwin because of unsafe default permissions for the key files. The other a broken openssh 8.7 that segfaulted on any find-principals operation. This extended prereq check avoids future test breakages in case ssh-keygen or any environment behaviour changes.
--- t/lib-gpg.sh | 53 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-)
t/lib-gpg.sh +40 -13
@@ -109,34 +109,61 @@ test_lazy_prereq GPGSSH ' echo $ssh_version | grep -q "find-principals:missing signature file" test $? = 0 || exit 1; - # some broken versions of ssh-keygen segfault on find-principals; - # avoid testing with them. - ssh-keygen -Y find-principals -f /dev/null -s /dev/null - test $? = 139 && exit 1 - + # Setup some keys and an allowed signers file mkdir -p "${GNUPGHOME}" && chmod 0700 "${GNUPGHOME}" && (setfacl -k "${GNUPGHOME}" 2>/dev/null || true) && ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null && - echo "\"principal with number 1\" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null && - echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && + + cat >"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && + "principal with number 1" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" + "principal with number 2" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" + "principal with number 3" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" + EOF + + # Verify if at least one key and ssh-keygen works as expected + echo "testpayload" | + ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_PRIMARY}" >gpgssh_prereq.sig && + ssh-keygen -Y find-principals -f "${GPGSSH_ALLOWED_SIGNERS}" -s gpgssh_prereq.sig && + echo "testpayload" | + ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with number 1" -s gpgssh_prereq.sig ' test_lazy_prereq GPGSSH_VERIFYTIME ' # Check if ssh-keygen has a verify-time option by passing an invalid date to it ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + + # Set up keys with key lifetimes ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && - echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_valid=$(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub") && ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && - echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_invalid=$(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub") && ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && - echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_expired=$(cat "${GPGSSH_KEY_EXPIRED}.pub") && ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && - echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" + key_notyetvalid=$(cat "${GPGSSH_KEY_NOTYETVALID}.pub") && + + # Timestamps outside of test_tick span + ts2005a=20050401000000 ts2005b=200504020000 && + # Timestamps within test_tick span + ts2005c=20050407000000 ts2005d=200504100000 && + # Definitely not yet valid / expired timestamps + ts2000=20000101000000 ts2999=29990101000000 && + + cat >>"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && + "timeboxed valid key" valid-after="$ts2005c",valid-before="$ts2005d" $key_valid" + "timeboxed invalid key" valid-after="$ts2005a",valid-before="$ts2005b" $key_invalid" + "principal with expired key" valid-before="$ts2000" $key_expired" + "principal with not yet valid key" valid-after="$ts2999" $key_notyetvalid" + EOF + + # and verify ssh-keygen verifies the key lifetime + echo "testpayload" | + ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_EXPIRED}" >gpgssh_verifytime_prereq.sig && + ! (ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with expired key" -s gpgssh_verifytime_prereq.sig) ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v5 8/8 t/fmt-merge-msg: make gpg/ssh tests more specific
In reply to Fabian StelzerAll the GPG, GPGSSH and the new GPGSSH_VERIFYTIME tests are redirecing stdout as well as stderr to actual and grep for success/failure over the resulting flie. However, no output is printed on stderr and we do not need to include it in the grep. The newer SSH signing based tests are also missing a grep for the merged tag to make sure the merge message is correct.
- remove unneccessary 2>&1 redirects
- add grep for merged tag to gpgssh* tests
--- t/t6200-fmt-merge-msg.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
t/t6200-fmt-merge-msg.sh +13 -8
@@ -124,7 +124,7 @@ test_expect_success 'message for merging local branch' ' test_expect_success GPG 'message for merging local tag signed by good key' ' git checkout main && git fetch . signed-good-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && grep "^# gpg: Good signature from" actual
@@ -133,7 +133,7 @@ test_expect_success GPG 'message for merging local tag signed by good key' ' test_expect_success GPG 'message for merging local tag signed by unknown key' ' git checkout main && git fetch . signed-good-tag && - GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
@@ -143,7 +143,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by good ssh key test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . signed-good-ssh-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual '
@@ -152,7 +152,8 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . signed-untrusted-ssh-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual && grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual && grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
@@ -162,7 +163,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . expired-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}expired-signed${apos}" actual && ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual '
@@ -170,7 +172,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . notyetvalid-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual && ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual '
@@ -178,7 +181,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . timeboxedvalid-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual && grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual '
@@ -187,7 +191,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . timeboxedinvalid-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual && ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual '
Signature · 1 line
2.31.1
Re: [PATCH v5 8/8] t/fmt-merge-msg: make gpg/ssh tests more specific
Quoted 7 lines · Fabian Stelzer
All the GPG, GPGSSH and the new
GPGSSH_VERIFYTIMEtests are redirecing stdout as well as stderr toactualand grep for success/failure over the resulting flie. However, no output is printed on stderr and we do not need to include it in the grep. The newer SSH signing based tests are also missing a grep for the merged tag to make sure the merge message is correct.
Quoted 7 lines
- remove unneccessary 2>&1 redirects
- add grep for merged tag to gpgssh* testsSigned-off-by Fabian Stelzer <[email protected]>--- t/t6200-fmt-merge-msg.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
The 4 hunks at the beginning seems to be a clean-up of the existing issue, but aren't hunks -162,7, -170,7, -178,7, 187,7 "oops, we screwed up in [6/8], and we patch up after the fact"?
For a new topic not yet in 'next', we'd prefer to pretend to be more perfect humans by not deliberatly keeping mistakes made in an earlier step, only to be corrected in a later step.
While there may not be any difference in the end-result, it would be cleaner and less sloppy to have the 4 hunks to fix the ones before the series as a preliminary clean-up step, and the other hunks folded into the step that introduced the problem, no?
Thanks.
Quoted 80 lines
t/t6200-fmt-merge-msg.sh +13
-8@@ -124,7 +124,7 @@ test_expect_success 'message for merging local branch' ' test_expect_success GPG 'message for merging local tag signed by good key' ' git checkout main && git fetch . signed-good-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && grep "^# gpg: Good signature from" actual@@ -133,7 +133,7 @@ test_expect_success GPG 'message for merging local tag signed by good key' ' test_expect_success GPG 'message for merging local tag signed by unknown key' ' git checkout main && git fetch . signed-good-tag && - GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual@@ -143,7 +143,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by good ssh key test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . signed-good-ssh-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual '@@ -152,7 +152,8 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . signed-untrusted-ssh-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual && grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual && grep "${GPGSSH_KEY_NOT_TRUSTED}" actual@@ -162,7 +163,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . expired-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}expired-signed${apos}" actual && ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual '@@ -170,7 +172,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . notyetvalid-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual && ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual '@@ -178,7 +181,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . timeboxedvalid-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual && grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual '@@ -187,7 +191,8 @@ test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag sign test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . timeboxedinvalid-signed && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual && ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual '
Re: [PATCH v5 8/8] t/fmt-merge-msg: make gpg/ssh tests more specific
Quoted 21 lines · Junio C Hamano
Quoted 7 lines · Fabian Stelzer
All the GPG, GPGSSH and the new
GPGSSH_VERIFYTIMEtests are redirecing stdout as well as stderr toactualand grep for success/failure over the resulting flie. However, no output is printed on stderr and we do not need to include it in the grep. The newer SSH signing based tests are also missing a grep for the merged tag to make sure the merge message is correct.Quoted 7 lines
- remove unneccessary 2>&1 redirects
- add grep for merged tag to gpgssh* testsSigned-off-by Fabian Stelzer <[email protected]>--- t/t6200-fmt-merge-msg.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)The 4 hunks at the beginning seems to be a clean-up of the existing issue, but aren't hunks -162,7, -170,7, -178,7, 187,7 "oops, we screwed up in [6/8], and we patch up after the fact"?
Quoted 9 lines
For a new topic not yet in 'next', we'd prefer to pretend to be more perfect humans by not deliberatly keeping mistakes made in an earlier step, only to be corrected in a later step.
While there may not be any difference in the end-result, it would be cleaner and less sloppy to have the 4 hunks to fix the ones before the series as a preliminary clean-up step, and the other hunks folded into the step that introduced the problem, no?
Ok, i will send a new version with the fixes for the earlier tests in extra commits. Your 5.1 includes a +"grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual &&" fix for a preexisting test in the first patch which now claims to only remove the stderr redirects though. Also another grep for the merged tag for an earlier test got lost somewhere. I'll send a 5.2
Thanks
v6 cover ssh signing: verify key lifetime
In reply to Fabian Stelzerchanges since v5:
- moved the fixes to existing test to the first two commits and merged those fixing new tests into the corresponding commit
changes since v4:
- removed unneccessary io redir in merge-msg tests
- added grep for merged tag to gpgssh merge-msg tests
changes since v3:
- improve readability of prereq setup code by using heredoc and some variables
changes since v2:
- fix swich/case indentation
- BUG() on unknown payload types
- improve test prereq by actually validating ssh-keygen functionality
changes since v1:
- struct signature_check is now used to input payload data into check_function
- payload metadata parsing is completely internal to check_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removed payload_signer parameter. since we now use the struct we can extend
this later.
Fabian Stelzer (9):
t/fmt-merge-msg: do not redirect stderr t/fmt-merge-msg: make gpgssh tests more specific ssh signing: use sigc struct to pass payload ssh signing: add key lifetime test prereqs ssh signing: make verify-commit consider key lifetime ssh signing: make git log verify key lifetime ssh signing: make verify-tag consider key lifetime ssh signing: make fmt-merge-msg consider key lifetime ssh signing: verify ssh-keygen in test prereq
Documentation/config/gpg.txt | 5 ++ builtin/receive-pack.c | 6 ++- commit.c | 6 ++- fmt-merge-msg.c | 5 +- gpg-interface.c | 90 +++++++++++++++++++++++++------- gpg-interface.h | 15 ++++-- log-tree.c | 10 ++-- t/lib-gpg.sh | 62 ++++++++++++++++++---- t/t4202-log.sh | 43 +++++++++++++++ t/t6200-fmt-merge-msg.sh | 68 ++++++++++++++++++++++-- t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++ t/t7528-signed-commit-ssh.sh | 42 +++++++++++++++ tag.c | 5 +- 13 files changed, 351 insertions(+), 48 deletions(-)
Range-diff against v5:
-: ---------- > 1: 0b3848d23b t/fmt-merge-msg: do not redirect stderr
-: ---------- > 2: f29d838574 t/fmt-merge-msg: make gpgssh tests more specific
1: c4447d30f2 = 3: b065dcb7fb ssh signing: use sigc struct to pass payload
2: 0bb1617529 = 4: c37d33db31 ssh signing: add key lifetime test prereqs
3: f60bd1efd0 = 5: 640e9a4a99 ssh signing: make verify-commit consider key lifetime
4: 5fc0ad5c37 = 6: 2e98307c18 ssh signing: make git log verify key lifetime
5: f1c225871f = 7: 75d213ab15 ssh signing: make verify-tag consider key lifetime
6: 1cbd4dbb6b ! 8: 498821af14 ssh signing: make fmt-merge-msg consider key lifetime
@@ t/t6200-fmt-merge-msg.sh: test_expect_success GPGSSH 'message for merging local
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+ git checkout main &&
+ git fetch . expired-signed &&
-+ git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
++ git fmt-merge-msg <.git/FETCH_HEAD >actual &&
++ grep "^Merge tag ${apos}expired-signed${apos}" actual &&
+ ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
+'
+
@@ t/t6200-fmt-merge-msg.sh: test_expect_success GPGSSH 'message for merging local
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+ git checkout main &&
+ git fetch . notyetvalid-signed &&
-+ git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
++ git fmt-merge-msg <.git/FETCH_HEAD >actual &&
++ grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual &&
+ ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
+'
+
@@ t/t6200-fmt-merge-msg.sh: test_expect_success GPGSSH 'message for merging local
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+ git checkout main &&
+ git fetch . timeboxedvalid-signed &&
-+ git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
++ git fmt-merge-msg <.git/FETCH_HEAD >actual &&
++ grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual &&
+ grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
+ ! grep "${GPGSSH_BAD_SIGNATURE}" actual
+'
@@ t/t6200-fmt-merge-msg.sh: test_expect_success GPGSSH 'message for merging local
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+ git checkout main &&
+ git fetch . timeboxedinvalid-signed &&
-+ git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
++ git fmt-merge-msg <.git/FETCH_HEAD >actual &&
++ grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual &&
+ ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
+'
+ 7: d60f4ec82c = 9: 0816dd2ec8 ssh signing: verify ssh-keygen in test prereq
Signature · 1 line
2.31.1
PATCH v6 1/9 t/fmt-merge-msg: do not redirect stderr
All the GPG and GPGSSH tests are redirecing stdout as well as stderr to actual and grep for success/failure over the resulting file. However, no output is printed on stderr and we do not need to include it in the grep.
--- t/t6200-fmt-merge-msg.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
t/t6200-fmt-merge-msg.sh +4 -4
@@ -104,7 +104,7 @@ test_expect_success 'message for merging local branch' ' test_expect_success GPG 'message for merging local tag signed by good key' ' git checkout main && git fetch . signed-good-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && grep "^# gpg: Good signature from" actual
@@ -113,7 +113,7 @@ test_expect_success GPG 'message for merging local tag signed by good key' ' test_expect_success GPG 'message for merging local tag signed by unknown key' ' git checkout main && git fetch . signed-good-tag && - GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
@@ -123,7 +123,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by good ssh key test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . signed-good-ssh-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual '
@@ -132,7 +132,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git checkout main && git fetch . signed-untrusted-ssh-tag && - git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && + git fmt-merge-msg <.git/FETCH_HEAD >actual && grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual && grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
Signature · 1 line
2.31.1
PATCH v6 2/9 t/fmt-merge-msg: make gpgssh tests more specific
In reply to Fabian StelzerSome GPGSSH fmt-merge-msg tests were only grepping for failed/successful signature validation and not checking for the tag in the resulting merge message. Add the missing grep for it.
--- t/t6200-fmt-merge-msg.sh | 2 ++ 1 file changed, 2 insertions(+)
t/t6200-fmt-merge-msg.sh +2 -0
@@ -124,6 +124,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by good ssh key git checkout main && git fetch . signed-good-ssh-tag && git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}signed-good-ssh-tag${apos}" actual && grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual '
@@ -133,6 +134,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh git checkout main && git fetch . signed-untrusted-ssh-tag && git fmt-merge-msg <.git/FETCH_HEAD >actual && + grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual && grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual && ! grep "${GPGSSH_BAD_SIGNATURE}" actual && grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
Signature · 1 line
2.31.1
PATCH v6 3/9 ssh signing: use sigc struct to pass payload
In reply to Fabian StelzerTo be able to extend the payload metadata with things like its creation timestamp or the creators ident we remove the payload parameters to check_signature() and use the already existing sigc->payload field instead, only adding the length field to the struct. This also allows us to get rid of the xmemdupz() calls in the verify functions. Since sigc is now used to input data as well as output the result move it to the front of the function list.
- Add payload_length to struct signature_check
- Populate sigc.payload/payload_len on all call sites
- Remove payload parameters to check_signature()
- Remove payload parameters to internal verify_* functions and use sigc instead
- Remove xmemdupz() used for verbose output since payload is now already populated.
--- builtin/receive-pack.c | 6 ++++-- commit.c | 5 +++-- fmt-merge-msg.c | 4 ++-- gpg-interface.c | 37 +++++++++++++++++-------------------- gpg-interface.h | 6 +++--- log-tree.c | 8 ++++---- tag.c | 4 ++-- 7 files changed, 35 insertions(+), 35 deletions(-)
builtin/receive-pack.c +4 -2
@@ -769,8 +769,10 @@ static void prepare_push_cert_sha1(struct child_process *proc)memset (&sigcheck,'\0' ,sizeof (sigcheck)); bogs =parse_signed_buffer (push_cert.buf, push_cert.len); -check_signature (push_cert.buf, bogs, push_cert.buf + bogs, - push_cert.len - bogs, &sigcheck); + sigcheck.payload =xmemdupz (push_cert.buf, bogs); + sigcheck.payload_len = bogs; +check_signature (&sigcheck, push_cert.buf + bogs, + push_cert.len - bogs); nonce_status =check_nonce (push_cert.buf, bogs); }
commit.c +3 -2
@@ -1212,8 +1212,9 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, sigc); + + sigc->payload =strbuf_detach (&payload, &sigc->payload_len); + ret =check_signature (sigc, signature.buf, signature.len); out:strbuf_release (&payload);
fmt-merge-msg.c +2 -2
@@ -533,8 +533,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; -if (check_signature (payload.buf, payload.len, sig.buf, - sig.len, &sigc) && + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); +if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)strbuf_addstr (&sig,"gpg verification failed.\n" );else
gpg-interface.c +17 -20
@@ -19,8 +19,8 @@ struct gpg_format {const char **verify_args;const char **sigs;int (*verify_signed_buffer)(struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);int (*sign_buffer)(struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -53,12 +53,12 @@ static const char *ssh_sigs[] = { };static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size);static int sign_buffer_gpg (struct strbuf *buffer,struct strbuf *signature,const char *signing_key);
@@ -314,8 +314,8 @@ static void parse_gpg_output(struct signature_check *sigc) }static int verify_gpg_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process gpg =CHILD_PROCESS_INIT ;
@@ -343,14 +343,13 @@ static int verify_gpg_signed_buffer(struct signature_check *sigc, NULL);sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&gpg, payload, payload_size, &gpg_stdout,0 , + ret =pipe_command (&gpg, sigc->payload, sigc->payload_len, &gpg_stdout,0 , &gpg_stderr,0 );sigchain_pop (SIGPIPE );delete_tempfile (&temp); ret |= !strstr (gpg_stdout.buf,"\n[GNUPG:] GOODSIG " ); - sigc->payload =xmemdupz (payload, payload_size); sigc->output =strbuf_detach (&gpg_stderr,NULL ); sigc->gpg_status =strbuf_detach (&gpg_stdout,NULL );
@@ -426,8 +425,8 @@ static void parse_ssh_output(struct signature_check *sigc) }static int verify_ssh_signed_buffer (struct signature_check *sigc, -struct gpg_format *fmt,const char *payload, -size_t payload_size,const char *signature, +struct gpg_format *fmt, +const char *signature,size_t signature_size) {struct child_process ssh_keygen =CHILD_PROCESS_INIT ;
@@ -480,7 +479,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,"-n" ,"git" ,"-s" , buffer_file->filename.buf, NULL); -pipe_command (&ssh_keygen, payload, payload_size, +pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );/*
@@ -526,7 +525,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, }sigchain_push (SIGPIPE ,SIG_IGN ); - ret =pipe_command (&ssh_keygen, payload, payload_size, + ret =pipe_command (&ssh_keygen, sigc->payload, sigc->payload_len, &ssh_keygen_out,0 , &ssh_keygen_err,0 );sigchain_pop (SIGPIPE );
@@ -540,7 +539,6 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc, } } - sigc->payload =xmemdupz (payload, payload_size);strbuf_stripspace (&ssh_keygen_out,0 );strbuf_stripspace (&ssh_keygen_err,0 );/* Add stderr outputs to show the user actual ssh-keygen errors */
@@ -562,8 +560,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,return ret; } -int check_signature (const char *payload,size_t plen,const char *signature, -size_t slen,struct signature_check *sigc) +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen) {struct gpg_format *fmt;int status;
@@ -575,8 +573,7 @@ int check_signature(const char *payload, size_t plen, const char *signature,if (!fmt)die (_ ("bad/incompatible signature '%s'" ), signature); - status = fmt->verify_signed_buffer (sigc, fmt, payload, plen, signature, - slen); + status = fmt->verify_signed_buffer (sigc, fmt, signature, slen);if (status && !sigc->output)return !!status;
@@ -593,7 +590,7 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags) sigc->output;if (flags &GPG_VERIFY_VERBOSE && sigc->payload) -fputs (sigc->payload, stdout); +fwrite (sigc->payload,1 , sigc->payload_len, stdout);if (output)fputs (output, stderr);
gpg-interface.h +3 -3
@@ -17,6 +17,7 @@ enum signature_trust_level {struct signature_check {char *payload; +size_t payload_len;char *output;char *gpg_status;
@@ -70,9 +71,8 @@ const char *get_signing_key(void);* Either a GPG KeyID or a SSH Key Fingerprint */ const char *get_signing_key_id (void ); -int check_signature (const char *payload,size_t plen, -const char *signature,size_t slen, -struct signature_check *sigc); +int check_signature (struct signature_check *sigc, +const char *signature,size_t slen);void print_signature_buffer (const struct signature_check *sigc,unsigned flags);
log-tree.c +4 -4
@@ -513,8 +513,8 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; - status =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)show_sig_lines (opt, status,"No signature\n" );else
@@ -583,8 +583,8 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ - status =check_signature (payload.buf, payload.len, - signature.buf, signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)strbuf_addstr (&verify_message, sigc.output);else
tag.c +2 -2
@@ -25,8 +25,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } - ret =check_signature (payload.buf, payload.len, signature.buf, - signature.len, &sigc); + sigc.payload =strbuf_detach (&payload, &sigc.payload_len); + ret =check_signature (&sigc, signature.buf, signature.len);if (!(flags &GPG_VERIFY_OMIT_STATUS ))print_signature_buffer (&sigc, flags);
Signature · 1 line
2.31.1
PATCH v6 4/9 ssh signing: add key lifetime test prereqs
In reply to Fabian Stelzerif ssh-keygen supports -Overify-time, add test keys marked as expired, not yet valid and valid both within the test_tick timeframe and outside of it.
--- t/lib-gpg.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
t/lib-gpg.sh +18 -1
@@ -90,6 +90,10 @@ test_lazy_prereq RFC1991 ' GPGSSH_KEY_PRIMARY="${GNUPGHOME}/ed25519_ssh_signing_key" GPGSSH_KEY_SECONDARY="${GNUPGHOME}/rsa_2048_ssh_signing_key" GPGSSH_KEY_UNTRUSTED="${GNUPGHOME}/untrusted_ssh_signing_key" +GPGSSH_KEY_EXPIRED="${GNUPGHOME}/expired_ssh_signing_key" +GPGSSH_KEY_NOTYETVALID="${GNUPGHOME}/notyetvalid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDVALID="${GNUPGHOME}/timeboxed_valid_ssh_signing_key" +GPGSSH_KEY_TIMEBOXEDINVALID="${GNUPGHOME}/timeboxed_invalid_ssh_signing_key" GPGSSH_KEY_WITH_PASSPHRASE="${GNUPGHOME}/protected_ssh_signing_key" GPGSSH_KEY_PASSPHRASE="super_secret" GPGSSH_ALLOWED_SIGNERS="${GNUPGHOME}/ssh.all_valid.allowedSignersFile"
@@ -119,7 +123,20 @@ test_lazy_prereq GPGSSH ' echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null +' + +test_lazy_prereq GPGSSH_VERIFYTIME ' + # Check if ssh-keygen has a verify-time option by passing an invalid date to it + ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && + echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && + echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && + echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && + echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v6 5/9 ssh signing: make verify-commit consider key lifetime
In reply to Fabian StelzerIf valid-before/after dates are configured for this signatures key in the allowedSigners file then the verification should check if the key was valid at the time the commit was made. This allows for graceful key rollover and revoking keys without invalidating all previous commits.
This feature needs openssh > 8.8. Older ssh-keygen versions will simply ignore this flag and use the current time.
Strictly speaking this feature is available in 8.7, but since 8.7 has a bug that makes it unusable in another needed call we require 8.8.
Timestamp information is present on most invocations of check_signature. However signer ident is not. We will need the signer email / name to be able to implement "Trust on first use" functionality later.
Since the payload contains all necessary information we can parse it from there. The caller only needs to provide us some info about the payload by setting payload_type in the signature_check struct.
- Add payload_type field & enum and payload_timestamp to struct signature_check
- Populate the timestamp when not already set if we know about the payload type
- Pass -Overify-time={payload_timestamp} in the users timezone to all ssh-keygen verification calls
- Set the payload type when verifying commits
- Add tests for expired, not yet valid and keys having a commit date outside of key validity as well as within
--- Documentation/config/gpg.txt | 5 ++++ commit.c | 1 + gpg-interface.c | 53 ++++++++++++++++++++++++++++++++++++ gpg-interface.h | 9 ++++++ t/t7528-signed-commit-ssh.sh | 42 ++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+)
Documentation/config/gpg.txt +5 -0
@@ -64,6 +64,11 @@ A repository that only allows signed commits can store the file in the repository itself using a path relative to the top-level of the working tree. This way only committers with an already valid key can add or change keys in the keyring. + +Since OpensSSH 8.8 this file allows specifying a key lifetime using valid-after & +valid-before options. Git will mark signatures as valid if the signing key was +valid at the time of the signatures creation. This allows users to change a +signing key without invalidating all previously made signatures. ++ Using a SSH CA key with the cert-authority option (see ssh-keygen(1) "CERTIFICATES") is also valid.
commit.c +1 -0
@@ -1213,6 +1213,7 @@ int check_commit_signature(const struct commit *commit, struct signature_check *if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc->payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc->payload =strbuf_detach (&payload, &sigc->payload_len); ret =check_signature (sigc, signature.buf, signature.len);
gpg-interface.c +53 -0
98 lines not on this page · raw message
gpg-interface.h +9 -0
@@ -15,9 +15,18 @@ enum signature_trust_level { TRUST_ULTIMATE, }; +enum payload_type { +SIGNATURE_PAYLOAD_UNDEFINED , +SIGNATURE_PAYLOAD_COMMIT , +SIGNATURE_PAYLOAD_TAG , +SIGNATURE_PAYLOAD_PUSH_CERT , +}; +struct signature_check {char *payload;size_t payload_len; +enum payload_type payload_type; +timestamp_t payload_timestamp;char *output;char *gpg_status;
t/t7528-signed-commit-ssh.sh +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v6 6/9 ssh signing: make git log verify key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling git log. Implements the same tests as for verify-commit.
--- log-tree.c | 2 ++ t/t4202-log.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
log-tree.c +2 -0
@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc.payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)
@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)
t/t4202-log.sh +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v6 7/9 ssh signing: make verify-tag consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling verify-tag. Implements the same tests as for verify-commit.
--- t/t7031-verify-tag-signed-ssh.sh | 42 ++++++++++++++++++++++++++++++++ tag.c | 1 + 2 files changed, 43 insertions(+)
t/t7031-verify-tag-signed-ssh.sh +42 -0
@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' ' git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' + test_when_finished "test_unconfig commit.gpgsign" && + test_config gpg.format ssh && + + echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && + git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && + + echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && + git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && + + echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && + + echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed +' + test_expect_success GPGSSH 'verify and show ssh signatures' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && (
@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' ' ) ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag expired-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag notyetvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git verify-tag timeboxedvalid-signed 2>actual && + grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && + ! grep "${GPGSSH_BAD_SIGNATURE}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag timeboxedinvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + test_expect_success GPGSSH 'detect fudged ssh signature' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git cat-file tag seventh-signed >raw &&
tag.c +1 -0
@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); ret =check_signature (&sigc, signature.buf, signature.len);
Signature · 1 line
2.31.1
PATCH v6 8/9 ssh signing: make fmt-merge-msg consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when generating merge messages to verify merged tags signatures key lifetimes.
Implements the same tests as for verify-commit.
--- fmt-merge-msg.c | 1 + t/t6200-fmt-merge-msg.sh | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
fmt-merge-msg.c +1 -0
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len);if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)
t/t6200-fmt-merge-msg.sh +58 -0
70 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v6 9/9 ssh signing: verify ssh-keygen in test prereq
In reply to Fabian StelzerDo a full ssh signing, find-principals and verify operation in the test prereq's to make sure ssh-keygen works as expected. Only generating the keys and verifying its presence is not sufficient in some situations. One example was ssh-keygen creating unusable ssh keys in cygwin because of unsafe default permissions for the key files. The other a broken openssh 8.7 that segfaulted on any find-principals operation. This extended prereq check avoids future test breakages in case ssh-keygen or any environment behaviour changes.
--- t/lib-gpg.sh | 53 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-)
t/lib-gpg.sh +40 -13
@@ -109,34 +109,61 @@ test_lazy_prereq GPGSSH ' echo $ssh_version | grep -q "find-principals:missing signature file" test $? = 0 || exit 1; - # some broken versions of ssh-keygen segfault on find-principals; - # avoid testing with them. - ssh-keygen -Y find-principals -f /dev/null -s /dev/null - test $? = 139 && exit 1 - + # Setup some keys and an allowed signers file mkdir -p "${GNUPGHOME}" && chmod 0700 "${GNUPGHOME}" && (setfacl -k "${GNUPGHOME}" 2>/dev/null || true) && ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_PRIMARY}" >/dev/null && - echo "\"principal with number 1\" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t rsa -b 2048 -N "" -C "git rsa2048 key" -f "${GPGSSH_KEY_SECONDARY}" >/dev/null && - echo "\"principal with number 2\" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && ssh-keygen -t ed25519 -N "${GPGSSH_KEY_PASSPHRASE}" -C "git ed25519 encrypted key" -f "${GPGSSH_KEY_WITH_PASSPHRASE}" >/dev/null && - echo "\"principal with number 3\" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && - ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null + ssh-keygen -t ed25519 -N "" -C "git ed25519 key" -f "${GPGSSH_KEY_UNTRUSTED}" >/dev/null && + + cat >"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && + "principal with number 1" $(cat "${GPGSSH_KEY_PRIMARY}.pub")" + "principal with number 2" $(cat "${GPGSSH_KEY_SECONDARY}.pub")" + "principal with number 3" $(cat "${GPGSSH_KEY_WITH_PASSPHRASE}.pub")" + EOF + + # Verify if at least one key and ssh-keygen works as expected + echo "testpayload" | + ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_PRIMARY}" >gpgssh_prereq.sig && + ssh-keygen -Y find-principals -f "${GPGSSH_ALLOWED_SIGNERS}" -s gpgssh_prereq.sig && + echo "testpayload" | + ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with number 1" -s gpgssh_prereq.sig ' test_lazy_prereq GPGSSH_VERIFYTIME ' # Check if ssh-keygen has a verify-time option by passing an invalid date to it ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" && + + # Set up keys with key lifetimes ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null && - echo "\"timeboxed valid key\" valid-after=\"20050407000000\",valid-before=\"200504100000\" $(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_valid=$(cat "${GPGSSH_KEY_TIMEBOXEDVALID}.pub") && ssh-keygen -t ed25519 -N "" -C "timeboxed invalid key" -f "${GPGSSH_KEY_TIMEBOXEDINVALID}" >/dev/null && - echo "\"timeboxed invalid key\" valid-after=\"20050401000000\",valid-before=\"20050402000000\" $(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_invalid=$(cat "${GPGSSH_KEY_TIMEBOXEDINVALID}.pub") && ssh-keygen -t ed25519 -N "" -C "expired key" -f "${GPGSSH_KEY_EXPIRED}" >/dev/null && - echo "\"principal with expired key\" valid-before=\"20000101000000\" $(cat "${GPGSSH_KEY_EXPIRED}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" && + key_expired=$(cat "${GPGSSH_KEY_EXPIRED}.pub") && ssh-keygen -t ed25519 -N "" -C "not yet valid key" -f "${GPGSSH_KEY_NOTYETVALID}" >/dev/null && - echo "\"principal with not yet valid key\" valid-after=\"29990101000000\" $(cat "${GPGSSH_KEY_NOTYETVALID}.pub")" >> "${GPGSSH_ALLOWED_SIGNERS}" + key_notyetvalid=$(cat "${GPGSSH_KEY_NOTYETVALID}.pub") && + + # Timestamps outside of test_tick span + ts2005a=20050401000000 ts2005b=200504020000 && + # Timestamps within test_tick span + ts2005c=20050407000000 ts2005d=200504100000 && + # Definitely not yet valid / expired timestamps + ts2000=20000101000000 ts2999=29990101000000 && + + cat >>"${GPGSSH_ALLOWED_SIGNERS}" <<-EOF && + "timeboxed valid key" valid-after="$ts2005c",valid-before="$ts2005d" $key_valid" + "timeboxed invalid key" valid-after="$ts2005a",valid-before="$ts2005b" $key_invalid" + "principal with expired key" valid-before="$ts2000" $key_expired" + "principal with not yet valid key" valid-after="$ts2999" $key_notyetvalid" + EOF + + # and verify ssh-keygen verifies the key lifetime + echo "testpayload" | + ssh-keygen -Y sign -n "git" -f "${GPGSSH_KEY_EXPIRED}" >gpgssh_verifytime_prereq.sig && + ! (ssh-keygen -Y verify -n "git" -f "${GPGSSH_ALLOWED_SIGNERS}" -I "principal with expired key" -s gpgssh_verifytime_prereq.sig) ' sanitize_pgp() {
Signature · 1 line
2.31.1
PATCH v2 4/6 ssh signing: make git log verify key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling git log. Implements the same tests as for verify-commit.
--- log-tree.c | 2 ++ t/t4202-log.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
log-tree.c +2 -0
@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)if (parse_signed_commit (commit, &payload, &signature, the_hash_algo) <=0 ) goto out; + sigc.payload_type =SIGNATURE_PAYLOAD_COMMIT ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (status && !sigc.output)
@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit, status =-1 ;if (parse_signature (extra->value, extra->len, &payload, &signature)) {/* could have a good signature */ + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); status =check_signature (&sigc, signature.buf, signature.len);if (sigc.output)
t/t4202-log.sh +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 5/6 ssh signing: make verify-tag consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when calling verify-tag. Implements the same tests as for verify-commit.
--- t/t7031-verify-tag-signed-ssh.sh | 42 ++++++++++++++++++++++++++++++++ tag.c | 1 + 2 files changed, 43 insertions(+)
t/t7031-verify-tag-signed-ssh.sh +42 -0
@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' ' git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' + test_when_finished "test_unconfig commit.gpgsign" && + test_config gpg.format ssh && + + echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && + git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && + + echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && + git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && + + echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && + + echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && + git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed +' + test_expect_success GPGSSH 'verify and show ssh signatures' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && (
@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' ' ) ' +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag expired-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag notyetvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git verify-tag timeboxedvalid-signed 2>actual && + grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && + ! grep "${GPGSSH_BAD_SIGNATURE}" actual +' + +test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + test_must_fail git verify-tag timeboxedinvalid-signed 2>actual && + ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual +' + test_expect_success GPGSSH 'detect fudged ssh signature' ' test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git cat-file tag seventh-signed >raw &&
tag.c +1 -0
@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)return error ("no signature found" ); } + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len); ret =check_signature (&sigc, signature.buf, signature.len);
Signature · 1 line
2.31.1
PATCH v2 6/6 ssh signing: make fmt-merge-msg consider key lifetime
In reply to Fabian StelzerSet the payload_type for check_signature() when generating merge messages to verify merged tags signatures key lifetimes.
Implements the same tests as for verify-commit.
--- fmt-merge-msg.c | 1 + t/t6200-fmt-merge-msg.sh | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
fmt-merge-msg.c +1 -0
@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)else { buf = payload.buf; len = payload.len; + sigc.payload_type =SIGNATURE_PAYLOAD_TAG ; sigc.payload =strbuf_detach (&payload, &sigc.payload_len);if (check_signature (&sigc, sig.buf, sig.len) && !sigc.output)
t/t6200-fmt-merge-msg.sh +54 -0
66 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 40 lines · Fabian Stelzer
This series adds key lifetime validity checks by parsing commit/tag dates from the paylod and passing them to the ssh-keygen operations.
changes since v1:
- structsignature_checkis now used to input payload data intocheck_function
- payload metadata parsing is completely internal tocheck_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removedpayload_signerparameter. since we now use the struct we can extend this later.Since the last 3 patches now only contain a minimal code change and the tests for the seperate callers we could merge them together. I don't mind either way.
Fabian Stelzer (6):
ssh signing: use sigc struct to pass payload ssh signing: add key lifetime test prereqs ssh signing: make verify-commit consider key lifetime ssh signing: make git log verify key lifetime ssh signing: make verify-tag consider key lifetime ssh signing: make fmt-merge-msg consider key lifetimeDocumentation/config/gpg.txt | 5 ++ builtin/receive-pack.c | 6 ++- commit.c | 6 ++- fmt-merge-msg.c | 5 +- gpg-interface.c | 87 ++++++++++++++++++++++++-------- gpg-interface.h | 15 ++++-- log-tree.c | 10 ++-- t/lib-gpg.sh | 19 ++++++- t/t4202-log.sh | 43 ++++++++++++++++ t/t6200-fmt-merge-msg.sh | 54 ++++++++++++++++++++ t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++ t/t7528-signed-commit-ssh.sh | 42 +++++++++++++++ tag.c | 5 +- 13 files changed, 303 insertions(+), 36 deletions(-)
Quoted 1 line
base-commit:
e9e5ba39a78c8f5057262d49e261b42a8660d5b9
As part of testing v2.34-rc0 on Cygwin, I've found this patch series is breaking t4202, t5534, and t6200.
Specifically, bisecting points to f265f2d630 (ssh signing: tests for logs, tags & push certs, 2021-09-10) as breaking t4202 and t5534, while responsibility for t6200 seems to be 9d12546de9 (ssh signing:
fmt-merge-msg tests & config parse, 2021-10-12).
I've not yet done any investigation into the specifics of these failures, but I wanted to report them early so other folks could get on with investigating as appropriate.
Quoted 16 lines · Adam Dinwoodie
Quoted 12 lines · Fabian Stelzer
This series adds key lifetime validity checks by parsing commit/tag dates from the paylod and passing them to the ssh-keygen operations.
changes since v1:
- structsignature_checkis now used to input payload data intocheck_function
- payload metadata parsing is completely internal tocheck_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removedpayload_signerparameter. since we now use the struct we can extend this later.As part of testing v2.34-rc0 on Cygwin, I've found this patch series is breaking t4202, t5534, and t6200.
Quoted 8 lines
Specifically, bisecting points to
f265f2d630(ssh signing: tests for logs, tags & push certs, 2021-09-10) as breaking t4202 and t5534, while responsibility for t6200 seems to be9d12546de9(ssh signing:
fmt-merge-msg tests & config parse, 2021-10-12).I've not yet done any investigation into the specifics of these failures, but I wanted to report them early so other folks could get on with investigating as appropriate.
What exactly are you testing? This patch series is not patch of the rc and will not be in v2.34. I even have a small reroll of this for after the release.
I assume the breaking tests are the new ones added in these commits. What openssh version are you using? (ssh -V)
Either the feature detecion for the lifetime checks is not working in cygwin or maybe you have the broken openssh 8.7 version.
Quoted 22 lines · Fabian Stelzer
Quoted 21 lines · Adam Dinwoodie
Quoted 12 lines · Fabian Stelzer
This series adds key lifetime validity checks by parsing commit/tag dates from the paylod and passing them to the ssh-keygen operations.
changes since v1:
- structsignature_checkis now used to input payload data intocheck_function
- payload metadata parsing is completely internal tocheck_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removedpayload_signerparameter. since we now use the struct we can extend this later.As part of testing v2.34-rc0 on Cygwin, I've found this patch series is breaking t4202, t5534, and t6200.
Specifically, bisecting points to
f265f2d630(ssh signing: tests for logs, tags & push certs, 2021-09-10) as breaking t4202 and t5534, while responsibility for t6200 seems to be9d12546de9(ssh signing:
fmt-merge-msg tests & config parse, 2021-10-12).
Quoted 5 lines
Quoted 3 lines
I've not yet done any investigation into the specifics of these failures, but I wanted to report them early so other folks could get on with investigating as appropriate.
What exactly are you testing?
I was initially running the tests using the Cygwin packaging paraphernalia, as I want to check the full build infrastructure is working as expected. When this failed, I reproduced the problems on a clean checkout of the main Git repository. In particular, I identified the failing commits with the following bisect command (subject to obvious modifications to select the correct script):
git bisect start v2.34.0-rc0 v2.33.1 && git bisect run bash -c 'make -j 20 || exit 125; cd t || exit 125; ./t4202-*.sh'
Quoted 3 lines
This patch series is not patch of the rc
and will not be in v2.34. I even have a small reroll of this for after the release.
That's odd. git tag --contains 9d12546de9, with a fresh pull of the Git repo, lists v2.34.0-rc0 and v2.34.0-rc1. It sounds like that's not expected?
Quoted 1 line
I assume the breaking tests are the new ones added in these commits.
For t4202-log.sh, the failing tests are "72 - setup sshkey signed branch" and "75 - log ssh key fingerprint".
For t5534-push-signed.sh, the failing tests are "8 - ssh signed push sends push certificate" and "12 - fail without key and heed user.signingkey ssh".
For t6200-fmt-merge-msg.sh, the failing tests are "3 - created ssh signed commit and tag", "7 - message for merging local tag signed by good ssh key" and "8 - message for merging local tag signed by unknown ssh key".
Quoted 1 line
What openssh version are you using? (ssh -V)
OpenSSH_8.8p1, OpenSSL 1.1.1l 24 Aug 2021
Quoted 2 lines
Either the feature detecion for the lifetime checks is not working in cygwin or maybe you have the broken openssh 8.7 version.
Quoted 15 lines · Adam Dinwoodie
Quoted 14 lines · Fabian Stelzer
Quoted 13 lines · Adam Dinwoodie
Quoted 12 lines · Fabian Stelzer
This series adds key lifetime validity checks by parsing commit/tag dates from the paylod and passing them to the ssh-keygen operations.
changes since v1:
- structsignature_checkis now used to input payload data intocheck_function
- payload metadata parsing is completely internal tocheck_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removedpayload_signerparameter. since we now use the struct we can extend this later.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
As part of testing v2.34-rc0 on Cygwin, I've found this patch series is breaking t4202, t5534, and t6200.
Specifically, bisecting points to
f265f2d630(ssh signing: tests for logs, tags & push certs, 2021-09-10) as breaking t4202 and t5534, while responsibility for t6200 seems to be9d12546de9(ssh signing:
fmt-merge-msg tests & config parse, 2021-10-12).
Ok, i should have read this closer / checked the commit. The commit you are referring to is not part of 'this' patch series, but an earlier one which was indeed merged and part of the rc.
Quoted 11 lines
For
t4202-log.sh, the failing tests are "72 - setup sshkey signed branch" and "75 - log ssh key fingerprint".For
t5534-push-signed.sh, the failing tests are "8 - ssh signed push sends push certificate" and "12 - fail without key and heed user.signingkey ssh".For
t6200-fmt-merge-msg.sh, the failing tests are "3 - created ssh signed commit and tag", "7 - message for merging local tag signed by good ssh key" and "8 - message for merging local tag signed by unknown ssh key".
Could you send the full output of these tests directly to me? Best would be sth like the full output of
"GIT_TRACE=1 sh t4202-log.sh -vx"
and maybe for one test with the trash directory in a zip file (just run the test with -vix, it will stop at the first failure and leave the test files in place)
I don't have much experience on windows (especially not cygwin) but maybe i can spot the problem.
Quoted 4 lines
Quoted 2 lines
What openssh version are you using? (ssh -V)
OpenSSH_8.8p1, OpenSSL 1.1.1l 24 Aug 2021
That should be recent enough for this to work.
Quoted 19 lines · Fabian Stelzer
Quoted 18 lines · Adam Dinwoodie
Quoted 17 lines · Fabian Stelzer
Quoted 16 lines · Adam Dinwoodie
Quoted 12 lines · Fabian Stelzer
This series adds key lifetime validity checks by parsing commit/tag dates from the paylod and passing them to the ssh-keygen operations.
changes since v1:
- structsignature_checkis now used to input payload data intocheck_function
- payload metadata parsing is completely internal tocheck_signature. the caller only need to set the payload type in the sigc struct
- small nits and readability fixes
- removedpayload_signerparameter. since we now use the struct we can extend this later.As part of testing v2.34-rc0 on Cygwin, I've found this patch series is breaking t4202, t5534, and t6200.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Specifically, bisecting points to
f265f2d630(ssh signing: tests for logs, tags & push certs, 2021-09-10) as breaking t4202 and t5534, while responsibility for t6200 seems to be9d12546de9(ssh signing:
fmt-merge-msg tests & config parse, 2021-10-12).Ok, i should have read this closer / checked the commit. The commit you are referring to is not part of 'this' patch series, but an earlier one which was indeed merged and part of the rc.
Ah! That's at least in part on me then; I'd found the most recent thread that looked like it was related to this patch series, and assumed it'd be the one that was included, without checking the actual commit contents. Apologies!
Quoted 19 lines
Quoted 11 lines
For
t4202-log.sh, the failing tests are "72 - setup sshkey signed branch" and "75 - log ssh key fingerprint".For
t5534-push-signed.sh, the failing tests are "8 - ssh signed push sends push certificate" and "12 - fail without key and heed user.signingkey ssh".For
t6200-fmt-merge-msg.sh, the failing tests are "3 - created ssh signed commit and tag", "7 - message for merging local tag signed by good ssh key" and "8 - message for merging local tag signed by unknown ssh key".Could you send the full output of these tests directly to me? Best would be sth like the full output of
"GIT_TRACE=1 sht4202-log.sh-vx"
and maybe for one test with the trash directory in a zip file (just run the test with -vix, it will stop at the first failure and leave the test files in place)
Quoted 2 lines
I don't have much experience on windows (especially not cygwin) but maybe i can spot the problem.
I'll send these to you shortly.
I don't have much experience with any of Git's signing functions, so perhaps between us we might be able to get somewhere :)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
What openssh version are you using? (ssh -V)
OpenSSH_8.8p1, OpenSSL 1.1.1l 24 Aug 2021That should be recent enough for this to work.