Files
mxaccess/analysis/decompiled/aaServicesCommon/ArchestrAServices.Common/FingerprintedDataProtector.cs
T
Joseph Doherty fe2a6db786
rust / build / test / clippy / fmt (push) Has been cancelled
Initial project state: .NET reference, design, Rust port (M0+M1), evidence
Layout:
- src/                    .NET 10 x64 reference: MxNativeCodec, MxNativeClient,
                          MxAsbClient, probes, tests, harnesses. Executable spec.
- design/                 Architectural plan for the Rust port (M0–M6), error
                          model, protocol invariants, risks (R1–R16), adversarial
                          review log (review.md).
- rust/                   Rust workspace. M0 skeleton + M1 codec parity.
                          mxaccess-codec: 215 unit tests + 2 cross-implementation
                          parity tests (byte-identical against .NET reference).
                          Other crates are M0 stubs awaiting M2+.
- captures/               Frida + netsh + pcap evidence per CLAUDE.md
                          ("captures are evidence, not throwaway logs").
- analysis/               Decompiled C# (frida/proxy/decompiled-*),
                          Ghidra exports for native DLLs (`exports/` only —
                          working state at `projects/` and AVEVA's input
                          binaries at `input/` are gitignored).
- docs/                   Reverse-engineering reference docs.
- tools/                  Setup-LiveProbeEnv.ps1 (Infisical credential fetcher),
                          Compute-Crc.ps1 (.NET parity helper).
- .github/workflows/      Rust CI: fmt + build + test + clippy on Windows.
- LICENSE                 MIT (Joseph Doherty, 2026).

Verified:
- cargo test --workspace → 217 passed (215 unit + 2 .NET parity), 0 failed
- cargo clippy --workspace -- -D warnings → clean
- cargo fmt --all -- --check → clean
- cargo publish --dry-run -p mxaccess-codec → packages cleanly

Excluded from history (see .gitignore):
- **/bin, **/obj, **/target — build artifacts
- analysis/ghidra/projects/ — Ghidra working state (regenerable)
- analysis/ghidra/input/ — AVEVA proprietary DLLs (vendor IP)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 06:21:00 -04:00

126 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Management;
using System.Security;
using System.Security.Cryptography;
using System.Text;
namespace ArchestrAServices.Common;
public static class FingerprintedDataProtector
{
private const string PrefixV1 = "____NCHENC___";
private static readonly byte[] AdditionalEntropy = Value;
private static readonly UTF8Encoding Encoding = new UTF8Encoding();
private static byte[] Value => GetHash(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2]
{
CpuId(),
BiosId()
}), string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2]
{
BaseId(),
DiskId()
}));
public static string Protect(string data)
{
return Convert.ToBase64String(Protect(Encoding.GetBytes(AttachPrefix(data))));
}
public static byte[] Protect(byte[] data)
{
return ProtectedData.Protect(data, AdditionalEntropy, DataProtectionScope.LocalMachine);
}
public static string Unprotect(string encoded)
{
return DetachPrefix(Encoding.GetString(Unprotect(Convert.FromBase64String(encoded))));
}
public static byte[] Unprotect(byte[] encoded)
{
return ProtectedData.Unprotect(encoded, AdditionalEntropy, DataProtectionScope.LocalMachine);
}
private static string AttachPrefix(string toEncode)
{
return "____NCHENC___" + toEncode;
}
private static string BaseId()
{
Dictionary<string, string> dictionary = Identifier("Win32_BaseBoard", "Model", "Manufacturer", "Name", "SerialNumber");
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}", dictionary["Model"], dictionary["Manufacturer"], dictionary["Name"], dictionary["SerialNumber"]);
}
private static string BiosId()
{
Dictionary<string, string> dictionary = Identifier("Win32_BIOS", "Manufacturer", "IdentificationCode");
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}", new object[2]
{
dictionary["Manufacturer"],
dictionary["IdentificationCode"]
});
}
private static string CpuId()
{
Dictionary<string, string> dictionary = Identifier("Win32_Processor", "UniqueId", "ProcessorId", "Name", "Manufacturer", "MaxClockSpeed");
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}-{4}", dictionary["UniqueId"], dictionary["ProcessorId"], dictionary["Name"], dictionary["Manufacturer"], dictionary["MaxClockSpeed"]);
}
private static string DetachPrefix(string decoded)
{
if (decoded.Length > "____NCHENC___".Length && decoded.StartsWith("____NCHENC___", StringComparison.Ordinal))
{
return decoded.Substring("____NCHENC___".Length);
}
throw new SecurityException("Invalid encoded string.");
}
private static string DiskId()
{
Dictionary<string, string> dictionary = Identifier("Win32_DiskDrive", "Model", "Manufacturer", "Signature", "TotalHeads");
return string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}", dictionary["Model"], dictionary["Manufacturer"], dictionary["Signature"], dictionary["TotalHeads"]);
}
private static byte[] GetHash(string partOne, string partTwo)
{
byte[] bytes = new UTF8Encoding().GetBytes(partTwo);
using Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(partOne, bytes);
return rfc2898DeriveBytes.GetBytes(16);
}
private static Dictionary<string, string> Identifier(string wmiClass, params string[] wmiProperties)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>(wmiProperties.Length);
string[] array = wmiProperties;
foreach (string key in array)
{
dictionary[key] = string.Empty;
}
using ManagementClass managementClass = new ManagementClass(wmiClass);
foreach (ManagementObject item in managementClass.GetInstances().Cast<ManagementObject>())
{
array = wmiProperties;
foreach (string text in array)
{
try
{
dictionary[text] = item[text].ToString();
}
catch (Exception)
{
dictionary[text] = string.Empty;
}
}
}
return dictionary;
}
}