MCPcopy
hub / github.com/gliderlabs/ssh / AddHostKey

Method AddHostKey

server.go:357–376  ·  view source on GitHub ↗

AddHostKey adds a private key as a host key. If an existing host key exists with the same algorithm, it is overwritten. Each server config must have at least one host key.

(key Signer)

Source from the content-addressed store, hash-verified

355// with the same algorithm, it is overwritten. Each server config must have at
356// least one host key.
357func (srv *Server) AddHostKey(key Signer) {
358 srv.mu.Lock()
359 defer srv.mu.Unlock()
360
361 // these are later added via AddHostKey on ServerConfig, which performs the
362 // check for one of every algorithm.
363
364 // This check is based on the AddHostKey method from the x/crypto/ssh
365 // library. This allows us to only keep one active key for each type on a
366 // server at once. So, if you're dynamically updating keys at runtime, this
367 // list will not keep growing.
368 for i, k := range srv.HostSigners {
369 if k.PublicKey().Type() == key.PublicKey().Type() {
370 srv.HostSigners[i] = key
371 return
372 }
373 }
374
375 srv.HostSigners = append(srv.HostSigners, key)
376}
377
378// SetOption runs a functional option against the server.
379func (srv *Server) SetOption(option Option) error {

Callers 4

TestAddHostKeyFunction · 0.95
configMethod · 0.80
HostKeyFileFunction · 0.80
HostKeyPEMFunction · 0.80

Calls 1

PublicKeyMethod · 0.65

Tested by 1

TestAddHostKeyFunction · 0.76