5
5
"crypto/sha1"
6
6
"crypto/sha256"
7
7
"encoding/base64"
8
+ "encoding/hex"
8
9
"errors"
9
10
"fmt"
10
11
"io"
@@ -28,6 +29,7 @@ const (
28
29
md5FingerprintLength = 47 // inclusive of space between bytes
29
30
hexSha1FingerprintLength = 59 // inclusive of space between bytes
30
31
base64Sha256FingerprintLength = 43
32
+ sha256FingerprintLength = 64
31
33
32
34
DefaultKeepAliveInterval = 30 * time .Second
33
35
)
@@ -331,9 +333,12 @@ func (c *SecureShell) terminalType() string {
331
333
return term
332
334
}
333
335
334
- func base64Sha256Fingerprint (key ssh.PublicKey ) string {
336
+ func sha256Fingerprint (key ssh.PublicKey , encode bool ) string {
335
337
sum := sha256 .Sum256 (key .Marshal ())
336
- return base64 .RawStdEncoding .EncodeToString (sum [:])
338
+ if encode {
339
+ return base64 .RawStdEncoding .EncodeToString (sum [:])
340
+ }
341
+ return hex .EncodeToString (sum [:])
337
342
}
338
343
339
344
func copyAndClose (wg * sync.WaitGroup , dest io.WriteCloser , src io.Reader ) {
@@ -364,8 +369,10 @@ func fingerprintCallback(skipHostValidation bool, expectedFingerprint string) ss
364
369
var fingerprint string
365
370
366
371
switch len (expectedFingerprint ) {
372
+ case sha256FingerprintLength :
373
+ fingerprint = sha256Fingerprint (key , false )
367
374
case base64Sha256FingerprintLength :
368
- fingerprint = base64Sha256Fingerprint (key )
375
+ fingerprint = sha256Fingerprint (key , true )
369
376
case hexSha1FingerprintLength :
370
377
fingerprint = hexSha1Fingerprint (key )
371
378
case md5FingerprintLength :
0 commit comments