Debian Codegraph @

command/ssh/fingerprint.go

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