MCPcopy Index your code
hub / github.com/smallstep/cli / inspectAction

Function inspectAction

command/ssh/inspect.go:59–170  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

57}
58
59func inspectAction(ctx *cli.Context) error {
60 if err := errs.MinMaxNumberOfArguments(ctx, 0, 1); err != nil {
61 return err
62 }
63
64 var name string
65 switch ctx.NArg() {
66 case 0:
67 name = "-"
68 case 1:
69 name = ctx.Args().First()
70 default:
71 return errs.TooManyArguments(ctx)
72 }
73
74 var (
75 format = ctx.String("format")
76 )
77
78 if format != "text" && format != "json" {
79 return errs.InvalidFlagValue(ctx, "format", format, "text, json")
80 }
81
82 b, err := utils.ReadFile(name)
83 if err != nil {
84 return err
85 }
86
87 pub, _, _, _, err := ssh.ParseAuthorizedKey(b)
88 if err != nil {
89 // Attempt to parse the key without the type.
90 b = bytes.TrimSpace(b)
91 keyBytes := make([]byte, base64.StdEncoding.DecodedLen(len(b)))
92 n, err := base64.StdEncoding.Decode(keyBytes, b)
93 if err != nil {
94 return errors.Wrap(err, "error parsing ssh certificate")
95 }
96 if pub, err = ssh.ParsePublicKey(keyBytes[:n]); err != nil {
97 return errors.Wrap(err, "error parsing ssh certificate")
98 }
99 }
100 cert, ok := pub.(*ssh.Certificate)
101 if !ok {
102 return errors.Errorf("error decoding ssh certificate: %T is not an *ssh.Certificate", pub)
103 }
104 inspect, err := sshutil.InspectCertificate(cert)
105 if err != nil {
106 return err
107 }
108
109 switch format {
110 case "text":
111 space := ""
112 fmt.Println(name + ":")
113 fmt.Printf("%8sType: %s %s certificate\n", space, inspect.KeyName, inspect.Type)
114 fmt.Printf("%8sPublic key: %s-CERT %s\n", space, inspect.KeyAlgo, inspect.KeyFingerprint)
115 fmt.Printf("%8sSigning CA: %s %s (using %s)\n", space, inspect.SigningKeyAlgo, inspect.SigningKeyFingerprint, inspect.Signature.Type)
116 fmt.Printf("%8sKey ID: \"%s\"\n", space, inspect.KeyID)

Callers

nothing calls this directly

Calls 4

ReadFileFunction · 0.92
InspectCertificateFunction · 0.92
ValidityMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…