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
src/eu/siacs/conversations/xmpp/jingle

View File

@ -94,7 +94,7 @@ public class JingleConnection {
mXmppConnectionService.databaseBackend.createMessage(message); mXmppConnectionService.databaseBackend.createMessage(message);
mXmppConnectionService.markMessage(message, Message.STATUS_RECIEVED); 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; package eu.siacs.conversations.xmpp.jingle;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import android.util.Base64; import android.util.Base64;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
@ -27,8 +28,8 @@ public class JingleInbandTransport extends JingleTransport {
private JingleFile file; private JingleFile file;
private FileInputStream fileInputStream = null; private InputStream fileInputStream = null;
private FileOutputStream fileOutputStream; private OutputStream fileOutputStream;
private long remainingSize; private long remainingSize;
private MessageDigest digest; private MessageDigest digest;
@ -84,7 +85,7 @@ public class JingleInbandTransport extends JingleTransport {
digest.reset(); digest.reset();
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
file.createNewFile(); file.createNewFile();
this.fileOutputStream = new FileOutputStream(file); this.fileOutputStream = getOutputStream(file);
this.remainingSize = file.getExpectedSize(); this.remainingSize = file.getExpectedSize();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
@ -100,7 +101,7 @@ public class JingleInbandTransport extends JingleTransport {
try { try {
this.digest = MessageDigest.getInstance("SHA-1"); this.digest = MessageDigest.getInstance("SHA-1");
this.digest.reset(); this.digest.reset();
fileInputStream = new FileInputStream(file); fileInputStream = this.getInputStream(file);
this.sendNextBlock(); this.sendNextBlock();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
@ -113,17 +114,17 @@ public class JingleInbandTransport extends JingleTransport {
byte[] buffer = new byte[this.bufferSize]; byte[] buffer = new byte[this.bufferSize];
try { try {
int count = fileInputStream.read(buffer); int count = fileInputStream.read(buffer);
if (count==-1) { if (count == -1) {
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest())); file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
fileInputStream.close(); fileInputStream.close();
this.onFileTransmitted.onFileTransmitted(file); this.onFileTransmitted.onFileTransmitted(file);
} else { } else {
this.digest.update(buffer); 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); IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
iq.setTo(this.counterpart); iq.setTo(this.counterpart);
Element data = iq Element data = iq.addChild("data",
.addChild("data", "http://jabber.org/protocol/ibb"); "http://jabber.org/protocol/ibb");
data.setAttribute("seq", "" + this.seq); data.setAttribute("seq", "" + this.seq);
data.setAttribute("block-size", "" + this.blockSize); data.setAttribute("block-size", "" + this.blockSize);
data.setAttribute("sid", this.sessionId); data.setAttribute("sid", this.sessionId);
@ -140,7 +141,10 @@ public class JingleInbandTransport extends JingleTransport {
private void receiveNextBlock(String data) { private void receiveNextBlock(String data) {
try { 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.remainingSize -= buffer.length;
this.fileOutputStream.write(buffer); this.fileOutputStream.write(buffer);
@ -172,7 +176,7 @@ public class JingleInbandTransport extends JingleTransport {
this.account.getXmppConnection().sendIqPacket( this.account.getXmppConnection().sendIqPacket(
packet.generateRespone(IqPacket.TYPE_RESULT), null); packet.generateRespone(IqPacket.TYPE_RESULT), null);
} else { } else {
//TODO some sort of exception // TODO some sort of exception
} }
} }
} }