Skip to content

Commit 744972e

Browse files
committed
Use go method to calculate key fingerprint
1 parent 5d3177d commit 744972e

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

models/ssh_key.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,11 @@ func checkKeyFingerprint(e Engine, fingerprint string) error {
361361

362362
func calcFingerprint(publicKeyContent string) (string, error) {
363363
// Calculate fingerprint.
364-
tmpPath, err := writeTmpKeyFile(publicKeyContent)
364+
pk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(publicKeyContent))
365365
if err != nil {
366366
return "", err
367367
}
368-
defer os.Remove(tmpPath)
369-
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)
370-
if err != nil {
371-
return "", fmt.Errorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr)
372-
} else if len(stdout) < 2 {
373-
return "", errors.New("not enough output for calculating fingerprint: " + stdout)
374-
}
375-
return strings.Split(stdout, " ")[1], nil
368+
return ssh.FingerprintSHA256(pk), nil
376369
}
377370

378371
func addKey(e Engine, key *PublicKey) (err error) {

0 commit comments

Comments
 (0)