[pgp]: Remove pgp file encryption

Use the standard Gajim AES file encryption instead
This commit is contained in:
Philipp Hörist
2025-11-01 23:34:55 +01:00
parent c3f8fc41e2
commit 416d040432
4 changed files with 0 additions and 65 deletions

View File

@@ -20,8 +20,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with PGP Gajim Plugin. If not, see <http://www.gnu.org/licenses/>. # along with PGP Gajim Plugin. If not, see <http://www.gnu.org/licenses/>.
from typing import Any
import logging import logging
import os import os
from functools import lru_cache from functools import lru_cache
@@ -65,9 +63,6 @@ class PGP(metaclass=Singleton):
return self._strip_header_footer(str(result)), error 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: def decrypt(self, payload: str) -> str:
data = self._add_header_footer(payload, "MESSAGE") data = self._add_header_footer(payload, "MESSAGE")
result = self._pgp.decrypt(data.encode("utf8")) result = self._pgp.decrypt(data.encode("utf8"))

View File

@@ -28,9 +28,3 @@ class PGPNotTrusted(ApplicationEvent):
name: str = field(init=False, default="pgp-not-trusted") name: str = field(init=False, default="pgp-not-trusted")
on_yes: Callable[..., Any] on_yes: Callable[..., Any]
on_no: Callable[..., Any] on_no: Callable[..., Any]
@dataclass
class PGPFileEncryptionError(ApplicationEvent):
name: str = field(init=False, default="pgp-file-encryption-error")
error: str

View File

@@ -17,12 +17,10 @@
from typing import Any from typing import Any
import os import os
import threading
import time import time
from collections.abc import Callable from collections.abc import Callable
import nbxmpp import nbxmpp
from gi.repository import GLib
from nbxmpp.client import Client as nbxmppClient from nbxmpp.client import Client as nbxmppClient
from nbxmpp.namespaces import Namespace from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Message from nbxmpp.protocol import Message
@@ -37,7 +35,6 @@ from gajim.common.client import Client
from gajim.common.const import Trust from gajim.common.const import Trust
from gajim.common.events import MessageNotSent from gajim.common.events import MessageNotSent
from gajim.common.modules.base import BaseModule from gajim.common.modules.base import BaseModule
from gajim.common.modules.httpupload import HTTPFileTransfer
from gajim.common.structs import OutgoingMessage from gajim.common.structs import OutgoingMessage
from gajim.plugins.plugins_i18n import _ 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 KeyMismatch
from pgp.exceptions import NoKeyIdFound from pgp.exceptions import NoKeyIdFound
from pgp.exceptions import SignError from pgp.exceptions import SignError
from pgp.modules.events import PGPFileEncryptionError
from pgp.modules.events import PGPNotTrusted from pgp.modules.events import PGPNotTrusted
from pgp.modules.util import prepare_stanza from pgp.modules.util import prepare_stanza
@@ -342,41 +338,6 @@ class PGPLegacy(BaseModule):
stanza.addChild(node=node) stanza.addChild(node=node)
message.set_stanza(stanza) 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]: def get_instance(*args: Any, **kwargs: Any) -> tuple[PGPLegacy, str]:
return PGPLegacy(*args, **kwargs), "PGPLegacy" return PGPLegacy(*args, **kwargs), "PGPLegacy"

View File

@@ -30,7 +30,6 @@ from packaging.version import Version as V
from gajim.common import app from gajim.common import app
from gajim.common import ged from gajim.common import ged
from gajim.common.client import Client from gajim.common.client import Client
from gajim.common.modules.httpupload import HTTPFileTransfer
from gajim.common.structs import OutgoingMessage from gajim.common.structs import OutgoingMessage
from gajim.gtk.alert import AlertDialog from gajim.gtk.alert import AlertDialog
from gajim.gtk.alert import CancelDialogResponse from gajim.gtk.alert import CancelDialogResponse
@@ -44,7 +43,6 @@ from gajim.plugins.plugins_i18n import _
from pgp.exceptions import KeyMismatch from pgp.exceptions import KeyMismatch
from pgp.gtk.config import PGPConfigDialog from pgp.gtk.config import PGPConfigDialog
from pgp.gtk.key import KeyDialog from pgp.gtk.key import KeyDialog
from pgp.modules.events import PGPFileEncryptionError
from pgp.modules.events import PGPNotTrusted from pgp.modules.events import PGPNotTrusted
from pgp.modules.util import find_gpg from pgp.modules.util import find_gpg
@@ -111,7 +109,6 @@ class PGPPlugin(GajimPlugin):
self.events_handlers = { self.events_handlers = {
"pgp-not-trusted": (ged.PRECORE, self._on_not_trusted), "pgp-not-trusted": (ged.PRECORE, self._on_not_trusted),
"pgp-file-encryption-error": (ged.PRECORE, self._on_file_encryption_error),
} }
@staticmethod @staticmethod
@@ -206,15 +203,3 @@ class PGPPlugin(GajimPlugin):
callback: Callable[[OutgoingMessage], None], callback: Callable[[OutgoingMessage], None],
): ):
self.get_pgp_module(client.name).encrypt_message(client, event, callback) 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)