From: Fabian Stelzer via GitGitGadget Date: Wed, 14 Jul 2021 12:10:07 GMT Subject: [PATCH v3 3/9] ssh signing: retrieve a default key from ssh-agent Message-ID: In-Reply-To: From: Fabian Stelzer calls ssh-add -L and uses the first key Signed-off-by: Fabian Stelzer --- gpg-interface.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gpg-interface.c b/gpg-interface.c index 3c9a48c8e7e..c956ed87475 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -467,6 +467,23 @@ int git_gpg_config(const char *var, const char *value, void *cb) return 0; } +/* Returns the first public key from an ssh-agent to use for signing */ +static char *get_default_ssh_signing_key(void) { + struct child_process ssh_add = CHILD_PROCESS_INIT; + int ret = -1; + struct strbuf key_stdout = STRBUF_INIT; + struct strbuf **keys; + + strvec_pushl(&ssh_add.args, "ssh-add", "-L", NULL); + ret = pipe_command(&ssh_add, NULL, 0, &key_stdout, 0, NULL, 0); + if (!ret) { + keys = strbuf_split_max(&key_stdout, '\n', 2); + if (keys[0]) + return strbuf_detach(keys[0], NULL); + } + + return ""; +} const char *get_signing_key(void) { if (configured_signing_key) -- gitgitgadget