aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/http')
-rw-r--r--src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java6
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java4
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpUploadConnection.java2
3 files changed, 9 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java b/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java
index 64188c5db..4ec164344 100644
--- a/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java
+++ b/src/main/java/de/pixart/messenger/http/AesGcmURLStreamHandler.java
@@ -4,10 +4,16 @@ import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.util.regex.Pattern;
public class AesGcmURLStreamHandler extends URLStreamHandler {
+ /**
+ * This matches a 48 or 44 byte IV + KEY hex combo, like used in http/aesgcm upload anchors
+ */
+ public static final Pattern IV_KEY = Pattern.compile("([A-Fa-f0-9]{2}){48}|([A-Fa-f0-9]{2}){44}");
+
public static final String PROTOCOL_NAME = "aesgcm";
@Override
diff --git a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
index 7326cbf4b..9f49ac218 100644
--- a/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpDownloadConnection.java
@@ -98,7 +98,7 @@ public class HttpDownloadConnection implements Transferable {
message.setRelativeFilePath(filename + "." + extension);
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
final String reference = mUrl.getRef();
- if (reference != null && reference.matches("([A-Fa-f0-9]{2}){48}")) {
+ if (reference != null && AesGcmURLStreamHandler.IV_KEY.matcher(reference).matches()) {
this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
}
@@ -383,7 +383,7 @@ public class HttpDownloadConnection implements Transferable {
message.setType(Message.TYPE_FILE);
final URL url;
final String ref = mUrl.getRef();
- if (ref != null && ref.matches("([A-Fa-f0-9]{2}){48}")) {
+ if (ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches()) {
url = CryptoHelper.toAesGcmUrl(mUrl);
} else {
url = mUrl;
diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
index 22fec6888..3d3ad5e73 100644
--- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
@@ -105,7 +105,7 @@ public class HttpUploadConnection implements Transferable {
if (Config.ENCRYPT_ON_HTTP_UPLOADED
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|| message.getEncryption() == Message.ENCRYPTION_OTR) {
- this.key = new byte[48];
+ this.key = new byte[48]; // todo: change this to 44 for 12-byte IV instead of 16-byte at some point in future
mXmppConnectionService.getRNG().nextBytes(this.key);
this.file.setKeyAndIv(this.key);
}