Fix(FRP): use UTC for privilegeKey timestamp to fix cross-timezone auth
This commit is contained in:
@@ -2650,8 +2650,11 @@ bool CMy2015RemoteDlg::GetEffectiveMasterAddress(std::string& outIP, int& outPor
|
|||||||
return false; // 使用本地配置
|
return false; // 使用本地配置
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日期字符串转 Unix 时间戳(当天 23:59:59)
|
// 日期字符串转 Unix 时间戳(当天 23:59:59 UTC)
|
||||||
// 输入: "20260323" -> 输出: 1774329599 (2026-03-23 23:59:59 UTC)
|
// 输入: "20260323" -> 输出: 1774310399 (2026-03-23 23:59:59 UTC)
|
||||||
|
// 必须使用 UTC(_mkgmtime)而非本地时间(mktime)—— 与上级 FrpDateToTimestamp
|
||||||
|
// 保持一致,否则跨时区的下级算出的 timestamp 与上级生成 privilegeKey 时所用的
|
||||||
|
// timestamp 不同,frps 校验失败(token mismatch)。
|
||||||
static time_t DateToTimestamp(const std::string& dateStr)
|
static time_t DateToTimestamp(const std::string& dateStr)
|
||||||
{
|
{
|
||||||
if (dateStr.length() != 8) return 0;
|
if (dateStr.length() != 8) return 0;
|
||||||
@@ -2661,7 +2664,7 @@ static time_t DateToTimestamp(const std::string& dateStr)
|
|||||||
t.tm_mon = std::stoi(dateStr.substr(4, 2)) - 1;
|
t.tm_mon = std::stoi(dateStr.substr(4, 2)) - 1;
|
||||||
t.tm_mday = std::stoi(dateStr.substr(6, 2));
|
t.tm_mday = std::stoi(dateStr.substr(6, 2));
|
||||||
t.tm_hour = 23; t.tm_min = 59; t.tm_sec = 59;
|
t.tm_hour = 23; t.tm_min = 59; t.tm_sec = 59;
|
||||||
return mktime(&t);
|
return _mkgmtime(&t);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -710,7 +710,10 @@ bool IsFrpTokenEncoded(const std::string& privilegeKey)
|
|||||||
return privilegeKey.length() >= 4 && privilegeKey.substr(0, 4) == "ENC:";
|
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)
|
time_t FrpDateToTimestamp(const std::string& dateStr)
|
||||||
{
|
{
|
||||||
if (dateStr.length() != 8) return 0;
|
if (dateStr.length() != 8) return 0;
|
||||||
@@ -722,7 +725,7 @@ time_t FrpDateToTimestamp(const std::string& dateStr)
|
|||||||
t.tm_hour = 23;
|
t.tm_hour = 23;
|
||||||
t.tm_min = 59;
|
t.tm_min = 59;
|
||||||
t.tm_sec = 59;
|
t.tm_sec = 59;
|
||||||
return mktime(&t);
|
return _mkgmtime(&t);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user