summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2021-08-05 14:24:21 +0200
committerMiklós Fazekas <mfazekas@szemafor.com>2021-08-05 14:39:08 +0200
commit903384d7c668dbe85ba9d00a6d1323cce5c53efc (patch)
treeb270aa63f4eaa674cd52741563fecef90c9110ad
parent7d2ad0fbc4a76dd130bde8b811ffa339c5297259 (diff)
downloadnet-ssh-903384d7c668dbe85ba9d00a6d1323cce5c53efc.tar.gz
Rubocop fixes
-rw-r--r--lib/net/ssh/known_hosts.rb26
-rw-r--r--test/integration/test_cert_host_auth.rb14
-rw-r--r--test/transport/test_algorithms.rb13
3 files changed, 29 insertions, 24 deletions
diff --git a/lib/net/ssh/known_hosts.rb b/lib/net/ssh/known_hosts.rb
index 7c8b3d5..df19e97 100644
--- a/lib/net/ssh/known_hosts.rb
+++ b/lib/net/ssh/known_hosts.rb
@@ -8,9 +8,12 @@ require 'byebug'
module Net
module SSH
module HostKeyEntries
+ # regular public key entry
class PubKey < Delegator
- def initialize(key)
+ def initialize(key, comment: nil)
+ super()
@key = key
+ @comment = comment
end
def ssh_type
@@ -35,6 +38,7 @@ module Net
end
end
+ # @cert-authority entry
class CertAuthority
def ssh_types
%w[
@@ -43,9 +47,10 @@ module Net
ecdsa-sha2-nistp521-cert-v01@openssh.com
]
end
-
- def initialize(key)
+
+ def initialize(key, comment: nil)
@key = key
+ @comment = comment
end
def matches_key?(server_key)
@@ -179,18 +184,17 @@ module Net
File.open(source) do |file|
file.each_line do |line|
- marker = nil
- hosts, type, key_content, comment, last = line.split(' ')
-
- if ['@cert-authority'].include?(hosts)
- marker, hosts, type, key_content, comment = hosts, type, key_content, comment, last
+ if line.start_with?('@')
+ marker, hosts, type, key_content, comment = line.split(' ')
+ else
+ marker = nil
+ hosts, type, key_content, comment = line.split(' ')
end
if marker == "@cert-authority"
blob = key_content.unpack("m*").first
- keys << HostKeyEntries::CertAuthority.new(Net::SSH::Buffer.new(blob).read_key)
+ keys << HostKeyEntries::CertAuthority.new(Net::SSH::Buffer.new(blob).read_key, comment: comment)
else
- hosts, type, key_content = line.split(' ')
# Skip empty line or one that is commented
next if hosts.nil? || hosts.start_with?('#')
@@ -205,7 +209,7 @@ module Net
next unless found
blob = key_content.unpack("m*").first
- keys << HostKeyEntries::PubKey.new(Net::SSH::Buffer.new(blob).read_key)
+ keys << HostKeyEntries::PubKey.new(Net::SSH::Buffer.new(blob).read_key, comment: comment)
end
end
end
diff --git a/test/integration/test_cert_host_auth.rb b/test/integration/test_cert_host_auth.rb
index 97aed81..9619c1f 100644
--- a/test/integration/test_cert_host_auth.rb
+++ b/test/integration/test_cert_host_auth.rb
@@ -17,7 +17,7 @@ class TestCertHostAuth < NetSSHTest
@badcert = "#{dir}/badca"
sh "rm -rf #{@badcert} #{@badcert}.pub"
sh "ssh-keygen -t rsa -N '' -C 'ca@hosts.netssh' -f #{@badcert}"
-
+
@cert = "#{dir}/ca"
sh "rm -rf #{@cert} #{@cert}.pub"
sh "ssh-keygen -t rsa -N '' -C 'ca@hosts.netssh' -f #{@cert}"
@@ -42,7 +42,7 @@ class TestCertHostAuth < NetSSHTest
puts "Data: #{data}"
f.write("@cert-authority *.hosts.netssh #{data}")
f.close
-
+
start_sshd_7_or_later(config: config_lines, debug: true) do |_pid, port|
Timeout.timeout(400) do
# We have our own sshd, give it a chance to come up before
@@ -64,7 +64,7 @@ class TestCertHostAuth < NetSSHTest
def test_failure
config_lines = []
config_lines.push("HostCertificate /etc/ssh/ssh_host_ecdsa_key-cert.pub")
-
+
Tempfile.open('empty_kh') do |f|
setup_ssh_env do |params|
data = File.read(params[:badcert_pub])
@@ -72,13 +72,11 @@ class TestCertHostAuth < NetSSHTest
puts "Data: #{data}"
f.write("@cert-authority *.hosts.netssh #{data}")
f.close
-
+
start_sshd_7_or_later(config: config_lines, debug: true) do |_pid, port|
Timeout.timeout(400) do
- # We have our own sshd, give it a chance to come up before
- # listening.
- #sh "ssh net_ssh_1@one.hosts.netssh -p #{port} -o UserKnownHostsFile=#{f.path}"
-
+ # sh "ssh net_ssh_1@one.hosts.netssh -p #{port} -o UserKnownHostsFile=#{f.path}"
+
sleep 0.2
assert_raises(Net::SSH::HostKeyMismatch) do
Net::SSH.start("one.hosts.netssh", "net_ssh_1", password: 'foopwd', port: port, verify_host_key: :always, user_known_hosts_file: [f.path], verbose: :debug) do |ssh|
diff --git a/test/transport/test_algorithms.rb b/test/transport/test_algorithms.rb
index fbe96a5..cef1b19 100644
--- a/test/transport/test_algorithms.rb
+++ b/test/transport/test_algorithms.rb
@@ -46,9 +46,10 @@ module Transport
end
def test_constructor_with_known_hosts_reporting_known_host_key_should_use_that_host_key_type
- Net::SSH::KnownHosts.expects(:search_for).with("net.ssh.test,127.0.0.1", {
- user_known_hosts_file: "/dev/null", global_known_hosts_file: "/dev/null"
- }).returns([stub("key", ssh_type: "ssh-dss")])
+ Net::SSH::KnownHosts.expects(:search_for).with(
+ "net.ssh.test,127.0.0.1",
+ { user_known_hosts_file: "/dev/null", global_known_hosts_file: "/dev/null" }
+ ).returns([stub("key", ssh_type: "ssh-dss")])
assert_equal %w[ssh-dss] + ed_ec_host_keys + %w[ssh-rsa-cert-v01@openssh.com ssh-rsa-cert-v00@openssh.com ssh-rsa rsa-sha2-256 rsa-sha2-512], algorithms[:host_key]
end
@@ -441,8 +442,10 @@ module Transport
def transport(transport_options={})
@transport ||= MockTransport.new(
- {user_known_hosts_file: '/dev/null',
- global_known_hosts_file: '/dev/null'}.merge(transport_options)
+ {
+ user_known_hosts_file: '/dev/null',
+ global_known_hosts_file: '/dev/null'
+ }.merge(transport_options)
)
end
end