MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / GenerateHostKey

Method GenerateHostKey

config/ssh.go:49–68  ·  view source on GitHub ↗

GenerateHostKey generates a random host key and adds it to SSHConfig

()

Source from the content-addressed store, hash-verified

47
48// GenerateHostKey generates a random host key and adds it to SSHConfig
49func (cfg *SSHConfig) GenerateHostKey() error {
50 reader := rand.Reader
51 bitSize := 4096
52 key, err := rsa.GenerateKey(reader, bitSize)
53 if err != nil {
54 return err
55 }
56 var privateKey = &pem.Block{
57 Type: "RSA PRIVATE KEY",
58 Bytes: x509.MarshalPKCS1PrivateKey(key),
59 }
60 var hostKeyBuffer bytes.Buffer
61 err = pem.Encode(&hostKeyBuffer, privateKey)
62 if err != nil {
63 return err
64 }
65
66 cfg.HostKeys = append(cfg.HostKeys, hostKeyBuffer.String())
67 return nil
68}
69
70func (cfg *SSHConfig) LoadHostKeys() ([]ssh.Signer, error) {
71 var hostKeys []ssh.Signer

Callers 7

TestReadyRejectionFunction · 0.95
startMethod · 0.95
startSSHServerFunction · 0.95
StartContainerSSHMethod · 0.80
generateHostKeysFunction · 0.80
NewTestServerFunction · 0.80

Calls 3

GenerateKeyMethod · 0.80
EncodeMethod · 0.65
StringMethod · 0.65

Tested by 5

TestReadyRejectionFunction · 0.76
startMethod · 0.76
startSSHServerFunction · 0.76
StartContainerSSHMethod · 0.64