nc_program_manager/Licensing/MachineFingerprint.cs
dtrentin 4cd7715594 fix(robustness): null guard WMI reads, dispose SHA256, abort LSV2 timeout (ISS-001, ISS-005, ISS-006)
ISS-001: MachineFingerprint.GetFingerprint() — null-safe WMI property reads
  - processorID and SerialNumber accessed with ?. and ?? string.Empty
  - prevents NullReferenceException on machines with missing WMI properties

ISS-005: LicenseValidator.Validate() — SHA256CryptoServiceProvider in using block
  - disposed on all code paths (success and failure)

ISS-006: Lsv2Client.Connect() — close TcpClient on timeout
  - _tcp.Close() called when ConnectAsync.Wait() times out
  - aborts pending socket task instead of leaking thread-pool slot

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 23:00:08 +02:00

34 lines
1,011 B
C#

using System.Management;
namespace NcProgramManager.Licensing
{
internal class MachineFingerprint : IMachineFingerprint
{
public string GetFingerprint()
{
string pcInfo = string.Empty;
using (var mc = new ManagementClass("win32_processor"))
using (ManagementObjectCollection moc = mc.GetInstances())
{
foreach (ManagementObject mo in moc)
{
pcInfo = mo.Properties["processorID"]?.Value?.ToString() ?? string.Empty;
break;
}
}
using (var searcher = new ManagementObjectSearcher(
"root\\CIMV2", "SELECT * FROM Win32_BaseBoard"))
{
foreach (ManagementObject obj in searcher.Get())
{
pcInfo += obj["SerialNumber"]?.ToString() ?? string.Empty;
break;
}
}
return pcInfo;
}
}
}