plugin XEP-0373, tools: Move GPG backend to tools.common:
GPG backend will be used for backup, and may be used in general to handle GPG. rel 480
This commit is contained in:
parent
18d55242b9
commit
7325353d18
8 changed files with 66 additions and 31 deletions
|
|
@ -38,6 +38,14 @@ from libervia.backend.plugins.plugin_xep_0045 import XEP_0045
|
|||
from libervia.backend.plugins.plugin_xep_0060 import XEP_0060
|
||||
from libervia.backend.plugins.plugin_xep_0163 import XEP_0163
|
||||
from libervia.backend.tools import xml_tools
|
||||
from libervia.backend.tools.common.gpg_provider import (
|
||||
GPGProvider,
|
||||
GPGProviderBase,
|
||||
GPGPublicKeyBase,
|
||||
GPGSecretKey,
|
||||
GPGSecretKeyBase,
|
||||
exceptions as xep_0373_exceptions,
|
||||
)
|
||||
from libervia.backend.tools.xmpp_datetime import format_datetime, parse_datetime
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
|
|
@ -46,30 +54,6 @@ from tx_xmpp import muc, pubsub
|
|||
from tx_xmpp.disco import DiscoFeature, DiscoInfo
|
||||
import xmlschema
|
||||
|
||||
from . import exceptions as xep_0373_exceptions
|
||||
from .models import GPGProviderBase, GPGPublicKeyBase, GPGSecretKeyBase
|
||||
|
||||
try:
|
||||
# GPG (GPG-ME) is the official Python binding, using system packages
|
||||
import gpg
|
||||
except ImportError:
|
||||
# If not availble, we fallback on python-gnupg, which an unofficial binding which can
|
||||
# be installed without system packages (gpg binary still needs to be installed).
|
||||
try:
|
||||
import gnupg
|
||||
except ImportError:
|
||||
raise exceptions.MissingModule(
|
||||
"You are missing the required GPG backend. You need either the 'gpg' package"
|
||||
" (recommended, requires 'gpgme' library) or the 'gnupg' package (Python"
|
||||
" wrapper for gpg command). See"
|
||||
" https://wiki.python.org/moin/GnuPrivacyGuard#Accessing_GnuPG_via_gpgme for"
|
||||
" the gpg package and https://gnupg.readthedocs.io/ for gnupg."
|
||||
)
|
||||
else:
|
||||
from .gnupg_backend import GPGPublicKey, GPGSecretKey, GPGProvider
|
||||
else:
|
||||
from .gpg_backend import GPGPublicKey, GPGSecretKey, GPGProvider
|
||||
|
||||
log = cast(Logger, getLogger(__name__)) # type: ignore[no-untyped-call]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ from libervia.backend.core.core_types import SatXMPPEntity
|
|||
from libervia.backend.core.i18n import _
|
||||
from libervia.backend.core.log import getLogger
|
||||
from libervia.backend.memory import persistent
|
||||
from libervia.backend.plugins.plugin_xep_0373.exceptions import DecryptionFailed
|
||||
from libervia.backend.tools import utils
|
||||
from libervia.backend.tools import xml_tools
|
||||
from libervia.backend.tools.common import data_format
|
||||
from libervia.backend.tools.common import uri
|
||||
from libervia.backend.tools.common.gpg_provider.exceptions import DecryptionFailed
|
||||
|
||||
from .plugin_xep_0373 import NS_OX, get_gpg_provider
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ from libervia.backend.core.i18n import _
|
|||
from libervia.backend.core.log import getLogger
|
||||
from libervia.backend.tools import utils
|
||||
from libervia.backend.tools.common import data_format
|
||||
|
||||
from .plugin_xep_0373.exceptions import VerificationFailed
|
||||
from libervia.backend.tools.common.gpg_provider.exceptions import VerificationFailed
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
|
|
|||
52
libervia/backend/tools/common/gpg_provider/__init__.py
Normal file
52
libervia/backend/tools/common/gpg_provider/__init__.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Libervia: an XMPP client
|
||||
# Copyright (C) 2025-2026 Jérôme Poisson (goffi@goffi.org)
|
||||
# Copyright (C) 2022-2026 Tim Henkes (me@syndace.dev)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program 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 Affero General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from libervia.backend.core import exceptions as core_exceptions
|
||||
|
||||
from .models import GPGProviderBase, GPGPublicKeyBase, GPGSecretKeyBase
|
||||
|
||||
try:
|
||||
# GPG (GPG-ME) is the official Python binding, using system packages
|
||||
import gpg
|
||||
except ImportError:
|
||||
# If not available, we fallback on python-gnupg, an unofficial binding which can be
|
||||
# installed without system packages (gpg binary still needs to be installed).
|
||||
try:
|
||||
import gnupg
|
||||
except ImportError:
|
||||
raise core_exceptions.MissingModule(
|
||||
"You are missing the required GPG backend. You need either the 'gpg' package"
|
||||
" (recommended, requires 'gpgme' library) or the 'gnupg' package (Python"
|
||||
" wrapper for gpg command). See"
|
||||
" https://wiki.python.org/moin/GnuPrivacyGuard#Accessing_GnuPG_via_gpgme for"
|
||||
" the gpg package and https://gnupg.readthedocs.io/ for gnupg."
|
||||
)
|
||||
else:
|
||||
from .python_gnupg import GPGProvider, GPGPublicKey, GPGSecretKey
|
||||
else:
|
||||
from .gpgme import GPGProvider, GPGPublicKey, GPGSecretKey
|
||||
|
||||
|
||||
def get_provider(home_dir: str | None = None) -> GPGProviderBase:
|
||||
"""Return a GPG provider
|
||||
|
||||
@param home_dir: GPG home to use, None for the default one
|
||||
@return: the GPG provider to use
|
||||
"""
|
||||
return GPGProvider(home_dir)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Libervia plugin for OpenPGP for XMPP
|
||||
# Libervia: an XMPP client
|
||||
# Copyright (C) 2025-2026 Jérôme Poisosn (goffi@goffi.org)
|
||||
# Copyright (C) 2022-2026 Tim Henkes (me@syndace.dev)
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Libervia plugin for OpenPGP for XMPP
|
||||
# Libervia: an XMPP client
|
||||
# Copyright (C) 2025-2026 Jérôme Poisosn (goffi@goffi.org)
|
||||
# Copyright (C) 2022-2026 Tim Henkes (me@syndace.dev)
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Libervia plugin for OpenPGP for XMPP
|
||||
# Libervia: an XMPP client
|
||||
# Copyright (C) 2025-2026 Jérôme Poisosn (goffi@goffi.org)
|
||||
# Copyright (C) 2022-2026 Tim Henkes (me@syndace.dev)
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Libervia plugin for OpenPGP for XMPP
|
||||
# Libervia: an XMPP client
|
||||
# Copyright (C) 2025-2026 Jérôme Poisosn (goffi@goffi.org)
|
||||
# Copyright (C) 2022-2026 Tim Henkes (me@syndace.dev)
|
||||
|
||||
Loading…
Reference in a new issue