Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

adding an identity backup #65

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pwnagotchi/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hashlib
import os
import logging
import shutil

DefaultPath = "/etc/pwnagotchi/"

Expand All @@ -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('loading 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.
Expand All @@ -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:
Expand Down