summaryrefslogtreecommitdiff
path: root/plugins/python/abackup/password.py
blob: d1162e83de50b08ea1c6bb0a26ad1e95da861fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

# Chrysalide - Outil d'analyse de fichiers binaires
# password.py - lecture des mots de passe pour une sauvegarde chiffrée
#
# Copyright (C) 2019 Cyrille Bagard
#
#  This file is part of Chrysalide.
#
#  Chrysalide is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  Chrysalide is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


from pychrysalide.gui import core
from gi.repository import GLib, Gtk
from threading import Event


class PasswordReader():
    """Features for getting a backup password."""


    @staticmethod
    def read_password_from_console():
        """Get the backup console from the console."""

        password = input('Enter the password of the backup: ')

        return password


    @staticmethod
    def _show_password_box(mutex, ref):

        dlgbox = Gtk.MessageDialog(parent = core.get_editor_window(),
                                   flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                   type = Gtk.MessageType.QUESTION,
                                   buttons = Gtk.ButtonsType.OK_CANCEL,
                                   message_format = 'The backup file is password protected. Please enter it here:')

        dlgbox.set_title('Android backup password')

        entry = Gtk.Entry()
        entry.set_visibility(False)
        entry.set_invisible_char("*")
        entry.set_size_request(250, 0)

        area = dlgbox.get_content_area()
        area.pack_end(entry, False, False, 0)

        dlgbox.show_all()
        response = dlgbox.run()

        if response == Gtk.ResponseType.OK:
            ref['password'] = entry.get_text()

        dlgbox.destroy()

        mutex.set()


    @staticmethod
    def read_password_from_gui():
        """Get the backup console from a dialog box."""

        evt = Event()
        ref = {}

        GLib.idle_add(PasswordReader._show_password_box, evt, ref)

        evt.wait()

        return ref['password'] if 'password' in ref.keys() else None