From 9f3d403eedd66cef9bb623b70bb8cbae2bb69279 Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:08:21 -0500 Subject: [PATCH 1/2] test: recognize deferred SEP policy-window unlock The cached ref-key path defines its unlock closure before dispatching it through the real-root policy window. Validate that complete dispatch and reject an unwrapped or extra invocation instead of inspecting only the source preceding the call inside the closure. Preserve the existing initrd exception, call-site inventory and Touch ID assertions. Add negative controls for an unguarded real-root call and extra direct use. No production SEP, keybag or guard-policy changes. Assisted-by: LLM --- tools/aurora-sep/tests/test_policy_window.py | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/aurora-sep/tests/test_policy_window.py b/tools/aurora-sep/tests/test_policy_window.py index fda87d68a3f0c..d226e1d0f23da 100644 --- a/tools/aurora-sep/tests/test_policy_window.py +++ b/tools/aurora-sep/tests/test_policy_window.py @@ -73,6 +73,35 @@ def setUp(self): self.sbio = (APPLE / "sbio.rs").read_text() self.activate = function(self.sbio, "activate_touchid") + def assert_cached_refkey_window(self, body, at): + # A deferred closure's wrapper comes after its definition. Match its + # complete dispatch rather than accepting any later window in the fn. + # Preserve offsets while ignoring words in comments. + clean = re.sub(r"//[^\n]*|/\*.*?\*/", lambda m: " " * len(m[0]), + body, flags=re.S) + closure = re.search(r"\blet\s+(?Punlock)\s*=\s*\|\|\s*\{", clean) + self.assertIsNotNone(closure) + opening = closure.end() - 1 + depth, end = 1, opening + 1 + while depth and end < len(clean): + depth += (clean[end] == "{") - (clean[end] == "}") + end += 1 + self.assertEqual(depth, 0) + self.assertTrue(opening < at < end) + self.assertEqual(clean.count(PREPARE), 1) + # The initrd deliberately leaves the real root's window unused; its + # guarded store is read-only. Only that branch may call unlock directly. + dispatch = re.search( + r"\blet\s+unlocked\s*=\s*if\s+self\.keystore_only\.load\(Relaxed\)\s*" + r"\{\s*(?Punlock)\(\)\s*\}\s*else\s*" + r"\{\s*crate::xart_guard::policy_window\((?Punlock)\)\s*\};", + clean) + self.assertIsNotNone(dispatch) + self.assertGreater(dispatch.start(), end) + self.assertEqual( + [m.start() for m in re.finditer(r"\bunlock\b", clean)], + [closure.start("binding"), dispatch.start("initrd"), dispatch.start("root")]) + def test_touchid_designates_inside_the_window(self): at = self.activate.index(DESIGNATE) self.assertIn("crate::xart_guard::policy_window(", statement(self.activate, at)) @@ -87,6 +116,26 @@ def test_touchid_designates_a_keybag_that_already_existed(self): self.assertLess(recovered, self.activate.index(DESIGNATE)) self.assertNotIn("sks_provision_identity_keybag(", self.activate) + def test_cached_refkey_window_wraps_deferred_unlock(self): + body = function((APPLE / "refkey.rs").read_text(), "refkey_unseal_cached") + self.assert_cached_refkey_window(body, body.index(PREPARE)) + + def test_cached_refkey_rejects_unguarded_real_root_unlock(self): + body = function((APPLE / "refkey.rs").read_text(), "refkey_unseal_cached") + wrapped = "crate::xart_guard::policy_window(unlock)" + self.assertEqual(body.count(wrapped), 1) + body = body.replace(wrapped, "unlock()") + with self.assertRaises(AssertionError): + self.assert_cached_refkey_window(body, body.index(PREPARE)) + + def test_cached_refkey_rejects_extra_unguarded_unlock(self): + body = function((APPLE / "refkey.rs").read_text(), "refkey_unseal_cached") + dispatch = "let unlocked = if self.keystore_only.load(Relaxed)" + self.assertEqual(body.count(dispatch), 1) + body = body.replace(dispatch, "unlock();\n " + dispatch) + with self.assertRaises(AssertionError): + self.assert_cached_refkey_window(body, body.index(PREPARE)) + def test_no_other_path_designates_outside_a_window(self): # A new designate of an existing keybag needs the window too; add it # here once it runs in one. @@ -99,6 +148,9 @@ def test_no_other_path_designates_outside_a_window(self): self.assertTrue(callers) for f, outer, body, at in callers: with self.subTest(caller=outer): + if (f, outer) == ("refkey.rs", "refkey_unseal_cached"): + self.assert_cached_refkey_window(body, at) + continue before = body[:at] self.assertTrue("crate::xart_guard::policy_window(" in before or "crate::xart_guard::close_policy_window(" in before, @@ -107,3 +159,4 @@ def test_no_other_path_designates_outside_a_window(self): if __name__ == "__main__": unittest.main() + From b3ae2543af48e2d057a63cea2aaebe11afa15658 Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:54:25 -0500 Subject: [PATCH 2/2] test: remove the extra policy-window fixture EOF blank Whitespace only; preserve every assertion and negative control. Assisted-by: LLM --- tools/aurora-sep/tests/test_policy_window.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/aurora-sep/tests/test_policy_window.py b/tools/aurora-sep/tests/test_policy_window.py index d226e1d0f23da..8ae2a619e44ad 100644 --- a/tools/aurora-sep/tests/test_policy_window.py +++ b/tools/aurora-sep/tests/test_policy_window.py @@ -159,4 +159,3 @@ def test_no_other_path_designates_outside_a_window(self): if __name__ == "__main__": unittest.main() -