Skip to content

Commit 3b3b0fc

Browse files
Maisem AliiQQBot
authored andcommitted
ssh: add ImplicitAuthMethod to ServerConfig
This allows specifying an ImplicitAuthMethod associated with NoClientAuthCallback. Signed-off-by: Maisem Ali <[email protected]>
1 parent fd8d529 commit 3b3b0fc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ssh/server.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ type ServerConfig struct {
6666

6767
hostKeys []Signer
6868

69+
// ImplictAuthMethod is sent to the client in the list of acceptable
70+
// authentication methods. To make an authentication decision based on
71+
// connection metadata use NoClientAuthCallback. If NoClientAuthCallback is
72+
// nil, the value is unused.
73+
ImplictAuthMethod string
74+
6975
// NoClientAuth is true if clients are allowed to connect without
7076
// authenticating.
7177
// To determine NoClientAuth at runtime, set NoClientAuth to true
@@ -664,6 +670,9 @@ userAuthLoop:
664670

665671
if errors.Is(authErr, ErrDenied) {
666672
var failureMsg userAuthFailureMsg
673+
if config.ImplictAuthMethod != "" {
674+
failureMsg.Methods = []string{config.ImplictAuthMethod}
675+
}
667676
if err := s.transport.writePacket(Marshal(failureMsg)); err != nil {
668677
return nil, err
669678
}
@@ -698,6 +707,9 @@ userAuthLoop:
698707
}
699708

700709
var failureMsg userAuthFailureMsg
710+
if config.NoClientAuthCallback != nil && config.ImplictAuthMethod != "" {
711+
failureMsg.Methods = append(failureMsg.Methods, config.ImplictAuthMethod)
712+
}
701713
if config.PasswordCallback != nil {
702714
failureMsg.Methods = append(failureMsg.Methods, "password")
703715
}

0 commit comments

Comments
 (0)