Enforce a configurable max envelope size.

fork-5.53.8
Greyson Parrelli 2020-10-22 16:01:52 -04:00 zatwierdzone przez Cody Henthorne
rodzic ac54b5cbdf
commit f676d1c61c
4 zmienionych plików z 30 dodań i 8 usunięć

Wyświetl plik

@ -99,7 +99,8 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()),
Optional.of(new SecurityEventListener(context)),
provideClientZkOperations().getProfileOperations(),
SignalExecutors.newCachedBoundedExecutor("signal-messages", 1, 16));
SignalExecutors.newCachedBoundedExecutor("signal-messages", 1, 16),
FeatureFlags.maxEnvelopeSize());
}
@Override

Wyświetl plik

@ -60,6 +60,7 @@ public final class FeatureFlags {
public static final String RESEARCH_MEGAPHONE_1 = "research.megaphone.1";
public static final String MODERN_PROFILE_SHARING = "android.modernProfileSharing";
private static final String VIEWED_RECEIPTS = "android.viewed.receipts";
private static final String MAX_ENVELOPE_SIZE = "android.maxEnvelopeSize";
/**
* We will only store remote values for flags in this set. If you want a flag to be controllable
@ -77,7 +78,8 @@ public final class FeatureFlags {
CLIENT_EXPIRATION,
RESEARCH_MEGAPHONE_1,
MODERN_PROFILE_SHARING,
VIEWED_RECEIPTS
VIEWED_RECEIPTS,
MAX_ENVELOPE_SIZE
);
/**
@ -245,13 +247,16 @@ public final class FeatureFlags {
return getBoolean(MODERN_PROFILE_SHARING, false);
}
/**
* Whether the user should display the content revealed dot in voice notes.
*/
/** Whether the user should display the content revealed dot in voice notes. */
public static boolean viewedReceipts() {
return getBoolean(VIEWED_RECEIPTS, false);
}
/** The max size envelope that is allowed to be sent. */
public static int maxEnvelopeSize() {
return getInteger(MAX_ENVELOPE_SIZE, 0);
}
/** Only for rendering debug info. */
public static synchronized @NonNull Map<String, Object> getMemoryValues() {
return new TreeMap<>(REMOTE_VALUES);

Wyświetl plik

@ -0,0 +1,7 @@
package org.whispersystems.signalservice.api;
public class ContentTooLargeException extends IllegalStateException {
public ContentTooLargeException(long size) {
super("Too large! Size: " + size + " bytes");
}
}

Wyświetl plik

@ -126,6 +126,7 @@ public class SignalServiceMessageSender {
private final AtomicBoolean isMultiDevice;
private final ExecutorService executor;
private final int maxEnvelopeSize;
/**
* Construct a SignalServiceMessageSender.
@ -149,7 +150,7 @@ public class SignalServiceMessageSender {
ClientZkProfileOperations clientZkProfileOperations,
ExecutorService executor)
{
this(urls, new StaticCredentialsProvider(uuid, e164, password, null), store, signalAgent, isMultiDevice, pipe, unidentifiedPipe, eventListener, clientZkProfileOperations, executor);
this(urls, new StaticCredentialsProvider(uuid, e164, password, null), store, signalAgent, isMultiDevice, pipe, unidentifiedPipe, eventListener, clientZkProfileOperations, executor, 0);
}
public SignalServiceMessageSender(SignalServiceConfiguration urls,
@ -161,7 +162,8 @@ public class SignalServiceMessageSender {
Optional<SignalServiceMessagePipe> unidentifiedPipe,
Optional<EventListener> eventListener,
ClientZkProfileOperations clientZkProfileOperations,
ExecutorService executor)
ExecutorService executor,
int maxEnvelopeSize)
{
this.socket = new PushServiceSocket(urls, credentialsProvider, signalAgent, clientZkProfileOperations);
this.store = store;
@ -171,6 +173,7 @@ public class SignalServiceMessageSender {
this.isMultiDevice = new AtomicBoolean(isMultiDevice);
this.eventListener = eventListener;
this.executor = executor != null ? executor : Executors.newSingleThreadExecutor();
this.maxEnvelopeSize = maxEnvelopeSize;
}
/**
@ -698,7 +701,13 @@ public class SignalServiceMessageSender {
builder.setTimestamp(message.getTimestamp());
return container.setDataMessage(builder).build().toByteArray();
byte[] content = container.setDataMessage(builder).build().toByteArray();
if (maxEnvelopeSize > 0 && content.length > maxEnvelopeSize) {
throw new ContentTooLargeException(content.length);
}
return content;
}
private byte[] createCallContent(SignalServiceCallMessage callMessage) {