"""Offline controls for the native entropy refusal harness; no QEMU is started."""
import unittest
from IndependentBingEvidence import HOME, REMOTE, RESPONSE, network_arguments
from TestTlsEntropyFailure import CPU, REFUSAL, validate_negative_profile, verify, verify_entropy_refusal
def refusal(address=HOME, window=4):
return ('XFE_NATIVE_WEB_ERROR_BEGIN\nSystem.InvalidOperationException: ' + REFUSAL + '\nXFE_NATIVE_WEB_ERROR_END\n'
f'XFE_BROWSER_STATE_BEGIN\n{window}|{address}\nNavigation failed: ' + REFUSAL + '\nXFE_BROWSER_STATE_END\n')
class TlsEntropyFailureGuards(unittest.TestCase):
def test_cpu_features_are_explicitly_disabled_but_real_nat_and_utc_remain(self):
arguments = ['-accel', 'tcg', '-cpu', CPU, '-rtc', 'base=utc', '-smp', '1', *network_arguments(True)]
validate_negative_profile(arguments)
invalid = [[item.replace(CPU, 'max') for item in arguments],
[item.replace('-rdseed', '+rdseed') for item in arguments],
[item.replace('e1000,', 'e1000e,') for item in arguments],
[item.replace('base=utc', 'base=localtime') for item in arguments],
arguments + ['-net', 'none'], arguments + ['-cpu', CPU]]
for value in invalid:
with self.subTest(arguments=value), self.assertRaises(AssertionError):
validate_negative_profile(value)
def test_actual_current_failure_requires_complete_native_diagnostic_and_window(self):
serial = refusal()
evidence = verify_entropy_refusal(serial, 0, 4)
self.assertIn(REFUSAL, evidence['Text'])
for value, after, window in ((serial, len(serial), 4), (serial, 0, 5),
(refusal('https://example.com/'), 0, 4),
(serial.replace('XFE_NATIVE_WEB_ERROR_END', ''), 0, 4),
(serial.replace(REFUSAL, 'A generic TLS error', 1), 0, 4)):
with self.subTest(serial=value, after=after, window=window), self.assertRaises(AssertionError):
verify_entropy_refusal(value, after, window)
def test_any_remote_receipt_or_guest_crash_rejects_the_negative_proof(self):
for marker in (RESPONSE + '_BEGIN', REMOTE + '_BEGIN', 'XFE_INDEPENDENT_APPLICATION_FAILED', 'XFE_RUNTIME_FATAL'):
with self.subTest(marker=marker), self.assertRaises(AssertionError):
verify_entropy_refusal(refusal() + marker, 0, 4)
def test_old_success_packets_before_actual_menu_input_are_not_new_evidence(self):
old = RESPONSE + '_BEGIN\n{}\n' + RESPONSE + '_END\n'
self.assertIn(REFUSAL, verify_entropy_refusal(old + refusal(), len(old), 4)['Text'])
def test_oversized_phase_deadlines_fail_before_reading_or_creating_anything(self):
for options in ({'boot_timeout': 61}, {'negative_timeout': 16}, {'boot_timeout': 0}, {'negative_timeout': 0}):
with self.subTest(options=options), self.assertRaisesRegex(AssertionError, 'deadlines'):
verify('NeverReadOrCreated.elf', **options)
if __name__ == '__main__':
unittest.main()
"""Offline controls for the native entropy refusal harness; no QEMU is started."""
import unittest
from IndependentBingEvidence import HOME, REMOTE, RESPONSE, network_arguments
from TestTlsEntropyFailure import CPU, REFUSAL, validate_negative_profile, verify, verify_entropy_refusal
def refusal(address=HOME, window=4):
return ('XFE_NATIVE_WEB_ERROR_BEGIN\nSystem.InvalidOperationException: ' + REFUSAL + '\nXFE_NATIVE_WEB_ERROR_END\n'
f'XFE_BROWSER_STATE_BEGIN\n{window}|{address}\nNavigation failed: ' + REFUSAL + '\nXFE_BROWSER_STATE_END\n')
class TlsEntropyFailureGuards(unittest.TestCase):
def test_cpu_features_are_explicitly_disabled_but_real_nat_and_utc_remain(self):
arguments = ['-accel', 'tcg', '-cpu', CPU, '-rtc', 'base=utc', '-smp', '1', *network_arguments(True)]
validate_negative_profile(arguments)
invalid = [[item.replace(CPU, 'max') for item in arguments],
[item.replace('-rdseed', '+rdseed') for item in arguments],
[item.replace('e1000,', 'e1000e,') for item in arguments],
[item.replace('base=utc', 'base=localtime') for item in arguments],
arguments + ['-net', 'none'], arguments + ['-cpu', CPU]]
for value in invalid:
with self.subTest(arguments=value), self.assertRaises(AssertionError):
validate_negative_profile(value)
def test_actual_current_failure_requires_complete_native_diagnostic_and_window(self):
serial = refusal()
evidence = verify_entropy_refusal(serial, 0, 4)
self.assertIn(REFUSAL, evidence['Text'])
for value, after, window in ((serial, len(serial), 4), (serial, 0, 5),
(refusal('https://example.com/'), 0, 4),
(serial.replace('XFE_NATIVE_WEB_ERROR_END', ''), 0, 4),
(serial.replace(REFUSAL, 'A generic TLS error', 1), 0, 4)):
with self.subTest(serial=value, after=after, window=window), self.assertRaises(AssertionError):
verify_entropy_refusal(value, after, window)
def test_any_remote_receipt_or_guest_crash_rejects_the_negative_proof(self):
for marker in (RESPONSE + '_BEGIN', REMOTE + '_BEGIN', 'XFE_INDEPENDENT_APPLICATION_FAILED', 'XFE_RUNTIME_FATAL'):
with self.subTest(marker=marker), self.assertRaises(AssertionError):
verify_entropy_refusal(refusal() + marker, 0, 4)
def test_old_success_packets_before_actual_menu_input_are_not_new_evidence(self):
old = RESPONSE + '_BEGIN\n{}\n' + RESPONSE + '_END\n'
self.assertIn(REFUSAL, verify_entropy_refusal(old + refusal(), len(old), 4)['Text'])
def test_oversized_phase_deadlines_fail_before_reading_or_creating_anything(self):
for options in ({'boot_timeout': 61}, {'negative_timeout': 16}, {'boot_timeout': 0}, {'negative_timeout': 0}):
with self.subTest(options=options), self.assertRaisesRegex(AssertionError, 'deadlines'):
verify('NeverReadOrCreated.elf', **options)
if __name__ == '__main__':
unittest.main()