()
| 17 | var SSHSigners []ssh.Signer |
| 18 | |
| 19 | func InitHostKey() { |
| 20 | if SSHSigners != nil { |
| 21 | return |
| 22 | } |
| 23 | sshPath := filepath.Join(flags.DataDir, "ssh") |
| 24 | if !utils.Exists(sshPath) { |
| 25 | err := utils.CreateNestedDirectory(sshPath) |
| 26 | if err != nil { |
| 27 | utils.Log.Errorf("failed to create ssh directory: %+v", err) |
| 28 | return |
| 29 | } |
| 30 | } |
| 31 | SSHSigners = make([]ssh.Signer, 0, 4) |
| 32 | if rsaKey, ok := LoadOrGenerateRSAHostKey(sshPath); ok { |
| 33 | SSHSigners = append(SSHSigners, rsaKey) |
| 34 | } |
| 35 | // TODO Add keys for other encryption algorithms |
| 36 | } |
| 37 | |
| 38 | func LoadOrGenerateRSAHostKey(parentDir string) (ssh.Signer, bool) { |
| 39 | privateKeyPath := filepath.Join(parentDir, "ssh_host_rsa_key") |
no test coverage detected