123
This commit is contained in:
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"cmii-uav-watchdog-common/models"
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -27,6 +28,11 @@ func (hs *HeartbeatService) ProcessHeartbeat(req models.HeartbeatRequest) (*mode
|
||||
return nil, errors.New("无效的时间戳")
|
||||
}
|
||||
|
||||
secondTOTPSecret := hs.authService.authorizationInfo.SecondTOTPSecret
|
||||
if secondTOTPSecret == "" {
|
||||
return nil, errors.New("二级TOTP密钥为空")
|
||||
}
|
||||
|
||||
// 添加主机信息到集合
|
||||
hs.authService.AddHostInfo(req.HostInfo)
|
||||
|
||||
@@ -36,17 +42,26 @@ func (hs *HeartbeatService) ProcessHeartbeat(req models.HeartbeatRequest) (*mode
|
||||
Authorized: false,
|
||||
TOTPCode: "",
|
||||
Timestamp: time.Now().Unix(),
|
||||
SecondTOTPSecret: "",
|
||||
SecondTOTPSecret: secondTOTPSecret,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 检查totp密码是都有效
|
||||
// 检查totp验证码是否有效
|
||||
if !hs.totpService.VerifyTierTwoTOTPCode(req.TOTPCode, secondTOTPSecret) {
|
||||
// 解析认证主机的相关信息
|
||||
|
||||
// 计算 请求时间与当前时间的时间差
|
||||
diff := time.Now().Unix() - req.Timestamp
|
||||
log.Printf("心跳请求时间与当前时间的时间差: %d", diff)
|
||||
|
||||
return nil, errors.New("无效的TOTP验证码,请检查系统时间是否正确!")
|
||||
}
|
||||
|
||||
// 检查主机是否已授权
|
||||
authorized := hs.authService.IsHostAuthorized(req.HostInfo)
|
||||
|
||||
// 生成TOTP验证码
|
||||
totpCode, err := hs.totpService.GenerateTOTP()
|
||||
totpCode, err := hs.totpService.GenerateTierTwoTOTPCode(secondTOTPSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user