automaticSSHKeyPair returns the paths to the automatic key pair files, if they both exist
(sshContext ssh.Context)
| 381 | |
| 382 | // automaticSSHKeyPair returns the paths to the automatic key pair files, if they both exist |
| 383 | func automaticSSHKeyPair(sshContext ssh.Context) *ssh.KeyPair { |
| 384 | publicKeys, err := sshContext.LocalPublicKeys() |
| 385 | if err != nil { |
| 386 | // The error would be that the .ssh dir doesn't exist, which just means that the keypair also doesn't exist |
| 387 | return nil |
| 388 | } |
| 389 | |
| 390 | for _, publicKey := range publicKeys { |
| 391 | if filepath.Base(publicKey) != automaticPrivateKeyName+".pub" { |
| 392 | continue |
| 393 | } |
| 394 | |
| 395 | privateKey := strings.TrimSuffix(publicKey, ".pub") |
| 396 | |
| 397 | _, err := os.Stat(privateKey) |
| 398 | if err == nil { |
| 399 | return &ssh.KeyPair{ |
| 400 | PrivateKeyPath: privateKey, |
| 401 | PublicKeyPath: publicKey, |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | return nil |
| 407 | } |
| 408 | |
| 409 | func generateAutomaticSSHKeys(sshContext ssh.Context) (*ssh.KeyPair, error) { |
| 410 | keyPair := checkAndUpdateOldKeyPair(sshContext) |
no test coverage detected