def test_parse_happy_day_cli(text_fixture): output_file = text_fixture['tmp_path'] / 'out.bin' cmd = [ '--debug', 'public-key', text_fixture['key_file'].as_posix(), '--out', output_file.as_posix() ] assert 0 == mtool.entry_point(cmd) assert output_file.is_file() assert output_file.stat().st_size == 65 # 0x04 + 32B + 32B private_key = serialization.load_pem_private_key( text_fixture['key_file'].read_bytes(), password=None, backend=default_backend() ) message = b'my super duper secret data to be signed' signature = private_key.sign( message, ec.ECDSA(hashes.SHA256()) ) public_key = ec.EllipticCurvePublicKey.from_encoded_point( curve=ec.SECP256R1(), data=output_file.read_bytes() ) public_key.verify(signature, message, ec.ECDSA(hashes.SHA256()))
def test_cli_parse_and_verify_happy_day_privkey(happy_day_data): cmd = [ '--debug', 'parse', happy_day_data['manifest_file'].as_posix(), '--private-key', happy_day_data['priv_key_file'].as_posix() ] assert 0 == mtool.entry_point(cmd)
def test_cli_parse_and_verify_happy_day_cert(happy_day_data): cmd = [ '--debug', 'parse', happy_day_data['manifest_file'].as_posix(), '--certificate', happy_day_data['certificate_file'].as_posix(), ] assert 0 == mtool.entry_point(cmd)
def cli_test_common(happy_day_data, manifest_version, update_type): tmp_cfg = happy_day_data['tmp_path'] / 'input.yaml' output_manifest = happy_day_data['tmp_path'] / 'foo.bin' if update_type == UpdateType.DELTA: file_path = happy_day_data['delta_file'].as_posix() file_format = 'arm-patch-stream' elif update_type == UpdateType.COMBINED: file_path = happy_day_data['package_data']['out_file_name'] file_format = 'combined' else: file_path = happy_day_data['fw_file'].as_posix() file_format = 'raw-binary' with tmp_cfg.open('wt') as fh: yaml.dump( { 'vendor': { 'domain': 'pelion.com' }, 'device': { 'model-name': 'my-device' }, 'priority': 15, 'payload': { 'url': 'https://my.server.com/some.file?new=1', 'file-path': file_path, 'format': file_format } }, fh) action = 'create' if 'v1' in manifest_version.get_name(): action = 'create-v1' cmd = [ '--debug', action, '--config', tmp_cfg.as_posix(), '--key', happy_day_data['key_file'].as_posix(), '--output', output_manifest.as_posix() ] if manifest_version.get_name() == 'v1': cmd.extend([ '--update-certificate', happy_day_data['certificate_file'].as_posix() ]) else: cmd.extend(['--fw-version', '100.0.500']) assert 0 == mtool.entry_point(cmd)
def test_create_happy_day_with_ids(happy_day_data, manifest_version): tmp_cfg = happy_day_data['tmp_path'] / 'input.yaml' output_manifest = happy_day_data['tmp_path'] / 'foo.bin' with tmp_cfg.open('wt') as fh: yaml.dump( { 'vendor': { 'vendor-id': uuid.uuid4().hex }, 'device': { 'class-id': uuid.uuid4().hex }, 'priority': 15, 'payload': { 'url': 'https://my.server.com/some.file?new=1', 'file-path': happy_day_data['delta_file'].as_posix(), 'format': 'arm-patch-stream' } }, fh) action = 'create' if 'v1' in manifest_version.get_name(): action = 'create-v1' cmd = [ '--debug', action, '--config', tmp_cfg.as_posix(), '--key', happy_day_data['key_file'].as_posix(), '--output', output_manifest.as_posix() ] if manifest_version.get_name() == 'v1': cmd.extend([ '--update-certificate', happy_day_data['certificate_file'].as_posix() ]) else: cmd.extend(['--fw-version', '100.500.8']) ret_code = mtool.entry_point(cmd) assert ret_code == 0
def test_print_schema(): print('Schema:') cmd = ['schema'] assert 0 == mtool.entry_point(cmd)