1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
require_relative 'common'
require 'net/ssh'
# environment: see playbook for full details.
# 1. cert files: /etc/ssh/users_ca and /etc/ssh/users_ca.pub and
# 2. /etc/ssh/sshd_config: TrustedUserCAKeys /etc/ssh/users_ca.pub
unless ENV['NET_SSH_NO_ED25519']
class TestCertUserAuth < NetSSHTest
include IntegrationTestHelpers
def test_ed25519_with_implicit_cert
Dir.mktmpdir do |dir|
sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub"
sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''"
sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub")
ret = Net::SSH.start("localhost", "net_ssh_1", keys: "#{dir}/id_rsa_ed25519") do |ssh|
ssh.exec! 'echo "hello from:$USER"'
end
assert_equal "hello from:net_ssh_1\n", ret
end
end
def test_ed25519_with_explicit_cert
Dir.mktmpdir do |dir|
sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub"
sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''"
sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub")
sh "mv #{dir}/id_rsa_ed25519-cert.pub #{dir}/cert"
ret = Net::SSH.start("localhost", "net_ssh_1", keys: "#{dir}/id_rsa_ed25519", keycerts: "#{dir}/cert") do |ssh|
ssh.exec! 'echo "hello from:$USER"'
end
assert_equal "hello from:net_ssh_1\n", ret
end
end
def test_ed25519_with_cert_in_agent
Dir.mktmpdir do |dir|
with_agent do
sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub"
sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N 'pwd'"
sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub")
ssh_add("#{dir}/id_rsa_ed25519", "pwd")
sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub #{dir}/id_rsa_ed25519-cert.pub"
ret = Net::SSH.start("localhost", "net_ssh_1") do |ssh|
ssh.exec! 'echo "hello from:$USER"'
end
assert_equal "hello from:net_ssh_1\n", ret
end
end
end
def test_ed25519_with_key_in_agent_and_explicit_cert
Dir.mktmpdir do |dir|
with_agent do
sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub"
sh "ssh-keygen -q -f #{dir}/id_rsa_ed25519 -t ed25519 -N ''"
# add key before signing cert
ssh_add("#{dir}/id_rsa_ed25519", "pwd")
sign_user_key('net_ssh_1',"#{dir}/id_rsa_ed25519.pub")
sh "rm -rf #{dir}/id_rsa_ed25519 #{dir}/id_rsa_ed25519.pub"
ret = Net::SSH.start("localhost", "net_ssh_1", keycerts: "#{dir}/id_rsa_ed25519-cert.pub") do |ssh|
ssh.exec! 'echo "hello from:$USER"'
end
assert_equal "hello from:net_ssh_1\n", ret
end
end
end
end
end
|