MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / InitHostKey

Function InitHostKey

server/sftp/hostkey.go:19–36  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17var SSHSigners []ssh.Signer
18
19func 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
38func LoadOrGenerateRSAHostKey(parentDir string) (ssh.Signer, bool) {
39 privateKeyPath := filepath.Join(parentDir, "ssh_host_rsa_key")

Callers 1

NewSftpDriverFunction · 0.92

Calls 3

ExistsFunction · 0.92
CreateNestedDirectoryFunction · 0.92
LoadOrGenerateRSAHostKeyFunction · 0.85

Tested by

no test coverage detected