Compare commits

..

3 Commits

Author SHA1 Message Date
Gara Dorta
f285a8516d
Merge 7773a3fd83f46ba018503a477e3f304b55eb503f into a03d17a9e4d9c420ba0e23f2d9c69d26315e0ec8 2026-04-13 00:11:47 +02:00
AsamK
a03d17a9e4 Use padded and encrypted attachment size for upload spec
Fixes #2014
2026-04-12 22:34:59 +02:00
AsamK
364f89f1d0 Prepare next release 2026-04-12 22:09:36 +02:00
7 changed files with 61 additions and 22 deletions

View File

@ -1,5 +1,7 @@
# Changelog # Changelog
## [Unreleased]
## [0.14.2] - 2026-04-04 ## [0.14.2] - 2026-04-04
### Added ### Added

View File

@ -10,7 +10,7 @@ plugins {
allprojects { allprojects {
group = "org.asamk" group = "org.asamk"
version = "0.14.2" version = "0.14.3-SNAPSHOT"
} }
java { java {

View File

@ -11,11 +11,14 @@ import org.signal.libsignal.protocol.InvalidMessageException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream; import org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherStreamUtil;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment; import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer; import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream; import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException; import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
import org.whispersystems.signalservice.api.util.StreamDetails; import org.whispersystems.signalservice.api.util.StreamDetails;
import org.whispersystems.signalservice.internal.crypto.PaddingInputStream;
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -89,12 +92,12 @@ public class AttachmentHelper {
final boolean voiceNote final boolean voiceNote
) throws AttachmentInvalidException { ) throws AttachmentInvalidException {
try { try {
final var streamDetails = Utils.createStreamDetails(attachment); final var streamDetailsAndFileName = Utils.createStreamDetails(attachment);
final var uploadSpec = dependencies.getMessageSender() final var streamDetails = streamDetailsAndFileName.first();
.getResumableUploadSpec(streamDetails.first().getLength()); final var uploadSpec = getResumableUploadSpec(streamDetails);
return AttachmentUtils.createAttachmentStream(streamDetails.first(), return AttachmentUtils.createAttachmentStream(streamDetails,
streamDetails.second(), streamDetailsAndFileName.second(),
voiceNote, voiceNote,
uploadSpec); uploadSpec);
} catch (IOException e) { } catch (IOException e) {
@ -102,6 +105,13 @@ public class AttachmentHelper {
} }
} }
public ResumableUploadSpec getResumableUploadSpec(final StreamDetails streamDetails) throws IOException {
final var streamLength = streamDetails.getLength();
final var ciphertextLength = AttachmentCipherStreamUtil.getCiphertextLength(PaddingInputStream.getPaddedSize(
streamLength));
return dependencies.getMessageSender().getResumableUploadSpec(ciphertextLength);
}
public SignalServiceAttachmentPointer uploadAttachment(String attachment) throws IOException, AttachmentInvalidException { public SignalServiceAttachmentPointer uploadAttachment(String attachment) throws IOException, AttachmentInvalidException {
final var attachmentStream = getAttachmentStream(attachment, false); final var attachmentStream = getAttachmentStream(attachment, false);
return uploadAttachment(attachmentStream); return uploadAttachment(attachmentStream);

View File

@ -123,7 +123,7 @@ public class GroupHelper {
return Optional.empty(); return Optional.empty();
} }
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec(streamDetails.getLength()); final var uploadSpec = context.getAttachmentHelper().getResumableUploadSpec(streamDetails);
return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec)); return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec));
} }

View File

