Skip to content

Commit 9802819

Browse files
committed
Add support for SHA256 fingerprint for diego-ssh
Add a new property sha256_fingerprint that diego can use to avoid incompatibilities when updating from sha1 to sha256
1 parent 3e1d2f4 commit 9802819

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lib/cloud_controller/diego/app_recipe_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def app_lrp_arguments
6060
routes[SSH_ROUTES_KEY] = Oj.dump({
6161
container_port: DEFAULT_SSH_PORT,
6262
private_key: ssh_key.private_key,
63-
host_fingerprint: ssh_key.fingerprint
63+
host_fingerprint: ssh_key.fingerprint,
64+
host_256_fingerprint: ssh_key.sha256_fingerprint
6465
})
6566
end
6667

lib/cloud_controller/diego/ssh_key.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def fingerprint
2626
@fingerprint ||= ::SSHKey.new(key.to_der).sha1_fingerprint
2727
end
2828

29+
def sha256_fingerprint
30+
@sha256_fingerprint ||= ::SSHKey.new(key.to_der).sha256_fingerprint
31+
end
32+
2933
private
3034

3135
def key

spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ module Diego
901901
expect(lrp.routes.routes['diego-ssh']).to eq(Oj.dump({
902902
container_port: 2222,
903903
private_key: ssh_key.private_key,
904-
host_fingerprint: ssh_key.fingerprint
904+
host_fingerprint: ssh_key.fingerprint,
905+
host_256_fingerprint: ssh_key.sha256_fingerprint
905906
}))
906907
end
907908
end
@@ -1001,7 +1002,8 @@ module Diego
10011002
expect(lrp.routes.routes['diego-ssh']).to eq(Oj.dump({
10021003
container_port: 2222,
10031004
private_key: ssh_key.private_key,
1004-
host_fingerprint: ssh_key.fingerprint
1005+
host_fingerprint: ssh_key.fingerprint,
1006+
host_256_fingerprint: ssh_key.sha256_fingerprint
10051007
}))
10061008
end
10071009
end
@@ -1344,7 +1346,8 @@ module Diego
13441346
expect(lrp.routes.routes['diego-ssh']).to eq(Oj.dump({
13451347
container_port: 2222,
13461348
private_key: ssh_key.private_key,
1347-
host_fingerprint: ssh_key.fingerprint
1349+
host_fingerprint: ssh_key.fingerprint,
1350+
host_256_fingerprint: ssh_key.sha256_fingerprint
13481351
}))
13491352
end
13501353
end

spec/unit/lib/cloud_controller/diego/ssh_key_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ module Diego
3939
expect(ssh_key.fingerprint).to match(/([0-9a-f]{2}:){19}[0-9a-f]{2}/)
4040
end
4141
end
42+
43+
describe '#fingerprint 256' do
44+
it 'returns an sha256 fingerprint' do
45+
ssh_key = SSHKey.new(1024)
46+
expect(ssh_key.sha256_fingerprint).to match(/[a-zA-Z0-9+\/=]{44}/)
47+
end
48+
end
4249
end
4350
end
4451
end

0 commit comments

Comments
 (0)