diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-10 19:37:21 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-10 19:37:21 +0200 |
| commit | f6e23930da2900c43a5389a2e7d1e38d8221a76f (patch) | |
| tree | 3352cc0d8c0819d5cc58fdf987ed39f87a30a34b /internal/ssh/server/hostkey.go | |
| parent | 1fc24f9affed5128702e4de80572cac8c82d399e (diff) | |
Refactor server-side config singleton reads
Diffstat (limited to 'internal/ssh/server/hostkey.go')
| -rw-r--r-- | internal/ssh/server/hostkey.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/internal/ssh/server/hostkey.go b/internal/ssh/server/hostkey.go index b2d4569..809a870 100644 --- a/internal/ssh/server/hostkey.go +++ b/internal/ssh/server/hostkey.go @@ -8,9 +8,19 @@ import ( "github.com/mimecast/dtail/internal/ssh" ) +const ( + defaultHostKeyBits = 4096 + defaultHostKeyFile = "./cache/ssh_host_key" +) + // PrivateHostKey retrieves the private server RSA host key. -func PrivateHostKey() []byte { - hostKeyFile := config.Server.HostKeyFile +func PrivateHostKey(hostKeyFile string, hostKeyBits int) []byte { + if hostKeyFile == "" { + hostKeyFile = defaultHostKeyFile + } + if hostKeyBits <= 0 { + hostKeyBits = defaultHostKeyBits + } if config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") { hostKeyFile = "./ssh_host_key" } @@ -18,7 +28,7 @@ func PrivateHostKey() []byte { if os.IsNotExist(err) { dlog.Server.Info("Generating private server RSA host key") - privateKey, err := ssh.GeneratePrivateRSAKey(config.Server.HostKeyBits) + privateKey, err := ssh.GeneratePrivateRSAKey(hostKeyBits) if err != nil { dlog.Server.FatalPanic("Failed to generate private server RSA host key", err) |
