add auther config
This commit is contained in:
@ -4,13 +4,15 @@ import (
|
||||
"crypto/tls"
|
||||
"net/url"
|
||||
|
||||
"github.com/go-gost/gost/pkg/auth"
|
||||
"github.com/go-gost/gost/pkg/chain"
|
||||
"github.com/go-gost/gost/pkg/logger"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Addr string
|
||||
Auths []*url.Userinfo
|
||||
Auther auth.Authenticator
|
||||
Auth *url.Userinfo
|
||||
TLSConfig *tls.Config
|
||||
Chain chain.Chainer
|
||||
Logger logger.Logger
|
||||
@ -24,9 +26,15 @@ func AddrOption(addr string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func AuthsOption(auths ...*url.Userinfo) Option {
|
||||
func AutherOption(auther auth.Authenticator) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Auths = auths
|
||||
opts.Auther = auther
|
||||
}
|
||||
}
|
||||
|
||||
func AuthOption(auth *url.Userinfo) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Auth = auth
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
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"
|
||||
@ -53,13 +52,12 @@ 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(authenticator),
|
||||
PasswordCallback: ssh_util.PasswordCallback(l.options.Auther),
|
||||
PublicKeyCallback: ssh_util.PublicKeyCallback(l.md.authorizedKeys),
|
||||
}
|
||||
config.AddHostKey(l.md.signer)
|
||||
if authenticator == nil && len(l.md.authorizedKeys) == 0 {
|
||||
if l.options.Auther == nil && len(l.md.authorizedKeys) == 0 {
|
||||
config.NoClientAuth = true
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
auth_util "github.com/go-gost/gost/pkg/common/util/auth"
|
||||
ssh_util "github.com/go-gost/gost/pkg/internal/util/ssh"
|
||||
sshd_util "github.com/go-gost/gost/pkg/internal/util/sshd"
|
||||
"github.com/go-gost/gost/pkg/listener"
|
||||
@ -62,13 +61,12 @@ func (l *sshdListener) Init(md md.Metadata) (err error) {
|
||||
|
||||
l.Listener = ln
|
||||
|
||||
authenticator := auth_util.AuthFromUsers(l.options.Auths...)
|
||||
config := &ssh.ServerConfig{
|
||||
PasswordCallback: ssh_util.PasswordCallback(authenticator),
|
||||
PasswordCallback: ssh_util.PasswordCallback(l.options.Auther),
|
||||
PublicKeyCallback: ssh_util.PublicKeyCallback(l.md.authorizedKeys),
|
||||
}
|
||||
config.AddHostKey(l.md.signer)
|
||||
if authenticator == nil && len(l.md.authorizedKeys) == 0 {
|
||||
if l.options.Auther == nil && len(l.md.authorizedKeys) == 0 {
|
||||
config.NoClientAuth = true
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user