Fix Sargo persistent state image binding

This commit is contained in:
OverSu 2026-11-21 02:11:14 +01:00
commit 6a44daeaaa

View file

@ -3,12 +3,27 @@
import hashlib
import json
import re
import subprocess
import uuid
from pathlib import Path
FEATURES = 'none,has_journal,ext_attr,dir_index,filetype,extent,sparse_super,large_file,uninit_bg,dir_nlink,extra_isize'
def embedded_system_sha(image):
"""Read the immutable-system binding stored inside a Tundra data image."""
try:
result = subprocess.run(
['debugfs', '-R', 'cat /system.sha256', str(image)],
check=True, capture_output=True, text=True, timeout=30)
except (OSError, subprocess.SubprocessError) as error:
raise ValueError('Cannot inspect the data image system binding') from error
value = result.stdout.strip()
if not re.fullmatch(r'[a-f0-9]{64}', value):
raise ValueError('Data image has no valid embedded system binding')
return value
def digest(path):
with Path(path).open('rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
@ -33,6 +48,8 @@ def validate_manifest(path):
image = path.parent/value['image']
if image.is_symlink() or image.stat().st_size != size or digest(image) != value['imageSha256']:
raise ValueError('Initial data image changed')
if embedded_system_sha(image) != value['systemImageSha256']:
raise ValueError('Data image is bound to a different system image')
if value.get('filesystemCheckPassed') is not True:
raise ValueError('Data filesystem has not passed verification')
return value