Add username authentication support

This commit is contained in:
SETTAI Yassine
2025-09-04 16:49:33 +02:00
parent 48a13bd973
commit ff8b1d74f0
7 changed files with 27 additions and 20 deletions
+6 -2
View File
@@ -105,7 +105,7 @@ type Teamserver interface {
type TsConnector struct {
Interface string
Port int
Hash string
Operators map[string]string
Endpoint string
Cert string
Key string
@@ -150,10 +150,14 @@ func NewTsConnector(ts Teamserver, tsProfile profile.TsProfile, tsResponse profi
connector.Interface = tsProfile.Interface
connector.Port = tsProfile.Port
connector.Endpoint = tsProfile.Endpoint
connector.Hash = krypt.SHA256([]byte(tsProfile.Password))
connector.Key = tsProfile.Key
connector.Cert = tsProfile.Cert
connector.Operators = make(map[string]string, len(tsProfile.Operators))
for username, password := range tsProfile.Operators {
connector.Operators[username] = krypt.SHA256([]byte(password))
}
connector.Engine.POST(tsProfile.Endpoint+"/login", default404Middleware(tsResponse), connector.tcLogin)
connector.Engine.POST(tsProfile.Endpoint+"/refresh", default404Middleware(tsResponse), token.RefreshTokenHandler)
connector.Engine.POST(tsProfile.Endpoint+"/sync", token.ValidateAccessToken(), default404Middleware(tsResponse), connector.tcSync)
+1 -1
View File
@@ -34,7 +34,7 @@ func (tc *TsConnector) tcLogin(ctx *gin.Context) {
recvHash := krypt.SHA256([]byte(creds.Password))
if recvHash != tc.Hash {
if recvHash != tc.Operators[creds.Username] {
_ = ctx.Error(errors.New("incorrect password"))
return
}
+2 -2
View File
@@ -24,8 +24,8 @@ func (p *AdaptixProfile) IsValid() error {
valid = false
}
if p.Server.Password == "" {
logs.Error("", "'Teamserver.password' must be set")
if len(p.Server.Operators) == 0 {
logs.Error("", "'Teamserver.operators' must be set")
valid = false
}
+9 -9
View File
@@ -7,15 +7,15 @@ type AdaptixProfile struct {
}
type TsProfile struct {
Interface string `json:"interface"`
Port int `json:"port"`
Endpoint string `json:"endpoint"`
Password string `json:"password"`
Cert string `json:"cert"`
Key string `json:"key"`
Extenders []string `json:"extenders"`
ATokenLive int `json:"access_token_live_hours"`
RTokenLive int `json:"refresh_token_live_hours"`
Interface string `json:"interface"`
Port int `json:"port"`
Endpoint string `json:"endpoint"`
Operators map[string]string `json:"operators"`
Cert string `json:"cert"`
Key string `json:"key"`
Extenders []string `json:"extenders"`
ATokenLive int `json:"access_token_live_hours"`
RTokenLive int `json:"refresh_token_live_hours"`
}
type TsResponse struct {
+2 -2
View File
@@ -48,12 +48,12 @@ func NewTeamserver() *Teamserver {
return ts
}
func (ts *Teamserver) SetSettings(host string, port int, endpoint string, password string, cert string, key string, extenders []string) {
func (ts *Teamserver) SetSettings(host string, port int, endpoint string, username string, password string, cert string, key string, extenders []string) {
ts.Profile.Server = &profile.TsProfile{
Interface: host,
Port: port,
Endpoint: endpoint,
Password: password,
Operators: map[string]string{username: password},
Cert: cert,
Key: key,
Extenders: extenders,
+4 -3
View File
@@ -20,6 +20,7 @@ func main() {
host = flag.String("i", "0.0.0.0", "Teamserver listen interface")
port = flag.Int("p", 0, "Teamserver handler port")
endpoint = flag.String("e", "", "Teamserver URI endpoint")
username = flag.String("u", "", "Teamserver username")
password = flag.String("pw", "", "Teamserver password")
certPath = flag.String("sc", "", "Path to the SSL certificate")
keyPath = flag.String("sk", "", "Path to the SSL key")
@@ -34,7 +35,7 @@ func main() {
flag.PrintDefaults()
fmt.Printf("\nEither provide options individually or use a JSON config file with -config flag.\n\n")
fmt.Printf("Example:\n")
fmt.Printf(" AdaptixServer -i 0.0.0.0 -p port -pw password -e endpoint -sc SslCert -sk SslKey [-ex ext1,ext2,...] [-debug]\n")
fmt.Printf(" AdaptixServer -i 0.0.0.0 -p port -u username -pw password -e endpoint -sc SslCert -sk SslKey [-ex ext1,ext2,...] [-debug]\n")
fmt.Printf(" AdaptixServer -profile profile.json [-debug]\n")
}
flag.Parse()
@@ -54,9 +55,9 @@ func main() {
logs.Error("", err.Error())
os.Exit(1)
}
} else if *port > 1 && *port < 65535 && *endpoint != "" && *password != "" {
} else if *port > 1 && *port < 65535 && *endpoint != "" && *username != "" && *password != "" {
extenders := strings.Split(*extenderPath, ",")
ts.SetSettings(*host, *port, *endpoint, *password, *certPath, *keyPath, extenders)
ts.SetSettings(*host, *port, *endpoint, *username, *password, *certPath, *keyPath, extenders)
} else {
flag.Usage()
os.Exit(0)
+3 -1
View File
@@ -3,7 +3,9 @@
"interface": "0.0.0.0",
"port": 4321,
"endpoint": "/endpoint",
"password": "pass",
"operators": {
"user": "password"
},
"cert": "server.rsa.crt",
"key": "server.rsa.key",
"extenders": [