aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-10-22 13:06:46 +0200
committeriNPUTmice <daniel@gultsch.de>2014-10-22 13:06:46 +0200
commit62b0fc3fdac1af440d61bb6d197dcd7fc34372b4 (patch)
tree9bda78ccbc7e7c10f2f643f9bf67eadf33c23443 /src/eu/siacs/conversations/entities
parent45bdadd915ed0e0135de16876f9842b3401f1ac4 (diff)
made httpconnection accept aes encrypted files
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r--src/eu/siacs/conversations/entities/DownloadableFile.java23
-rw-r--r--src/eu/siacs/conversations/entities/Message.java5
2 files changed, 17 insertions, 11 deletions
diff --git a/src/eu/siacs/conversations/entities/DownloadableFile.java b/src/eu/siacs/conversations/entities/DownloadableFile.java
index 50b00fb87..1605c75b4 100644
--- a/src/eu/siacs/conversations/entities/DownloadableFile.java
+++ b/src/eu/siacs/conversations/entities/DownloadableFile.java
@@ -19,7 +19,6 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import eu.siacs.conversations.Config;
-import eu.siacs.conversations.utils.CryptoHelper;
import android.util.Log;
public class DownloadableFile extends File {
@@ -43,7 +42,11 @@ public class DownloadableFile extends File {
public long getExpectedSize() {
if (this.aeskey != null) {
- return (this.expectedSize / 16 + 1) * 16;
+ if (this.expectedSize == 0) {
+ return 0;
+ } else {
+ return (this.expectedSize / 16 + 1) * 16;
+ }
} else {
return this.expectedSize;
}
@@ -62,7 +65,14 @@ public class DownloadableFile extends File {
}
public void setKey(byte[] key) {
- if (key.length >= 32) {
+ if (key.length == 48) {
+ byte[] secretKey = new byte[32];
+ byte[] iv = new byte[16];
+ System.arraycopy(key, 0, iv, 0, 16);
+ System.arraycopy(key, 16, secretKey, 0, 32);
+ this.aeskey = new SecretKeySpec(secretKey, "AES");
+ this.iv = iv;
+ } else if (key.length >= 32) {
byte[] secretKey = new byte[32];
System.arraycopy(key, 0, secretKey, 0, 32);
this.aeskey = new SecretKeySpec(secretKey, "AES");
@@ -70,12 +80,7 @@ public class DownloadableFile extends File {
byte[] secretKey = new byte[16];
System.arraycopy(key, 0, secretKey, 0, 16);
this.aeskey = new SecretKeySpec(secretKey, "AES");
- } else {
- Log.d(Config.LOGTAG, "weird key");
}
- Log.d(Config.LOGTAG,
- "using aes key "
- + CryptoHelper.bytesToHex(this.aeskey.getEncoded()));
}
public Key getKey() {
@@ -123,7 +128,7 @@ public class DownloadableFile extends File {
}
} else {
try {
- IvParameterSpec ips = new IvParameterSpec(iv);
+ IvParameterSpec ips = new IvParameterSpec(this.iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, this.getKey(), ips);
Log.d(Config.LOGTAG, "opening encrypted output stream");
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index dab285393..a390c7ca0 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -403,8 +403,9 @@ public class Message extends AbstractEntity {
extensionParts[extensionParts.length - 1])) {
return true;
} else if (extensionParts.length == 3
- && Arrays.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
- .contains(extensionParts.length - 1)
+ && Arrays
+ .asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
+ .contains(extensionParts[extensionParts.length - 1])
&& Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
extensionParts[extensionParts.length - 2])) {
return true;