def test_generate_cfpa(data_dir): config = json.loads(load_file(data_dir, 'cfpa_test.json')) binary = load_file(data_dir, 'CFPA_test.bin', mode='rb') cfpa = CFPA('lpc55s6x', user_config=config['settings']) data = cfpa.export(add_seal=True, compute_inverses=False) assert binary == data
def test_generate_cmpa(data_dir): config = json.loads(load_file(data_dir, 'cmpa_96mhz.json')) binary = load_file(data_dir, 'CMPA_96MHz.bin', mode='rb') key = load_pem_private_key(load_file(data_dir, 'selfsign_privatekey_rsa2048.pem', mode='rb'), password=None, backend=default_backend()) cmpa = CMPA('lpc55s6x', keys=[key.public_key()], user_config=config['settings']) assert binary == cmpa.export(add_seal=False, compute_inverses=True)
def test_generate_cmpa(data_dir): """Test PFR tool - Generating CMPA binary.""" binary = load_file(data_dir, "CMPA_96MHz.bin", mode="rb") key = load_pem_private_key( load_file(data_dir, "selfsign_privatekey_rsa2048.pem", mode="rb"), password=None, backend=default_backend(), ) pfr_cfg_json = PfrConfiguration(os.path.join(data_dir, "cmpa_96mhz.json")) cmpa_json = CMPA("lpc55s6x", user_config=pfr_cfg_json) assert binary == cmpa_json.export(add_seal=False, keys=[key.public_key()]) pfr_cfg_yml = PfrConfiguration(os.path.join(data_dir, "cmpa_96mhz.yml")) cmpa_yml = CMPA("lpc55s6x", user_config=pfr_cfg_yml) assert binary == cmpa_yml.export(add_seal=False, keys=[key.public_key()])
def test_load_binary(data_dir): """Test loading binary files using load_binary and load_file.""" data = load_binary(data_dir, "file.bin") data2 = load_file(data_dir, "file.bin", mode="rb") assert data == data2 assert data == bytes(i for i in range(10))
def test_generate_cfpa(data_dir): """Test PFR tool - Generating CFPA binary.""" binary = load_file(data_dir, "CFPA_test.bin", mode="rb") pfr_cfg_json = PfrConfiguration(os.path.join(data_dir, "cfpa_test.json")) cfpa_json = CFPA("lpc55s6x", user_config=pfr_cfg_json) assert cfpa_json.export(add_seal=True) == binary pfr_cfg_yml = PfrConfiguration(os.path.join(data_dir, "cfpa_test.yml")) cfpa_yml = CFPA("lpc55s6x", user_config=pfr_cfg_yml) assert cfpa_yml.export(add_seal=True) == binary
def test_write_file(data_dir, tmpdir): """Test writing data to data using write_file.""" data = load_binary(data_dir, "file.bin") text = load_file(data_dir, "file.txt") write_file(data, tmpdir, "file.bin", mode="wb") write_file(text, tmpdir, "file.txt") assert filecmp.cmp(os.path.join(data_dir, "file.bin"), os.path.join(tmpdir, "file.bin")) assert filecmp.cmp(os.path.join(data_dir, "file.txt"), os.path.join(tmpdir, "file.txt"))
def _get_trustzone(config: elftosb_helper.MasterBootImageConfig) -> TrustZone: """Create appropriate TrustZone instance.""" if not config.trustzone_preset_file: return TrustZone.disabled() try: tz_config_data = json.loads(load_file(config.trustzone_preset_file)) tz_config = elftosb_helper.TrustZoneConfig(tz_config_data) return TrustZone.custom( family=tz_config.family, revision=tz_config.revision, customizations=tz_config.presets ) except ValueError: tz_raw_data = load_binary(config.trustzone_preset_file) return TrustZone.from_binary( family=config.family, revision=config.revision, raw_data=tz_raw_data )
def test_load_file(data_dir): """Test loading text file.""" text = load_file(data_dir, "file.txt") assert text == "Hello\nworld"