Exemple #1
0
    def confirm_migration(self) -> bool:
        """
        Before beginning migration, we'll notify the user that the legacy keyring needs to be
        migrated and warn about backing up the mnemonic seeds.

        If a master passphrase hasn't been explicitly set yet, we'll attempt to prompt and set
        the passphrase prior to beginning migration.
        """

        master_passphrase, _ = self.get_cached_master_passphrase()
        if master_passphrase == DEFAULT_PASSPHRASE_IF_NO_MASTER_PASSPHRASE:
            print(
                "\nYour existing keys need to be migrated to a new keyring that is optionally secured by a master "
                "passphrase.")
            print(
                "Would you like to set a master passphrase now? Use 'chia passphrase set' to change the passphrase.\n"
            )

            response = prompt_yes_no("Set keyring master passphrase? (y/n) ")
            if response:
                from chia.cmds.passphrase_funcs import prompt_for_new_passphrase

                # Prompt for a master passphrase and cache it
                new_passphrase, save_passphrase = prompt_for_new_passphrase()
                self.set_master_passphrase(
                    current_passphrase=None,
                    new_passphrase=new_passphrase,
                    write_to_keyring=False,
                    save_passphrase=save_passphrase,
                )
            else:
                print(
                    "Will skip setting a master passphrase. Use 'chia passphrase set' to set the master passphrase.\n"
                )
        else:
            import colorama

            colorama.init()

            print(
                "\nYour existing keys will be migrated to a new keyring that is secured by your master passphrase"
            )
            print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + "WARNING: " +
                  colorama.Style.RESET_ALL,
                  end="")
            print(
                "It is strongly recommended that you ensure you have a copy of the mnemonic seed for each of your "
                "keys prior to beginning migration\n")

        return prompt_yes_no("Begin keyring migration? (y/n) ")
Exemple #2
0
 def confirm_legacy_keyring_cleanup(self, migration_results) -> bool:
     """
     Ask the user whether we should remove keys from the legacy keyring.
     """
     return prompt_yes_no(
         f"Remove keys from old keyring ({str(migration_results.legacy_keyring.file_path)})? (y/n) "
     )
    def confirm_legacy_keyring_cleanup(self, legacy_keyring, service, users):
        """
        Ask the user whether we should remove keys from the legacy keyring. We can't just
        delete the file because other python processes might use the same keyring file.
        """

        response = prompt_yes_no(f"Remove keys from old keyring ({str(legacy_keyring.file_path)})? (y/n) ")

        if response:
            for user in users:
                legacy_keyring.delete_password(service, user)
            print("Removed keys from old keyring")
        else:
            print("Keys in old keyring left intact")
Exemple #4
0
    def confirm_legacy_keyring_cleanup(self, migration_results) -> bool:
        """
        Ask the user whether we should remove keys from the legacy keyring. In the case
        of CryptFileKeyring, we can't just delete the file because other python processes
        might use the same keyring file.
        """
        keyring_name: str = ""
        legacy_keyring_type: Type = type(migration_results.legacy_keyring)

        if legacy_keyring_type is CryptFileKeyring:
            keyring_name = str(migration_results.legacy_keyring.file_path)
        elif legacy_keyring_type is MacKeyring:
            keyring_name = "macOS Keychain"
        elif legacy_keyring_type is WinKeyring:
            keyring_name = "Windows Credential Manager"

        prompt = "Remove keys from old keyring"
        if len(keyring_name) > 0:
            prompt += f" ({keyring_name})?"
        else:
            prompt += "?"
        prompt += " (y/n) "
        return prompt_yes_no(prompt)
Exemple #5
0
def prompt_to_save_passphrase() -> bool:
    save: bool = False

    try:
        if supports_os_passphrase_storage():
            location: Optional[str] = None
            warning: Optional[str] = None

            if sys.platform == "darwin":
                location = "macOS Keychain"
                warning = SAVE_MASTER_PASSPHRASE_WARNING
            elif sys.platform == "win32" or sys.platform == "cygwin":
                location = "Windows Credential Manager"
                warning = SAVE_MASTER_PASSPHRASE_WARNING

            if location is None:
                raise ValueError("OS-specific credential store not specified")

            print(
                "\n"
                "Your passphrase can be stored in your system's secure credential store. "
                "Other Chia processes will be able to access your keys without prompting for your passphrase."
            )
            if warning is not None:
                colorama.init()

                print(warning)
            save = prompt_yes_no(
                f"Would you like to save your passphrase to the {location} (y/n) "
            )

    except Exception as e:
        print(f"Caught exception: {e}")
        return False

    return save