1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
package ssh
import (
"fmt"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
)
func fingerPrintCommand() cli.Command {
return cli.Command{
Name: "fingerprint",
Action: command.ActionFunc(fingerprint),
Usage: "print the fingerprint of an SSH public key or certificate",
UsageText: `**step ssh fingerprint** <file>`,
Description: `**step ssh fingerprint** prints the fingerprint of an ssh public key or
certificate.
## POSITIONAL ARGUMENTS
<file>
: The path to an SSH public key or certificate.
## EXAMPLES
Print the fingerprint for a certificate:
'''
$ step ssh fingerprint id_ecdsa-cert.pub
'''
Print the fingerprint for an SSH public key:
'''
$ step ssh fingerprint id_ecdsa.pub
'''`,
}
}
func fingerprint(ctx *cli.Context) error {
if err := errs.MinMaxNumberOfArguments(ctx, 0, 1); err != nil {
return err
}
name := ctx.Args().First()
if name == "" {
name = "-"
}
b, err := utils.ReadFile(name)
if err != nil {
return err
}
s, err := sshutil.Fingerprint(b)
if err != nil {
return err
}
fmt.Println(s)
return nil
}
|