Skip to content

Commit e96542e

Browse files
MarcPaquettegeofffranks
authored andcommitted
Support SHA1 & SHA256
1 parent fcfa02a commit e96542e

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

helpers/fingerprint.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package helpers
22

33
import (
44
"crypto/md5"
5+
"crypto/sha1"
56
"crypto/sha256"
67
"fmt"
78
"strings"
@@ -10,6 +11,7 @@ import (
1011
)
1112

1213
const MD5_FINGERPRINT_LENGTH = 47
14+
const SHA1_FINGERPRINT_LENGTH = 59
1315
const SHA256_FINGERPRINT_LENGTH = 95
1416

1517
func MD5Fingerprint(key ssh.PublicKey) string {
@@ -22,6 +24,11 @@ func SHA256Fingerprint(key ssh.PublicKey) string {
2224
return colonize(fmt.Sprintf("% x", sha256sum))
2325
}
2426

27+
func SHA1Fingerprint(key ssh.PublicKey) string {
28+
sha1sum := sha1.Sum(key.Marshal())
29+
return colonize(fmt.Sprintf("% x", sha1sum))
30+
}
31+
2532
func colonize(s string) string {
2633
return strings.Replace(s, " ", ":", -1)
2734
}

helpers/fingerprint_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ HbXzxBM4Ki0l1kaUjDVKjz3fsIq9Pl/lBoKYAmDvkK4xoxcs05ws
4040
-----END RSA PRIVATE KEY-----`
4141

4242
ExpectedMD5Fingerprint = `24:2e:53:c3:72:4f:25:b8:72:29:2d:e3:56:63:4b:c8`
43+
ExpectedSHA1Fingerprint = `8b:d1:ce:b8:3a:f0:37:7f:56:9e:33:1a:72:4b:32:5a:bc:9d:3b:49`
4344
ExpectedSHA256Fingerprint = `c7:e1:1c:47:3b:7b:11:f5:6e:5d:3c:67:16:dd:35:96:4c:5a:6c:f5:0b:82:e5:20:a6:f7:29:a3:9d:bf:3e:e7`
4445
)
4546

@@ -68,6 +69,20 @@ var _ = Describe("Fingerprint", func() {
6869
})
6970
})
7071

72+
Describe("SHA1 Fingerprint", func() {
73+
BeforeEach(func() {
74+
fingerprint = helpers.SHA1Fingerprint(publicKey)
75+
})
76+
77+
It("should have the correct length", func() {
78+
Expect(utf8.RuneCountInString(fingerprint)).To(Equal(helpers.SHA1_FINGERPRINT_LENGTH))
79+
})
80+
81+
It("should match the expected fingerprint", func() {
82+
Expect(fingerprint).To(Equal(ExpectedSHA1Fingerprint))
83+
})
84+
})
85+
7186
Describe("SHA256 Fingerprint", func() {
7287
BeforeEach(func() {
7388
fingerprint = helpers.SHA256Fingerprint(publicKey)

proxy/proxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ func NewClientConn(logger lager.Logger, permissions *ssh.Permissions, tlsConfig
401401
switch utf8.RuneCountInString(expectedFingerprint) {
402402
case helpers.MD5_FINGERPRINT_LENGTH:
403403
actualFingerprint = helpers.MD5Fingerprint(key)
404+
case helpers.SHA1_FINGERPRINT_LENGTH:
405+
actualFingerprint = helpers.SHA1Fingerprint(key)
404406
case helpers.SHA256_FINGERPRINT_LENGTH:
405407
actualFingerprint = helpers.SHA256Fingerprint(key)
406408
}

proxy/proxy_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,29 @@ var _ = Describe("Proxy", func() {
245245
})
246246

247247
Context("when the host fingerprint is a sha1 hash", func() {
248+
BeforeEach(func() {
249+
targetConfigJson, err := json.Marshal(proxy.TargetConfig{
250+
Address: sshdListener.Addr().String(),
251+
HostFingerprint: helpers.SHA1Fingerprint(TestHostKey.PublicKey()),
252+
User: "some-user",
253+
Password: "fake-some-password",
254+
})
255+
Expect(err).NotTo(HaveOccurred())
256+
257+
permissions := &ssh.Permissions{
258+
CriticalOptions: map[string]string{
259+
"proxy-target-config": string(targetConfigJson),
260+
},
261+
}
262+
proxyAuthenticator.AuthenticateReturns(permissions, nil)
263+
})
264+
265+
It("handshakes with the target using the provided configuration", func() {
266+
Eventually(daemonAuthenticator.AuthenticateCallCount).Should(Equal(1))
267+
})
268+
})
269+
270+
Context("when the host fingerprint is a sha256 hash", func() {
248271
BeforeEach(func() {
249272
targetConfigJson, err := json.Marshal(proxy.TargetConfig{
250273
Address: sshdListener.Addr().String(),

0 commit comments

Comments
 (0)