aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java17
-rw-r--r--src/main/java/de/pixart/messenger/utils/CryptoHelper.java14
2 files changed, 25 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index d49111dbf..722c1dea9 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -75,9 +75,9 @@ public class HttpDownloadConnection implements Transferable {
this.message.setTransferable(this);
try {
if (message.hasFileOnRemoteHost()) {
- mUrl = message.getFileParams().url;
+ mUrl = CryptoHelper.toHttpsUrl(message.getFileParams().url);
} else {
- mUrl = new URL(message.getBody());
+ mUrl = CryptoHelper.toHttpsUrl(new URL(message.getBody()));
}
String[] parts = mUrl.getPath().toLowerCase().split("\\.");
String lastPart = parts.length >= 1 ? parts[parts.length - 1] : null;
@@ -97,8 +97,8 @@ public class HttpDownloadConnection implements Transferable {
String filename = fileDateFormat.format(new Date(message.getTimeSent())) + "_" + message.getUuid().substring(0, 4);
message.setRelativeFilePath(filename + "." + extension);
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
- String reference = mUrl.getRef();
- if (reference != null && reference.length() == 96) {
+ final String reference = mUrl.getRef();
+ if (reference != null && reference.matches("([A-Fa-f0-9]{2}){48}")) {
this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
}
@@ -342,7 +342,14 @@ public class HttpDownloadConnection implements Transferable {
private void updateImageBounds() {
message.setType(Message.TYPE_FILE);
- mXmppConnectionService.getFileBackend().updateFileParams(message, mUrl);
+ final URL url;
+ final String ref = mUrl.getRef();
+ if (ref != null && ref.matches("([A-Fa-f0-9]{2}){48}")) {
+ url = CryptoHelper.toAesGcmUrl(mUrl);
+ } else {
+ url = mUrl;
+ }
+ mXmppConnectionService.getFileBackend().updateFileParams(message, url);
mXmppConnectionService.updateMessage(message);
}
diff --git a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java
index 06fda4163..d15f4bef5 100644
--- a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java
@@ -29,6 +29,7 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Message;
+import de.pixart.messenger.http.AesGcmURLStreamHandler;
import de.pixart.messenger.xmpp.jid.InvalidJidException;
import de.pixart.messenger.xmpp.jid.Jid;
@@ -238,7 +239,18 @@ public final class CryptoHelper {
return url;
}
try {
- return new URL("aesgcm" + url.toString().substring(url.getProtocol().length()));
+ return new URL(AesGcmURLStreamHandler.PROTOCOL_NAME + url.toString().substring(url.getProtocol().length()));
+ } catch (MalformedURLException e) {
+ return url;
+ }
+ }
+
+ public static URL toHttpsUrl(URL url) {
+ if (!url.getProtocol().equalsIgnoreCase(AesGcmURLStreamHandler.PROTOCOL_NAME)) {
+ return url;
+ }
+ try {
+ return new URL("https" + url.toString().substring(url.getProtocol().length()));
} catch (MalformedURLException e) {
return url;
}