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)
| 355 | // with the same algorithm, it is overwritten. Each server config must have at |
| 356 | // least one host key. |
| 357 | func (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. |
| 379 | func (srv *Server) SetOption(option Option) error { |