enabled otr encryption for ibb filetransfer as well

This commit is contained in:
iNPUTmice 2014-06-23 16:01:51 +02:00
parent c25f1283a1
commit 996bee8836
2 changed files with 20 additions and 16 deletions

View file

@ -94,7 +94,7 @@ public class JingleConnection {
mXmppConnectionService.databaseBackend.createMessage(message);
mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVED);
}
Log.d("xmppService","sucessfully transmitted file:"+file.getName()+" encryption:"+message.getEncryption());
Log.d("xmppService","sucessfully transmitted file:"+file.getAbsolutePath());
}
};

View file

@ -1,11 +1,12 @@
package eu.siacs.conversations.xmpp.jingle;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import android.util.Base64;
import eu.siacs.conversations.entities.Account;
@ -27,8 +28,8 @@ public class JingleInbandTransport extends JingleTransport {
private JingleFile file;
private FileInputStream fileInputStream = null;
private FileOutputStream fileOutputStream;
private InputStream fileInputStream = null;
private OutputStream fileOutputStream;
private long remainingSize;
private MessageDigest digest;
@ -84,7 +85,7 @@ public class JingleInbandTransport extends JingleTransport {
digest.reset();
file.getParentFile().mkdirs();
file.createNewFile();
this.fileOutputStream = new FileOutputStream(file);
this.fileOutputStream = getOutputStream(file);
this.remainingSize = file.getExpectedSize();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
@ -100,7 +101,7 @@ public class JingleInbandTransport extends JingleTransport {
try {
this.digest = MessageDigest.getInstance("SHA-1");
this.digest.reset();
fileInputStream = new FileInputStream(file);
fileInputStream = this.getInputStream(file);
this.sendNextBlock();
} catch (FileNotFoundException e) {
e.printStackTrace();
@ -119,11 +120,11 @@ public class JingleInbandTransport extends JingleTransport {
this.onFileTransmitted.onFileTransmitted(file);
} else {
this.digest.update(buffer);
String base64 = Base64.encodeToString(buffer, Base64.DEFAULT);
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
iq.setTo(this.counterpart);
Element data = iq
.addChild("data", "http://jabber.org/protocol/ibb");
Element data = iq.addChild("data",
"http://jabber.org/protocol/ibb");
data.setAttribute("seq", "" + this.seq);
data.setAttribute("block-size", "" + this.blockSize);
data.setAttribute("sid", this.sessionId);
@ -140,7 +141,10 @@ public class JingleInbandTransport extends JingleTransport {
private void receiveNextBlock(String data) {
try {
byte[] buffer = Base64.decode(data, Base64.DEFAULT);
byte[] buffer = Base64.decode(data, Base64.NO_WRAP);
if (this.remainingSize < buffer.length) {
buffer = Arrays.copyOfRange(buffer, 0, (int) this.remainingSize);
}
this.remainingSize -= buffer.length;
this.fileOutputStream.write(buffer);