diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/DownloadableFile.java | 7 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/Message.java | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/DownloadableFile.java b/src/main/java/de/pixart/messenger/entities/DownloadableFile.java index 94fae97a4..6993b6b38 100644 --- a/src/main/java/de/pixart/messenger/entities/DownloadableFile.java +++ b/src/main/java/de/pixart/messenger/entities/DownloadableFile.java @@ -50,11 +50,18 @@ public class DownloadableFile extends File { } public void setKeyAndIv(byte[] keyIvCombo) { + // originally, we used a 16 byte IV, then found for aes-gcm a 12 byte IV is ideal + // this code supports reading either length, with sending 12 byte IV to be done in future if (keyIvCombo.length == 48) { this.aeskey = new byte[32]; this.iv = new byte[16]; System.arraycopy(keyIvCombo, 0, this.iv, 0, 16); System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32); + } else if (keyIvCombo.length == 44) { + this.aeskey = new byte[32]; + this.iv = new byte[12]; + System.arraycopy(keyIvCombo, 0, this.iv, 0, 12); + System.arraycopy(keyIvCombo, 12, this.aeskey, 0, 32); } else if (keyIvCombo.length >= 32) { this.aeskey = new byte[32]; System.arraycopy(keyIvCombo, 0, aeskey, 0, 32); diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 317605167..06bfcf4b6 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -675,7 +675,7 @@ public class Message extends AbstractEntity { final URL url = new URL(body); final String ref = url.getRef(); final String protocol = url.getProtocol(); - final boolean encrypted = ref != null && ref.matches("([A-Fa-f0-9]{2}){48}"); + final boolean encrypted = ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches(); treatAsDownloadable = (AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted) || (("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted)); } catch (MalformedURLException e) { |