diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-10-04 13:22:05 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-10-04 13:22:05 +0200 |
commit | 431b6204cd2ed291b81943b46ea9c2851cb2ec1a (patch) | |
tree | a5e34ccd6889b1b3de2b3fd635601f432b5ec6ae /src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java | |
parent | 219d5f113bf809b2e5929256d4a9812a4aa21f8c (diff) |
refactored file encryption to give access to inner stream
Conscrypt on some plattforms doesn’t like when we close the CipherInputStream. Therefor we refactor the api to give us access to the inner stream so we can close that independently.
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java | 48 |
1 files changed, 22 insertions, 26 deletions
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 6c726c8b9..77540bc9c 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java @@ -2,8 +2,8 @@ package de.pixart.messenger.xmpp.jingle; import android.util.Base64; import android.util.Log; -import android.util.Pair; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -489,36 +489,32 @@ public class JingleConnection implements Transferable { if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { content.setTransportId(this.transportId); this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false); - Pair<InputStream, Integer> pair; - try { - if (message.getEncryption() == Message.ENCRYPTION_OTR) { - Conversational conversation = this.message.getConversation(); - if (!this.mXmppConnectionService.renewSymmetricKey((Conversation) conversation)) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not set symmetric key"); - cancel(); - } - Conversation c = (Conversation) this.message.getConversation(); - this.file.setKeyAndIv(c.getSymmetricKey()); - pair = AbstractConnectionManager.createInputStream(this.file, false); - this.file.setExpectedSize(pair.second); - content.setFileOffer(this.file, true, this.ftVersion); - } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { - this.file.setKey(mXmppAxolotlMessage.getInnerKey()); - this.file.setIv(mXmppAxolotlMessage.getIV()); - pair = AbstractConnectionManager.createInputStream(this.file, true); - this.file.setExpectedSize(pair.second); - content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement()); - } else { - pair = AbstractConnectionManager.createInputStream(this.file, false); - this.file.setExpectedSize(pair.second); - content.setFileOffer(this.file, false, this.ftVersion); + if (message.getEncryption() == Message.ENCRYPTION_OTR) { + Conversational conversation = this.message.getConversation(); + if (!this.mXmppConnectionService.renewSymmetricKey((Conversation) conversation)) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not set symmetric key"); + cancel(); } + Conversation c = (Conversation) this.message.getConversation(); + this.file.setKeyAndIv(c.getSymmetricKey()); + this.file.setExpectedSize((file.getSize() / 16 + 1) * 16); + content.setFileOffer(this.file, true, this.ftVersion); + } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { + this.file.setKey(mXmppAxolotlMessage.getInnerKey()); + this.file.setIv(mXmppAxolotlMessage.getIV()); + this.file.setExpectedSize(file.getSize() + 16); + content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement()); + } else { + this.file.setExpectedSize(file.getSize()); + content.setFileOffer(this.file, false, this.ftVersion); + } + message.resetFileParams(); + try { + this.mFileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { cancel(); return; } - message.resetFileParams(); - this.mFileInputStream = pair.first; content.setTransportId(this.transportId); content.socks5transport().setChildren(getCandidatesAsElements()); packet.setContent(content); |