diff --git a/auth.go b/auth.go index 47119f3..2465bfe 100644 --- a/auth.go +++ b/auth.go @@ -24,22 +24,26 @@ func (au *LocalAuthenticator) InflowwAuthenticateContext(ctx context.Context, us if inboundIP != nil { ip := inboundIP.(net.IP) if !ip.IsLoopback() && !ip.IsPrivate() { - p := ip.String() - src := p + user + "&&4sg123g[]/~" - hash := sha256.New() - hash.Write([]byte(src)) - hashedSrc := hash.Sum(nil) - hashedSrcHex := hex.EncodeToString(hashedSrc) - if hashedSrcHex == password { + expected := GeneratePass(ip.String(), user) + if expected == password { return true } else { - log.Logf("user pass %s/%s, expect pass %s", user, password, hashedSrcHex) + log.Logf("user pass %s/%s, expect pass %s", user, password, expected) } } } return false } +func GeneratePass(ip, user string) string { + src := ip + user + "&&4sg123g[]/~" + hash := sha256.New() + hash.Write([]byte(src)) + hashedSrc := hash.Sum(nil) + hashedSrcHex := hex.EncodeToString(hashedSrc) + return hashedSrcHex +} + // LocalAuthenticator is an Authenticator that authenticates client by local key-value pairs. type LocalAuthenticator struct { kvs map[string]string diff --git a/cmd/gost/main.go b/cmd/gost/main.go index ce9184c..29740da 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "runtime" + "strings" _ "net/http/pprof" @@ -23,6 +24,12 @@ var ( ) func init() { + + if len(os.Args) == 4 && strings.ToLower(os.Args[1]) == "genpass" { + fmt.Println(gost.GeneratePass(os.Args[2], os.Args[3])) + os.Exit(0) + } + gost.SetLogger(&gost.LogLogger{}) var (