From 35f92c4c114b9ee5087165d72797a04a27d652d3 Mon Sep 17 00:00:00 2001 From: V0r-T3x <70115207+V0r-T3x@users.noreply.github.com> Date: Sat, 23 Dec 2023 15:44:41 -0500 Subject: [PATCH 1/2] adding an identity backup The code make a backup of the key and fingerprint, and if those files are corrupted, the backup is loaded instead of re-generating the key. The pwnagotchi identity is protected in case of crash. --- 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 4294232f6d6516a2eac41e18c18c6a667bab5b29 Mon Sep 17 00:00:00 2001 From: V0rT3x <70115207+V0r-T3x@users.noreply.github.com> Date: Sun, 24 Dec 2023 10:15:50 -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: