{"thread":{"id":"57056","subject":"[PATCH v5.1 0/8] redo ssh-signing-key-lifetime topic","startedAt":"2021-12-08T23:43:16Z","lastAt":"2021-12-08T23:43:41Z","messageCount":9,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":5,"patchTotal":8},"messages":[{"id":"443538","messageId":"20211208234313.3052303-1-gitster@pobox.com","threadId":"57056","inReplyTo":null,"subject":"[PATCH v5.1 0/8] redo ssh-signing-key-lifetime topic","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:05Z","receivedAt":"2021-12-08T23:43:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"So, here is a quick attempt to move the fixes to the existing tests\nto the front as a preliminary clean-up as [1/8], and stop step [7/8]\n(used to be [6/8]) from copying the mistake we already cleaned in\n[1/8] from the beginning.\n\nNo other changes intended, although I think I fixed a typo in the\nproposed log message in [1/8] (the early half of the old [8/8]).\n\nFabian Stelzer (8):\n  t/fmt-merge-msg: make gpg/ssh tests more specific\n  ssh signing: use sigc struct to pass payload\n  ssh signing: add key lifetime test prereqs\n  ssh signing: make verify-commit consider key lifetime\n  ssh signing: make git log verify key lifetime\n  ssh signing: make verify-tag consider key lifetime\n  ssh signing: make fmt-merge-msg consider key lifetime\n  ssh signing: verify ssh-keygen in test prereq\n\n Documentation/config/gpg.txt     |  5 ++\n builtin/receive-pack.c           |  6 ++-\n commit.c                         |  6 ++-\n fmt-merge-msg.c                  |  5 +-\n gpg-interface.c                  | 90 +++++++++++++++++++++++++-------\n gpg-interface.h                  | 15 ++++--\n log-tree.c                       | 10 ++--\n t/lib-gpg.sh                     | 62 ++++++++++++++++++----\n t/t4202-log.sh                   | 43 +++++++++++++++\n t/t6200-fmt-merge-msg.sh         | 67 ++++++++++++++++++++++--\n t/t7031-verify-tag-signed-ssh.sh | 42 +++++++++++++++\n t/t7528-signed-commit-ssh.sh     | 42 +++++++++++++++\n tag.c                            |  5 +-\n 13 files changed, 350 insertions(+), 48 deletions(-)\n\n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443539","messageId":"20211208234313.3052303-2-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 1/8] t/fmt-merge-msg: make gpg/ssh tests more specific","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:06Z","receivedAt":"2021-12-08T23:43:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nAll the GPG and GPGSSH tests are redirecing stdout as well as stderr\nto `actual` and grep for success/failure over the resulting file.\nHowever, no output is printed on stderr and we do not need to\ninclude it in the grep.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t6200-fmt-merge-msg.sh | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex 06c5fb5615..b18ba58745 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -104,7 +104,7 @@ test_expect_success 'message for merging local branch' '\n test_expect_success GPG 'message for merging local tag signed by good key' '\n \tgit checkout main &&\n \tgit fetch . signed-good-tag &&\n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \tgrep \"^Merge tag ${apos}signed-good-tag${apos}\" actual &&\n \tgrep \"^# gpg: Signature made\" actual &&\n \tgrep \"^# gpg: Good signature from\" actual\n@@ -113,7 +113,7 @@ test_expect_success GPG 'message for merging local tag signed by good key' '\n test_expect_success GPG 'message for merging local tag signed by unknown key' '\n \tgit checkout main &&\n \tgit fetch . signed-good-tag &&\n-\tGNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&\n+\tGNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \tgrep \"^Merge tag ${apos}signed-good-tag${apos}\" actual &&\n \tgrep \"^# gpg: Signature made\" actual &&\n \tgrep -E \"^# gpg: Can${apos}t check signature: (public key not found|No public key)\" actual\n@@ -123,7 +123,7 @@ test_expect_success GPGSSH 'message for merging local tag signed by good ssh key\n \ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \tgit checkout main &&\n \tgit fetch . signed-good-ssh-tag &&\n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n \tgrep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual &&\n \t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual\n '\n@@ -132,7 +132,8 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh\n \ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \tgit checkout main &&\n \tgit fetch . signed-untrusted-ssh-tag &&\n-\tgit fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgrep \"^Merge tag ${apos}signed-untrusted-ssh-tag${apos}\" actual &&\n \tgrep \"${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}\" actual &&\n \t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual &&\n \tgrep \"${GPGSSH_KEY_NOT_TRUSTED}\" actual\n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443540","messageId":"20211208234313.3052303-3-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 2/8] ssh signing: use sigc struct to pass payload","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:07Z","receivedAt":"2021-12-08T23:43:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nTo be able to extend the payload metadata with things like its creation\ntimestamp or the creators ident we remove the payload parameters to\ncheck_signature() and use the already existing sigc->payload field\ninstead, only adding the length field to the struct. This also allows\nus to get rid of the xmemdupz() calls in the verify functions. Since\nsigc is now used to input data as well as output the result move it to\nthe front of the function list.\n\n - Add payload_length to struct signature_check\n - Populate sigc.payload/payload_len on all call sites\n - Remove payload parameters to check_signature()\n - Remove payload parameters to internal verify_* functions and use sigc\n   instead\n - Remove xmemdupz() used for verbose output since payload is now already\n   populated.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/receive-pack.c |  6 ++++--\n commit.c               |  5 +++--\n fmt-merge-msg.c        |  4 ++--\n gpg-interface.c        | 37 +++++++++++++++++--------------------\n gpg-interface.h        |  6 +++---\n log-tree.c             |  8 ++++----\n tag.c                  |  4 ++--\n 7 files changed, 35 insertions(+), 35 deletions(-)\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 49b846d960..61ab63c2ea 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -769,8 +769,10 @@ static void prepare_push_cert_sha1(struct child_process *proc)\n \t\tmemset(&sigcheck, '\\0', sizeof(sigcheck));\n \n \t\tbogs = parse_signed_buffer(push_cert.buf, push_cert.len);\n-\t\tcheck_signature(push_cert.buf, bogs, push_cert.buf + bogs,\n-\t\t\t\tpush_cert.len - bogs, &sigcheck);\n+\t\tsigcheck.payload = xmemdupz(push_cert.buf, bogs);\n+\t\tsigcheck.payload_len = bogs;\n+\t\tcheck_signature(&sigcheck, push_cert.buf + bogs,\n+\t\t\t\tpush_cert.len - bogs);\n \n \t\tnonce_status = check_nonce(push_cert.buf, bogs);\n \t}\ndiff --git a/commit.c b/commit.c\nindex 551de4903c..64e040a99b 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1212,8 +1212,9 @@ int check_commit_signature(const struct commit *commit, struct signature_check *\n \n \tif (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0)\n \t\tgoto out;\n-\tret = check_signature(payload.buf, payload.len, signature.buf,\n-\t\tsignature.len, sigc);\n+\n+\tsigc->payload = strbuf_detach(&payload, &sigc->payload_len);\n+\tret = check_signature(sigc, signature.buf, signature.len);\n \n  out:\n \tstrbuf_release(&payload);\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 5216191488..deca1ea3a3 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -533,8 +533,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)\n \t\telse {\n \t\t\tbuf = payload.buf;\n \t\t\tlen = payload.len;\n-\t\t\tif (check_signature(payload.buf, payload.len, sig.buf,\n-\t\t\t\t\t    sig.len, &sigc) &&\n+\t\t\tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n+\t\t\tif (check_signature(&sigc, sig.buf, sig.len) &&\n \t\t\t    !sigc.output)\n \t\t\t\tstrbuf_addstr(&sig, \"gpg verification failed.\\n\");\n \t\t\telse\ndiff --git a/gpg-interface.c b/gpg-interface.c\nindex 3e7255a2a9..75ab6faacb 100644\n--- a/gpg-interface.c\n+++ b/gpg-interface.c\n@@ -19,8 +19,8 @@ struct gpg_format {\n \tconst char **verify_args;\n \tconst char **sigs;\n \tint (*verify_signed_buffer)(struct signature_check *sigc,\n-\t\t\t\t    struct gpg_format *fmt, const char *payload,\n-\t\t\t\t    size_t payload_size, const char *signature,\n+\t\t\t\t    struct gpg_format *fmt,\n+\t\t\t\t    const char *signature,\n \t\t\t\t    size_t signature_size);\n \tint (*sign_buffer)(struct strbuf *buffer, struct strbuf *signature,\n \t\t\t   const char *signing_key);\n@@ -53,12 +53,12 @@ static const char *ssh_sigs[] = {\n };\n \n static int verify_gpg_signed_buffer(struct signature_check *sigc,\n-\t\t\t\t    struct gpg_format *fmt, const char *payload,\n-\t\t\t\t    size_t payload_size, const char *signature,\n+\t\t\t\t    struct gpg_format *fmt,\n+\t\t\t\t    const char *signature,\n \t\t\t\t    size_t signature_size);\n static int verify_ssh_signed_buffer(struct signature_check *sigc,\n-\t\t\t\t    struct gpg_format *fmt, const char *payload,\n-\t\t\t\t    size_t payload_size, const char *signature,\n+\t\t\t\t    struct gpg_format *fmt,\n+\t\t\t\t    const char *signature,\n \t\t\t\t    size_t signature_size);\n static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,\n \t\t\t   const char *signing_key);\n@@ -314,8 +314,8 @@ static void parse_gpg_output(struct signature_check *sigc)\n }\n \n static int verify_gpg_signed_buffer(struct signature_check *sigc,\n-\t\t\t\t    struct gpg_format *fmt, const char *payload,\n-\t\t\t\t    size_t payload_size, const char *signature,\n+\t\t\t\t    struct gpg_format *fmt,\n+\t\t\t\t    const char *signature,\n \t\t\t\t    size_t signature_size)\n {\n \tstruct child_process gpg = CHILD_PROCESS_INIT;\n@@ -343,14 +343,13 @@ static int verify_gpg_signed_buffer(struct signature_check *sigc,\n \t\t     NULL);\n \n \tsigchain_push(SIGPIPE, SIG_IGN);\n-\tret = pipe_command(&gpg, payload, payload_size, &gpg_stdout, 0,\n+\tret = pipe_command(&gpg, sigc->payload, sigc->payload_len, &gpg_stdout, 0,\n \t\t\t   &gpg_stderr, 0);\n \tsigchain_pop(SIGPIPE);\n \n \tdelete_tempfile(&temp);\n \n \tret |= !strstr(gpg_stdout.buf, \"\\n[GNUPG:] GOODSIG \");\n-\tsigc->payload = xmemdupz(payload, payload_size);\n \tsigc->output = strbuf_detach(&gpg_stderr, NULL);\n \tsigc->gpg_status = strbuf_detach(&gpg_stdout, NULL);\n \n@@ -426,8 +425,8 @@ static void parse_ssh_output(struct signature_check *sigc)\n }\n \n static int verify_ssh_signed_buffer(struct signature_check *sigc,\n-\t\t\t\t    struct gpg_format *fmt, const char *payload,\n-\t\t\t\t    size_t payload_size, const char *signature,\n+\t\t\t\t    struct gpg_format *fmt,\n+\t\t\t\t    const char *signature,\n \t\t\t\t    size_t signature_size)\n {\n \tstruct child_process ssh_keygen = CHILD_PROCESS_INIT;\n@@ -480,7 +479,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \t\t\t     \"-n\", \"git\",\n \t\t\t     \"-s\", buffer_file->filename.buf,\n \t\t\t     NULL);\n-\t\tpipe_command(&ssh_keygen, payload, payload_size,\n+\t\tpipe_command(&ssh_keygen, sigc->payload, sigc->payload_len,\n \t\t\t\t   &ssh_keygen_out, 0, &ssh_keygen_err, 0);\n \n \t\t/*\n@@ -526,7 +525,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \t\t\t}\n \n \t\t\tsigchain_push(SIGPIPE, SIG_IGN);\n-\t\t\tret = pipe_command(&ssh_keygen, payload, payload_size,\n+\t\t\tret = pipe_command(&ssh_keygen, sigc->payload, sigc->payload_len,\n \t\t\t\t\t   &ssh_keygen_out, 0, &ssh_keygen_err, 0);\n \t\t\tsigchain_pop(SIGPIPE);\n \n@@ -540,7 +539,6 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \t\t}\n \t}\n \n-\tsigc->payload = xmemdupz(payload, payload_size);\n \tstrbuf_stripspace(&ssh_keygen_out, 0);\n \tstrbuf_stripspace(&ssh_keygen_err, 0);\n \t/* Add stderr outputs to show the user actual ssh-keygen errors */\n@@ -562,8 +560,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \treturn ret;\n }\n \n-int check_signature(const char *payload, size_t plen, const char *signature,\n-\tsize_t slen, struct signature_check *sigc)\n+int check_signature(struct signature_check *sigc,\n+\t\t    const char *signature, size_t slen)\n {\n \tstruct gpg_format *fmt;\n \tint status;\n@@ -575,8 +573,7 @@ int check_signature(const char *payload, size_t plen, const char *signature,\n \tif (!fmt)\n \t\tdie(_(\"bad/incompatible signature '%s'\"), signature);\n \n-\tstatus = fmt->verify_signed_buffer(sigc, fmt, payload, plen, signature,\n-\t\t\t\t\t   slen);\n+\tstatus = fmt->verify_signed_buffer(sigc, fmt, signature, slen);\n \n \tif (status && !sigc->output)\n \t\treturn !!status;\n@@ -593,7 +590,7 @@ void print_signature_buffer(const struct signature_check *sigc, unsigned flags)\n \t\t\t\t\t\t\t    sigc->output;\n \n \tif (flags & GPG_VERIFY_VERBOSE && sigc->payload)\n-\t\tfputs(sigc->payload, stdout);\n+\t\tfwrite(sigc->payload, 1, sigc->payload_len, stdout);\n \n \tif (output)\n \t\tfputs(output, stderr);\ndiff --git a/gpg-interface.h b/gpg-interface.h\nindex beefacbb1e..5ee7d8b6b9 100644\n--- a/gpg-interface.h\n+++ b/gpg-interface.h\n@@ -17,6 +17,7 @@ enum signature_trust_level {\n \n struct signature_check {\n \tchar *payload;\n+\tsize_t payload_len;\n \tchar *output;\n \tchar *gpg_status;\n \n@@ -70,9 +71,8 @@ const char *get_signing_key(void);\n  * Either a GPG KeyID or a SSH Key Fingerprint\n  */\n const char *get_signing_key_id(void);\n-int check_signature(const char *payload, size_t plen,\n-\t\t    const char *signature, size_t slen,\n-\t\t    struct signature_check *sigc);\n+int check_signature(struct signature_check *sigc,\n+\t\t    const char *signature, size_t slen);\n void print_signature_buffer(const struct signature_check *sigc,\n \t\t\t    unsigned flags);\n \ndiff --git a/log-tree.c b/log-tree.c\nindex 644893fd8c..a46cf60e1e 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -513,8 +513,8 @@ static void show_signature(struct rev_info *opt, struct commit *commit)\n \tif (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0)\n \t\tgoto out;\n \n-\tstatus = check_signature(payload.buf, payload.len, signature.buf,\n-\t\t\t\t signature.len, &sigc);\n+\tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n+\tstatus = check_signature(&sigc, signature.buf, signature.len);\n \tif (status && !sigc.output)\n \t\tshow_sig_lines(opt, status, \"No signature\\n\");\n \telse\n@@ -583,8 +583,8 @@ static int show_one_mergetag(struct commit *commit,\n \tstatus = -1;\n \tif (parse_signature(extra->value, extra->len, &payload, &signature)) {\n \t\t/* could have a good signature */\n-\t\tstatus = check_signature(payload.buf, payload.len,\n-\t\t\t\t\t signature.buf, signature.len, &sigc);\n+\t\tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n+\t\tstatus = check_signature(&sigc, signature.buf, signature.len);\n \t\tif (sigc.output)\n \t\t\tstrbuf_addstr(&verify_message, sigc.output);\n \t\telse\ndiff --git a/tag.c b/tag.c\nindex 3e18a41841..62fb09f5a5 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -25,8 +25,8 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)\n \t\treturn error(\"no signature found\");\n \t}\n \n-\tret = check_signature(payload.buf, payload.len, signature.buf,\n-\t\t\t\tsignature.len, &sigc);\n+\tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n+\tret = check_signature(&sigc, signature.buf, signature.len);\n \n \tif (!(flags & GPG_VERIFY_OMIT_STATUS))\n \t\tprint_signature_buffer(&sigc, flags);\n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443541","messageId":"20211208234313.3052303-4-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 3/8] ssh signing: add key lifetime test prereqs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:08Z","receivedAt":"2021-12-08T23:43:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nif ssh-keygen supports -Overify-time, add test keys marked as expired,\nnot yet valid and valid both within the test_tick timeframe and outside of it.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/lib-gpg.sh | 19 ++++++++++++++++++-\n 1 file changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/t/lib-gpg.sh b/t/lib-gpg.sh\nindex a3f285f515..fc03c8f89b 100644\n--- a/t/lib-gpg.sh\n+++ b/t/lib-gpg.sh\n@@ -90,6 +90,10 @@ test_lazy_prereq RFC1991 '\n GPGSSH_KEY_PRIMARY=\"${GNUPGHOME}/ed25519_ssh_signing_key\"\n GPGSSH_KEY_SECONDARY=\"${GNUPGHOME}/rsa_2048_ssh_signing_key\"\n GPGSSH_KEY_UNTRUSTED=\"${GNUPGHOME}/untrusted_ssh_signing_key\"\n+GPGSSH_KEY_EXPIRED=\"${GNUPGHOME}/expired_ssh_signing_key\"\n+GPGSSH_KEY_NOTYETVALID=\"${GNUPGHOME}/notyetvalid_ssh_signing_key\"\n+GPGSSH_KEY_TIMEBOXEDVALID=\"${GNUPGHOME}/timeboxed_valid_ssh_signing_key\"\n+GPGSSH_KEY_TIMEBOXEDINVALID=\"${GNUPGHOME}/timeboxed_invalid_ssh_signing_key\"\n GPGSSH_KEY_WITH_PASSPHRASE=\"${GNUPGHOME}/protected_ssh_signing_key\"\n GPGSSH_KEY_PASSPHRASE=\"super_secret\"\n GPGSSH_ALLOWED_SIGNERS=\"${GNUPGHOME}/ssh.all_valid.allowedSignersFile\"\n@@ -119,7 +123,20 @@ test_lazy_prereq GPGSSH '\n \techo \"\\\"principal with number 2\\\" $(cat \"${GPGSSH_KEY_SECONDARY}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \tssh-keygen -t ed25519 -N \"${GPGSSH_KEY_PASSPHRASE}\" -C \"git ed25519 encrypted key\" -f \"${GPGSSH_KEY_WITH_PASSPHRASE}\" >/dev/null &&\n \techo \"\\\"principal with number 3\\\" $(cat \"${GPGSSH_KEY_WITH_PASSPHRASE}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n-\tssh-keygen -t ed25519 -N \"\" -f \"${GPGSSH_KEY_UNTRUSTED}\" >/dev/null\n+\tssh-keygen -t ed25519 -N \"\" -C \"git ed25519 key\" -f \"${GPGSSH_KEY_UNTRUSTED}\" >/dev/null\n+'\n+\n+test_lazy_prereq GPGSSH_VERIFYTIME '\n+\t# Check if ssh-keygen has a verify-time option by passing an invalid date to it\n+\tssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F \"Invalid \\\"verify-time\\\"\" &&\n+\tssh-keygen -t ed25519 -N \"\" -C \"timeboxed valid key\" -f \"${GPGSSH_KEY_TIMEBOXEDVALID}\" >/dev/null &&\n+\techo \"\\\"timeboxed valid key\\\" valid-after=\\\"20050407000000\\\",valid-before=\\\"200504100000\\\" $(cat \"${GPGSSH_KEY_TIMEBOXEDVALID}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tssh-keygen -t ed25519 -N \"\" -C \"timeboxed invalid key\" -f \"${GPGSSH_KEY_TIMEBOXEDINVALID}\" >/dev/null &&\n+\techo \"\\\"timeboxed invalid key\\\" valid-after=\\\"20050401000000\\\",valid-before=\\\"20050402000000\\\" $(cat \"${GPGSSH_KEY_TIMEBOXEDINVALID}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tssh-keygen -t ed25519 -N \"\" -C \"expired key\" -f \"${GPGSSH_KEY_EXPIRED}\" >/dev/null &&\n+\techo \"\\\"principal with expired key\\\" valid-before=\\\"20000101000000\\\" $(cat \"${GPGSSH_KEY_EXPIRED}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tssh-keygen -t ed25519 -N \"\" -C \"not yet valid key\" -f \"${GPGSSH_KEY_NOTYETVALID}\" >/dev/null &&\n+\techo \"\\\"principal with not yet valid key\\\" valid-after=\\\"29990101000000\\\" $(cat \"${GPGSSH_KEY_NOTYETVALID}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\"\n '\n \n sanitize_pgp() {\n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443542","messageId":"20211208234313.3052303-5-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 4/8] ssh signing: make verify-commit consider key lifetime","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:09Z","receivedAt":"2021-12-08T23:43:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nIf valid-before/after dates are configured for this signatures key in the\nallowedSigners file then the verification should check if the key was valid at\nthe time the commit was made. This allows for graceful key rollover and\nrevoking keys without invalidating all previous commits.\nThis feature needs openssh > 8.8. Older ssh-keygen versions will simply\nignore this flag and use the current time.\nStrictly speaking this feature is available in 8.7, but since 8.7 has a\nbug that makes it unusable in another needed call we require 8.8.\n\nTimestamp information is present on most invocations of check_signature.\nHowever signer ident is not. We will need the signer email / name to be able\nto implement \"Trust on first use\" functionality later.\nSince the payload contains all necessary information we can parse it\nfrom there. The caller only needs to provide us some info about the\npayload by setting payload_type in the signature_check struct.\n\n - Add payload_type field & enum and payload_timestamp to struct\n   signature_check\n - Populate the timestamp when not already set if we know about the\n   payload type\n - Pass -Overify-time={payload_timestamp} in the users timezone to all\n   ssh-keygen verification calls\n - Set the payload type when verifying commits\n - Add tests for expired, not yet valid and keys having a commit date\n   outside of key validity as well as within\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/config/gpg.txt |  5 ++++\n commit.c                     |  1 +\n gpg-interface.c              | 53 ++++++++++++++++++++++++++++++++++++\n gpg-interface.h              |  9 ++++++\n t/t7528-signed-commit-ssh.sh | 42 ++++++++++++++++++++++++++++\n 5 files changed, 110 insertions(+)\n\ndiff --git a/Documentation/config/gpg.txt b/Documentation/config/gpg.txt\nindex 4f30c7dbdd..c9be554c73 100644\n--- a/Documentation/config/gpg.txt\n+++ b/Documentation/config/gpg.txt\n@@ -64,6 +64,11 @@ A repository that only allows signed commits can store the file\n in the repository itself using a path relative to the top-level of the working tree.\n This way only committers with an already valid key can add or change keys in the keyring.\n +\n+Since OpensSSH 8.8 this file allows specifying a key lifetime using valid-after &\n+valid-before options. Git will mark signatures as valid if the signing key was\n+valid at the time of the signatures creation. This allows users to change a\n+signing key without invalidating all previously made signatures.\n++\n Using a SSH CA key with the cert-authority option\n (see ssh-keygen(1) \"CERTIFICATES\") is also valid.\n \ndiff --git a/commit.c b/commit.c\nindex 64e040a99b..a348f085b2 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1213,6 +1213,7 @@ int check_commit_signature(const struct commit *commit, struct signature_check *\n \tif (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0)\n \t\tgoto out;\n \n+\tsigc->payload_type = SIGNATURE_PAYLOAD_COMMIT;\n \tsigc->payload = strbuf_detach(&payload, &sigc->payload_len);\n \tret = check_signature(sigc, signature.buf, signature.len);\n \ndiff --git a/gpg-interface.c b/gpg-interface.c\nindex 75ab6faacb..330cfc5845 100644\n--- a/gpg-interface.c\n+++ b/gpg-interface.c\n@@ -439,6 +439,13 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \tstruct strbuf ssh_principals_err = STRBUF_INIT;\n \tstruct strbuf ssh_keygen_out = STRBUF_INIT;\n \tstruct strbuf ssh_keygen_err = STRBUF_INIT;\n+\tstruct strbuf verify_time = STRBUF_INIT;\n+\tconst struct date_mode verify_date_mode = {\n+\t\t.type = DATE_STRFTIME,\n+\t\t.strftime_fmt = \"%Y%m%d%H%M%S\",\n+\t\t/* SSH signing key validity has no timezone information - Use the local timezone */\n+\t\t.local = 1,\n+\t};\n \n \tif (!ssh_allowed_signers) {\n \t\terror(_(\"gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification\"));\n@@ -456,11 +463,16 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \t\treturn -1;\n \t}\n \n+\tif (sigc->payload_timestamp)\n+\t\tstrbuf_addf(&verify_time, \"-Overify-time=%s\",\n+\t\t\tshow_date(sigc->payload_timestamp, 0, &verify_date_mode));\n+\n \t/* Find the principal from the signers */\n \tstrvec_pushl(&ssh_keygen.args, fmt->program,\n \t\t     \"-Y\", \"find-principals\",\n \t\t     \"-f\", ssh_allowed_signers,\n \t\t     \"-s\", buffer_file->filename.buf,\n+\t\t     verify_time.buf,\n \t\t     NULL);\n \tret = pipe_command(&ssh_keygen, NULL, 0, &ssh_principals_out, 0,\n \t\t\t   &ssh_principals_err, 0);\n@@ -478,6 +490,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \t\t\t     \"-Y\", \"check-novalidate\",\n \t\t\t     \"-n\", \"git\",\n \t\t\t     \"-s\", buffer_file->filename.buf,\n+\t\t\t     verify_time.buf,\n \t\t\t     NULL);\n \t\tpipe_command(&ssh_keygen, sigc->payload, sigc->payload_len,\n \t\t\t\t   &ssh_keygen_out, 0, &ssh_keygen_err, 0);\n@@ -512,6 +525,7 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \t\t\t\t     \"-f\", ssh_allowed_signers,\n \t\t\t\t     \"-I\", principal,\n \t\t\t\t     \"-s\", buffer_file->filename.buf,\n+\t\t\t\t     verify_time.buf,\n \t\t\t\t     NULL);\n \n \t\t\tif (ssh_revocation_file) {\n@@ -556,10 +570,46 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,\n \tstrbuf_release(&ssh_principals_err);\n \tstrbuf_release(&ssh_keygen_out);\n \tstrbuf_release(&ssh_keygen_err);\n+\tstrbuf_release(&verify_time);\n \n \treturn ret;\n }\n \n+static int parse_payload_metadata(struct signature_check *sigc)\n+{\n+\tconst char *ident_line = NULL;\n+\tsize_t ident_len;\n+\tstruct ident_split ident;\n+\tconst char *signer_header;\n+\n+\tswitch (sigc->payload_type) {\n+\tcase SIGNATURE_PAYLOAD_COMMIT:\n+\t\tsigner_header = \"committer\";\n+\t\tbreak;\n+\tcase SIGNATURE_PAYLOAD_TAG:\n+\t\tsigner_header = \"tagger\";\n+\t\tbreak;\n+\tcase SIGNATURE_PAYLOAD_UNDEFINED:\n+\tcase SIGNATURE_PAYLOAD_PUSH_CERT:\n+\t\t/* Ignore payloads we don't want to parse */\n+\t\treturn 0;\n+\tdefault:\n+\t\tBUG(\"invalid value for sigc->payload_type\");\n+\t}\n+\n+\tident_line = find_commit_header(sigc->payload, signer_header, &ident_len);\n+\tif (!ident_line || !ident_len)\n+\t\treturn 1;\n+\n+\tif (split_ident_line(&ident, ident_line, ident_len))\n+\t\treturn 1;\n+\n+\tif (!sigc->payload_timestamp && ident.date_begin && ident.date_end)\n+\t\tsigc->payload_timestamp = parse_timestamp(ident.date_begin, NULL, 10);\n+\n+\treturn 0;\n+}\n+\n int check_signature(struct signature_check *sigc,\n \t\t    const char *signature, size_t slen)\n {\n@@ -573,6 +623,9 @@ int check_signature(struct signature_check *sigc,\n \tif (!fmt)\n \t\tdie(_(\"bad/incompatible signature '%s'\"), signature);\n \n+\tif (parse_payload_metadata(sigc))\n+\t\treturn 1;\n+\n \tstatus = fmt->verify_signed_buffer(sigc, fmt, signature, slen);\n \n \tif (status && !sigc->output)\ndiff --git a/gpg-interface.h b/gpg-interface.h\nindex 5ee7d8b6b9..b30cbdcd3d 100644\n--- a/gpg-interface.h\n+++ b/gpg-interface.h\n@@ -15,9 +15,18 @@ enum signature_trust_level {\n \tTRUST_ULTIMATE,\n };\n \n+enum payload_type {\n+\tSIGNATURE_PAYLOAD_UNDEFINED,\n+\tSIGNATURE_PAYLOAD_COMMIT,\n+\tSIGNATURE_PAYLOAD_TAG,\n+\tSIGNATURE_PAYLOAD_PUSH_CERT,\n+};\n+\n struct signature_check {\n \tchar *payload;\n \tsize_t payload_len;\n+\tenum payload_type payload_type;\n+\ttimestamp_t payload_timestamp;\n \tchar *output;\n \tchar *gpg_status;\n \ndiff --git a/t/t7528-signed-commit-ssh.sh b/t/t7528-signed-commit-ssh.sh\nindex badf3ed320..dae76ded0c 100755\n--- a/t/t7528-signed-commit-ssh.sh\n+++ b/t/t7528-signed-commit-ssh.sh\n@@ -76,6 +76,23 @@ test_expect_success GPGSSH 'create signed commits' '\n \tgit tag twelfth-signed-alt $(cat oid)\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed commits with keys having defined lifetimes' '\n+\ttest_when_finished \"test_unconfig commit.gpgsign\" &&\n+\ttest_config gpg.format ssh &&\n+\n+\techo expired >file && test_tick && git commit -a -m expired -S\"${GPGSSH_KEY_EXPIRED}\" &&\n+\tgit tag expired-signed &&\n+\n+\techo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S\"${GPGSSH_KEY_NOTYETVALID}\" &&\n+\tgit tag notyetvalid-signed &&\n+\n+\techo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S\"${GPGSSH_KEY_TIMEBOXEDVALID}\" &&\n+\tgit tag timeboxedvalid-signed &&\n+\n+\techo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S\"${GPGSSH_KEY_TIMEBOXEDINVALID}\" &&\n+\tgit tag timeboxedinvalid-signed\n+'\n+\n test_expect_success GPGSSH 'verify and show signatures' '\n \ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \ttest_config gpg.mintrustlevel UNDEFINED &&\n@@ -122,6 +139,31 @@ test_expect_success GPGSSH 'verify-commit exits failure on untrusted signature'\n \tgrep \"${GPGSSH_KEY_NOT_TRUSTED}\" actual\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-commit exits failure on expired signature key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\ttest_must_fail git verify-commit expired-signed 2>actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-commit exits failure on not yet valid signature key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\ttest_must_fail git verify-commit notyetvalid-signed 2>actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-commit succeeds with commit date and key validity matching' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit verify-commit timeboxedvalid-signed 2>actual &&\n+\tgrep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual &&\n+\t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-commit exits failure with commit date outside of key validity' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\ttest_must_fail git verify-commit timeboxedinvalid-signed 2>actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n test_expect_success GPGSSH 'verify-commit exits success with matching minTrustLevel' '\n \ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \ttest_config gpg.minTrustLevel fully &&\n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443543","messageId":"20211208234313.3052303-6-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 5/8] ssh signing: make git log verify key lifetime","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:10Z","receivedAt":"2021-12-08T23:43:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nSet the payload_type for check_signature() when calling git log.\nImplements the same tests as for verify-commit.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n log-tree.c     |  2 ++\n t/t4202-log.sh | 43 +++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 45 insertions(+)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex a46cf60e1e..d3e7a40b64 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -513,6 +513,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)\n \tif (parse_signed_commit(commit, &payload, &signature, the_hash_algo) <= 0)\n \t\tgoto out;\n \n+\tsigc.payload_type = SIGNATURE_PAYLOAD_COMMIT;\n \tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n \tstatus = check_signature(&sigc, signature.buf, signature.len);\n \tif (status && !sigc.output)\n@@ -583,6 +584,7 @@ static int show_one_mergetag(struct commit *commit,\n \tstatus = -1;\n \tif (parse_signature(extra->value, extra->len, &payload, &signature)) {\n \t\t/* could have a good signature */\n+\t\tsigc.payload_type = SIGNATURE_PAYLOAD_TAG;\n \t\tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n \t\tstatus = check_signature(&sigc, signature.buf, signature.len);\n \t\tif (sigc.output)\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex 7884e3d46b..ba855ec893 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -1677,6 +1677,24 @@ test_expect_success GPGSSH 'setup sshkey signed branch' '\n \tgit commit -S -m signed_commit\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed commits with keys having defined lifetimes' '\n+\ttest_config gpg.format ssh &&\n+\ttouch file &&\n+\tgit add file &&\n+\n+\techo expired >file && test_tick && git commit -a -m expired -S\"${GPGSSH_KEY_EXPIRED}\" &&\n+\tgit tag expired-signed &&\n+\n+\techo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S\"${GPGSSH_KEY_NOTYETVALID}\" &&\n+\tgit tag notyetvalid-signed &&\n+\n+\techo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S\"${GPGSSH_KEY_TIMEBOXEDVALID}\" &&\n+\tgit tag timeboxedvalid-signed &&\n+\n+\techo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S\"${GPGSSH_KEY_TIMEBOXEDINVALID}\" &&\n+\tgit tag timeboxedinvalid-signed\n+'\n+\n test_expect_success GPGSM 'log x509 fingerprint' '\n \techo \"F8BF62E0693D0694816377099909C779FA23FD65 | \" >expect &&\n \tgit log -n1 --format=\"%GF | %GP\" signed-x509 >actual &&\n@@ -1714,6 +1732,31 @@ test_expect_success GPGSSH 'log --graph --show-signature ssh' '\n \tgrep \"${GOOD_SIGNATURE_TRUSTED}\" actual\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure on expired signature key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit log --graph --show-signature -n1 expired-signed >actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure on not yet valid signature key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit log --graph --show-signature -n1 notyetvalid-signed >actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log show success with commit date and key validity matching' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit log --graph --show-signature -n1 timeboxedvalid-signed >actual &&\n+\tgrep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual &&\n+\t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'log shows failure with commit date outside of key validity' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit log --graph --show-signature -n1 timeboxedinvalid-signed >actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n test_expect_success GPG 'log --graph --show-signature for merged tag' '\n \ttest_when_finished \"git reset --hard && git checkout main\" &&\n \tgit checkout -b plain main &&\n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443544","messageId":"20211208234313.3052303-7-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 6/8] ssh signing: make verify-tag consider key lifetime","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:11Z","receivedAt":"2021-12-08T23:43:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nSet the payload_type for check_signature() when calling verify-tag.\nImplements the same tests as for verify-commit.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t7031-verify-tag-signed-ssh.sh | 42 ++++++++++++++++++++++++++++++++\n tag.c                            |  1 +\n 2 files changed, 43 insertions(+)\n\ndiff --git a/t/t7031-verify-tag-signed-ssh.sh b/t/t7031-verify-tag-signed-ssh.sh\nindex 06c9dd6c93..1cb36b9ab8 100755\n--- a/t/t7031-verify-tag-signed-ssh.sh\n+++ b/t/t7031-verify-tag-signed-ssh.sh\n@@ -48,6 +48,23 @@ test_expect_success GPGSSH 'create signed tags ssh' '\n \tgit tag -u\"${GPGSSH_KEY_UNTRUSTED}\" -m eighth eighth-signed-alt\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '\n+\ttest_when_finished \"test_unconfig commit.gpgsign\" &&\n+\ttest_config gpg.format ssh &&\n+\n+\techo expired >file && test_tick && git commit -a -m expired -S\"${GPGSSH_KEY_EXPIRED}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_EXPIRED}\" -m expired-signed expired-signed &&\n+\n+\techo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S\"${GPGSSH_KEY_NOTYETVALID}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_NOTYETVALID}\" -m notyetvalid-signed notyetvalid-signed &&\n+\n+\techo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S\"${GPGSSH_KEY_TIMEBOXEDVALID}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_TIMEBOXEDVALID}\" -m timeboxedvalid-signed timeboxedvalid-signed &&\n+\n+\techo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S\"${GPGSSH_KEY_TIMEBOXEDINVALID}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_TIMEBOXEDINVALID}\" -m timeboxedinvalid-signed timeboxedinvalid-signed\n+'\n+\n test_expect_success GPGSSH 'verify and show ssh signatures' '\n \ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \t(\n@@ -80,6 +97,31 @@ test_expect_success GPGSSH 'verify and show ssh signatures' '\n \t)\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on expired signature key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\ttest_must_fail git verify-tag expired-signed 2>actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag exits failure on not yet valid signature key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\ttest_must_fail git verify-tag notyetvalid-signed 2>actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag succeeds with tag date and key validity matching' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit verify-tag timeboxedvalid-signed 2>actual &&\n+\tgrep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual &&\n+\t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'verify-tag failes with tag date outside of key validity' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\ttest_must_fail git verify-tag timeboxedinvalid-signed 2>actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n test_expect_success GPGSSH 'detect fudged ssh signature' '\n \ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \tgit cat-file tag seventh-signed >raw &&\ndiff --git a/tag.c b/tag.c\nindex 62fb09f5a5..dfbcd7fcc2 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -25,6 +25,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)\n \t\treturn error(\"no signature found\");\n \t}\n \n+\tsigc.payload_type = SIGNATURE_PAYLOAD_TAG;\n \tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n \tret = check_signature(&sigc, signature.buf, signature.len);\n \n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443545","messageId":"20211208234313.3052303-8-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 7/8] ssh signing: make fmt-merge-msg consider key lifetime","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:12Z","receivedAt":"2021-12-08T23:43:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nSet the payload_type for check_signature() when generating merge messages to\nverify merged tags signatures key lifetimes.\nImplements the same tests as for verify-commit.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n fmt-merge-msg.c          |  1 +\n t/t6200-fmt-merge-msg.sh | 58 ++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 59 insertions(+)\n\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex deca1ea3a3..e4f7810be2 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -533,6 +533,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)\n \t\telse {\n \t\t\tbuf = payload.buf;\n \t\t\tlen = payload.len;\n+\t\t\tsigc.payload_type = SIGNATURE_PAYLOAD_TAG;\n \t\t\tsigc.payload = strbuf_detach(&payload, &sigc.payload_len);\n \t\t\tif (check_signature(&sigc, sig.buf, sig.len) &&\n \t\t\t    !sigc.output)\ndiff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh\nindex b18ba58745..12a1e62bf0 100755\n--- a/t/t6200-fmt-merge-msg.sh\n+++ b/t/t6200-fmt-merge-msg.sh\n@@ -91,6 +91,26 @@ test_expect_success GPGSSH 'created ssh signed commit and tag' '\n \tgit tag -s -u\"${GPGSSH_KEY_UNTRUSTED}\" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left\n '\n \n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' '\n+\ttest_when_finished \"test_unconfig commit.gpgsign\" &&\n+\ttest_config gpg.format ssh &&\n+\tgit checkout -b signed-expiry-ssh &&\n+\ttouch file &&\n+\tgit add file &&\n+\n+\techo expired >file && test_tick && git commit -a -m expired -S\"${GPGSSH_KEY_EXPIRED}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_EXPIRED}\" -m expired-signed expired-signed &&\n+\n+\techo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S\"${GPGSSH_KEY_NOTYETVALID}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_NOTYETVALID}\" -m notyetvalid-signed notyetvalid-signed &&\n+\n+\techo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S\"${GPGSSH_KEY_TIMEBOXEDVALID}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_TIMEBOXEDVALID}\" -m timeboxedvalid-signed timeboxedvalid-signed &&\n+\n+\techo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S\"${GPGSSH_KEY_TIMEBOXEDINVALID}\" &&\n+\tgit tag -s -u \"${GPGSSH_KEY_TIMEBOXEDINVALID}\" -m timeboxedinvalid-signed timeboxedinvalid-signed\n+'\n+\n test_expect_success 'message for merging local branch' '\n \techo \"Merge branch ${apos}left${apos}\" >expected &&\n \n@@ -138,6 +158,44 @@ test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh\n \t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual &&\n \tgrep \"${GPGSSH_KEY_NOT_TRUSTED}\" actual\n '\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit checkout main &&\n+\tgit fetch . expired-signed &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgrep \"^Merge tag ${apos}expired-signed${apos}\" actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit checkout main &&\n+\tgit fetch . notyetvalid-signed &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgrep \"^Merge tag ${apos}notyetvalid-signed${apos}\" actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit checkout main &&\n+\tgit fetch . timeboxedvalid-signed &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgrep \"^Merge tag ${apos}timeboxedvalid-signed${apos}\" actual &&\n+\tgrep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual &&\n+\t! grep \"${GPGSSH_BAD_SIGNATURE}\" actual\n+'\n+\n+test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' '\n+\ttest_config gpg.ssh.allowedSignersFile \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tgit checkout main &&\n+\tgit fetch . timeboxedinvalid-signed &&\n+\tgit fmt-merge-msg <.git/FETCH_HEAD >actual &&\n+\tgrep \"^Merge tag ${apos}timeboxedinvalid-signed${apos}\" actual &&\n+\t! grep \"${GPGSSH_GOOD_SIGNATURE_TRUSTED}\" actual\n+'\n+\n test_expect_success 'message for merging external branch' '\n \techo \"Merge branch ${apos}left${apos} of $(pwd)\" >expected &&\n \n-- \n2.34.1-365-gae484d3562\n\n"},{"id":"443546","messageId":"20211208234313.3052303-9-gitster@pobox.com","threadId":"57056","inReplyTo":"20211208234313.3052303-1-gitster@pobox.com","subject":"[PATCH v5.1 8/8] ssh signing: verify ssh-keygen in test prereq","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-12-08T23:43:13Z","receivedAt":"2021-12-08T23:43:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Fabian Stelzer <fs@gigacodes.de>\n\nDo a full ssh signing, find-principals and verify operation in the test\nprereq's to make sure ssh-keygen works as expected. Only generating the\nkeys and verifying its presence is not sufficient in some situations.\nOne example was ssh-keygen creating unusable ssh keys in cygwin because\nof unsafe default permissions for the key files. The other a broken\nopenssh 8.7 that segfaulted on any find-principals operation. This\nextended prereq check avoids future test breakages in case ssh-keygen or\nany environment behaviour changes.\n\nSigned-off-by: Fabian Stelzer <fs@gigacodes.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/lib-gpg.sh | 53 +++++++++++++++++++++++++++++++++++++++-------------\n 1 file changed, 40 insertions(+), 13 deletions(-)\n\ndiff --git a/t/lib-gpg.sh b/t/lib-gpg.sh\nindex fc03c8f89b..3fadfcb306 100644\n--- a/t/lib-gpg.sh\n+++ b/t/lib-gpg.sh\n@@ -109,34 +109,61 @@ test_lazy_prereq GPGSSH '\n \techo $ssh_version | grep -q \"find-principals:missing signature file\"\n \ttest $? = 0 || exit 1;\n \n-\t# some broken versions of ssh-keygen segfault on find-principals;\n-\t# avoid testing with them.\n-\tssh-keygen -Y find-principals -f /dev/null -s /dev/null\n-\ttest $? = 139 && exit 1\n-\n+\t# Setup some keys and an allowed signers file\n \tmkdir -p \"${GNUPGHOME}\" &&\n \tchmod 0700 \"${GNUPGHOME}\" &&\n \t(setfacl -k \"${GNUPGHOME}\" 2>/dev/null || true) &&\n \tssh-keygen -t ed25519 -N \"\" -C \"git ed25519 key\" -f \"${GPGSSH_KEY_PRIMARY}\" >/dev/null &&\n-\techo \"\\\"principal with number 1\\\" $(cat \"${GPGSSH_KEY_PRIMARY}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \tssh-keygen -t rsa -b 2048 -N \"\" -C \"git rsa2048 key\" -f \"${GPGSSH_KEY_SECONDARY}\" >/dev/null &&\n-\techo \"\\\"principal with number 2\\\" $(cat \"${GPGSSH_KEY_SECONDARY}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n \tssh-keygen -t ed25519 -N \"${GPGSSH_KEY_PASSPHRASE}\" -C \"git ed25519 encrypted key\" -f \"${GPGSSH_KEY_WITH_PASSPHRASE}\" >/dev/null &&\n-\techo \"\\\"principal with number 3\\\" $(cat \"${GPGSSH_KEY_WITH_PASSPHRASE}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n-\tssh-keygen -t ed25519 -N \"\" -C \"git ed25519 key\" -f \"${GPGSSH_KEY_UNTRUSTED}\" >/dev/null\n+\tssh-keygen -t ed25519 -N \"\" -C \"git ed25519 key\" -f \"${GPGSSH_KEY_UNTRUSTED}\" >/dev/null &&\n+\n+\tcat >\"${GPGSSH_ALLOWED_SIGNERS}\" <<-EOF &&\n+\t\"principal with number 1\" $(cat \"${GPGSSH_KEY_PRIMARY}.pub\")\"\n+\t\"principal with number 2\" $(cat \"${GPGSSH_KEY_SECONDARY}.pub\")\"\n+\t\"principal with number 3\" $(cat \"${GPGSSH_KEY_WITH_PASSPHRASE}.pub\")\"\n+\tEOF\n+\n+\t# Verify if at least one key and ssh-keygen works as expected\n+\techo \"testpayload\" |\n+\tssh-keygen -Y sign -n \"git\" -f \"${GPGSSH_KEY_PRIMARY}\" >gpgssh_prereq.sig &&\n+\tssh-keygen -Y find-principals -f \"${GPGSSH_ALLOWED_SIGNERS}\" -s gpgssh_prereq.sig &&\n+\techo \"testpayload\" |\n+\tssh-keygen -Y verify -n \"git\" -f \"${GPGSSH_ALLOWED_SIGNERS}\" -I \"principal with number 1\" -s gpgssh_prereq.sig\n '\n \n test_lazy_prereq GPGSSH_VERIFYTIME '\n \t# Check if ssh-keygen has a verify-time option by passing an invalid date to it\n \tssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F \"Invalid \\\"verify-time\\\"\" &&\n+\n+\t# Set up keys with key lifetimes\n \tssh-keygen -t ed25519 -N \"\" -C \"timeboxed valid key\" -f \"${GPGSSH_KEY_TIMEBOXEDVALID}\" >/dev/null &&\n-\techo \"\\\"timeboxed valid key\\\" valid-after=\\\"20050407000000\\\",valid-before=\\\"200504100000\\\" $(cat \"${GPGSSH_KEY_TIMEBOXEDVALID}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tkey_valid=$(cat \"${GPGSSH_KEY_TIMEBOXEDVALID}.pub\") &&\n \tssh-keygen -t ed25519 -N \"\" -C \"timeboxed invalid key\" -f \"${GPGSSH_KEY_TIMEBOXEDINVALID}\" >/dev/null &&\n-\techo \"\\\"timeboxed invalid key\\\" valid-after=\\\"20050401000000\\\",valid-before=\\\"20050402000000\\\" $(cat \"${GPGSSH_KEY_TIMEBOXEDINVALID}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tkey_invalid=$(cat \"${GPGSSH_KEY_TIMEBOXEDINVALID}.pub\") &&\n \tssh-keygen -t ed25519 -N \"\" -C \"expired key\" -f \"${GPGSSH_KEY_EXPIRED}\" >/dev/null &&\n-\techo \"\\\"principal with expired key\\\" valid-before=\\\"20000101000000\\\" $(cat \"${GPGSSH_KEY_EXPIRED}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\" &&\n+\tkey_expired=$(cat \"${GPGSSH_KEY_EXPIRED}.pub\") &&\n \tssh-keygen -t ed25519 -N \"\" -C \"not yet valid key\" -f \"${GPGSSH_KEY_NOTYETVALID}\" >/dev/null &&\n-\techo \"\\\"principal with not yet valid key\\\" valid-after=\\\"29990101000000\\\" $(cat \"${GPGSSH_KEY_NOTYETVALID}.pub\")\" >> \"${GPGSSH_ALLOWED_SIGNERS}\"\n+\tkey_notyetvalid=$(cat \"${GPGSSH_KEY_NOTYETVALID}.pub\") &&\n+\n+\t# Timestamps outside of test_tick span\n+\tts2005a=20050401000000 ts2005b=200504020000 &&\n+\t# Timestamps within test_tick span\n+\tts2005c=20050407000000 ts2005d=200504100000 &&\n+\t# Definitely not yet valid / expired timestamps\n+\tts2000=20000101000000 ts2999=29990101000000 &&\n+\n+\tcat >>\"${GPGSSH_ALLOWED_SIGNERS}\" <<-EOF &&\n+\t\"timeboxed valid key\" valid-after=\"$ts2005c\",valid-before=\"$ts2005d\" $key_valid\"\n+\t\"timeboxed invalid key\" valid-after=\"$ts2005a\",valid-before=\"$ts2005b\" $key_invalid\"\n+\t\"principal with expired key\" valid-before=\"$ts2000\" $key_expired\"\n+\t\"principal with not yet valid key\" valid-after=\"$ts2999\" $key_notyetvalid\"\n+\tEOF\n+\n+\t# and verify ssh-keygen verifies the key lifetime\n+\techo \"testpayload\" |\n+\tssh-keygen -Y sign -n \"git\" -f \"${GPGSSH_KEY_EXPIRED}\" >gpgssh_verifytime_prereq.sig &&\n+\t! (ssh-keygen -Y verify -n \"git\" -f \"${GPGSSH_ALLOWED_SIGNERS}\" -I \"principal with expired key\" -s gpgssh_verifytime_prereq.sig)\n '\n \n sanitize_pgp() {\n-- \n2.34.1-365-gae484d3562\n\n"}]}