Fix(FRP): use UTC for privilegeKey timestamp to fix cross-timezone auth

This commit is contained in:
yuanyuanxiang
2026-05-21 23:06:45 +02:00
parent 5b7d3903b5
commit 83d671c90f
2 changed files with 11 additions and 5 deletions

View File

@@ -710,7 +710,10 @@ bool IsFrpTokenEncoded(const std::string& privilegeKey)
return privilegeKey.length() >= 4 && privilegeKey.substr(0, 4) == "ENC:";
}
// 日期字符串转 Unix 时间戳(当天 23:59:59 本地时间)
// 日期字符串转 Unix 时间戳(当天 23:59:59 UTC
// 必须使用 UTC_mkgmtime而非本地时间mktime—— privilegeKey 由上级生成、
// 下级二次计算后发给 frps 校验若两端时区不同mktime 会返回不同的 UTC 时间戳,
// 导致 MD5 不匹配frps 报 "token in login doesn't match token from configuration"。
time_t FrpDateToTimestamp(const std::string& dateStr)
{
if (dateStr.length() != 8) return 0;
@@ -722,7 +725,7 @@ time_t FrpDateToTimestamp(const std::string& dateStr)
t.tm_hour = 23;
t.tm_min = 59;
t.tm_sec = 59;
return mktime(&t);
return _mkgmtime(&t);
} catch (...) {
return 0;
}