From 0fcef2d5421b029f42af60b288450a9b9e81f1a4 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Thu, 4 Mar 2021 11:36:19 +1100 Subject: [PATCH] add padding for future & clean --- .../libsession/messaging/fileserver/FileServerAPI.kt | 1 - .../libsession/messaging/jobs/AttachmentUploadJob.kt | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt index e72e0c0a33..37230d79d8 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt @@ -29,7 +29,6 @@ class FileServerAPI(public val server: String, userPublicKey: String, userPrivat * possible after proof of work has been calculated and the onion request encryption has happened, which takes several seconds. */ public val fileSizeORMultiplier = 2 // TODO: It should be possible to set this to 1.5? - val server = "https://file.getsession.org" public val fileStorageBucketURL = "https://file-static.lokinet.org" // endregion diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt index e00fcf174b..a8820f7e52 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/AttachmentUploadJob.kt @@ -14,11 +14,9 @@ import org.session.libsignal.service.internal.crypto.PaddingInputStream import org.session.libsignal.service.internal.push.PushAttachmentData import org.session.libsignal.service.internal.push.http.AttachmentCipherOutputStreamFactory import org.session.libsignal.service.internal.util.Util -import org.session.libsignal.service.loki.api.opengroups.PublicChat import org.session.libsignal.service.loki.utilities.PlaintextOutputStreamFactory import org.session.libsignal.utilities.ThreadUtils import org.session.libsignal.utilities.logging.Log -import java.io.InputStream class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val message: Message, val messageSendJobID: String) : Job { @@ -52,8 +50,9 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess val attachment = MessagingConfiguration.shared.messageDataProvider.getScaledSignalAttachmentStream(attachmentID) ?: return@queue handleFailure(Error.NoAttachment) - var server = FileServerAPI.server + var server = FileServerAPI.shared.server var shouldEncrypt = true + val usePadding = false val openGroup = MessagingConfiguration.shared.storage.getOpenGroup(threadID) openGroup?.let { server = it.server @@ -61,10 +60,12 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess } val attachmentKey = Util.getSecretBytes(64) - val ciphertextLength = if (shouldEncrypt) AttachmentCipherOutputStream.getCiphertextLength(attachment.length) else attachment.length + val paddedLength = if (usePadding) PaddingInputStream.getPaddedSize(attachment.length) else attachment.length + val dataStream = if (usePadding) PaddingInputStream(attachment.inputStream, attachment.length) else attachment.inputStream + val ciphertextLength = if (shouldEncrypt) AttachmentCipherOutputStream.getCiphertextLength(paddedLength) else attachment.length val outputStreamFactory = if (shouldEncrypt) AttachmentCipherOutputStreamFactory(attachmentKey) else PlaintextOutputStreamFactory() - val attachmentData = PushAttachmentData(attachment.contentType, attachment.inputStream, ciphertextLength, outputStreamFactory, attachment.listener) + val attachmentData = PushAttachmentData(attachment.contentType, dataStream, ciphertextLength, outputStreamFactory, attachment.listener) val uploadResult = FileServerAPI.shared.uploadAttachment(server, attachmentData) handleSuccess(attachment, attachmentKey, uploadResult)