예제 #1
0
 def on_card_registered():
     nonlocal registered
     device = devices[registered]
     device.on_registered()
     registered += 1
     ws_log_message(
         f'Successfully registered: {device.device_type} {device.mac}')
     # Auto-start emulators
     if device.is_emulator:
         emulators_controller.start_apps([device.mac])
예제 #2
0
def publish_new_tl():
    tl_path, version = _generate_incremented_tl_version()
    upload_response = tl_service_api.upload_file(tl_path)
    if upload_response.status_code != 201:
        raise Exception(f'Failed to upload TrustList to cloud\n'
                        f'Status code: {upload_response.status_code}\n'
                        f'Text: {upload_response.text}')
    ws_log_message(f'TrustList v{version} successfully uploaded to cloud')

    tl_id = upload_response.json().get('id')
    publish_response = tl_service_api.publish(100, [], tl_id)
    if publish_response.status_code != 200:
        raise Exception(f'Failed to publish TrustList\n'
                        f'Status code: {publish_response.status_code}\n'
                        f'Text: {publish_response.text}')
    ws_log_message(f'TrustList v{version} successfully published')
예제 #3
0
def _publish(update_file):
    # Upload
    upload_response = fw_service_api.upload_file(update_file)
    if upload_response.status_code != 201:
        raise Exception(f'Failed to upload Firmware to cloud\n'
                        f'Status code: {upload_response.status_code}\n'
                        f'Text: {upload_response.text}')
    ws_log_message('Firmware successfully uploaded to cloud')

    # Publish
    fw_id = upload_response.json().get('id')
    publish_response = fw_service_api.publish(100, [], fw_id)
    if publish_response.status_code != 200:
        raise Exception(f'Failed to publish Firmware\n'
                        f'Status code: {publish_response.status_code}\n'
                        f'Text: {publish_response.text}')
    ws_log_message('Firmware successfully published')
예제 #4
0
def _generate_incremented_fw_version(src, model, manufacturer):
    # Determine latest version on cloud
    latest = fw_service_api.get_latest_version(model)
    if latest is None:
        latest = '0.0.1.1'
    version = increment_version(latest)

    # Log
    ws_log_message(f'Signing firmware: model={model}, '
                   f'manufacturer={manufacturer}, version={version}')

    # Sign
    signer = FWSigner(fw_source=_prepare_emulator_fw(src),
                      version=version,
                      manufacturer=manufacturer,
                      model=model)
    output_files = signer.sign()
    return output_files
예제 #5
0
    def on_initialized(line):
        card_request_b64 = line.split()[-1].strip()

        # Get mac of initialized thing
        card_request = base64.b64decode(card_request_b64).decode()
        signatures = json.loads(card_request).get('signatures')
        self_sign, *_ = [s for s in signatures if s.get('signer') == 'self']
        snapshot_b64 = self_sign.get('snapshot')
        snapshot = base64.b64decode(snapshot_b64).decode()
        mac = json.loads(snapshot).get('mac').lower()
        if not mac:
            raise Exception(
                f'Failed to extract mac from card request: {card_request_b64}')

        # Update device in model
        device = Device.objects.get(mac=mac)
        device.on_initialized(card_request_b64)

        # Log
        ws_log_message(f'Successfully initialized: {device.device_type} {mac}')
예제 #6
0
 def inner_wrapper():
     ws_log_message(f'Starting: {action.value}...')
     try:
         # Check if action can be started
         # - check predicate
         if predicate:
             predicate_fn, predicate_desc = predicate
             if not predicate_fn():
                 ws_log_error(
                     f'Cannot start "{action.value}": {predicate_desc}'
                 )
                 return
         # - check if forbidden for simultaneous run actions are in progress
         actions_in_progress = ActionsRegistry.get_in_progress()
         forbidden_in_progress = [
             a for a in forbidden_on if a in actions_in_progress
         ]
         if forbidden_in_progress:
             forbidden_in_progress = ', '.join(
                 f'"{a.value}"' for a in forbidden_in_progress)
             ws_log_error(
                 f'Cannot start "{action.value}" while the '
                 f'following are in progress: {forbidden_in_progress}'
             )
             return
         # Add action to registry
         ActionsRegistry.add_in_progress(action)
         # Execute decorated function
         try:
             func(*args, **kwargs)
         except Exception as e:
             ws_log_error(
                 f'Error occurred during "{action.value}": {str(e)}'
             )
             raise e
         finally:
             # Delete action from registry
             ActionsRegistry.remove_in_progress(action)
     finally:
         ws_log_message(f'Done: {action.value}')
예제 #7
0
 def _get_cb(msg):
     return lambda: ws_log_message(msg)