版本封存
This commit is contained in:
@@ -2,8 +2,10 @@ package services
|
||||
|
||||
import (
|
||||
"cmii-uav-watchdog-common/models"
|
||||
"cmii-uav-watchdog-common/totp_tier_two"
|
||||
"cmii-uav-watchdog-common/utils"
|
||||
"cmii-uav-watchdog-common/wdd_log"
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -30,6 +32,7 @@ func (hs *HeartbeatService) ProcessHeartbeat(req models.HeartbeatRequest) (*mode
|
||||
|
||||
secondTOTPSecret := hs.authService.authorizationInfo.SecondTOTPSecret
|
||||
if secondTOTPSecret == "" {
|
||||
wdd_log.Error("二级TOTP密钥为空")
|
||||
return nil, errors.New("二级TOTP密钥为空")
|
||||
}
|
||||
|
||||
@@ -47,12 +50,13 @@ func (hs *HeartbeatService) ProcessHeartbeat(req models.HeartbeatRequest) (*mode
|
||||
}
|
||||
|
||||
// 检查totp验证码是否有效
|
||||
if !hs.totpService.VerifyTierTwoTOTPCode(req.TOTPCode, secondTOTPSecret) {
|
||||
if !totp_tier_two.VerifyTierTwoTOTPCode(req.TOTPCode, secondTOTPSecret) {
|
||||
// 解析认证主机的相关信息
|
||||
|
||||
// 计算 请求时间与当前时间的时间差
|
||||
utils.CurentTimeUnix()
|
||||
diff := time.Now().Unix() - req.Timestamp
|
||||
log.Printf("心跳请求时间与当前时间的时间差: %d", diff)
|
||||
wdd_log.Error("TOTP验证失败!心跳请求时间与当前时间的时间差: %d", diff)
|
||||
|
||||
return nil, errors.New("无效的TOTP验证码,请检查系统时间是否正确!")
|
||||
}
|
||||
@@ -61,7 +65,7 @@ func (hs *HeartbeatService) ProcessHeartbeat(req models.HeartbeatRequest) (*mode
|
||||
authorized := hs.authService.IsHostAuthorized(req.HostInfo)
|
||||
|
||||
// 生成TOTP验证码
|
||||
totpCode, err := hs.totpService.GenerateTierTwoTOTPCode(secondTOTPSecret)
|
||||
totpCode, err := totp_tier_two.GenerateTierTwoTOTPCode(secondTOTPSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -82,3 +86,16 @@ func (hs *HeartbeatService) isTimestampValid(timestamp int64) bool {
|
||||
// 允许5分钟的时间偏差
|
||||
return diff < 300 && diff > -300
|
||||
}
|
||||
|
||||
// GetAllHostInfo 获取所有主机信息
|
||||
func (hs *HeartbeatService) GetAllHostInfo() (map[string]models.HostInfo, error) {
|
||||
// 调用AuthService的方法获取所有主机信息
|
||||
hostInfoMap := hs.authService.GetAllHostInfo()
|
||||
|
||||
// 如果没有主机信息,返回一个空的map
|
||||
if len(hostInfoMap) == 0 {
|
||||
return make(map[string]models.HostInfo), nil
|
||||
}
|
||||
|
||||
return hostInfoMap, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user