Return fixed Windows maintenance results over a foreground loopback SSH forward
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-15 17:03:38 +01:00
parent 577132fb42
commit d37160ba41
2 changed files with 123 additions and 0 deletions
@@ -0,0 +1,105 @@
#requires -Version 5.1
#requires -RunAsAdministrator
# The relay receives a fixed public receipt. There is no command reader.
$ErrorActionPreference = 'Stop'
$until = [DateTimeOffset]::Parse('2026-11-15T17:00:00+00:00')
$deadline = [DateTimeOffset]::UtcNow.AddMinutes(12)
if ($deadline -gt $until) { $deadline = $until }
if ($deadline -le [DateTimeOffset]::UtcNow) { throw 'Das Wartungsfenster ist abgelaufen.' }
$base = 'https://gitea.incoso.eu/kevin_janssen/rust-discovery/raw/commit/577132fb422bf854276b3afb5bafdb12d2c08427/deploy/windows'
$bootstrap = 'C:\ProgramData\RustDiscoveryBootstrap'
$caseId = 'ad9fd154-b2be-4f5d-9e17-65abb721ceaf'
$case = Join-Path $bootstrap "time-profile-$caseId"
$access = 'C:\ProgramData\RmmDevAccess'
$sshBin = Join-Path $env:WINDIR 'System32\OpenSSH'
$known = Join-Path $access 'known_hosts'
$key = Join-Path $access 'tunnel_ed25519'
$fp = & "$sshBin\ssh-keygen.exe" -lf $known
if ($LASTEXITCODE -ne 0 -or @($fp).Count -ne 1 -or
$fp.Split(' ')[1] -cne 'SHA256:+NEin4XJc3CbhjQi7/ZpMIgxOrXn8AT2tlpTaXW5quw') { throw 'Server-Hostpin stimmt nicht.' }
$session = [guid]::NewGuid().ToString()
$work = Join-Path $bootstrap "time-receipt-$session"
$null = New-Item -ItemType Directory -Path $work
$listener = $null
$ssh = $null
$scripts = [ordered]@{
'Complete-OriginalTimeProfile.ps1' = '5ad85ae7a3a513d3cc2f5f5dca3e48eb42fd863522c3384f9c64cdcf0273ef1a'
'Read-PassiveTimeSamples.ps1' = 'd9e2b9344c19af1296b86ec70ba754ef820f369ac5ec897979bd4233e0722d04'
}
try {
foreach ($name in $scripts.Keys) {
$path = Join-Path $work $name
Invoke-WebRequest -UseBasicParsing -Uri "$base/$name" -OutFile $path -TimeoutSec 30
if ((Get-FileHash -LiteralPath $path).Hash -ne $scripts[$name]) { throw "Downloadhash: $name" }
Unblock-File -LiteralPath $path
}
$listener = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback, 0)
$listener.Start(4)
$port = $listener.LocalEndpoint.Port
$options = @('-F','NUL','-N','-T','-o','BatchMode=yes','-o','IdentitiesOnly=yes',
'-o','ForwardAgent=no','-o','StrictHostKeyChecking=yes','-o','GlobalKnownHostsFile=NUL',
'-o',"UserKnownHostsFile=$known",'-o','ExitOnForwardFailure=yes','-o','ConnectTimeout=10',
'-o','ServerAliveInterval=15','-o','ServerAliveCountMax=2','-i',$key,
'-R',"127.0.0.1:22240:127.0.0.1:$port",'rmm-win-tunnel@discovery.ease-technologies.de')
$ssh = Start-Process -FilePath "$sshBin\ssh.exe" -ArgumentList $options -PassThru -NoNewWindow
if ($ssh.WaitForExit(1800)) { throw "SSH Exit $($ssh.ExitCode)" }
Write-Host 'Wartungsfenster aktiv. Dieses Fenster offen lassen. Strg+C beendet es.'
$receipt = [ordered]@{session=$session; case_id=$caseId; phase='preflight'; read_only_channel=$true}
$result = Join-Path $case 'result.json'
try {
if (!(Test-Path -LiteralPath $result)) {
$null = & (Join-Path $work 'Complete-OriginalTimeProfile.ps1')
}
$record = Get-Content -LiteralPath $result -Raw | ConvertFrom-Json
$actual = Get-FileHash -LiteralPath 'C:\ProgramData\RustDiscoverySystem\time-attestation.json'
if ($record.id -cne $caseId -or $record.installed -ne $true -or
$record.console_finalized -ne $true -or $record.clock_runtime_qualified -ne $false -or
$actual.Hash -ne '2b4a8a7080770304b80e2a665fa5f5ee1ebbd9182e7c80b184e75b114575b42b') { throw 'Unexpected publication result' }
$marker = Get-Content -LiteralPath (Join-Path $case 'console-finalization-intent.json') -Raw | ConvertFrom-Json
if ($marker.id -cne $caseId -or $marker.config_sha256 -ne $actual.Hash) { throw 'Unexpected finalization intent' }
$receipt.phase = 'published'
$receipt.publication_since = $marker.utc
$receipt.result_sha256 = (Get-FileHash -LiteralPath $result).Hash
} catch {
$receipt.phase = 'finalization_failed'
$receipt.exception_type = $_.Exception.GetBaseException().GetType().FullName
$receipt.line = $_.InvocationInfo.ScriptLineNumber
$receipt.file = [IO.Path]::GetFileName($_.InvocationInfo.ScriptName)
Write-Warning $_.Exception.Message
$failurePath = Join-Path $case 'console-finalization-error.json'
if (Test-Path -LiteralPath $failurePath) {
$failure = Get-Content -LiteralPath $failurePath -Raw | ConvertFrom-Json
if ($failure.id -ceq $caseId -and $failure.hresult -cmatch '^0x[0-9A-Fa-f]{8}$') { $receipt.move_hresult = $failure.hresult }
}
}
$readScript = Join-Path $work 'Read-PassiveTimeSamples.ps1'
$readInput = @{id=$session; agent_sha256='0549d9ebea73cff996938f859b92192cc333de194128d7c6859a3f1d2e85893c'; helper_sha256='59675a3cbb3a5d213fc764f38379d6b81baaf9d47a7124470cc2767d4985763e'} | ConvertTo-Json -Compress
while ([DateTimeOffset]::UtcNow -lt $deadline -and !$ssh.HasExited) {
if (!$listener.Pending()) { Start-Sleep -Milliseconds 250; continue }
$client = $listener.AcceptTcpClient()
try {
if ($receipt.phase -eq 'published') {
$receipt.native = $null
try {
$json = $readInput | & "$env:WINDIR\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy RemoteSigned -File $readScript
if ($LASTEXITCODE -eq 0) { $receipt.native = ($json -join "`n") | ConvertFrom-Json }
} catch { Write-Warning 'Passive Zeitbelege aktuell nicht lesbar.' }
}
$client.SendTimeout = 3000
$body = [Text.Encoding]::UTF8.GetBytes(($receipt | ConvertTo-Json -Depth 16 -Compress))
if ($body.Length -gt 65536) { throw 'Ergebnis zu gross.' }
$client.GetStream().Write($body,0,$body.Length)
} catch { Write-Warning $_.Exception.Message } finally { $client.Dispose() }
}
} finally {
if ($null -ne $ssh) {
try { if (!$ssh.HasExited) { $ssh.Kill(); $ssh.WaitForExit() } } finally { $ssh.Dispose() }
}
if ($null -ne $listener) { $listener.Stop() }
foreach ($name in $scripts.Keys) {
$path = Join-Path $work $name
if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path }
}
if ((Get-ChildItem -LiteralPath $work -Force | Measure-Object).Count -eq 0) { [IO.Directory]::Delete($work) }
}
+18
View File
@@ -291,3 +291,21 @@ Lokal geprüft wurden die PowerShell-Syntax, die Bindung an die gespeicherten
Originalbelege und der Vergleich mit der tatsächlichen Kandidatenidentität.
Eine veränderte FileID wurde im lokalen Vergleich abgewiesen. Die Ausführung
des Abschlussbefehls auf der VM und die anschließende Zeitprüfung stehen aus.
## Ergebnis vom Konsolenschritt automatisch abholen
Für den vorbereiteten Profilabschluss steht `Open-TimeProfileReceiptWindow.ps1`
zur Verfügung. Die Bedienperson startet es auf der Windows-VM. Das Skript prüft
die beiden Downloads gegen feste SHA-256-Werte, öffnet den vorhandenen
Reverse-SSH-Transport und führt den festen Abschluss lokal aus. Die
Weiterleitung auf dem Server ist an `127.0.0.1:22240` gebunden. Auf der VM
endet sie an einem temporären Loopback-Port. Der Prozess sendet dort den
Abschlussstatus und die öffentlichen Belege der beiden Zeitdienstrollen.
Er liest keine Befehle vom Socket. Die Gast-Kontofrist und die Aufgabenplanung
werden nicht geändert. Strg+C oder zwölf Minuten beenden das Vordergrundfenster.
Die serverseitige Frist für den vorhandenen Transportschlüssel und der aktive
Abschalttimer wurden für den 15. November 2026, 18:00 Uhr MEZ, geprüft.
Beim Bereitstellen wurden der PowerShell-Parser, die Downloadhashes, die
bestehenden Quellprüfungen und die sechs lokalen Prüffälle für die Zeitbelege
ausgeführt. Ein Ergebnis von der VM liegt bei Bereitstellung noch nicht vor.