Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2023-02-05 22:34:25 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-02-05 22:34:25 +0300
commite837ef4e0a2f170d792c909a15a1ff977d62942e (patch)
treee17260eeeafca1c3e9c3c9af1de5ac5dadebb8a0
parent97679843f08b2dba4943417edb546e52ff86060f (diff)
feat: Improve KeepassXC Integration
Provide setting which improves the KeepassXC Integration NOTES: If you already used KeepassXC with Gajim, enabling the new integration setting will trigger new entries in the password manager
-rw-r--r--gajim/common/application.py4
-rw-r--r--gajim/common/helpers.py13
-rw-r--r--gajim/common/passwords.py8
-rw-r--r--gajim/common/setting_values.py2
-rw-r--r--gajim/gtk/preferences.py9
-rw-r--r--typings/keyring/backend.pyi3
6 files changed, 35 insertions, 4 deletions
diff --git a/gajim/common/application.py b/gajim/common/application.py
index 109fcab72..4a524476e 100644
--- a/gajim/common/application.py
+++ b/gajim/common/application.py
@@ -75,11 +75,11 @@ class CoreApplication(ged.EventHelper):
app.detect_dependencies()
configpaths.create_paths()
- passwords.init()
-
app.settings = Settings()
app.settings.init()
+ passwords.init()
+
app.config = LegacyConfig()
app.commands = ChatCommands()
diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py
index e9bc17c6d..ca9a6d161 100644
--- a/gajim/common/helpers.py
+++ b/gajim/common/helpers.py
@@ -37,6 +37,7 @@ import collections
import copy
import functools
import hashlib
+import importlib.metadata
import inspect
import json
import logging
@@ -77,6 +78,7 @@ from nbxmpp.protocol import Iq
from nbxmpp.protocol import JID
from nbxmpp.structs import CommonError
from nbxmpp.structs import ProxyData
+from packaging.requirements import Requirement
from packaging.version import Version as V
from gajim.common import app
@@ -1510,6 +1512,17 @@ def get_glib_version() -> str:
GLib.MICRO_VERSION]))
+def package_version(requirement: str) -> bool:
+ req = Requirement(requirement)
+
+ try:
+ installed_version = importlib.metadata.version(req.name)
+ except importlib.metadata.PackageNotFoundError:
+ return False
+
+ return installed_version in req.specifier
+
+
def make_path_from_jid(base_path: Path, jid: JID) -> Path:
assert jid.domain is not None
domain = jid.domain[:50]
diff --git a/gajim/common/passwords.py b/gajim/common/passwords.py
index 996f0b561..783666afb 100644
--- a/gajim/common/passwords.py
+++ b/gajim/common/passwords.py
@@ -30,6 +30,7 @@ import logging
import keyring
from gajim.common import app
+from gajim.common.helpers import package_version
__all__ = [
'init',
@@ -56,7 +57,12 @@ class Interface:
for backend in backends:
log.info('Found keyring backend: %s', backend)
- self.backend = keyring.get_keyring()
+ if (app.settings.get('enable_keepassxc_integration') and
+ package_version('keyring>=23.8.1')):
+ _keyring = keyring.get_keyring()
+ self.backend = _keyring.with_properties(scheme='KeePassXC')
+ else:
+ self.backend = keyring.get_keyring()
log.info('Select %s backend', self.backend)
self._is_keyring_available = keyring.core.recommended(self.backend)
diff --git a/gajim/common/setting_values.py b/gajim/common/setting_values.py
index bdf3957d8..55ed53ecd 100644
--- a/gajim/common/setting_values.py
+++ b/gajim/common/setting_values.py
@@ -51,6 +51,7 @@ BoolSettings = Literal[
'dev_force_bookmark_2',
'developer_modus',
'enable_emoji_shortcodes',
+ 'enable_keepassxc_integration',
'enable_negative_priority',
'enable_file_preview',
'escape_key_closes',
@@ -193,6 +194,7 @@ APP_SETTINGS = {
'developer_modus': False,
'dictionary_url': 'WIKTIONARY',
'enable_emoji_shortcodes': True,
+ 'enable_keepassxc_integration': False,
'enable_negative_priority': False,
'enable_file_preview': True,
'escape_key_closes': False,
diff --git a/gajim/gtk/preferences.py b/gajim/gtk/preferences.py
index 765329e83..88481ad18 100644
--- a/gajim/gtk/preferences.py
+++ b/gajim/gtk/preferences.py
@@ -30,6 +30,7 @@ from gajim.common.const import THRESHOLD_OPTIONS
from gajim.common.events import StyleChanged
from gajim.common.events import ThemeUpdate
from gajim.common.helpers import open_directory
+from gajim.common.helpers import package_version
from gajim.common.i18n import _
from gajim.common.multimedia_helpers import AudioInputManager
from gajim.common.multimedia_helpers import AudioOutputManager
@@ -888,6 +889,14 @@ class Miscellaneous(PreferenceBox):
desc=_('Use your system’s keyring to store passwords')),
]
+ if (sys.platform not in ('win32', 'darwin') and
+ package_version('keyring>=23.8.1')):
+ settings.append(
+ Setting(SettingKind.SWITCH,
+ _('Enable KeepassXC Integration'),
+ SettingType.CONFIG,
+ 'enable_keepassxc_integration'))
+
if sys.platform in ('win32', 'darwin'):
settings.append(
Setting(SettingKind.SWITCH,
diff --git a/typings/keyring/backend.pyi b/typings/keyring/backend.pyi
index 29ad39579..7f2e67b14 100644
--- a/typings/keyring/backend.pyi
+++ b/typings/keyring/backend.pyi
@@ -1,5 +1,5 @@
-
+from typing import Any
from typing import Optional
class KeyringBackend:
@@ -7,6 +7,7 @@ class KeyringBackend:
def get_password(self, service: str, username: str) -> Optional[str]: ...
def set_password(self, service: str, username: str, password: str) -> None: ...
def delete_password(self, service: str, username: str) -> None: ...
+ def with_properties(self, **kwargs: Any) -> KeyringBackend: ...
def get_all_keyring() -> list[KeyringBackend]: ...