From 416d0404326aa960649d9db7c18df4ad6fd5d9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 1 Nov 2025 23:34:55 +0100 Subject: [PATCH] [pgp]: Remove pgp file encryption Use the standard Gajim AES file encryption instead --- pgp/backend/python_gnupg.py | 5 ----- pgp/modules/events.py | 6 ------ pgp/modules/pgp_legacy.py | 39 ------------------------------------- pgp/plugin.py | 15 -------------- 4 files changed, 65 deletions(-) diff --git a/pgp/backend/python_gnupg.py b/pgp/backend/python_gnupg.py index 14c9696..c75c448 100644 --- a/pgp/backend/python_gnupg.py +++ b/pgp/backend/python_gnupg.py @@ -20,8 +20,6 @@ # You should have received a copy of the GNU General Public License # along with PGP Gajim Plugin. If not, see . -from typing import Any - import logging import os from functools import lru_cache @@ -65,9 +63,6 @@ class PGP(metaclass=Singleton): return self._strip_header_footer(str(result)), error - def encrypt_file(self, file: Any, recipients: list[str]) -> gnupg.Crypt: - return self._pgp.encrypt_file(file, recipients) - def decrypt(self, payload: str) -> str: data = self._add_header_footer(payload, "MESSAGE") result = self._pgp.decrypt(data.encode("utf8")) diff --git a/pgp/modules/events.py b/pgp/modules/events.py index 7d95aab..632b38f 100644 --- a/pgp/modules/events.py +++ b/pgp/modules/events.py @@ -28,9 +28,3 @@ class PGPNotTrusted(ApplicationEvent): name: str = field(init=False, default="pgp-not-trusted") on_yes: Callable[..., Any] on_no: Callable[..., Any] - - -@dataclass -class PGPFileEncryptionError(ApplicationEvent): - name: str = field(init=False, default="pgp-file-encryption-error") - error: str diff --git a/pgp/modules/pgp_legacy.py b/pgp/modules/pgp_legacy.py index ff8534d..7885a66 100644 --- a/pgp/modules/pgp_legacy.py +++ b/pgp/modules/pgp_legacy.py @@ -17,12 +17,10 @@ from typing import Any import os -import threading import time from collections.abc import Callable import nbxmpp -from gi.repository import GLib from nbxmpp.client import Client as nbxmppClient from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Message @@ -37,7 +35,6 @@ from gajim.common.client import Client from gajim.common.const import Trust from gajim.common.events import MessageNotSent from gajim.common.modules.base import BaseModule -from gajim.common.modules.httpupload import HTTPFileTransfer from gajim.common.structs import OutgoingMessage from gajim.plugins.plugins_i18n import _ @@ -46,7 +43,6 @@ from pgp.backend.store import KeyStore from pgp.exceptions import KeyMismatch from pgp.exceptions import NoKeyIdFound from pgp.exceptions import SignError -from pgp.modules.events import PGPFileEncryptionError from pgp.modules.events import PGPNotTrusted from pgp.modules.util import prepare_stanza @@ -342,41 +338,6 @@ class PGPLegacy(BaseModule): stanza.addChild(node=node) message.set_stanza(stanza) - def encrypt_file( - self, transfer: HTTPFileTransfer, callback: Callable[[HTTPFileTransfer], None] - ) -> None: - thread = threading.Thread( - target=self._encrypt_file_thread, args=(transfer, callback) - ) - thread.daemon = True - thread.start() - - def _encrypt_file_thread( - self, transfer: HTTPFileTransfer, callback: Callable[[HTTPFileTransfer], None] - ) -> None: - try: - key_id, own_key_id = self._get_key_ids(str(transfer.contact.jid)) - except NoKeyIdFound as error: - self._log.warning(error) - return - - stream = open(transfer.path, "rb") - encrypted = self._pgp.encrypt_file(stream, [key_id, own_key_id]) - stream.close() - - if not encrypted: - GLib.idle_add(self._on_file_encryption_error, encrypted.status) - return - - transfer.size = len(encrypted.data) - transfer.set_uri_transform_func(lambda uri: "%s.pgp" % uri) - transfer.set_encrypted_data(encrypted.data) - GLib.idle_add(callback, transfer) - - @staticmethod - def _on_file_encryption_error(error: str) -> None: - app.ged.raise_event(PGPFileEncryptionError(error=error)) - def get_instance(*args: Any, **kwargs: Any) -> tuple[PGPLegacy, str]: return PGPLegacy(*args, **kwargs), "PGPLegacy" diff --git a/pgp/plugin.py b/pgp/plugin.py index fa12fe3..c93346e 100644 --- a/pgp/plugin.py +++ b/pgp/plugin.py @@ -30,7 +30,6 @@ from packaging.version import Version as V from gajim.common import app from gajim.common import ged from gajim.common.client import Client -from gajim.common.modules.httpupload import HTTPFileTransfer from gajim.common.structs import OutgoingMessage from gajim.gtk.alert import AlertDialog from gajim.gtk.alert import CancelDialogResponse @@ -44,7 +43,6 @@ from gajim.plugins.plugins_i18n import _ from pgp.exceptions import KeyMismatch from pgp.gtk.config import PGPConfigDialog from pgp.gtk.key import KeyDialog -from pgp.modules.events import PGPFileEncryptionError from pgp.modules.events import PGPNotTrusted from pgp.modules.util import find_gpg @@ -111,7 +109,6 @@ class PGPPlugin(GajimPlugin): self.events_handlers = { "pgp-not-trusted": (ged.PRECORE, self._on_not_trusted), - "pgp-file-encryption-error": (ged.PRECORE, self._on_file_encryption_error), } @staticmethod @@ -206,15 +203,3 @@ class PGPPlugin(GajimPlugin): callback: Callable[[OutgoingMessage], None], ): self.get_pgp_module(client.name).encrypt_message(client, event, callback) - - def encrypt_file( - self, - transfer: HTTPFileTransfer, - account: str, - callback: Callable[[HTTPFileTransfer], None], - ): - self.get_pgp_module(account).encrypt_file(transfer, callback) - - @staticmethod - def _on_file_encryption_error(event: PGPFileEncryptionError) -> None: - InformationAlertDialog(_("Error"), event.error)