707
return 0;
708
}
709
710
+/*
711
+ * Returns 1 if `string` contains a literal ssh key, 0 otherwise
712
+ * `key` will be set to the start of the actual key if a prefix is present.
713
+ */
714
+static int is_literal_ssh_key(const char *string, const char **key)
715
+{
716
+ if (skip_prefix(string, "key::", key))
717
+ return 1;
718
+ if (starts_with(string, "ssh-")) {
719
+ *key = string;
720
+ return 1;
721
+ }
722
+ return 0;
723
+}
724
+
725
static char *get_ssh_key_fingerprint(const char *signing_key)
726
{
727
struct child_process ssh_keygen = CHILD_PROCESS_INIT;
729
struct strbuf fingerprint_stdout = STRBUF_INIT;
730
struct strbuf **fingerprint;
731
char *fingerprint_ret;
732
+ const char *literal_key = NULL;
733
734
/*
735
* With SSH Signing this can contain a filename or a public key
736
* For textual representation we usually want a fingerprint
737
*/
722
- if (starts_with(signing_key, "ssh-")) {
738
+ if (is_literal_ssh_key(signing_key, &literal_key)) {
739
strvec_pushl(&ssh_keygen.args, "ssh-keygen", "-lf", "-", NULL);
724
- ret = pipe_command(&ssh_keygen, signing_key,
725
- strlen(signing_key), &fingerprint_stdout, 0,
740
+ ret = pipe_command(&ssh_keygen, literal_key,
741
+ strlen(literal_key), &fingerprint_stdout, 0,
742
NULL, 0);
743
} else {
744
strvec_pushl(&ssh_keygen.args, "ssh-keygen", "-lf",
773
const char **argv;
774
int n;
775
char *default_key = NULL;
776
+ const char *literal_key = NULL;
777
778
if (!ssh_default_key_command)
779
die(_("either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured"));
791
792
if (!ret) {
793
keys = strbuf_split_max(&key_stdout, '\n', 2);
777
- if (keys[0] && starts_with(keys[0]->buf, "ssh-")) {
794
+ if (keys[0] && is_literal_ssh_key(keys[0]->buf, &literal_key)) {
795
+ /*
796
+ * We only use `is_literal_ssh_key` here to check validity
797
+ * The prefix will be stripped when the key is used.
798
+ */
799
default_key = strbuf_detach(keys[0], NULL);
800
} else {
801
warning(_("gpg.ssh.defaultKeyCommand succeeded but returned no keys: %s %s"),
910
struct tempfile *key_file = NULL, *buffer_file = NULL;
911
char *ssh_signing_key_file = NULL;
912
struct strbuf ssh_signature_filename = STRBUF_INIT;
913
+ const char *literal_key = NULL;
914
915
if (!signing_key || signing_key[0] == '\0')
916
return error(
917
_("user.signingkey needs to be set for ssh signing"));
918
897
- if (starts_with(signing_key, "ssh-")) {
919
+ if (is_literal_ssh_key(signing_key, &literal_key)) {
920
/* A literal ssh key */
921
key_file = mks_tempfile_t(".git_signing_key_tmpXXXXXX");
922
if (!key_file)
923
return error_errno(
924
_("could not create temporary file"));
903
- keylen = strlen(signing_key);
904
- if (write_in_full(key_file->fd, signing_key, keylen) < 0 ||
925
+ keylen = strlen(literal_key);
926
+ if (write_in_full(key_file->fd, literal_key, keylen) < 0 ||
927
close_tempfile_gently(key_file) < 0) {
928
error_errno(_("failed writing ssh signing key to '%s'"),
929
key_file->filename.buf);