Example #1
0
def auth(pass_obj: dict, beacon: int, certificate: str, key: str, force: bool) -> None:
    """Perform the Debug Authentication."""
    try:
        logger.info("Starting Debug Authentication")
        mail_box = pass_obj['debug_mailbox']
        with open(certificate, 'rb') as f:
            debug_cred_data = f.read()
        debug_cred = DebugCredential.parse(debug_cred_data)
        dac_data = dm_commands.DebugAuthenticationStart(dm=mail_box).run()
        # convert List[int] to bytes
        dac_data_bytes = struct.pack(f'<{len(dac_data)}I', *dac_data)
        dac = DebugAuthenticationChallenge.parse(dac_data_bytes)
        logger.debug(f'DAC: \n{dac.info()}')
        dar = DebugAuthenticateResponse.create(
            version=pass_obj['protocol'], socc=dac.socc,
            dc=debug_cred, auth_beacon=beacon, dac=dac, dck=key
        )
        logger.debug(f'DAR:\n{dar.info()}')
        dar_data = dar.export()
        # convert bytes to List[int]
        dar_data_words = list(struct.unpack(f'<{len(dar_data)//4}I', dar_data))
        dar_response = dm_commands.DebugAuthenticationResponse(
            dm=mail_box, paramlen=len(dar_data_words)
        ).run(dar_data_words)
        logger.debug(f'DAR response: {dar_response}')
        exit_response = dm_commands.ExitDebugMailbox(dm=mail_box).run()
        logger.debug(f'Exit response: {exit_response}')
        logger.info("Debug Authentication successful")
    except Exception as e:
        logger.error(f"Start Debug Mailbox failed!\n{e}")
Example #2
0
def exit(pass_obj: dict) -> None:
    """Exit DebugMailBox."""
    try:
        dm_commands.ExitDebugMailbox(dm=pass_obj['debug_mailbox']).run()
        logger.info("Exit Debug Mailbox successful")
    except:
        logger.error("Exit Debug Mailbox failed!")
Example #3
0
def exit(pass_obj: dict) -> None:
    """Exit DebugMailBox."""
    result = False
    try:
        with _open_debugmbox(pass_obj) as mail_box:
            dm_commands.ExitDebugMailbox(dm=mail_box).run()
        result = True
    finally:
        print_output(result, "Exit Debug Mailbox")
Example #4
0
def auth(pass_obj: dict, beacon: int, certificate: str, key: str,
         no_exit: bool) -> None:
    """Perform the Debug Authentication."""
    try:
        logger.info("Starting Debug Authentication")
        with _open_debugmbox(pass_obj) as mail_box:
            with open(certificate, "rb") as f:
                debug_cred_data = f.read()
            debug_cred = DebugCredential.parse(debug_cred_data)
            dac_rsp_len = 30 if debug_cred.HASH_LENGTH == 48 and debug_cred.socc == 4 else 26
            dac_data = dm_commands.DebugAuthenticationStart(
                dm=mail_box, resplen=dac_rsp_len).run()
            # convert List[int] to bytes
            dac_data_bytes = struct.pack(f"<{len(dac_data)}I", *dac_data)
            dac = DebugAuthenticationChallenge.parse(dac_data_bytes)
            logger.debug(f"DAC: \n{dac.info()}")
            dar = DebugAuthenticateResponse.create(
                version=pass_obj["protocol"],
                socc=dac.socc,
                dc=debug_cred,
                auth_beacon=beacon,
                dac=dac,
                dck=key,
            )
            logger.debug(f"DAR:\n{dar.info()}")
            dar_data = dar.export()
            # convert bytes to List[int]
            dar_data_words = list(
                struct.unpack(f"<{len(dar_data) // 4}I", dar_data))
            dar_response = dm_commands.DebugAuthenticationResponse(
                dm=mail_box, paramlen=len(dar_data_words)).run(dar_data_words)
            logger.debug(f"DAR response: {dar_response}")
            if not no_exit:
                exit_response = dm_commands.ExitDebugMailbox(dm=mail_box).run()
                logger.debug(f"Exit response: {exit_response}")
                # Re-open debug probe
                mail_box.debug_probe.close()
                mail_box.debug_probe.open()
                # Do test of access to AHB bus
                ahb_access_granted = test_ahb_access(mail_box.debug_probe)
                res_str = ((colorama.Fore.GREEN +
                            "successfully") if ahb_access_granted else
                           (colorama.Fore.RED + "without AHB access"))
                logger.info(
                    f"Debug Authentication ends {res_str}{colorama.Fore.RESET}."
                )
                if not ahb_access_granted:
                    click.get_current_context().exit(1)
            else:
                logger.info(
                    "Debug Authentication ends without exit and without test of AHB access."
                )

    except SPSDKError as e:
        logger.error(f"Start Debug Mailbox failed!\n{e}")
        click.get_current_context().exit(1)
Example #5
0
def blankauth(pass_obj: dict, file: str, no_exit: bool) -> None:
    """Debug Authentication for Blank Device."""
    try:
        token = []
        logger.info("Starting Debug Authentication for Blank Device..")
        with _open_debugmbox(pass_obj) as mail_box:
            with open(file, "rb") as f:
                while True:
                    chunk = f.read(8).strip()
                    if not chunk:
                        break
                    token.append(int(chunk, 16))
                f.close()
            dm_commands.EnterBlankDebugAuthentication(dm=mail_box).run(token)
            if not no_exit:
                exit_response = dm_commands.ExitDebugMailbox(dm=mail_box).run()
                logger.debug(f"Exit response: {exit_response}")
                # Re-open debug probe
                mail_box.debug_probe.close()
                mail_box.debug_probe.open()
                # Do test of access to AHB bus
                ahb_access_granted = test_ahb_access(mail_box.debug_probe)
                res_str = ((colorama.Fore.GREEN +
                            "successfully") if ahb_access_granted else
                           (colorama.Fore.RED + "without AHB access"))
                logger.info(
                    f"Debug Authentication ends {res_str}{colorama.Fore.RESET}."
                )
                if not ahb_access_granted:
                    click.get_current_context().exit(1)
            else:
                logger.info(
                    "Debug Authentication ends without exit and without test of AHB access."
                )

    except SPSDKError as e:
        logger.error(colorama.Fore.RED +
                     f"Debug authentication for Blank device failed!\n{e}")
        click.get_current_context().exit(1)