def prompt_for_secret(keypath=None, password=None): """ Prompts for the secret key to decrypt the keyfile before loading. """ keypath = keypath or app.config["FLASHCUBE_KEY"] if not os.path.exists(keypath): return None keyfile = EncryptedFileKey(keypath) password = password or os.environ.get("FLASHCUBE_PASSPHRASE", None) password = password or getpass("Passphrase for Flashcube Key: ") try: return keyfile.read(password) except CheckSumError: return prompt_for_secret()
def write_key(self, path, keydata, password=None): try: keyfile = EncryptedFileKey(path) if password else EncryptedFileKey(path, False) keyfile.write(keydata, password) except Exception as e: raise ConsoleError("Could not write keydata to path.")