Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit 123f55b

Browse files
author
Jonathan Claudius
authored
Merge pull request #487 from mozilla/add_ecdsa_and_ed25519_support
Add support for ecdsa and ed25519 keys
2 parents d7c795b + 459929c commit 123f55b

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

lib/ssh_scan/public_key.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def type
2020
return "rsa"
2121
elsif @key_string.start_with?("ssh-dss")
2222
return "dsa"
23+
elsif @key_string.start_with?("ecdsa-sha2-nistp256")
24+
return "ecdsa-sha2-nistp256"
25+
elsif @key_string.start_with?("ssh-ed25519")
26+
return "ed25519"
2327
else
2428
return "unknown"
2529
end

lib/ssh_scan/scan_engine.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def scan_target(socket, opts)
123123

124124
output = ""
125125

126-
cmd = ['ssh-keyscan', '-t', 'rsa,dsa', '-p', port.to_s, target].join(" ")
126+
cmd = ['ssh-keyscan', '-t', 'rsa,dsa,ecdsa,ed25519', '-p', port.to_s, target].join(" ")
127127

128128
Utils::Subprocess.new(cmd) do |stdout, stderr, thread|
129129
if stdout
@@ -144,6 +144,16 @@ def scan_target(socket, opts)
144144
key = SSHScan::Crypto::PublicKey.new([host_keys[i], host_keys[i + 1]].join(" "))
145145
keys.merge!(key.to_hash)
146146
end
147+
148+
if host_keys[i].eql? "ecdsa-sha2-nistp256"
149+
key = SSHScan::Crypto::PublicKey.new([host_keys[i], host_keys[i + 1]].join(" "))
150+
keys.merge!(key.to_hash)
151+
end
152+
153+
if host_keys[i].eql? "ssh-ed25519"
154+
key = SSHScan::Crypto::PublicKey.new([host_keys[i], host_keys[i + 1]].join(" "))
155+
keys.merge!(key.to_hash)
156+
end
147157
end
148158

149159
result.keys = keys

spec/public_key_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,61 @@
7575
end
7676
end
7777

78+
context "when parsing an ecdsa key string" do
79+
it "should parse it and have the right values for each attribute" do
80+
key_string = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyN" +
81+
"TYAAAAIbmlzdHAyNTYAAABBBC4gXA5naQtjcKu90NJ7A4jQ1U" +
82+
"gxYGdnndJyr4PSZJ59qJUzkoH3VgdTlseXbIZHwO4k2gNcFpa" +
83+
"Mq5gqVRobAwU="
84+
key = SSHScan::Crypto::PublicKey.new(key_string)
85+
expect(key).to be_kind_of SSHScan::Crypto::PublicKey
86+
expect(key.valid?).to be true
87+
expect(key.type).to eq("ecdsa-sha2-nistp256")
88+
expect(key.length).to be 520
89+
expect(key.fingerprint_md5).to eq("be:04:32:74:c6:63:fa:24:c3:c6:78:c2:cd:d2:3e:f4")
90+
expect(key.fingerprint_sha1).to eq("00:67:e3:4d:78:2f:65:94:87:bf:54:5a:1e:92:af:67:0b:8d:b5:2c")
91+
expect(key.fingerprint_sha256).to eq("EZe8ZoSwAzDOLR45H2PZ1aGGfnt59ZLrL5bwnjQwTUI=")
92+
expect(key.to_hash).to eq(
93+
{
94+
"ecdsa-sha2-nistp256" => {
95+
"fingerprints" => {
96+
"md5"=>"be:04:32:74:c6:63:fa:24:c3:c6:78:c2:cd:d2:3e:f4",
97+
"sha1"=>"00:67:e3:4d:78:2f:65:94:87:bf:54:5a:1e:92:af:67:0b:8d:b5:2c",
98+
"sha256"=>"EZe8ZoSwAzDOLR45H2PZ1aGGfnt59ZLrL5bwnjQwTUI="
99+
},
100+
"length" => 520,
101+
"raw" => "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC4gXA5naQtjcKu90NJ7A4jQ1UgxYGdnndJyr4PSZJ59qJUzkoH3VgdTlseXbIZHwO4k2gNcFpaMq5gqVRobAwU=",
102+
}
103+
}
104+
)
105+
end
106+
end
107+
108+
context "when parsing an ed25519 key string" do
109+
it "should parse it and have the right values for each attribute" do
110+
key_string = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINO+ybidO9DGOb1dDwyVvGcrCD/wILFWTYtWUQZVxXwH"
111+
key = SSHScan::Crypto::PublicKey.new(key_string)
112+
expect(key).to be_kind_of SSHScan::Crypto::PublicKey
113+
expect(key.valid?).to be true
114+
expect(key.type).to eq("ed25519")
115+
expect(key.length).to be 256
116+
expect(key.fingerprint_md5).to eq("0f:db:50:54:15:22:b3:6f:31:7c:ee:22:23:77:bc:77")
117+
expect(key.fingerprint_sha1).to eq("32:d1:e8:50:ae:1c:cb:11:c5:09:fa:02:6e:f4:e8:dc:11:11:4c:48")
118+
expect(key.fingerprint_sha256).to eq("p+P78wR61KZ4UvQZpr84EqslnRkhZ7txT1bN8vA/oHU=")
119+
expect(key.to_hash).to eq(
120+
{
121+
"ed25519" => {
122+
"fingerprints" => {
123+
"md5"=>"0f:db:50:54:15:22:b3:6f:31:7c:ee:22:23:77:bc:77",
124+
"sha1"=>"32:d1:e8:50:ae:1c:cb:11:c5:09:fa:02:6e:f4:e8:dc:11:11:4c:48",
125+
"sha256"=>"p+P78wR61KZ4UvQZpr84EqslnRkhZ7txT1bN8vA/oHU="
126+
},
127+
"length" => 256,
128+
"raw" => "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINO+ybidO9DGOb1dDwyVvGcrCD/wILFWTYtWUQZVxXwH",
129+
}
130+
}
131+
)
132+
end
133+
end
134+
78135
end

0 commit comments

Comments
 (0)