From e2557bb9f5743ef01ea8a2b1b95530aa46f5af1a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 13 Mar 2025 12:24:43 +0100 Subject: [PATCH] remove unused code from DownloadableFile --- .../entities/DownloadableFile.java | 163 +++++++++--------- .../jingle/JingleFileTransferConnection.java | 5 + .../xmpp/model/disco/external/Services.java | 2 - 3 files changed, 83 insertions(+), 87 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java index 072b4fd065248948a6c473d053b6e08fcc6fd439..841bcee515c22dc11605881495efeaace0ab0eb9 100644 --- a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java +++ b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java @@ -1,94 +1,87 @@ package eu.siacs.conversations.entities; import android.util.Log; - -import java.io.File; - import eu.siacs.conversations.Config; import eu.siacs.conversations.utils.MimeUtils; +import java.io.File; public class DownloadableFile extends File { - private static final long serialVersionUID = 2247012619505115863L; - - private long expectedSize = 0; - private byte[] sha1sum; - private byte[] aeskey; - private byte[] iv; - - public DownloadableFile(final File parent, final String file) { - super(parent, file); - } - - public DownloadableFile(String path) { - super(path); - } - - public long getSize() { - return super.length(); - } - - public long getExpectedSize() { - return this.expectedSize; - } - - public String getMimeType() { - String path = this.getAbsolutePath(); - int start = path.lastIndexOf('.') + 1; - if (start < path.length()) { - String mime = MimeUtils.guessMimeTypeFromExtension(path.substring(start)); - return mime == null ? "" : mime; - } else { - return ""; - } - } - - public void setExpectedSize(long size) { - this.expectedSize = size; - } - - public byte[] getSha1Sum() { - return this.sha1sum; - } - - public void setSha1Sum(byte[] sum) { - this.sha1sum = sum; - } - - public void setKeyAndIv(byte[] keyIvCombo) { - // originally, we used a 16 byte IV, then found for aes-gcm a 12 byte IV is ideal - // this code supports reading either length, with sending 12 byte IV to be done in future - if (keyIvCombo.length == 48) { - this.aeskey = new byte[32]; - this.iv = new byte[16]; - System.arraycopy(keyIvCombo, 0, this.iv, 0, 16); - System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32); - } else if (keyIvCombo.length == 44) { - this.aeskey = new byte[32]; - this.iv = new byte[12]; - System.arraycopy(keyIvCombo, 0, this.iv, 0, 12); - System.arraycopy(keyIvCombo, 12, this.aeskey, 0, 32); - } else if (keyIvCombo.length >= 32) { - this.aeskey = new byte[32]; - this.iv = new byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0xf }; - System.arraycopy(keyIvCombo, 0, aeskey, 0, 32); - } - Log.d(Config.LOGTAG,"using "+this.iv.length+"-byte IV for file transmission"); - } - - public void setKey(byte[] key) { - this.aeskey = key; - } - - public void setIv(byte[] iv) { - this.iv = iv; - } - - public byte[] getKey() { - return this.aeskey; - } - - public byte[] getIv() { - return this.iv; - } + private static final long serialVersionUID = 2247012619505115863L; + + private long expectedSize = 0; + private byte[] aeskey; + private byte[] iv; + + public DownloadableFile(final File parent, final String file) { + super(parent, file); + } + + public DownloadableFile(String path) { + super(path); + } + + public long getSize() { + return super.length(); + } + + public long getExpectedSize() { + return this.expectedSize; + } + + public String getMimeType() { + String path = this.getAbsolutePath(); + int start = path.lastIndexOf('.') + 1; + if (start < path.length()) { + String mime = MimeUtils.guessMimeTypeFromExtension(path.substring(start)); + return mime == null ? "" : mime; + } else { + return ""; + } + } + + public void setExpectedSize(long size) { + this.expectedSize = size; + } + + public void setKeyAndIv(byte[] keyIvCombo) { + // originally, we used a 16 byte IV, then found for aes-gcm a 12 byte IV is ideal + // this code supports reading either length, with sending 12 byte IV to be done in future + if (keyIvCombo.length == 48) { + this.aeskey = new byte[32]; + this.iv = new byte[16]; + System.arraycopy(keyIvCombo, 0, this.iv, 0, 16); + System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32); + } else if (keyIvCombo.length == 44) { + this.aeskey = new byte[32]; + this.iv = new byte[12]; + System.arraycopy(keyIvCombo, 0, this.iv, 0, 12); + System.arraycopy(keyIvCombo, 12, this.aeskey, 0, 32); + } else if (keyIvCombo.length >= 32) { + this.aeskey = new byte[32]; + this.iv = + new byte[] { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0xf + }; + System.arraycopy(keyIvCombo, 0, aeskey, 0, 32); + } + Log.d(Config.LOGTAG, "using " + this.iv.length + "-byte IV for file transmission"); + } + + public void setKey(byte[] key) { + this.aeskey = key; + } + + public void setIv(byte[] iv) { + this.iv = iv; + } + + public byte[] getKey() { + return this.aeskey; + } + + public byte[] getIv() { + return this.iv; + } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java index ca035d5dfc7a7ab00c165c14e6b6db78d95a9f35..fbaf7ffe3e7a52d5a9148cc780cb0d6135448912 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java @@ -355,6 +355,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection Log.d( Config.LOGTAG, "got file offer " + file + " jet=" + Objects.nonNull(keyTransportMessage)); + // TODO store hashes if there are any setFileOffer(file); if (keyTransportMessage != null) { this.transportSecurity = @@ -548,10 +549,13 @@ public class JingleFileTransferConnection extends AbstractJingleConnection private void receiveSessionInfoChecksum(final FileTransferDescription.Checksum checksum) { Log.d(Config.LOGTAG, "received checksum " + checksum); + // TODO check that we are receiver + // TODO store hashes } private void receiveSessionInfoReceived(final FileTransferDescription.Received received) { Log.d(Config.LOGTAG, "peer confirmed received " + received); + // TODO check that we are sender } private synchronized void receiveSessionTerminate(final Iq jinglePacket, final Jingle jingle) { @@ -902,6 +906,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection sendSessionInfoChecksum(hashes); } else { Log.d(Config.LOGTAG, "file transfer complete " + hashes); + // TODO compare with stored file hashes sendFileSessionInfoReceived(); terminateTransport(); messageReceivedSuccess(); diff --git a/src/main/java/im/conversations/android/xmpp/model/disco/external/Services.java b/src/main/java/im/conversations/android/xmpp/model/disco/external/Services.java index ecf24606cc97bd60ff71b86f71b5674443ea705e..b3d64f803c4aa18a1e84d8bf8c540f15e741aa3f 100644 --- a/src/main/java/im/conversations/android/xmpp/model/disco/external/Services.java +++ b/src/main/java/im/conversations/android/xmpp/model/disco/external/Services.java @@ -1,9 +1,7 @@ package im.conversations.android.xmpp.model.disco.external; import android.util.Log; - import androidx.annotation.NonNull; - import com.google.common.base.Objects; import com.google.common.base.Strings; import com.google.common.collect.Collections2;