Skip to content

Commit

Permalink
feat: increase number of public key attempts before failing
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketeerbkw committed Jun 10, 2024
1 parent 5379ddc commit 4bfd725
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/sshserver/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
// (e.g. via signal)
const shutdownTimeout = 8 * time.Second

// disableSHA1Kex returns a ServerConfig which relies on default for everything
// except key exchange algorithms. There it removes the SHA1 based algorithms.
//
// This works around https://github.com/golang/go/issues/59593
func disableSHA1Kex(_ ssh.Context) *gossh.ServerConfig {
// serverConfig returns a ServerConfig of default values with overriden public
// key algorithms and failure attempts.
func serverConfig(_ ssh.Context) *gossh.ServerConfig {
c := gossh.ServerConfig{}

// Remove the SHA1 based key algorithms.
// This works around https://github.com/golang/go/issues/59593
c.Config.KeyExchanges = []string{
"curve25519-sha256",
"[email protected]",
Expand All @@ -33,6 +34,10 @@ func disableSHA1Kex(_ ssh.Context) *gossh.ServerConfig {
"ecdh-sha2-nistp521",
"diffie-hellman-group14-sha256",
}

// Increase the number of public-key attempts before failure.
c.MaxAuthTries = 18

return &c
}

Expand All @@ -53,7 +58,7 @@ func Serve(
"sftp": ssh.SubsystemHandler(sessionHandler(log, c, true, logAccessEnabled)),
},
PublicKeyHandler: pubKeyAuth(log, nc, c),
ServerConfigCallback: disableSHA1Kex,
ServerConfigCallback: serverConfig,
Banner: banner,
}
for _, hk := range hostKeys {
Expand Down

0 comments on commit 4bfd725

Please sign in to comment.