Skip to content

Commit

Permalink
Use go method to calculate key fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Jun 5, 2019
1 parent 5d3177d commit 744972e
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions models/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,11 @@ func checkKeyFingerprint(e Engine, fingerprint string) error {

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

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

0 comments on commit 744972e

Please sign in to comment.