-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New HWID system prep * Allow HWID to be disabled. Both client and server can now request HWID to be disabled. On the server via CVar, if disabled the client won't send it. On the client via env var, if disabled it won't be sent to the client. This involved moving legacy HWID to be sent in MsgEncryptionResponse instead of MsgLoginStart. This means the legacy HWID won't be available anymore if the connection isn't authenticated. * Fix tests * Fix another test * Review * Thanks Rider
- Loading branch information
Showing
20 changed files
with
269 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.IO; | ||
using System.Security.Cryptography; | ||
using Microsoft.Win32; | ||
using Robust.Client.Utility; | ||
using Robust.Shared.IoC; | ||
using Robust.Shared.Network; | ||
|
||
namespace Robust.Client.HWId; | ||
|
||
internal sealed class BasicHWId : IHWId | ||
{ | ||
[Dependency] private readonly IGameControllerInternal _gameController = default!; | ||
|
||
public const int LengthHwid = 32; | ||
|
||
public byte[] GetLegacy() | ||
{ | ||
if (OperatingSystem.IsWindows()) | ||
return GetWindowsHWid("Hwid"); | ||
|
||
return []; | ||
} | ||
|
||
public byte[] GetModern() | ||
{ | ||
byte[] raw; | ||
|
||
if (OperatingSystem.IsWindows()) | ||
raw = GetWindowsHWid("Hwid2"); | ||
else | ||
raw = GetFileHWid(); | ||
|
||
return [0, ..raw]; | ||
} | ||
|
||
private static byte[] GetWindowsHWid(string keyName) | ||
{ | ||
const string keyPath = @"HKEY_CURRENT_USER\SOFTWARE\Space Wizards\Robust"; | ||
|
||
var regKey = Registry.GetValue(keyPath, keyName, null); | ||
if (regKey is byte[] { Length: LengthHwid } bytes) | ||
return bytes; | ||
|
||
var newId = new byte[LengthHwid]; | ||
RandomNumberGenerator.Fill(newId); | ||
Registry.SetValue( | ||
keyPath, | ||
keyName, | ||
newId, | ||
RegistryValueKind.Binary); | ||
|
||
return newId; | ||
} | ||
|
||
private byte[] GetFileHWid() | ||
{ | ||
var path = UserDataDir.GetRootUserDataDir(_gameController); | ||
var hwidPath = Path.Combine(path, ".hwid"); | ||
|
||
var value = ReadHWidFile(hwidPath); | ||
if (value != null) | ||
return value; | ||
|
||
value = RandomNumberGenerator.GetBytes(LengthHwid); | ||
File.WriteAllBytes(hwidPath, value); | ||
|
||
return value; | ||
} | ||
|
||
private static byte[]? ReadHWidFile(string path) | ||
{ | ||
try | ||
{ | ||
var value = File.ReadAllBytes(path); | ||
if (value.Length == LengthHwid) | ||
return value; | ||
} | ||
catch (FileNotFoundException) | ||
{ | ||
// First time the file won't exist. | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using Robust.Shared.Console; | ||
using Robust.Shared.IoC; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Robust.Shared.Network; | ||
|
||
/// <summary> | ||
/// Fetches HWID (hardware ID) unique identifiers for the local system. | ||
/// </summary> | ||
internal interface IHWId | ||
{ | ||
/// <summary> | ||
/// Gets the "legacy" HWID. | ||
/// </summary> | ||
/// <remarks> | ||
/// These are directly sent to servers and therefore susceptible to malicious spoofing. | ||
/// They should not be relied on for the future. | ||
/// </remarks> | ||
/// <returns> | ||
/// An opaque value that gets sent to the server to identify this computer, | ||
/// or an empty array if legacy HWID is not supported on this platform. | ||
/// </returns> | ||
byte[] GetLegacy(); | ||
|
||
/// <summary> | ||
/// Gets the "modern" HWID. | ||
/// </summary> | ||
/// <returns> | ||
/// An opaque value that gets sent to the auth server to identify this computer, | ||
/// or null if modern HWID is not supported on this platform. | ||
/// </returns> | ||
byte[]? GetModern(); | ||
} | ||
|
||
/// <summary> | ||
/// Implementation of <see cref="IHWId"/> that does nothing, always returning an empty result. | ||
/// </summary> | ||
internal sealed class DummyHWId : IHWId | ||
{ | ||
public byte[] GetLegacy() | ||
{ | ||
return []; | ||
} | ||
|
||
public byte[] GetModern() | ||
{ | ||
return []; | ||
} | ||
} | ||
|
||
#if DEBUG | ||
internal sealed class HwidCommand : LocalizedCommands | ||
{ | ||
[Dependency] private readonly IHWId _hwId = default!; | ||
|
||
public override string Command => "hwid"; | ||
|
||
public override void Execute(IConsoleShell shell, string argStr, string[] args) | ||
{ | ||
shell.WriteLine($""" | ||
legacy: {Convert.ToBase64String(_hwId.GetLegacy(), Base64FormattingOptions.None)} | ||
modern: {Base64Helpers.ToBase64Nullable(_hwId.GetModern())} | ||
"""); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.