enabled otr encryption for ibb filetransfer as well
This commit is contained in:
parent
c25f1283a1
commit
996bee8836
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
@ -113,17 +114,17 @@ public class JingleInbandTransport extends JingleTransport {
|
|||
byte[] buffer = new byte[this.bufferSize];
|
||||
try {
|
||||
int count = fileInputStream.read(buffer);
|
||||
if (count==-1) {
|
||||
if (count == -1) {
|
||||
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
||||
fileInputStream.close();
|
||||
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);
|
||||
|
@ -172,7 +176,7 @@ public class JingleInbandTransport extends JingleTransport {
|
|||
this.account.getXmppConnection().sendIqPacket(
|
||||
packet.generateRespone(IqPacket.TYPE_RESULT), null);
|
||||
} else {
|
||||
//TODO some sort of exception
|
||||
// TODO some sort of exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue