Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
fix(ci): check the update task's permissions by their access rights
Bee0114553e66d2
diff --git a/scripts/smoke-installer.ps1 b/scripts/smoke-installer.ps1index 83da570..a0a6900 100644--- a/scripts/smoke-installer.ps1+++ b/scripts/smoke-installer.ps1@@ -31,6 +31,22 @@ function Check($what, [bool]$ok) {Write-Host "ok: $what"}function FirewallRule { (netsh advfirewall firewall show rule name=Nectarlink) -match 'Nectarlink' }+# Whether an allow entry for `$sid` grants every bit of `$rights`.+function Test-TaskRights($sd, [string]$sid, [int]$rights) {+ [bool]($sd.DiscretionaryAcl | Where-Object {+ $_.AceQualifier -eq 'AccessAllowed' -and $_.SecurityIdentifier.Value -eq $sid -and+ ($_.AccessMask -band $rights) -eq $rights })+}+# Whether anyone but SYSTEM and administrators may write, delete or re-permission it.+function Test-OthersMayWrite($sd) {+ # FILE_WRITE_DATA, APPEND, WRITE_EA, WRITE_ATTRIBUTES, DELETE, WRITE_DAC,+ # WRITE_OWNER, GENERIC_ALL, GENERIC_WRITE.+ $write = 0x2 -bor 0x4 -bor 0x10 -bor 0x100 -bor 0x10000 -bor 0x40000 -bor 0x80000 -bor 0x10000000 -bor 0x40000000+ [bool]($sd.DiscretionaryAcl | Where-Object {+ $_.AceQualifier -eq 'AccessAllowed' -and+ $_.SecurityIdentifier.Value -notin @('S-1-5-18', 'S-1-5-32-544') -and+ ($_.AccessMask -band $write) -ne 0 })+}function UpdateTask {$scheduler = New-Object -ComObject Schedule.Service$scheduler.Connect()@@ -51,10 +67,19 @@ Check "the update task runs the installed app as SYSTEM" ($task.Definition.Principal.UserId -match '^(SYSTEM|S-1-5-18|NT AUTHORITY\\SYSTEM)$' -and$task.Definition.Actions.Item(1).Path.Trim('"') -eq $exe -and$task.Definition.Actions.Item(1).Arguments -eq '--update-service')-# 4: the DACL. Signed-in users may read and run it, not change it.-$dacl = $task.GetSecurityDescriptor(4)-Check "signed-in users may only read and start the update task" (- $dacl -match '\(A;;GRGX;;;AU\)' -and $dacl -match '\(A;;FA;;;SY\)' -and $dacl -match '\(A;;FA;;;BA\)')+# 4: the DACL. Signed-in users may read and run it, not change it. Windows+# reports the rights it maps them to (GRGX comes back as 0x1200a9), so check+# the access masks rather than the text.+$sddl = $task.GetSecurityDescriptor(4)+Write-Host "update task permissions: $sddl"+$sd = New-Object System.Security.AccessControl.RawSecurityDescriptor $sddl+Check "SYSTEM and administrators may change the update task" (+ ((Test-TaskRights $sd 'S-1-5-18' 0x1F01FF) -or (Test-TaskRights $sd 'S-1-5-18' 0x10000000)) -and+ ((Test-TaskRights $sd 'S-1-5-32-544' 0x1F01FF) -or (Test-TaskRights $sd 'S-1-5-32-544' 0x10000000)))+# FILE_EXECUTE, or GENERIC_EXECUTE if it isn't mapped.+Check "signed-in users may start the update task" (+ (Test-TaskRights $sd 'S-1-5-11' 0x20) -or (Test-TaskRights $sd 'S-1-5-11' 0x20000000))+Check "nobody else may change or delete the update task" (-not (Test-OthersMayWrite $sd))# The installed copy starts on its own files and quits when asked.$app = Start-Process $exe -ArgumentList '--minimized', '--data-dir', $data -PassThru