Skip to content

Commit

Permalink
[Tech|UI] Implement encryption
Browse files Browse the repository at this point in the history
- Support enabling encryption by enabling checkbox and inserting password
- Do the same when restoring encrypted backup
- libutilities funcs now have a new password parameter
  • Loading branch information
redromnon committed Dec 3, 2022
1 parent 38a3221 commit a960310
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
25 changes: 21 additions & 4 deletions src/libutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,33 @@ class Action:

process = None

def backup(self, folder):
def backup(self, folder, password):

self.process = subprocess.Popen(["idevicebackup2", "backup", folder])
#Enable encryption if password is given
if password is None:

self.process = subprocess.Popen(["idevicebackup2", "backup", folder])

else:

print("Checking encryption...")
self.encrypt_process = subprocess.Popen(["idevicebackup2", "encryption", "on", password, folder])
self.process = subprocess.Popen(["idevicebackup2", "backup", folder])

while(self.process.poll() == None):
pass

def restore(self, folder):
def restore(self, folder, password):

if password is None:

self.process = subprocess.Popen(["idevicebackup2", "restore", folder])

self.process = subprocess.Popen(["idevicebackup2", "restore", folder])
else:

print("Restoring encrypted backup...")
self.process = subprocess.Popen(["idevicebackup2", "restore", "--password", password, folder])


while(self.process.poll() == None):
pass
Expand Down
19 changes: 13 additions & 6 deletions src/ui/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import flet as ft
from libutilities import scan, Action
from ui.about import About
from ui.encrypt import Encrypt

class App(ft.UserControl):

Expand All @@ -9,6 +10,9 @@ def build(self):

#Import about dialog
self.about_button = About()

#Import encryption password container row
self.pwd_encrypt = Encrypt()

#Action (operations - backup, restore and cancel) obj to used later
self.action = Action()
Expand All @@ -21,7 +25,7 @@ def build(self):
[ft.Text("This will take some time"), ft.ProgressRing()],
height=50, horizontal_alignment="center"
),
actions=[ft.TextButton(ft.Text("Cancel", text_align="center"), on_click=self.cancel_op)],
actions=[ft.TextButton("Cancel", on_click=self.cancel_op)],
content_padding=40, modal=True
)

Expand All @@ -31,7 +35,7 @@ def build(self):
[ft.Text("This will take some time"), ft.ProgressRing()],
height=50, horizontal_alignment="center"
),
actions=[ft.TextButton(ft.Text("Cancel", text_align="center"), on_click=self.cancel_op)],
actions=[ft.TextButton("Cancel", on_click=self.cancel_op)],
content_padding=40, modal=True
)

Expand Down Expand Up @@ -98,8 +102,9 @@ def build(self):

#Others
ft.Column(
[self.folder_container, self.options_container, self.about_button],
spacing=35, horizontal_alignment="center"
[self.folder_container, self.pwd_encrypt, self.options_container,
self.about_button],
spacing=30, horizontal_alignment="center"
)
]
)
Expand Down Expand Up @@ -152,7 +157,8 @@ def do_backup(self, e):

#Run backup operation
print("Backup running...")
self.action.backup(self.display_folderpath.value)
pwd = self.pwd_encrypt.get_pwd()#Check if password is given
self.action.backup(self.display_folderpath.value, pwd)

#Successfully executed with return code as 0
if self.action.process.poll() == 0:
Expand Down Expand Up @@ -206,7 +212,8 @@ def do_restore(self, e):

#Run restore operation
print("Restore running...")
self.action.restore(self.display_folderpath.value)
pwd = self.pwd_encrypt.get_pwd()#Check if password is given
self.action.restore(self.display_folderpath.value, pwd)

#Successfully executed with return code as 0
if self.action.process.poll() == 0:
Expand Down
38 changes: 38 additions & 0 deletions src/ui/encrypt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import flet as ft

class Encrypt(ft.UserControl):

def build(self):

self.encrypt_checkbox = ft.Checkbox(
fill_color={ft.MaterialState.HOVERED: ft.colors.LIGHT_BLUE}, on_change=self.enable_checkbox,
tooltip="Enable encryption"
)

self.password_field = ft.TextField(
password=True, can_reveal_password=True, disabled=True, width=250, height=40,
content_padding=ft.padding.only(bottom=15, left=10), hint_text="Encryption password"
)

return ft.Row([self.encrypt_checkbox, self.password_field], spacing=10, alignment="center")


def enable_checkbox(self,e):

if self.encrypt_checkbox.value:

self.password_field.disabled=False
self.update()

else:

self.password_field.disabled=True
self.update()

def get_pwd(self):

if self.encrypt_checkbox.value:

if len(self.password_field.value) > 0:

return self.password_field.value

0 comments on commit a960310

Please sign in to comment.