add auther config

This commit is contained in:
ginuerzh
2022-02-12 00:33:20 +08:00
parent c1bf501734
commit a8a6bbc3a3
37 changed files with 261 additions and 183 deletions

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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
}