aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/jingle/jingle_helper.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2019-09-10 20:57:10 +0200
committerMarvin W <git@larma.de>2019-09-16 23:31:11 +0200
commit392cb472abcdff9424197c8504175ee79c22dde5 (patch)
treedb3e2b7ef7fd729a3b7e316250485d53246b1b73 /plugins/omemo/src/jingle/jingle_helper.vala
parente899668213ee8f7d3566bb5754b488d8633c30c7 (diff)
downloaddino-392cb472abcdff9424197c8504175ee79c22dde5.tar.gz
dino-392cb472abcdff9424197c8504175ee79c22dde5.zip
Add support for JET-OMEMO
Diffstat (limited to 'plugins/omemo/src/jingle/jingle_helper.vala')
-rw-r--r--plugins/omemo/src/jingle/jingle_helper.vala53
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/omemo/src/jingle/jingle_helper.vala b/plugins/omemo/src/jingle/jingle_helper.vala
new file mode 100644
index 00000000..6814fd00
--- /dev/null
+++ b/plugins/omemo/src/jingle/jingle_helper.vala
@@ -0,0 +1,53 @@
+using Dino.Entities;
+using Xmpp;
+
+namespace Dino.Plugins.JetOmemo {
+public class EncryptionHelper : JingleFileEncryptionHelper, Object {
+ private StreamInteractor stream_interactor;
+
+ public EncryptionHelper(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+ }
+
+ public bool can_transfer(Conversation conversation) {
+ return true;
+ }
+
+ public bool can_encrypt(Conversation conversation, FileTransfer file_transfer, Jid? full_jid) {
+ XmppStream? stream = stream_interactor.get_stream(conversation.account);
+ if (stream == null) return false;
+
+ Gee.List<Jid>? resources = stream.get_flag(Presence.Flag.IDENTITY).get_resources(conversation.counterpart);
+ if (resources == null) return false;
+
+ if (full_jid == null) {
+ foreach (Jid test_jid in resources) {
+ if (stream.get_module(Module.IDENTITY).is_available(stream, test_jid)) {
+ return true;
+ }
+ }
+ } else {
+ if (stream.get_module(Module.IDENTITY).is_available(stream, full_jid)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public string? get_precondition_name(Conversation conversation, FileTransfer file_transfer) {
+ return Xep.Jet.NS_URI;
+ }
+
+ public Object? get_precondition_options(Conversation conversation, FileTransfer file_transfer) {
+ return new Xep.Jet.Options(Omemo.NS_URI, AES_128_GCM_URI);
+ }
+
+ public FileMeta complete_meta(FileTransfer file_transfer, FileReceiveData receive_data, FileMeta file_meta, Xmpp.Xep.JingleFileTransfer.FileTransfer jingle_transfer) {
+ Xep.Jet.SecurityParameters? security = jingle_transfer.security as Xep.Jet.SecurityParameters;
+ if (security != null && security.encoding.get_type_uri() == Omemo.NS_URI) {
+ file_transfer.encryption = Encryption.OMEMO;
+ }
+ return file_meta;
+ }
+}
+} \ No newline at end of file