aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2019-12-24 13:39:18 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2019-12-24 13:49:54 +0100
commit80c0e7d575616455626e883df08ce443f9ac9740 (patch)
tree7960bb05fff3862e40d43fddc73b20e9642b1553 /src/main/java/de/pixart/messenger
parent23cfd788b10f19d84cad22c714d4548a162602ea (diff)
createOutputStream(): allow to disable decryption
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java21
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java2
2 files changed, 8 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
index 7414c40c7..19a7341f8 100644
--- a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
+++ b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
@@ -64,11 +64,11 @@ public class AbstractConnectionManager {
return createOutputStream(file, gcm, false);
}
- private static OutputStream createOutputStream(DownloadableFile file, boolean gcm, boolean append) {
+ public static OutputStream createOutputStream(DownloadableFile file, boolean append, boolean decrypt) {
FileOutputStream os;
try {
os = new FileOutputStream(file, append);
- if (file.getKey() == null) {
+ if (file.getKey() == null || !decrypt) {
return os;
}
} catch (FileNotFoundException e) {
@@ -76,18 +76,11 @@ public class AbstractConnectionManager {
return null;
}
try {
- if (gcm) {
- final Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER);
- SecretKeySpec keySpec = new SecretKeySpec(file.getKey(), KEYTYPE);
- IvParameterSpec ivSpec = new IvParameterSpec(file.getIv());
- cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
- return new CipherOutputStream(os, cipher);
- } else {
- IvParameterSpec ips = new IvParameterSpec(file.getIv());
- final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(file.getKey(), KEYTYPE), ips);
- return new CipherOutputStream(os, cipher);
- }
+ final Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER);
+ SecretKeySpec keySpec = new SecretKeySpec(file.getKey(), KEYTYPE);
+ IvParameterSpec ivSpec = new IvParameterSpec(file.getIv());
+ cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
+ return new CipherOutputStream(os, cipher);
} catch (Exception e) {
Log.d(Config.LOGTAG, "unable to create cipher output stream", e);
return null;
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
index 2d9abc562..478c8c992 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
@@ -215,7 +215,7 @@ public class JingleConnection implements Transferable {
}
this.file.getParentFile().mkdirs();
this.file.createNewFile();
- this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file);
+ this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file, false, true);
return this.mFileOutputStream;
}