mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-24 09:42:17 -05:00
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.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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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;
|
||||||
@ -26,14 +27,14 @@ public class JingleInbandTransport extends JingleTransport {
|
|||||||
private boolean established = false;
|
private boolean established = false;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
private OnFileTransmitted onFileTransmitted;
|
|
||||||
|
|
||||||
|
private OnFileTransmitted onFileTransmitted;
|
||||||
|
|
||||||
private OnIqPacketReceived onAckReceived = new OnIqPacketReceived() {
|
private OnIqPacketReceived onAckReceived = new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user