Beispiel #1
0
def test_base_info(data_dir):
    """Basic test for MasterBootImage - information """
    # plain image
    mbi = MasterBootImage(app=bytes(range(64)),
                          load_addr=0,
                          enable_hw_user_mode_keys=True)
    output = mbi.info()
    repr_strings = [
        "Master Boot Image", "Image type", "Image length", "TrustZone",
        'HW user mode keys'
    ]
    for req_string in repr_strings:
        assert req_string in output, f'string {req_string} is not in the output: {output}'
    # CRC image
    mbi = MasterBootImage(app=bytes(range(64)),
                          image_type=MasterBootImageType.CRC_RAM_IMAGE,
                          load_addr=0x1000)
    output = mbi.info()
    repr_strings = [
        "Master Boot Image", "Image type", "Image length", "TrustZone"
    ]
    for req_string in repr_strings:
        assert req_string in output, f'string {req_string} is not in the output: {output}'
    # signed image
    priv_key_pem_data = _load_private_key(data_dir, 'private_rsa4096.pem')
    cert_block = certificate_block(
        data_dir, ['selfsign_4096_v3.der.crt', 'selfsign_3072_v3.der.crt'], 0)
    mbi = MasterBootImage(app=bytes(range(64)),
                          load_addr=0x12345678,
                          image_type=MasterBootImageType.SIGNED_XIP_IMAGE,
                          trust_zone=TrustZone.custom(
                              "lpc55xx",
                              {"MPU Control Register.(cm33_mpu_ctrl)": "0x0"}),
                          cert_block=cert_block,
                          priv_key_pem_data=priv_key_pem_data)
    output = mbi.info()
    repr_strings = [
        "Master Boot Image", "Image type", "Image length", "TrustZone"
    ]
    for req_string in repr_strings:
        assert req_string in output, f'string {req_string} is not in the output: {output}'
Beispiel #2
0
def test_encrypted_random_ctr_single_certificate_no_tz(data_dir):
    """Test encrypted image with random counter init vector"""
    with open(os.path.join(data_dir, 'testfffffff.bin'), "rb") as f:
        org_data = f.read()
    user_key = 'E39FD7AB61AE6DDDA37158A0FC3008C6D61100A03C7516EA1BE55A39F546BAD5'
    key_store = KeyStore(KeySourceType.KEYSTORE, None)
    cert_block = certificate_block(data_dir, ['selfsign_2048_v3.der.crt'])
    priv_key_pem_data = _load_private_key(data_dir, 'selfsign_privatekey_rsa2048.pem')
    mbi = MasterBootImage(app=org_data, image_type=MasterBootImageType.ENCRYPTED_RAM_IMAGE, load_addr=0x12345678,
                          trust_zone=TrustZone.disabled(),
                          cert_block=cert_block, priv_key_pem_data=priv_key_pem_data,
                          hmac_key=user_key, key_store=key_store)
    assert mbi.export()
    assert mbi.info()