Merge pull request #2696 from ripienaar/always_nonce

support always presenting a nonce to clients
This commit is contained in:
R.I.Pienaar
2021-11-17 23:19:54 +01:00
committed by GitHub
3 changed files with 28 additions and 1 deletions

View File

@@ -33,7 +33,7 @@ func (s *Server) NonceRequired() bool {
// nonceRequired tells us if we should send a nonce.
// Lock should be held on entry.
func (s *Server) nonceRequired() bool {
return len(s.nkeys) > 0 || s.trustedKeys != nil
return s.opts.AlwaysEnableNonce || len(s.nkeys) > 0 || s.trustedKeys != nil
}
// Generate a nonce for INFO challenge.

View File

@@ -54,6 +54,28 @@ func mixedSetup() (*Server, *testAsyncClient, *bufio.Reader, string) {
return rawSetup(opts)
}
func TestServerInfoNonceAlwaysEnabled(t *testing.T) {
opts := defaultServerOptions
opts.AlwaysEnableNonce = true
s, c, _, l := rawSetup(opts)
defer s.WaitForShutdown()
defer s.Shutdown()
defer c.close()
if !strings.HasPrefix(l, "INFO ") {
t.Fatalf("INFO response incorrect: %s\n", l)
}
var info nonceInfo
err := json.Unmarshal([]byte(l[5:]), &info)
if err != nil {
t.Fatalf("Could not parse INFO json: %v\n", err)
}
if info.Nonce == "" {
t.Fatalf("Expected a non-empty nonce with AlwaysEnableNonce set")
}
}
func TestServerInfoNonce(t *testing.T) {
c, l := setUpClientWithResponse()
defer c.close()

View File

@@ -262,6 +262,11 @@ type Options struct {
AccountResolver AccountResolver `json:"-"`
AccountResolverTLSConfig *tls.Config `json:"-"`
// AlwaysEnableNonce will always present a nonce to new connections
// typically used by custom Authentication implementations who embeds
// the server and so not presented as a configuration option
AlwaysEnableNonce bool
CustomClientAuthentication Authentication `json:"-"`
CustomRouterAuthentication Authentication `json:"-"`