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 {
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

7
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 (

Loading…
Cancel
Save