Compare commits

..
Author SHA1 Message Date
kevin_janssen 5adf209f1e Capture both security descriptors at the exclusive profile creation handle
Rust development slice / linux (push) Failing after 7s
2026-11-15 20:28:38 +01:00
3 changed files with 48 additions and 43 deletions
@@ -128,22 +128,29 @@ public static class RmmInitialProfileFile {
'@
}
function Get-HeldProfileIdentity([IO.FileStream]$Stream) {
[RmmInitialProfileFile]::CheckSingleFile($Stream.SafeFileHandle, 1177)
function Get-HeldProfileFileId([IO.FileStream]$Stream) {
$id = New-Object RmmPipeNative+FileId
if (![RmmPipeNative]::GetFileInformationByHandleEx($Stream.SafeFileHandle, 18, [ref]$id, 24)) {
throw 'New file identity unavailable'
}
return @{
volume_serial=$id.Volume.ToString([Globalization.CultureInfo]::InvariantCulture)
file_id=([BitConverter]::ToString($id.Id)).Replace('-','').ToLowerInvariant()
}
}
function Get-HeldProfileIdentity([IO.FileStream]$Stream) {
[RmmInitialProfileFile]::CheckSingleFile($Stream.SafeFileHandle, 1177)
$identity = Get-HeldProfileFileId $Stream
$Stream.Position = 0
$algorithm = [Security.Cryptography.SHA256]::Create()
try { $digest = [BitConverter]::ToString($algorithm.ComputeHash($Stream)).Replace('-','').ToLowerInvariant() }
finally { $algorithm.Dispose() }
$sddl = $Stream.GetAccessControl().GetSecurityDescriptorSddlForm($aclSections)
return @{
volume_serial=$id.Volume.ToString([Globalization.CultureInfo]::InvariantCulture)
file_id=([BitConverter]::ToString($id.Id)).Replace('-','').ToLowerInvariant()
bytes=$Stream.Length; sha256=$digest; acl_sha256=(BytesHash ([Text.Encoding]::UTF8.GetBytes($sddl)))
}
$identity.bytes = $Stream.Length
$identity.sha256 = $digest
$identity.acl_sha256 = BytesHash ([Text.Encoding]::UTF8.GetBytes($sddl))
return $identity
}
function New-OriginalPublicProfile {
@@ -165,6 +172,7 @@ function New-OriginalPublicProfile {
$since = [DateTime]::UtcNow.ToString('o')
WriteNew $initialReservation @{id=$caseId; config_sha256=$configHash; utc=$since; staged=$expected; create_new=$true}
$phase = 'CreateNew'
$descriptorFailure = $null
try {
$rights = [Security.AccessControl.FileSystemRights]'ReadData,WriteData,ReadAttributes,ReadPermissions,ChangePermissions,Synchronize'
$stream = [IO.FileStream]::new($target, [IO.FileMode]::CreateNew,
@@ -172,7 +180,17 @@ function New-OriginalPublicProfile {
[IO.FileOptions]::WriteThrough, $draftAcl)
try {
$phase = 'verify_creation'
if ($stream.GetAccessControl().GetSecurityDescriptorSddlForm($aclSections) -cne $draftSddl) {
$actualSddl = $stream.GetAccessControl().GetSecurityDescriptorSddlForm($aclSections)
if ($actualSddl -cne $draftSddl) {
$descriptorFailure = @{expected_sddl=$draftSddl; actual_sddl=$actualSddl; bytes=$null}
try {
$descriptorFailure.bytes = $stream.Length
$fileId = Get-HeldProfileFileId $stream
$descriptorFailure.file_id = $fileId.file_id
$descriptorFailure.volume_serial = $fileId.volume_serial
} catch {
$descriptorFailure.metadata_hresult = '0x{0:X8}' -f $_.Exception.GetBaseException().HResult
}
throw 'Unexpected security descriptor on new file'
}
[RmmInitialProfileFile]::CheckSingleFile($stream.SafeFileHandle, 0)
@@ -222,7 +240,9 @@ function New-OriginalPublicProfile {
}
} catch {
$cause = $_.Exception.GetBaseException()
WriteNew $initialError @{id=$caseId; phase=$phase; hresult=('0x{0:X8}' -f $cause.HResult); exception=$cause.GetType().FullName}
$failure = @{id=$caseId; phase=$phase; hresult=('0x{0:X8}' -f $cause.HResult); exception=$cause.GetType().FullName}
if ($null -ne $descriptorFailure) { $failure.creation_descriptor = $descriptorFailure }
WriteNew $initialError $failure
throw
}
}
@@ -47,14 +47,8 @@ try {
Write-Host 'Wartungsfenster aktiv. Dieses Fenster offen lassen. Strg+C beendet es.'
$receipt = [ordered]@{session=$session; case_id=$caseId; method='initial_create'; phase='preflight'; read_only_channel=$true}
$result = Join-Path $case 'console-initial-create-result.json'
$intentPath = Join-Path $case 'console-initial-create-intent.json'
$failurePath = Join-Path $case 'console-initial-create-error.json'
$receipt.finalizer_invoked = $false
try {
if (Test-Path -LiteralPath $failurePath) { throw 'Previous profile finalization error recorded' }
if (!(Test-Path -LiteralPath $result)) {
if (Test-Path -LiteralPath $intentPath) { throw 'Previous profile finalization intent without result' }
$receipt.finalizer_invoked = $true
$null = & (Join-Path $work 'Complete-OriginalTimeProfile.ps1') -InitialCreate
}
$record = Get-Content -LiteralPath $result -Raw | ConvertFrom-Json
@@ -63,7 +57,7 @@ try {
$record.initial_create -ne $true -or $record.source_candidate_preserved -ne $true -or
$record.services_changed -ne $false -or $record.private_key_read -ne $false -or $record.clock_runtime_qualified -ne $false -or
$actual.Hash -ne '2b4a8a7080770304b80e2a665fa5f5ee1ebbd9182e7c80b184e75b114575b42b') { throw 'Unexpected publication result' }
$marker = Get-Content -LiteralPath $intentPath -Raw | ConvertFrom-Json
$marker = Get-Content -LiteralPath (Join-Path $case 'console-initial-create-intent.json') -Raw | ConvertFrom-Json
if ($marker.id -cne $caseId -or $marker.utc -cne $record.publication_since -or
$marker.config_sha256 -ne $actual.Hash -or $record.configuration.sha256 -ne $actual.Hash -or
$record.original_candidate.file_id -cne '6d990300000003000000000000000000' -or
@@ -85,24 +79,10 @@ try {
$receipt.line = $_.InvocationInfo.ScriptLineNumber
$receipt.file = [IO.Path]::GetFileName($_.InvocationInfo.ScriptName)
Write-Warning $_.Exception.Message
$failurePath = Join-Path $case 'console-initial-create-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.hresult = $failure.hresult
if ($failure.phase -cmatch '^[A-Za-z][A-Za-z0-9_.-]{0,63}$') { $receipt.failure_phase = $failure.phase }
$descriptor = $failure.creation_descriptor
if ($failure.phase -ceq 'verify_creation' -and $null -ne $descriptor -and
$descriptor.expected_sddl -is [string] -and $descriptor.expected_sddl.Length -le 4096 -and
$descriptor.actual_sddl -is [string] -and $descriptor.actual_sddl.Length -le 4096) {
$receipt.creation_descriptor = @{
expected_sddl=$descriptor.expected_sddl; actual_sddl=$descriptor.actual_sddl; bytes=$descriptor.bytes
}
if ($descriptor.file_id -cmatch '^[0-9a-f]{32}$' -and $descriptor.volume_serial -cmatch '^[0-9]{1,20}$') {
$receipt.creation_descriptor.file_id = $descriptor.file_id
$receipt.creation_descriptor.volume_serial = $descriptor.volume_serial
}
}
}
if ($failure.id -ceq $caseId -and $failure.hresult -cmatch '^0x[0-9A-Fa-f]{8}$') { $receipt.hresult = $failure.hresult; if ($failure.phase -cmatch '^[A-Za-z][A-Za-z0-9_.-]{0,63}$') { $receipt.failure_phase = $failure.phase } }
}
}
$readScript = Join-Path $work 'Read-PassiveTimeSamples.ps1'
+16 -11
View File
@@ -489,15 +489,20 @@ Gerät, Agent, Assignment, Enrollmentgeneration und authentifiziertes Zertifikat
stimmten mit dem früheren Abnahmebeleg überein. Beleg-SHA-256
`7ea828b42b3c7948956aad56845502ffa52192ce6ca14728203f8574d70a28ec`.
Der Konsolenstarter prüft im aktualisierten Quellstand vor einem Aufruf des
Abschlussbefehls auf einen vorhandenen Fehler oder einen offenen Intent.
In beiden Fällen liest er den vorhandenen Stand. Die Rückmeldung kennzeichnet
mit `finalizer_invoked`, ob dieser Start den Abschlussbefehl aufgerufen hat.
Enthält der Fehlerbeleg die bei der Erstellung verglichenen Deskriptoren,
überträgt der Starter sie mit der Länge und den vorhandenen Datei-IDs an den
Ergebnisempfänger. Ältere Fehlerbelege bleiben ohne diese Angaben lesbar.
### Fehlerbeleg beim ersten Vergleich des Sicherheitsdeskriptors
Der PowerShell-Parser und fünf lokale Fälle bestanden: erster Aufruf,
vorliegender Fehler, offener Intent, bereits vorliegender Erfolg und
widersprüchliche Erfolgs-/Fehlermarker. Nur der erste Fall rief im Test den
simulierten Abschluss auf. Diese Prüfung lief auf dem Entwicklungsrechner.
Unterscheiden sich Soll- und Ist-SDDL an der neu angelegten Datei, erfasst der
Controller beide Werte für Besitzer, Gruppe und DACL am exklusiv gehaltenen
Dateihandle. Der private Fehlerbeleg enthält dazu das optionale Feld
`creation_descriptor` mit `expected_sddl`, `actual_sddl` und `bytes`.
Bei erfolgreicher nativer Identitätsabfrage kommen `file_id` und
`volume_serial` hinzu. Scheitert das Lesen der Zusatzmetadaten, hält
`metadata_hresult` dessen Fehlercode fest. Die ursprüngliche Abweichung
bricht den Aufruf vor dem Schreiben der Profilbytes und der Rechtefreigabe ab.
Der ältere Gastbeleg enthält diese neuen Felder noch nicht.
Lokal bestanden die Parserprüfung, vier PowerShell-Fälle für Vergleich und
Fehlerbeleg sowie die acht vorhandenen Profiltests. Die vier Fälle umfassten
ungleiche Deskriptoren mit lesbarer beziehungsweise fehlender FileID, einen
gleichen Deskriptor und einen unabhängigen Folgefehler. Die FileID-Abfrage war
simuliert. Eine native Abnahme dieser Belegerweiterung steht aus.