mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-03 04:27:39 +03:00
password auth
This commit is contained in:
parent
244d0d43a9
commit
b107eae34a
5 changed files with 30 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -180,3 +180,4 @@ $RECYCLE.BIN/
|
|||
# End of https://www.gitignore.io/api/go,linux,macos,windows,intellij+all
|
||||
|
||||
cmd/relay/*.json
|
||||
hy_linux
|
||||
|
|
5
build.ps1
Normal file
5
build.ps1
Normal file
|
@ -0,0 +1,5 @@
|
|||
$env:GOOS = "windows"
|
||||
go build -ldflags="-w -s" -o "hy_windows.exe" ./cmd
|
||||
|
||||
$env:GOOS = "linux"
|
||||
go build -ldflags="-w -s" -o "hy_linux" ./cmd
|
|
@ -1 +0,0 @@
|
|||
go build -ldflags="-w -s" ./cmd
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/yosuke-furukawa/json5/encoding/json5"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -26,8 +27,8 @@ type serverConfig struct {
|
|||
ACL string `json:"acl"`
|
||||
Obfs string `json:"obfs"`
|
||||
Auth struct {
|
||||
Mode string `json:"mode"`
|
||||
Config interface{} `json:"config"`
|
||||
Mode string `json:"mode"`
|
||||
Config json5.RawMessage `json:"config"`
|
||||
} `json:"auth"`
|
||||
ReceiveWindowConn uint64 `json:"recv_window_conn"`
|
||||
ReceiveWindowClient uint64 `json:"recv_window_client"`
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
hyCongestion "github.com/tobyxdd/hysteria/pkg/congestion"
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/obfs"
|
||||
"github.com/yosuke-furukawa/json5/encoding/json5"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func server(config *serverConfig) {
|
||||
|
@ -48,13 +48,30 @@ func server(config *serverConfig) {
|
|||
}
|
||||
// Auth
|
||||
var authFunc func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string)
|
||||
if len(config.Auth.Mode) == 0 || strings.EqualFold(config.Auth.Mode, "none") {
|
||||
switch authMode := config.Auth.Mode; authMode {
|
||||
case "", "none":
|
||||
logrus.Warn("No authentication configured")
|
||||
authFunc = func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) {
|
||||
return true, "Welcome"
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
case "password":
|
||||
logrus.Info("Password authentication enabled")
|
||||
var pwdConfig map[string]string
|
||||
err = json5.Unmarshal(config.Auth.Config, &pwdConfig)
|
||||
if err != nil || len(pwdConfig["password"]) == 0 {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Fatal("Invalid password authentication config")
|
||||
}
|
||||
pwd := pwdConfig["password"]
|
||||
authFunc = func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) {
|
||||
if string(auth) == pwd {
|
||||
return true, "Welcome"
|
||||
} else {
|
||||
return false, "Wrong password"
|
||||
}
|
||||
}
|
||||
default:
|
||||
logrus.WithField("mode", config.Auth.Mode).Fatal("Unsupported authentication mode")
|
||||
}
|
||||
// Obfuscator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue