| 407 | } |
| 408 | |
| 409 | func generateAutomaticSSHKeys(sshContext ssh.Context) (*ssh.KeyPair, error) { |
| 410 | keyPair := checkAndUpdateOldKeyPair(sshContext) |
| 411 | if keyPair != nil { |
| 412 | return keyPair, nil |
| 413 | } |
| 414 | |
| 415 | keyPair, err := sshContext.GenerateSSHKey(automaticPrivateKeyName, "") |
| 416 | if err != nil && !errors.Is(err, ssh.ErrKeyAlreadyExists) { |
| 417 | return nil, err |
| 418 | } |
| 419 | |
| 420 | return keyPair, nil |
| 421 | } |
| 422 | |
| 423 | // checkAndUpdateOldKeyPair handles backward compatibility with the old keypair names. |
| 424 | // If the old public and private keys both exist they are renamed to the new name. |