update handler options
This commit is contained in:
@ -1,14 +1,15 @@
|
||||
package listener
|
||||
|
||||
import (
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
"net/url"
|
||||
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Addr string
|
||||
Authenticator auth.Authenticator
|
||||
Logger logger.Logger
|
||||
Addr string
|
||||
Auths []*url.Userinfo
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type Option func(opts *Options)
|
||||
@ -19,9 +20,9 @@ func AddrOption(addr string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func AuthenticatorOption(auth auth.Authenticator) Option {
|
||||
func AuthsOption(auths ...*url.Userinfo) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Authenticator = auth
|
||||
opts.Auths = auths
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
auth_util "github.com/go-gost/gost/pkg/common/util/auth"
|
||||
ssh_util "github.com/go-gost/gost/pkg/internal/util/ssh"
|
||||
"github.com/go-gost/gost/pkg/listener"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
@ -20,12 +20,12 @@ func init() {
|
||||
type sshListener struct {
|
||||
addr string
|
||||
net.Listener
|
||||
config *ssh.ServerConfig
|
||||
authenticator auth.Authenticator
|
||||
cqueue chan net.Conn
|
||||
errChan chan error
|
||||
logger logger.Logger
|
||||
md metadata
|
||||
config *ssh.ServerConfig
|
||||
cqueue chan net.Conn
|
||||
errChan chan error
|
||||
logger logger.Logger
|
||||
md metadata
|
||||
options listener.Options
|
||||
}
|
||||
|
||||
func NewListener(opts ...listener.Option) listener.Listener {
|
||||
@ -51,14 +51,13 @@ func (l *sshListener) Init(md md.Metadata) (err error) {
|
||||
|
||||
l.Listener = ln
|
||||
|
||||
authenticator := auth_util.AuthFromUsers(l.options.Auths...)
|
||||
config := &ssh.ServerConfig{
|
||||
PasswordCallback: ssh_util.PasswordCallback(l.authenticator),
|
||||
PasswordCallback: ssh_util.PasswordCallback(authenticator),
|
||||
PublicKeyCallback: ssh_util.PublicKeyCallback(l.md.authorizedKeys),
|
||||
}
|
||||
|
||||
config.AddHostKey(l.md.signer)
|
||||
|
||||
if l.authenticator == nil && len(l.md.authorizedKeys) == 0 {
|
||||
if authenticator == nil && len(l.md.authorizedKeys) == 0 {
|
||||
config.NoClientAuth = true
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user