Browse Source

支持genpass命令

pull/1077/head
karl 3 years ago
parent
commit
af954386b4
  1. 20
      auth.go
  2. 7
      cmd/gost/main.go

20
auth.go

@ -24,22 +24,26 @@ func (au *LocalAuthenticator) InflowwAuthenticateContext(ctx context.Context, us
if inboundIP != nil { if inboundIP != nil {
ip := inboundIP.(net.IP) ip := inboundIP.(net.IP)
if !ip.IsLoopback() && !ip.IsPrivate() { if !ip.IsLoopback() && !ip.IsPrivate() {
p := ip.String() expected := GeneratePass(ip.String(), user)
src := p + user + "&&4sg123g[]/~" if expected == password {
hash := sha256.New()
hash.Write([]byte(src))
hashedSrc := hash.Sum(nil)
hashedSrcHex := hex.EncodeToString(hashedSrc)
if hashedSrcHex == password {
return true return true
} else { } 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 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. // LocalAuthenticator is an Authenticator that authenticates client by local key-value pairs.
type LocalAuthenticator struct { type LocalAuthenticator struct {
kvs map[string]string kvs map[string]string

7
cmd/gost/main.go

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"runtime" "runtime"
"strings"
_ "net/http/pprof" _ "net/http/pprof"
@ -23,6 +24,12 @@ var (
) )
func init() { 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{}) gost.SetLogger(&gost.LogLogger{})
var ( var (

Loading…
Cancel
Save