diff options
| author | Marvin W <git@larma.de> | 2026-06-07 21:52:00 +0200 |
|---|---|---|
| committer | Marvin W <git@larma.de> | 2026-06-07 23:13:07 +0200 |
| commit | 9b7b0d98cb9a41e8bd06ae627474d4e1e97139e6 (patch) | |
| tree | 61a36db5611fb57f9681c1c239ffa05931c7dc07 /plugins/openpgp/src/stream_module.vala | |
| parent | 8c05d7b066f03d0c024cc0701b69279fffb4e0cf (diff) | |
OpenPGP: Process signatures on presences only once needed
- Incoming signatures are stored in the database and processed when needed
(to send PGP encrypted messages or to display them in the contact details)
- Outgoing signatures are stored in the database and cached until the key is
changed
Diffstat (limited to 'plugins/openpgp/src/stream_module.vala')
| -rw-r--r-- | plugins/openpgp/src/stream_module.vala | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/plugins/openpgp/src/stream_module.vala b/plugins/openpgp/src/stream_module.vala index 32a77580..9985df26 100644 --- a/plugins/openpgp/src/stream_module.vala +++ b/plugins/openpgp/src/stream_module.vala @@ -10,26 +10,28 @@ namespace Dino.Plugins.OpenPgp { public class Module : XmppStreamModule { public static Xmpp.ModuleIdentity<Module> IDENTITY = new Xmpp.ModuleIdentity<Module>(NS_URI, "0027_current_pgp_usage"); - public signal void received_jid_key_id(XmppStream stream, Jid jid, string key_id); + public signal void received_jid_presence_signature(XmppStream stream, Jid jid, string sig, string signed_data); private string? signed_status = null; private Key? own_key = null; private ReceivedPipelineDecryptListener received_pipeline_decrypt_listener = new ReceivedPipelineDecryptListener(); - public Module(string? own_key_id = null) { - set_private_key_id(own_key_id); + public Module(string? own_key_id = null, ref string? signed_data, ref string? sig) { + set_private_key_id(own_key_id, ref signed_data, ref sig); } - public void set_private_key_id(string? own_key_id) { - if (own_key_id != null) { + public void set_private_key_id(string? own_key_id, ref string? signed_data, ref string? sig) { + if (own_key_id != null && sig == null) { try { own_key = GPGHelper.get_private_key(own_key_id); if (own_key == null) warning("Can't get PGP private key"); } catch (Error e) { } if (own_key != null) { - signed_status = gpg_sign("", own_key); + if (signed_data == null) signed_data = ""; + sig = gpg_sign(signed_data, own_key); } } + signed_status = own_key_id != null ? sig : null; } public bool encrypt(MessageStanza message, GPG.Key[] keys) { @@ -47,7 +49,6 @@ namespace Dino.Plugins.OpenPgp { stream.get_module(Presence.Module.IDENTITY).received_presence.connect(on_received_presence); stream.get_module(Presence.Module.IDENTITY).pre_send_presence_stanza.connect(on_pre_send_presence_stanza); stream.get_module(MessageModule.IDENTITY).received_pipeline.connect(received_pipeline_decrypt_listener); - stream.add_flag(new Flag()); } public override void detach(XmppStream stream) { @@ -56,10 +57,6 @@ namespace Dino.Plugins.OpenPgp { stream.get_module(MessageModule.IDENTITY).received_pipeline.disconnect(received_pipeline_decrypt_listener); } - public static void require(XmppStream stream) { - if (stream.get_module(IDENTITY) == null) stream.add_module(new Module()); - } - public override string get_ns() { return NS_URI; } public override string get_id() { return IDENTITY.id; } @@ -68,18 +65,8 @@ namespace Dino.Plugins.OpenPgp { if (x_node == null) return; string? sig = x_node.get_string_content(); if (sig == null) return; - new Thread<void*> (null, () => { - string signed_data = presence.status == null ? "" : presence.status; - string? key_id = get_sign_key(sig, signed_data); - if (key_id != null) { - stream.get_flag(Flag.IDENTITY).set_key_id(presence.from, key_id); - Idle.add(() => { - received_jid_key_id(stream, presence.from, key_id); - return false; - }); - } - return null; - }); + string signed_data = presence.status == null ? "" : presence.status; + received_jid_presence_signature(stream, presence.from, sig, signed_data); } private void on_pre_send_presence_stanza(XmppStream stream, Presence.Stanza presence) { @@ -99,15 +86,6 @@ namespace Dino.Plugins.OpenPgp { return encr.substring(encryption_start, encr.length - "\n-----END PGP MESSAGE-----".length - encryption_start); } - private static string? get_sign_key(string sig, string signed_text) { - string armor = "-----BEGIN PGP MESSAGE-----\n\n" + sig + "\n-----END PGP MESSAGE-----"; - string? sign_key = null; - try { - sign_key = GPGHelper.get_sign_key(armor, signed_text); - } catch (Error e) { } - return sign_key; - } - private static string? gpg_sign(string str, Key key) { string signed; try { |
