Example #1
0
    def __handle_default_output__(self, output):

        # defaults.
        if isinstance(output, list):
            output = utils.__array_to_string__(output, joiner="\n")

        # handle.
        if "Incorrect PUK" in output:
            return dev0s.response.error(f"Provided an incorrect puk code.")
        elif "Incorrect PIN" in output:
            info = self.get_info()
            if info['success']:
                return dev0s.response.error(
                    f"Provided an incorrect pin code, {info['pin_attempts']} attempts left."
                )
            else:
                return dev0s.response.error(f"Provided an incorrect pin code.")
            return response
        elif "PUK is blocked" in output:
            return False, dev0s.response.error(
                f"The puk code of smart card [{self.serial_number}] is blocked."
            )
        elif "Error: " in output:
            return dev0s.response.error(
                output.split("Error: ")[1].replace('.\n',
                                                   '. ').replace('\n', ''))

        # success.
        return dev0s.response.success("Successfully checked the output.")
Example #2
0
    def export_keys(
        self,
        # optionally save the keys to a file.
        path=None,
    ):

        # output.
        command = f"ssh-keygen -D {self.path} -e"
        output = utils.__execute_script__(command,
                                          shell=True,
                                          return_format="array")

        # error.
        if len(output) == 0 or "ssh-rsa " not in output[0]:
            return dev0s.response.error(
                f"Failed to export smart card [{self.serial_number}].")
        else:

            # write out.
            if path != None:
                try:
                    Files.save(path,
                               utils.__array_to_string__(output, joiner="\n"))
                except:
                    return dev0s.response.error(
                        f"Failed to write out the exported key from smart card [{self.serial_number}]."
                    )

            # success.
            return dev0s.response.success(
                f"Successfully exported smart card [{self.serial_number}].",
                {"public_keys": output})