Returns the first public key from an ssh-agent to use for signing */
| 870 | |
| 871 | /* Returns the first public key from an ssh-agent to use for signing */ |
| 872 | static char *get_default_ssh_signing_key(void) |
| 873 | { |
| 874 | struct child_process ssh_default_key = CHILD_PROCESS_INIT; |
| 875 | int ret = -1; |
| 876 | struct strbuf key_stdout = STRBUF_INIT, key_stderr = STRBUF_INIT; |
| 877 | char *key_command = NULL; |
| 878 | const char **argv; |
| 879 | int n; |
| 880 | char *default_key = NULL; |
| 881 | const char *literal_key = NULL; |
| 882 | char *begin, *new_line, *first_line; |
| 883 | |
| 884 | if (!ssh_default_key_command) |
| 885 | die(_("either user.signingkey or gpg.ssh.defaultKeyCommand needs to be configured")); |
| 886 | |
| 887 | key_command = xstrdup(ssh_default_key_command); |
| 888 | n = split_cmdline(key_command, &argv); |
| 889 | |
| 890 | if (n < 0) |
| 891 | die(_("malformed build-time gpg.ssh.defaultKeyCommand: %s"), |
| 892 | split_cmdline_strerror(n)); |
| 893 | |
| 894 | strvec_pushv(&ssh_default_key.args, argv); |
| 895 | ret = pipe_command(&ssh_default_key, NULL, 0, &key_stdout, 0, |
| 896 | &key_stderr, 0); |
| 897 | |
| 898 | if (!ret) { |
| 899 | begin = key_stdout.buf; |
| 900 | new_line = strchr(begin, '\n'); |
| 901 | if (new_line) |
| 902 | first_line = xmemdupz(begin, new_line - begin); |
| 903 | else |
| 904 | first_line = xstrdup(begin); |
| 905 | if (is_literal_ssh_key(first_line, &literal_key)) { |
| 906 | /* |
| 907 | * We only use `is_literal_ssh_key` here to check validity |
| 908 | * The prefix will be stripped when the key is used. |
| 909 | */ |
| 910 | default_key = first_line; |
| 911 | } else { |
| 912 | free(first_line); |
| 913 | warning(_("gpg.ssh.defaultKeyCommand succeeded but returned no keys: %s %s"), |
| 914 | key_stderr.buf, key_stdout.buf); |
| 915 | } |
| 916 | |
| 917 | } else { |
| 918 | warning(_("gpg.ssh.defaultKeyCommand failed: %s %s"), |
| 919 | key_stderr.buf, key_stdout.buf); |
| 920 | } |
| 921 | |
| 922 | free(key_command); |
| 923 | free(argv); |
| 924 | strbuf_release(&key_stdout); |
| 925 | |
| 926 | return default_key; |
| 927 | } |
| 928 | |
| 929 | static char *get_ssh_key_id(void) |
nothing calls this directly
no test coverage detected