mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
improve: use stream reduce auth check time
This commit is contained in:
@@ -2,6 +2,7 @@ package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
petname "github.com/dustinkirkland/golang-petname"
|
||||
@@ -27,13 +28,22 @@ func (a *authHandler) Check(ctx context.Context) (uint64, error) {
|
||||
|
||||
var clientSecret string
|
||||
if value, ok := md["client_secret"]; ok {
|
||||
clientSecret = value[0]
|
||||
clientSecret = strings.TrimSpace(value[0])
|
||||
}
|
||||
|
||||
if clientSecret != singleton.Conf.AgentSecretKey {
|
||||
if clientSecret == "" {
|
||||
return 0, status.Error(codes.Unauthenticated, "客户端认证失败")
|
||||
}
|
||||
|
||||
ip, _ := ctx.Value(model.CtxKeyRealIP{}).(string)
|
||||
|
||||
if clientSecret != singleton.Conf.AgentSecretKey {
|
||||
model.BlockIP(singleton.DB, ip, model.WAFBlockReasonTypeAgentAuthFail)
|
||||
return 0, status.Error(codes.Unauthenticated, "客户端认证失败")
|
||||
}
|
||||
|
||||
model.ClearIP(singleton.DB, ip)
|
||||
|
||||
var clientUUID string
|
||||
if value, ok := md["client_uuid"]; ok {
|
||||
clientUUID = value[0]
|
||||
|
||||
Reference in New Issue
Block a user