aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2018-11-27 18:28:28 +0100
committerfiaxh <git@lightrise.org>2018-11-27 18:28:28 +0100
commit7c1d580e174ff31a55677e976d87284868bd99c6 (patch)
tree986a66282848c06390ce1e9f0e9494965aa6a1d3 /plugins
parent141db9e40a3a81cfa3ad3587dc47f69c541d0fde (diff)
downloaddino-7c1d580e174ff31a55677e976d87284868bd99c6.tar.gz
dino-7c1d580e174ff31a55677e976d87284868bd99c6.zip
Fix aesgcm http file up/download bugs
Diffstat (limited to 'plugins')
-rw-r--r--plugins/http-files/src/file_provider.vala12
-rw-r--r--plugins/omemo/src/file_provider.vala41
-rw-r--r--plugins/omemo/src/file_sender.vala4
3 files changed, 36 insertions, 21 deletions
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 19d34bb0..3fa32097 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -63,16 +63,18 @@ public class FileProvider : Dino.FileProvider, Object {
file_transfer.info = message.id.to_string();
if (stream_interactor.get_module(FileManager.IDENTITY).is_sender_trustworthy(file_transfer, conversation)) {
- ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item(conversation, 1, message.id);
- if (content_item != null) {
- stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
- }
yield get_meta_info(file_transfer);
+ if (file_transfer.size >= 0 && file_transfer.size < 5000000) {
+ ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item(conversation, 1, message.id);
+ if (content_item != null) {
+ stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
+ }
+ }
file_incoming(file_transfer, conversation);
}
}
- private async void get_meta_info(FileTransfer file_transfer) {
+ public async void get_meta_info(FileTransfer file_transfer) {
string url_body = dino_db.message.select({dino_db.message.body}).with(dino_db.message.id, "=", int.parse(file_transfer.info))[dino_db.message.body];
var session = new Soup.Session();
var head_message = new Soup.Message("HEAD", url_body);
diff --git a/plugins/omemo/src/file_provider.vala b/plugins/omemo/src/file_provider.vala
index 810da084..70e59574 100644
--- a/plugins/omemo/src/file_provider.vala
+++ b/plugins/omemo/src/file_provider.vala
@@ -65,36 +65,43 @@ public class FileProvider : Dino.FileProvider, Object {
file_transfer.info = message.id.to_string();
if (stream_interactor.get_module(FileManager.IDENTITY).is_sender_trustworthy(file_transfer, conversation)) {
- ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item(conversation, 1, message.id);
- if (content_item != null) {
- stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
- }
yield get_meta_info(file_transfer);
+ if (file_transfer.size >= 0 && file_transfer.size < 5000000) {
+ ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item(conversation, 1, message.id);
+ if (content_item != null) {
+ stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
+ }
+ }
file_incoming(file_transfer, conversation);
}
}
- private async void get_meta_info(FileTransfer file_transfer) {
+ public async void get_meta_info(FileTransfer file_transfer) {
string url_body = dino_db.message.select({dino_db.message.body}).with(dino_db.message.id, "=", int.parse(file_transfer.info))[dino_db.message.body];
+ string url = this.aesgcm_to_https_link(url_body);
var session = new Soup.Session();
- var head_message = new Soup.Message("HEAD", url_body);
+ var head_message = new Soup.Message("HEAD", url);
if (head_message != null) {
yield session.send_async(head_message, null);
- string? content_type = null, content_length = null;
- head_message.response_headers.foreach((name, val) => {
- if (name == "Content-Type") content_type = val;
- if (name == "Content-Length") content_length = val;
- });
- file_transfer.mime_type = content_type;
- file_transfer.size = int.parse(content_length);
+ if (head_message.status_code >= 200 && head_message.status_code < 300) {
+ string? content_type = null, content_length = null;
+ head_message.response_headers.foreach((name, val) => {
+ if (name == "Content-Type") content_type = val;
+ if (name == "Content-Length") content_length = val;
+ });
+ file_transfer.mime_type = content_type;
+ file_transfer.size = int.parse(content_length);
+ } else {
+ warning("HTTP HEAD download status code " + head_message.status_code.to_string());
+ }
}
}
public async void download(FileTransfer file_transfer, File file) {
try {
string url_body = dino_db.message.select({dino_db.message.body}).with(dino_db.message.id, "=", int.parse(file_transfer.info))[dino_db.message.body];
- string url = "https://" + url_body.substring(9);
+ string url = this.aesgcm_to_https_link(url_body);
var session = new Soup.Session();
Soup.Request request = session.request(url);
@@ -149,6 +156,12 @@ public class FileProvider : Dino.FileProvider, Object {
}
return bin;
}
+
+ private string aesgcm_to_https_link(string aesgcm_link) {
+ MatchInfo match_info;
+ this.url_regex.match(aesgcm_link, 0, out match_info);
+ return "https://" + match_info.fetch(1);
+ }
}
}
diff --git a/plugins/omemo/src/file_sender.vala b/plugins/omemo/src/file_sender.vala
index a760bc7b..b63d3dc5 100644
--- a/plugins/omemo/src/file_sender.vala
+++ b/plugins/omemo/src/file_sender.vala
@@ -46,7 +46,7 @@ public class AesGcmFileSender : StreamInteractionModule, FileSender, Object {
foreach (uint8 byte in iv) iv_and_key += byte.to_string("%02x");
foreach (uint8 byte in key) iv_and_key += byte.to_string("%02x");
- stream_interactor.module_manager.get_module(file_transfer.account, Xmpp.Xep.HttpFileUpload.Module.IDENTITY).request_slot(stream, file_transfer.server_file_name, (int) data.length, file_transfer.mime_type,
+ stream_interactor.module_manager.get_module(file_transfer.account, Xmpp.Xep.HttpFileUpload.Module.IDENTITY).request_slot(stream, file_transfer.server_file_name, (int) ciphertext.length, file_transfer.mime_type,
(stream, url_down, url_up) => {
Soup.Message message = new Soup.Message("PUT", url_up);
message.set_request(file_transfer.mime_type, Soup.MemoryUse.COPY, ciphertext);
@@ -69,7 +69,7 @@ public class AesGcmFileSender : StreamInteractionModule, FileSender, Object {
stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
}
} else {
- warning("HTTP status code " + message.status_code.to_string());
+ warning("HTTP upload status code " + message.status_code.to_string());
file_transfer.state = FileTransfer.State.FAILED;
}
} catch (Error e) {