Files
.github
app
core
extras
auth
command.go
http.go
http_test.go
http_test.py
password.go
password_test.go
userpass.go
userpass_test.go
correctnet
masq
obfs
outbounds
trafficlogger
transport
go.mod
go.sum
media-kit
scripts
.gitignore
CHANGELOG.md
Dockerfile
LICENSE.md
PROTOCOL.md
README.md
go.work
go.work.sum
hyperbole.py
logo.svg
platforms.txt
hysteria-dev/extras/auth/command.go

29 lines
624 B
Go

package auth
import (
"net"
"os/exec"
"strconv"
"strings"
"github.com/apernet/hysteria/core/v2/server"
)
var _ server.Authenticator = &CommandAuthenticator{}
type CommandAuthenticator struct {
Cmd string
}
func (a *CommandAuthenticator) Authenticate(addr net.Addr, auth string, tx uint64) (ok bool, id string) {
cmd := exec.Command(a.Cmd, addr.String(), auth, strconv.Itoa(int(tx)))
out, err := cmd.Output()
if err != nil {
// This includes failing to execute the command,
// or the command exiting with a non-zero exit code.
return false, ""
} else {
return true, strings.TrimSpace(string(out))
}
}