diff options
Diffstat (limited to 'plugins/openpgp/src')
-rw-r--r-- | plugins/openpgp/src/contact_details_provider.vala | 7 | ||||
-rw-r--r-- | plugins/openpgp/src/encryption_list_entry.vala | 4 | ||||
-rw-r--r-- | plugins/openpgp/src/in_file_processor.vala | 28 | ||||
-rw-r--r-- | plugins/openpgp/src/manager.vala | 18 | ||||
-rw-r--r-- | plugins/openpgp/src/out_file_processor.vala | 14 |
5 files changed, 44 insertions, 27 deletions
diff --git a/plugins/openpgp/src/contact_details_provider.vala b/plugins/openpgp/src/contact_details_provider.vala index 5529549c..b691cc19 100644 --- a/plugins/openpgp/src/contact_details_provider.vala +++ b/plugins/openpgp/src/contact_details_provider.vala @@ -18,8 +18,11 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object { string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); if (key_id != null) { Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true }; - Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id); - if (keys.size > 0) { + Gee.List<GPG.Key>? keys = null; + try { + keys = GPGHelper.get_keylist(key_id); + } catch (Error e) { } + if (keys != null && keys.size > 0) { label.label = markup_colorize_id(keys[0].fpr, true); } else { label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false); diff --git a/plugins/openpgp/src/encryption_list_entry.vala b/plugins/openpgp/src/encryption_list_entry.vala index e0a11865..d2cbd13f 100644 --- a/plugins/openpgp/src/encryption_list_entry.vala +++ b/plugins/openpgp/src/encryption_list_entry.vala @@ -23,7 +23,9 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object { public bool can_encrypt(Entities.Conversation conversation) { if (conversation.type_ == Conversation.Type.CHAT) { string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); - return key_id != null && GPGHelper.get_keylist(key_id).size > 0; + try { + return key_id != null && GPGHelper.get_keylist(key_id).size > 0; + } catch (Error e) { return false; } } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { Gee.List<Jid> muc_jids = new Gee.ArrayList<Jid>(); Gee.List<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account); diff --git a/plugins/openpgp/src/in_file_processor.vala b/plugins/openpgp/src/in_file_processor.vala index 2a06bbdf..61baa37e 100644 --- a/plugins/openpgp/src/in_file_processor.vala +++ b/plugins/openpgp/src/in_file_processor.vala @@ -8,19 +8,23 @@ public class InFileProcessor : IncommingFileProcessor, Object { } public void process(FileTransfer file_transfer) { - uint8[] buf = new uint8[256]; - Array<uint8> data = new Array<uint8>(false, true, 0); - size_t len = -1; - do { - len = file_transfer.input_stream.read(buf); - data.append_vals(buf, (uint) len); - } while(len > 0); + try { + uint8[] buf = new uint8[256]; + Array<uint8> data = new Array<uint8>(false, true, 0); + size_t len = -1; + do { + len = file_transfer.input_stream.read(buf); + data.append_vals(buf, (uint) len); + } while(len > 0); - uint8[] clear_data = GPGHelper.decrypt_data(data.data); - file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free); - file_transfer.encryption = Encryption.PGP; - if (file_transfer.file_name.has_suffix(".pgp")) { - file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4); + uint8[] clear_data = GPGHelper.decrypt_data(data.data); + file_transfer.input_stream = new MemoryInputStream.from_data(clear_data, GLib.free); + file_transfer.encryption = Encryption.PGP; + if (file_transfer.file_name.has_suffix(".pgp")) { + file_transfer.file_name = file_transfer.file_name.substring(0, file_transfer.file_name.length - 4); + } + } catch (Error e) { + file_transfer.state = FileTransfer.State.FAILED; } } } diff --git a/plugins/openpgp/src/manager.vala b/plugins/openpgp/src/manager.vala index 74f6027c..3f0fe3dd 100644 --- a/plugins/openpgp/src/manager.vala +++ b/plugins/openpgp/src/manager.vala @@ -30,7 +30,7 @@ public class Manager : StreamInteractionModule, Object { stream_interactor.get_module(MessageProcessor.IDENTITY).pre_message_send.connect(check_encypt); } - public GPG.Key[] get_key_fprs(Conversation conversation) { + public GPG.Key[] get_key_fprs(Conversation conversation) throws Error { Gee.List<string> keys = new Gee.ArrayList<string>(); keys.add(db.get_account_key(conversation.account)); if (conversation.type_ == Conversation.Type.GROUPCHAT) { @@ -70,13 +70,17 @@ public class Manager : StreamInteractionModule, Object { } private void check_encypt(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { - if (message.encryption == Encryption.PGP) { - GPG.Key[] keys = get_key_fprs(conversation); - Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); - if (stream != null) { - bool encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, keys); - if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND; + try { + if (message.encryption == Encryption.PGP) { + GPG.Key[] keys = get_key_fprs(conversation); + Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); + if (stream != null) { + bool encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, keys); + if (!encrypted) message.marked = Entities.Message.Marked.WONTSEND; + } } + } catch (Error e) { + message.marked = Entities.Message.Marked.WONTSEND; } } diff --git a/plugins/openpgp/src/out_file_processor.vala b/plugins/openpgp/src/out_file_processor.vala index 81c53b16..a09e17a6 100644 --- a/plugins/openpgp/src/out_file_processor.vala +++ b/plugins/openpgp/src/out_file_processor.vala @@ -16,11 +16,15 @@ public class OutFileProcessor : OutgoingFileProcessor, Object { public void process(Conversation conversation, FileTransfer file_transfer) { string uri = file_transfer.get_uri(); - GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation); - uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST); - file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free); - file_transfer.encryption = Encryption.PGP; - file_transfer.server_file_name = file_transfer.server_file_name + ".pgp"; + try { + GPG.Key[] keys = stream_interactor.get_module(Manager.IDENTITY).get_key_fprs(conversation); + uint8[] enc_content = GPGHelper.encrypt_file(uri, keys, GPG.EncryptFlags.ALWAYS_TRUST); + file_transfer.input_stream = new MemoryInputStream.from_data(enc_content, GLib.free); + file_transfer.encryption = Encryption.PGP; + file_transfer.server_file_name = file_transfer.server_file_name + ".pgp"; + } catch (Error e) { + file_transfer.state = FileTransfer.State.FAILED; + } } } |