1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"launchpad.net/juju-core/utils"
13
// keyFingerprint returns the fingerprint and comment for the specified key.
14
// It calls ssh-keygen to do the work as there is no equivalent Go implementation.
15
func keyFingerprint(key string) (fingerprint, comment string, err error) {
16
// Instead of invoking ssh-keygen directly, it has to be called indirectly via a
17
// shell command because it doesn't read from stdin properly.
18
// See https://bugzilla.mindrot.org/show_bug.cgi?id=1477
19
shellCmd := fmt.Sprintf("ssh-keygen -lf /dev/stdin <<<'%s'", key)
20
output, err := utils.RunCommand("bash", "-c", shellCmd)
22
return "", "", fmt.Errorf("generating key fingerprint: %v", err)
25
n, err := fmt.Sscanf(output, "%s %s %s", &ignore, &fingerprint, &comment)
27
return "", "", fmt.Errorf("unexpected ssh-keygen output %q: %v", output, err)
29
if comment == "/dev/stdin" {
32
return fingerprint, comment, nil