report wrong file size in otr encrypted jingle file transfers to be compatible with conversations > 1.6

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/Config.java                             | 2 
src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java | 3 
src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java       | 8 
3 files changed, 10 insertions(+), 3 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/Config.java 🔗

@@ -42,6 +42,8 @@ public final class Config {
 
 	public static final boolean ENCRYPT_ON_HTTP_UPLOADED = false;
 
+	public static final boolean REPORT_WRONG_FILESIZE_IN_OTR_JINGLE = true;
+
 	public static final boolean SHOW_REGENERATE_AXOLOTL_KEYS_BUTTON = false;
 
 	public static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;

src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java 🔗

@@ -72,7 +72,8 @@ public class AbstractConnectionManager {
 				Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
 				cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(file.getKey(), "AES"), ips);
 				Log.d(Config.LOGTAG, "opening encrypted input stream");
-				return new Pair<InputStream,Integer>(new CipherInputStream(is, cipher),(size / 16 + 1) * 16);
+				final int s = Config.REPORT_WRONG_FILESIZE_IN_OTR_JINGLE ? size : (size / 16 + 1) * 16;
+				return new Pair<InputStream,Integer>(new CipherInputStream(is, cipher),s);
 			}
 		} catch (InvalidKeyException e) {
 			return null;

src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java 🔗

@@ -272,7 +272,7 @@ public class JingleConnection implements Transferable {
 										});
 								mergeCandidate(candidate);
 							} else {
-								Log.d(Config.LOGTAG,"no primary candidate of our own was found");
+								Log.d(Config.LOGTAG, "no primary candidate of our own was found");
 								sendInitRequest();
 							}
 						}
@@ -391,7 +391,11 @@ public class JingleConnection implements Transferable {
 					}
 				}
 				this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file,message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
-				this.file.setExpectedSize(size);
+				if (message.getEncryption() == Message.ENCRYPTION_OTR && Config.REPORT_WRONG_FILESIZE_IN_OTR_JINGLE) {
+					this.file.setExpectedSize((size / 16 + 1) * 16);
+				} else {
+					this.file.setExpectedSize(size);
+				}
 				Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
 			} else {
 				this.sendCancel();