Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
NitroPy
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Le Filament
security_key
NitroPy
Validations
2b0f4e26
Valider
2b0f4e26
rédigé
22 sept. 2022
par
Théo - Le Filament
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
refactor: simplify storage locking and unlocking
parent
a1310197
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/nitropy
+46
-43
46 ajouts, 43 suppressions
src/nitropy
avec
46 ajouts
et
43 suppressions
src/nitropy
+
46
−
43
Voir le fichier @
2b0f4e26
...
@@ -23,10 +23,6 @@ class Tray:
...
@@ -23,10 +23,6 @@ class Tray:
Manage password database openning.
Manage password database openning.
storage : Storage
storage : Storage
Manipulate encrypted storage.
Manipulate encrypted storage.
storage_is_locked : bool
If encrypted storage if locked.
menu_storage : str
Label of storage item menu.
passwords_visible : list
passwords_visible : list
List of setted passwords.
List of setted passwords.
passwords_slot_names : list
passwords_slot_names : list
...
@@ -54,12 +50,10 @@ class Tray:
...
@@ -54,12 +50,10 @@ class Tray:
Ask user to enter a PIN.
Ask user to enter a PIN.
open_keepass()
open_keepass()
Open KeePass database.
Open KeePass database.
get_storage_label()
Get storage label according to state.
storage_action()
storage_action()
Perform lock or unlock of encrypted storage depend of state.
Perform lock or unlock of encrypted storage depend of state.
unlock_storage()
Unlock encrypted storage.
lock_storage()
Lock encrypted storage.
quit()
quit()
Exit tray.
Exit tray.
...
@@ -69,18 +63,13 @@ class Tray:
...
@@ -69,18 +63,13 @@ class Tray:
self
.
nk
=
nitrokey
self
.
nk
=
nitrokey
self
.
keepass
=
keepass
self
.
keepass
=
keepass
self
.
storage
=
storage
self
.
storage
=
storage
self
.
storage_is_locked
=
self
.
storage
.
is_locked
()
self
.
menu_storage
=
"
🔓 Unlock storage
"
if
not
self
.
storage_is_locked
:
self
.
menu_storage
=
"
🔒 Lock storage
"
self
.
passwords_visible
=
[
False
]
*
8
self
.
passwords_visible
=
[
False
]
*
8
self
.
passwords_slot_names
=
[
""
]
*
8
self
.
passwords_slot_names
=
[
""
]
*
8
menu
=
Menu
(
menu
=
Menu
(
MenuItem
(
"
🔑 Open KeePassXC
"
,
self
.
open_keepass
),
MenuItem
(
"
🔑 Open KeePassXC
"
,
self
.
open_keepass
),
MenuItem
(
lambda
text
:
self
.
menu
_storage
,
self
.
storage_action
),
MenuItem
(
lambda
text
:
self
.
get
_storage
_label
()
,
self
.
storage_action
),
MenuItem
(
"
😺 Get password entries
"
,
self
.
get_password_entries
),
MenuItem
(
"
😺 Get password entries
"
,
self
.
get_password_entries
),
MenuItem
(
MenuItem
(
"
📋 Static password
"
,
"
📋 Static password
"
,
...
@@ -294,38 +283,24 @@ class Tray:
...
@@ -294,38 +283,24 @@ class Tray:
except
Exception
as
message
:
except
Exception
as
message
:
print_err
(
message
)
print_err
(
message
)
def
storage_action
(
self
)
->
None
:
def
get_storage_label
(
self
)
->
str
:
"""
Perform lock or unlock of encrypted storage depend of state.
"""
Get storage label according to state.
"""
if
self
.
storage_is_locked
:
self
.
unlock_storage
()
else
:
self
.
lock_storage
()
def
unlock_storage
(
self
)
->
None
:
Returns
"""
Unlock encrypted storage.
-------
str
Storage label.
"""
"""
print_info
(
"
ui: request to unlock storage
"
)
if
self
.
storage
.
is_locked
:
if
self
.
storage
.
unlock
():
return
"
🔓 Unlock storage
"
self
.
storage_is_locked
=
False
return
"
🔒 Lock storage
"
self
.
menu_storage
=
"
🔒 Lock storage
"
print_info
(
"
ui: unlocking storage success
"
)
else
:
print_err
(
"
ui: fail to unlock storage
"
)
def
lock_
storage
(
self
)
->
None
:
def
storage
_action
(
self
)
->
None
:
"""
L
ock encrypted storage.
"""
Perform lock or unl
ock
of
encrypted storage
according to state
.
"""
"""
print_info
(
"
ui: request to lock storage
"
)
self
.
storage
.
toggle
()
if
self
.
storage
.
lock
():
self
.
storage_is_locked
=
True
self
.
menu_storage
=
"
🔓 Unlock storage
"
print_info
(
"
ui: locking storage success
"
)
else
:
print_err
(
"
ui: fail to lock storage
"
)
def
quit
(
self
)
->
None
:
def
quit
(
self
)
->
None
:
"""
Exit tray.
"""
Exit tray.
...
@@ -637,6 +612,8 @@ class Storage:
...
@@ -637,6 +612,8 @@ class Storage:
Path to directory where plain filesystem is mounted.
Path to directory where plain filesystem is mounted.
keyfile : Path
keyfile : Path
Path of the keyfile to decrypt filesystem.
Path of the keyfile to decrypt filesystem.
is_locked : bool
Whether storage is locked.
Methods
Methods
-------
-------
...
@@ -646,6 +623,7 @@ class Storage:
...
@@ -646,6 +623,7 @@ class Storage:
Request to mount encrypted storage.
Request to mount encrypted storage.
lock()
lock()
Unmount encrypted storage.
Unmount encrypted storage.
toggle()
"""
"""
def
__init__
(
self
,
cipher_dir
,
plain_dir
,
keyfile
):
def
__init__
(
self
,
cipher_dir
,
plain_dir
,
keyfile
):
...
@@ -660,7 +638,9 @@ class Storage:
...
@@ -660,7 +638,9 @@ class Storage:
if
not
self
.
keyfile
.
is_file
():
if
not
self
.
keyfile
.
is_file
():
raise
Exception
(
f
"
bad keyfile:
{
keyfile
}
"
)
raise
Exception
(
f
"
bad keyfile:
{
keyfile
}
"
)
def
is_locked
(
self
)
->
bool
:
self
.
is_locked
=
self
.
lock_check
()
def
lock_check
(
self
)
->
bool
:
"""
Check if encrypted storage is unmounted.
"""
Check if encrypted storage is unmounted.
Returns
Returns
...
@@ -693,7 +673,7 @@ class Storage:
...
@@ -693,7 +673,7 @@ class Storage:
`True` if unlock succeed.
`True` if unlock succeed.
"""
"""
if
not
self
.
is_
lock
ed
():
if
not
self
.
lock
_check
():
print_info
(
"
ui: storage is already unlocked
"
)
print_info
(
"
ui: storage is already unlocked
"
)
return
True
return
True
...
@@ -719,7 +699,7 @@ class Storage:
...
@@ -719,7 +699,7 @@ class Storage:
`True` if lock succeed.
`True` if lock succeed.
"""
"""
if
self
.
is_
lock
ed
():
if
self
.
lock
_check
():
print_info
(
"
ui: storage is already locked
"
)
print_info
(
"
ui: storage is already locked
"
)
return
True
return
True
...
@@ -733,6 +713,29 @@ class Storage:
...
@@ -733,6 +713,29 @@ class Storage:
return
gocryptfs
.
wait
()
==
0
return
gocryptfs
.
wait
()
==
0
def
toggle
(
self
)
->
bool
:
"""
Mount or Unmount encrypted storage according to lock state.
Attribute `is_locked` is also updated.
Returns
-------
bool
`True` if locked, `False` if unlocked.
See Also
--------
unlock, lock
"""
if
self
.
is_locked
:
res
=
self
.
unlock
()
else
:
res
=
self
.
lock
()
# Good optimisation. ;)
self
.
is_locked
^=
res
return
self
.
is_locked
class
Config
:
class
Config
:
"""
Config container and parser.
"""
Config container and parser.
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter