analyzeKeyFile analyzes a potential SSH key file
(path string)
| 249 | |
| 250 | // analyzeKeyFile analyzes a potential SSH key file |
| 251 | func analyzeKeyFile(path string) *SSHKeyInfo { |
| 252 | data, err := os.ReadFile(path) |
| 253 | if err != nil { |
| 254 | return nil |
| 255 | } |
| 256 | |
| 257 | // Try to parse as private key |
| 258 | _, err = ssh.ParseRawPrivateKey(data) |
| 259 | |
| 260 | info := &SSHKeyInfo{ |
| 261 | Path: path, |
| 262 | Filename: filepath.Base(path), |
| 263 | } |
| 264 | |
| 265 | if err != nil { |
| 266 | // Check if it's an encrypted key |
| 267 | if _, ok := err.(*ssh.PassphraseMissingError); ok { |
| 268 | info.IsEncrypted = true |
| 269 | } else { |
| 270 | // Not a valid private key |
| 271 | return nil |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | return info |
| 276 | } |
| 277 | |
| 278 | // generateAlias generates a suggested alias from the filename |
| 279 | func generateAlias(filename string) string { |