@ -38,6 +38,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOper
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage; import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage; import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.StreamDetails;
import org.whispersystems.signalservice.internal.push.SyncMessage; import org.whispersystems.signalservice.internal.push.SyncMessage;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -131,13 +132,14 @@ public class SyncHelper {
if (groupsFile.exists() && groupsFile.length() > 0) { if (groupsFile.exists() && groupsFile.length() > 0) {
try (var groupsFileStream = new FileInputStream(groupsFile)) { try (var groupsFileStream = new FileInputStream(groupsFile)) {
final var uploadSpec = context.getDependencies() final var streamDetails = new StreamDetails(groupsFileStream,
.getMessageSender() MimeUtils.OCTET_STREAM,
.getResumableUploadSpec(groupsFile.length()); groupsFile.length());
final var uploadSpec = context.getAttachmentHelper().getResumableUploadSpec(streamDetails);
var attachmentStream = SignalServiceAttachment.newStreamBuilder() var attachmentStream = SignalServiceAttachment.newStreamBuilder()
.withStream(groupsFileStream) .withStream(streamDetails.getStream())
.withContentType(MimeUtils.OCTET_STREAM) .withContentType(streamDetails.getContentType())
.withLength(groupsFile.length()) .withLength(streamDetails.getLength())
.withResumableUploadSpec(uploadSpec) .withResumableUploadSpec(uploadSpec)
.build(); .build();
@ -192,13 +194,14 @@ public class SyncHelper {
if (contactsFile.exists() && contactsFile.length() > 0) { if (contactsFile.exists() && contactsFile.length() > 0) {
try (var contactsFileStream = new FileInputStream(contactsFile)) { try (var contactsFileStream = new FileInputStream(contactsFile)) {
final var uploadSpec = context.getDependencies() final var streamDetails = new StreamDetails(contactsFileStream,
.getMessageSender() MimeUtils.OCTET_STREAM,
.getResumableUploadSpec(contactsFile.length()); contactsFile.length());
final var uploadSpec = context.getAttachmentHelper().getResumableUploadSpec(streamDetails);
var attachmentStream = SignalServiceAttachment.newStreamBuilder() var attachmentStream = SignalServiceAttachment.newStreamBuilder()
.withStream(contactsFileStream) .withStream(streamDetails.getStream())
.withContentType(MimeUtils.OCTET_STREAM) .withContentType(streamDetails.getContentType())
.withLength(contactsFile.length()) .withLength(streamDetails.getLength())
.withResumableUploadSpec(uploadSpec) .withResumableUploadSpec(uploadSpec)
.build(); .build();

View File

@ -839,8 +839,7 @@ public class ManagerImpl implements Manager {
final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes), final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes),
MimeUtils.LONG_TEXT, MimeUtils.LONG_TEXT,
messageBytes.length); messageBytes.length);
final var uploadSpec = dependencies.getMessageSender() final var uploadSpec = context.getAttachmentHelper().getResumableUploadSpec(streamDetails);
.getResumableUploadSpec(streamDetails.getLength());
final var textAttachment = AttachmentUtils.createAttachmentStream(streamDetails, final var textAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
Optional.empty(), Optional.empty(),
uploadSpec); uploadSpec);
@ -908,7 +907,7 @@ public class ManagerImpl implements Manager {
if (streamDetails == null) { if (streamDetails == null) {
throw new InvalidStickerException("Missing local sticker file"); throw new InvalidStickerException("Missing local sticker file");
} }
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec(streamDetails.getLength()); final var uploadSpec = context.getAttachmentHelper().getResumableUploadSpec(streamDetails);
final var stickerAttachment = AttachmentUtils.createAttachmentStream(streamDetails, final var stickerAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
Optional.empty(), Optional.empty(),
uploadSpec); uploadSpec);

View File

@ -1486,6 +1486,13 @@
"type": "kotlin.Pair", "type": "kotlin.Pair",
"jniAccessible": true, "jniAccessible": true,
"methods": [ "methods": [
{
"name": "<init>",
"parameterTypes": [
"java.lang.Object",
"java.lang.Object"
]
},
{ {
"name": "getFirst", "name": "getFirst",
"parameterTypes": [] "parameterTypes": []
@ -1496,6 +1503,9 @@
} }
] ]
}, },
{
"type": "kotlin.Pair[]"
},
{ {
"type": "kotlin.SafePublicationLazyImpl", "type": "kotlin.SafePublicationLazyImpl",
"fields": [ "fields": [
@ -5821,6 +5831,21 @@
} }
] ]
}, },
{
"type": "org.signal.libsignal.net.UploadForm",
"jniAccessible": true,
"methods": [
{
"name": "fromNative",
"parameterTypes": [
"int",
"java.lang.String",
"java.lang.Object[]",
"java.lang.String"
]
}
]
},
{ {
"type": "org.signal.libsignal.net.internal.BridgeChatListener", "type": "org.signal.libsignal.net.internal.BridgeChatListener",
"jniAccessible": true "jniAccessible": true