~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/utils/ssh/fingerprint_notwin.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-29 11:40:20 UTC
  • mfrom: (23.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140129114020-ejieitm8smtt5vln
Tags: 1.17.1-0ubuntu2
d/tests/local-provider: Don't fail tests if ~/.juju is present as its
created by the juju version command. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
//
4
 
// +build !windows
5
 
 
6
 
package ssh
7
 
 
8
 
import (
9
 
        "fmt"
10
 
        "launchpad.net/juju-core/utils"
11
 
)
12
 
 
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)
21
 
        if err != nil {
22
 
                return "", "", fmt.Errorf("generating key fingerprint: %v", err)
23
 
        }
24
 
        var ignore string
25
 
        n, err := fmt.Sscanf(output, "%s %s %s", &ignore, &fingerprint, &comment)
26
 
        if n < 3 {
27
 
                return "", "", fmt.Errorf("unexpected ssh-keygen output %q: %v", output, err)
28
 
        }
29
 
        if comment == "/dev/stdin" {
30
 
                comment = ""
31
 
        }
32
 
        return fingerprint, comment, nil
33
 
}