Security: Agent-Key in config.json per Windows DPAPI verschlüsselt (v2.9.0)
agent_key liegt jetzt nicht mehr im Klartext auf der Platte, sondern via ProtectedData.Protect (DataProtectionScope.LocalMachine) verschlüsselt — nur das SYSTEM-Konto auf genau diesem einen Rechner kann den Wert wieder entschlüsseln. Reines Auslesen von config.json bringt einem lokalen Angreifer/Malware also nichts mehr. Migration automatisch beim ersten Start von v2.9.0: erkennt das alte Klartext-Format, verschlüsselt beim nächsten Save() automatisch — kein manueller Eingriff nötig, läuft über den bestehenden Staged-Rollout. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ namespace ITNexusAgent;
|
||||
|
||||
public class AgentWorker
|
||||
{
|
||||
private const string Version = "2.8.0";
|
||||
private const string Version = "2.9.0";
|
||||
private const string DataDir = @"C:\ProgramData\IT Nexus Agent";
|
||||
private const string ConfigPath = @"C:\ProgramData\IT Nexus Agent\config.json";
|
||||
private const string StatusPath = @"C:\ProgramData\IT Nexus Agent\status.json";
|
||||
@@ -44,10 +44,11 @@ public class AgentWorker
|
||||
// Idempotent (Server liefert bestehenden Key erneut) — daher bei jedem Start sicher aufrufbar.
|
||||
var hostname = SystemInfoService.GetHostname();
|
||||
var enrolledKey = await _api.EnrollAsync(hostname);
|
||||
if (!string.IsNullOrEmpty(enrolledKey) && enrolledKey != _config.AgentKey)
|
||||
var configWasUnencrypted = !File.ReadAllText(ConfigPath).Contains("dpapi:");
|
||||
if (!string.IsNullOrEmpty(enrolledKey) && (enrolledKey != _config.AgentKey || configWasUnencrypted))
|
||||
{
|
||||
_config.AgentKey = enrolledKey;
|
||||
_config.Save(ConfigPath);
|
||||
_config.Save(ConfigPath); // schreibt agent_key jetzt DPAPI-verschlüsselt statt im Klartext
|
||||
_api.UpdateKey(enrolledKey);
|
||||
Log("ENROLL: Per-Device-Key erhalten und gespeichert");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user