| 39 | } |
| 40 | |
| 41 | func (i *InspectCmd) Run() error { |
| 42 | // Check if the input is a file path |
| 43 | if _, err := os.Stat(i.KeyOrCert); err == nil { |
| 44 | // It's a file, read its contents |
| 45 | data, err := os.ReadFile(i.KeyOrCert) |
| 46 | if err != nil { |
| 47 | return fmt.Errorf("error reading input file: %v", err) |
| 48 | } |
| 49 | i.KeyOrCert = string(data) |
| 50 | } |
| 51 | |
| 52 | // Trim whitespace and newlines |
| 53 | i.KeyOrCert = strings.TrimSpace(i.KeyOrCert) |
| 54 | |
| 55 | // Parse the SSH key or certificate |
| 56 | pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(i.KeyOrCert)) |
| 57 | if err != nil { |
| 58 | return fmt.Errorf("failed to parse SSH key: %v", err) |
| 59 | } |
| 60 | |
| 61 | // Check if it's a certificate |
| 62 | if cert, ok := pubKey.(*ssh.Certificate); ok { |
| 63 | i.inspectCertificate(cert) |
| 64 | } else { |
| 65 | // It's a regular public key |
| 66 | i.inspectPublicKey(pubKey) |
| 67 | } |
| 68 | |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func (i *InspectCmd) inspectCertificate(cert *ssh.Certificate) { |
| 73 | i.printf("--- SSH Certificate Information ---\n") |