Misc 2FA enhancements

This commit is contained in:
JustArchi
2022-06-05 12:39:04 +02:00
parent aedad9d5b3
commit add0cad881
2 changed files with 10 additions and 11 deletions

View File

@@ -259,12 +259,10 @@ public static class Utilities {
internal static ulong MathAdd(ulong first, int second) {
if (second >= 0) {
first += (uint) second;
} else {
first -= (uint) -second;
return first + (uint) second;
}
return first;
return first - (uint) -second;
}
internal static bool RelativeDirectoryStartsWith(string directory, params string[] prefixes) {

View File

@@ -44,8 +44,8 @@ public sealed class MobileAuthenticator : IDisposable {
private const byte CodeInterval = 30;
// For how many hours we can assume that SteamTimeDifference is correct
private const byte SteamTimeTTL = 24;
// For how many minutes we can assume that SteamTimeDifference is correct
private const byte SteamTimeTTL = 10;
internal static readonly ImmutableSortedSet<char> CodeCharacters = ImmutableSortedSet.Create('2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y');
@@ -402,7 +402,7 @@ public sealed class MobileAuthenticator : IDisposable {
int? steamTimeDifference = SteamTimeDifference;
if (steamTimeDifference.HasValue && (DateTime.UtcNow.Subtract(LastSteamTimeCheck).TotalHours < SteamTimeTTL)) {
if (steamTimeDifference.HasValue && (DateTime.UtcNow.Subtract(LastSteamTimeCheck).TotalMinutes < SteamTimeTTL)) {
return Utilities.MathAdd(Utilities.GetUnixTime(), steamTimeDifference.Value);
}
@@ -411,7 +411,7 @@ public sealed class MobileAuthenticator : IDisposable {
try {
steamTimeDifference = SteamTimeDifference;
if (steamTimeDifference.HasValue && (DateTime.UtcNow.Subtract(LastSteamTimeCheck).TotalHours < SteamTimeTTL)) {
if (steamTimeDifference.HasValue && (DateTime.UtcNow.Subtract(LastSteamTimeCheck).TotalMinutes < SteamTimeTTL)) {
return Utilities.MathAdd(Utilities.GetUnixTime(), steamTimeDifference.Value);
}
@@ -422,14 +422,15 @@ public sealed class MobileAuthenticator : IDisposable {
}
// We assume that the difference between times will be within int range, therefore we accept underflow here (for subtraction), and since we cast that result to int afterwards, we also accept overflow for the cast itself
SteamTimeDifference = unchecked((int) (serverTime - Utilities.GetUnixTime()));
steamTimeDifference = unchecked((int) (serverTime - Utilities.GetUnixTime()));
SteamTimeDifference = steamTimeDifference;
LastSteamTimeCheck = DateTime.UtcNow;
return Utilities.MathAdd(Utilities.GetUnixTime(), SteamTimeDifference.Value);
} finally {
TimeSemaphore.Release();
}
return Utilities.MathAdd(Utilities.GetUnixTime(), steamTimeDifference.Value);
}
private static async Task LimitConfirmationsRequestsAsync() {