@@ -13,42 +13,46 @@ class VortaKeyring:
13
13
@classmethod
14
14
def get_keyring (cls ):
15
15
"""
16
- Attempts to get secure keyring at runtime if current keyring is insecure.
17
- Once it finds a secure keyring, it wil always use that keyring
16
+ Choose available Keyring or save passwords to settings database.
17
+
18
+ Will always use Keychain on macOS. Will try KWallet and then Secret
19
+ Storage on Linux and *BSD. If non are available or usage of system keychain
20
+ is disabled, fall back to saving passwords to DB.
18
21
"""
19
22
20
- # Using system keychain is disabled in settings
21
23
from vorta .models import SettingsModel
22
- if not SettingsModel .get (key = 'use_system_keyring' ).value :
23
- from .db import VortaDBKeyring
24
- cls ._keyring = VortaDBKeyring ()
25
- elif cls ._keyring is None or not cls ._keyring .is_primary :
26
- if sys .platform == 'darwin' : # Use Keychain on macOS
27
- from .darwin import VortaDarwinKeyring
28
- cls ._keyring = VortaDarwinKeyring ()
29
- else :
30
- # Try to use KWallet (KDE)
31
- from .kwallet import VortaKWallet5Keyring , KWalletNotAvailableException
32
- try :
33
- cls ._keyring = VortaKWallet5Keyring ()
34
- except KWalletNotAvailableException :
35
- # Try to use DBus and Gnome-Keyring (available on Linux and *BSD)
36
- # Put this last as gnome keyring is included by default on many distros
37
- import secretstorage
38
- from .secretstorage import VortaSecretStorageKeyring
39
-
40
- # secretstorage has two different libraries based on version
41
- if parse_version (secretstorage .__version__ ) >= parse_version ("3.0.0" ):
42
- from jeepney .wrappers import DBusErrorResponse as DBusException
43
- else :
44
- from dbus .exceptions import DBusException
24
+ from .db import VortaDBKeyring
45
25
26
+ if SettingsModel .get (key = 'use_system_keyring' ).value :
27
+ if cls ._keyring is None or not cls ._keyring .is_system :
28
+ # macOS: Only Keychain available
29
+ if sys .platform == 'darwin' :
30
+ from .darwin import VortaDarwinKeyring
31
+ cls ._keyring = VortaDarwinKeyring ()
32
+ else :
33
+ # Others: Try KWallet first
34
+ from .kwallet import VortaKWallet5Keyring , KWalletNotAvailableException
46
35
try :
47
- cls ._keyring = VortaSecretStorageKeyring ()
48
- except (secretstorage .exceptions .SecretStorageException , DBusException ):
49
- # Save passwords in DB, if all else fails.
50
- from .db import VortaDBKeyring
51
- cls ._keyring = VortaDBKeyring ()
36
+ cls ._keyring = VortaKWallet5Keyring ()
37
+ except KWalletNotAvailableException :
38
+ # Try to use DBus and Gnome Keyring (available on Linux and *BSD)
39
+ # Put this last as Gnome Keyring is included by default on many distros
40
+ import secretstorage
41
+ from .secretstorage import VortaSecretStorageKeyring
42
+
43
+ # Secret Storage has two different libraries based on version
44
+ if parse_version (secretstorage .__version__ ) >= parse_version ("3.0.0" ):
45
+ from jeepney .wrappers import DBusErrorResponse as DBusException
46
+ else :
47
+ from dbus .exceptions import DBusException
48
+ try :
49
+ cls ._keyring = VortaSecretStorageKeyring ()
50
+ except (secretstorage .exceptions .SecretStorageException , DBusException ):
51
+ # Fall back to using DB, if all else fails.
52
+ cls ._keyring = VortaDBKeyring ()
53
+ else :
54
+ cls ._keyring = VortaDBKeyring ()
55
+
52
56
return cls ._keyring
53
57
54
58
def set_password (self , service , repo_url , password ):
@@ -64,7 +68,7 @@ def get_password(self, service, repo_url):
64
68
raise NotImplementedError
65
69
66
70
@property
67
- def is_primary (self ):
71
+ def is_system (self ):
68
72
"""
69
73
Return True if the current subclass is the system's primary keychain mechanism,
70
74
rather than a fallback (like our own VortaDBKeyring).
0 commit comments