From 3edd3edfadb311b0d7568800d657e68e3e20594c Mon Sep 17 00:00:00 2001 From: V0r-T3x <70115207+V0r-T3x@users.noreply.github.com> Date: Sat, 23 Dec 2023 23:27:28 -0500 Subject: [PATCH 1/2] adding an identity backup A backup is created when the keys and fingerprint are created. If the files are corrupted, the backup is loaded instead of generating the identity again. This is protecting the identity in case of crashes or corruptions. Signed-off-by: V0r-T3x --- pwnagotchi/identity.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/identity.py b/pwnagotchi/identity.py index 0ac5935f1..09c883499 100644 --- a/pwnagotchi/identity.py +++ b/pwnagotchi/identity.py @@ -5,6 +5,7 @@ import hashlib import os import logging +import shutil DefaultPath = "/etc/pwnagotchi/" @@ -25,9 +26,14 @@ def __init__(self, path=DefaultPath, view=None): while True: # first time, generate new keys if not os.path.exists(self.priv_path) or not os.path.exists(self.pub_path): - self._view.on_keys_generation() - logging.info("generating %s ..." % self.priv_path) - os.system("pwngrid -generate -keys '%s'" % self.path) + if os.path.exists(f'{self.priv_path}.original') and os.path.exists(f'{self.pub_path}.original') and os.path.exists(f'{self.fingerprint_path}.original'): + logging.warning('laoding backup') + shutil.copy(f'{self.priv_path}.original', self.priv_path) + shutil.copy(f'{self.pub_path}.original', self.pub_path) + else: + self._view.on_keys_generation() + logging.info("generating %s ..." % self.priv_path) + os.system("pwngrid -generate -keys '%s'" % self.path) # load keys: they might be corrupted if the unit has been turned off during the generation, in this case # the exception will remove the files and go back at the beginning of this loop. @@ -52,6 +58,12 @@ def __init__(self, path=DefaultPath, view=None): # no exception, keys loaded correctly. self._view.on_starting() + if not os.path.exists(f'{self.priv_path}.original'): + shutil.copy(self.priv_path, f'{self.priv_path}.original') + if not os.path.exists(f'{self.pub_path}.original'): + shutil.copy(self.pub_path, f'{self.pub_path}.original') + if not os.path.exists(f'{self.fingerprint_path}.original'): + shutil.copy(self.fingerprint_path, f'{self.fingerprint_path}.original') return except Exception as e: From 964a94bc436d420b7ba15bdd54c0c147c5b51ac6 Mon Sep 17 00:00:00 2001 From: V0rT3x <70115207+V0r-T3x@users.noreply.github.com> Date: Sun, 24 Dec 2023 10:14:28 -0500 Subject: [PATCH 2/2] Update identity.py type fix --- pwnagotchi/identity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwnagotchi/identity.py b/pwnagotchi/identity.py index 09c883499..ffb152931 100644 --- a/pwnagotchi/identity.py +++ b/pwnagotchi/identity.py @@ -27,7 +27,7 @@ def __init__(self, path=DefaultPath, view=None): # first time, generate new keys if not os.path.exists(self.priv_path) or not os.path.exists(self.pub_path): if os.path.exists(f'{self.priv_path}.original') and os.path.exists(f'{self.pub_path}.original') and os.path.exists(f'{self.fingerprint_path}.original'): - logging.warning('laoding backup') + logging.warning('loading backup') shutil.copy(f'{self.priv_path}.original', self.priv_path) shutil.copy(f'{self.pub_path}.original', self.pub_path) else: