diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2024-01-24 17:39:33 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2024-01-24 17:58:24 +0000 |
commit | 9140655a36a6ba7fbfcd0dcdb4042c18295511a4 (patch) | |
tree | 6fbeb490930835e3c48ad796eb8763ac8e18dd68 | |
parent | 94f28034477ea6b8d931a55a2e866e922eaf4f38 (diff) |
setup-sshd: fix use of direct key
The prompt asks for a ssh key. Fix so it actually accepts the key
pasted.
-rw-r--r-- | setup-sshd.in | 6 | ||||
-rwxr-xr-x | tests/setup_sshd_test | 23 |
2 files changed, 29 insertions, 0 deletions
diff --git a/setup-sshd.in b/setup-sshd.in index e3eec54..4dadb5c 100644 --- a/setup-sshd.in +++ b/setup-sshd.in @@ -139,6 +139,12 @@ if [ "$sshdchoice" = "openssh" ] && [ -z "$authorized_key" ] && [ -z "$users" ]; none) break ;; + *) + if printf "%s\n" "$resp" | ssh-keygen -l -f - >/dev/null; then + authorized_key="$resp" + break + fi + ;; esac done fi diff --git a/tests/setup_sshd_test b/tests/setup_sshd_test index 633a3d4..099f14d 100755 --- a/tests/setup_sshd_test +++ b/tests/setup_sshd_test @@ -12,6 +12,7 @@ init_tests \ setup_sshd_interactive_openssh_prohibitpass \ setup_sshd_interactive_openssh_nokey \ setup_sshd_interactive_openssh_user_exist \ + setup_sshd_interactive_openssh_direct_key \ setup_sshd_openssh_ssh_key setup_sshd_usage_body() { @@ -166,6 +167,28 @@ setup_sshd_interactive_openssh_user_exist_body() { setup-sshd < answers } +setup_sshd_interactive_openssh_direct_key_body() { + atf_require_prog ssh-keygen + init_env + mkdir -p etc/ssh + echo "PermitRootLogin foobar" > etc/ssh/sshd_config + local key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBblcU1qMyXsRG1zDI0GfcfXk01O4p6bAlM3A6zHHxnM joe@example.tld" + ( + echo "openssh" + echo "" + echo "ssh-asdfaasdfasdf" + echo "$key" + ) >answers + atf_check -s exit:0 \ + -o match:"Which ssh server" \ + -o match:"Allow root ssh login.*\[prohibit-password\]" \ + -o match:"Enter ssh key" \ + -e match:"is not a public key file" \ + setup-sshd <answers + grep -x "$key" root/.ssh/authorized_keys \ + || atf_fail "failed to fetch key from github" +} + setup_sshd_openssh_ssh_key_body() { init_env SSH_KEY="ssh-rsa foobar user@example.com" atf_check -s exit:0 \ |