55 "crypto/sha1"
66 "crypto/sha256"
77 "encoding/base64"
8+ "encoding/hex"
89 "errors"
910 "fmt"
1011 "io"
@@ -28,6 +29,7 @@ const (
2829 md5FingerprintLength = 47 // inclusive of space between bytes
2930 hexSha1FingerprintLength = 59 // inclusive of space between bytes
3031 base64Sha256FingerprintLength = 43
32+ sha256FingerprintLength = 64
3133
3234 DefaultKeepAliveInterval = 30 * time .Second
3335)
@@ -331,9 +333,12 @@ func (c *SecureShell) terminalType() string {
331333 return term
332334}
333335
334- func base64Sha256Fingerprint (key ssh.PublicKey ) string {
336+ func sha256Fingerprint (key ssh.PublicKey , encode bool ) string {
335337 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 [:])
337342}
338343
339344func copyAndClose (wg * sync.WaitGroup , dest io.WriteCloser , src io.Reader ) {
@@ -364,8 +369,10 @@ func fingerprintCallback(skipHostValidation bool, expectedFingerprint string) ss
364369 var fingerprint string
365370
366371 switch len (expectedFingerprint ) {
372+ case sha256FingerprintLength :
373+ fingerprint = sha256Fingerprint (key , false )
367374 case base64Sha256FingerprintLength :
368- fingerprint = base64Sha256Fingerprint (key )
375+ fingerprint = sha256Fingerprint (key , true )
369376 case hexSha1FingerprintLength :
370377 fingerprint = hexSha1Fingerprint (key )
371378 case md5FingerprintLength :
0 commit comments