Skip to content

Commit 48ada8e

Browse files
authored
Clarify roles/responsibilities of components in the message-handling pathway
1 parent 282bcf6 commit 48ada8e

33 files changed

+1336
-1197
lines changed

service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public void run(WhisperServerConfiguration config, Environment environment) thro
431431
config.getDynamoDbTables().getRemoteConfig().getTableName());
432432
PushChallengeDynamoDb pushChallengeDynamoDb = new PushChallengeDynamoDb(dynamoDbClient,
433433
config.getDynamoDbTables().getPushChallenge().getTableName());
434-
ReportMessageDynamoDb reportMessageDynamoDb = new ReportMessageDynamoDb(dynamoDbClient,
434+
ReportMessageDynamoDb reportMessageDynamoDb = new ReportMessageDynamoDb(dynamoDbClient, dynamoDbAsyncClient,
435435
config.getDynamoDbTables().getReportMessage().getTableName(),
436436
config.getReportMessageConfiguration().getReportTtl());
437437
RegistrationRecoveryPasswords registrationRecoveryPasswords = new RegistrationRecoveryPasswords(
@@ -618,7 +618,7 @@ public void run(WhisperServerConfiguration config, Environment environment) thro
618618
ReportMessageManager reportMessageManager = new ReportMessageManager(reportMessageDynamoDb, rateLimitersCluster,
619619
config.getReportMessageConfiguration().getCounterTtl());
620620
MessagesManager messagesManager = new MessagesManager(messagesDynamoDb, messagesCache, reportMessageManager,
621-
messageDeletionAsyncExecutor);
621+
messageDeletionAsyncExecutor, Clock.systemUTC());
622622
AccountLockManager accountLockManager = new AccountLockManager(dynamoDbClient,
623623
config.getDynamoDbTables().getDeletedAccountsLock().getTableName());
624624
ClientPublicKeysManager clientPublicKeysManager =
@@ -1128,7 +1128,7 @@ protected void configureServer(final ServerBuilder<?> serverBuilder) {
11281128
new KeyTransparencyController(keyTransparencyServiceClient),
11291129
new MessageController(rateLimiters, messageByteLimitCardinalityEstimator, messageSender, receiptSender,
11301130
accountsManager, messagesManager, phoneNumberIdentifiers, pushNotificationManager, pushNotificationScheduler,
1131-
reportMessageManager, multiRecipientMessageExecutor, messageDeliveryScheduler, clientReleaseManager,
1131+
reportMessageManager, messageDeliveryScheduler, clientReleaseManager,
11321132
dynamicConfigurationManager, zkSecretParams, spamChecker, messageMetrics, messageDeliveryLoopMonitor,
11331133
Clock.systemUTC()),
11341134
new PaymentsController(currencyManager, paymentsCredentialsGenerator),

service/src/main/java/org/whispersystems/textsecuregcm/auth/UnidentifiedAccessUtil.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import org.whispersystems.textsecuregcm.storage.Account;
99
import java.security.MessageDigest;
10+
import java.util.Collection;
11+
import java.util.function.Predicate;
12+
import java.util.stream.IntStream;
1013

1114
public class UnidentifiedAccessUtil {
1215

@@ -31,4 +34,42 @@ public static boolean checkUnidentifiedAccess(final Account targetAccount, final
3134
.map(targetUnidentifiedAccessKey -> MessageDigest.isEqual(targetUnidentifiedAccessKey, unidentifiedAccessKey))
3235
.orElse(false);
3336
}
37+
38+
/**
39+
* Checks whether an action (e.g. sending a message or retrieving pre-keys) may be taken on the collection of target
40+
* accounts by an actor presenting the given combined unidentified access key.
41+
*
42+
* @param targetAccounts the accounts on which an actor wishes to take an action
43+
* @param combinedUnidentifiedAccessKey the unidentified access key presented by the actor
44+
*
45+
* @return {@code true} if an actor presenting the given unidentified access key has permission to take an action on
46+
* the target accounts or {@code false} otherwise
47+
*/
48+
public static boolean checkUnidentifiedAccess(final Collection<Account> targetAccounts, final byte[] combinedUnidentifiedAccessKey) {
49+
return MessageDigest.isEqual(getCombinedUnidentifiedAccessKey(targetAccounts), combinedUnidentifiedAccessKey);
50+
}
51+
52+
/**
53+
* Calculates a combined unidentified access key for the given collection of accounts.
54+
*
55+
* @param accounts the accounts from which to derive a combined unidentified access key
56+
* @return a combined unidentified access key
57+
*
58+
* @throws IllegalArgumentException if one or more of the given accounts had an unidentified access key with an
59+
* unexpected length
60+
*/
61+
public static byte[] getCombinedUnidentifiedAccessKey(final Collection<Account> accounts) {
62+
return accounts.stream()
63+
.filter(Predicate.not(Account::isUnrestrictedUnidentifiedAccess))
64+
.map(account ->
65+
account.getUnidentifiedAccessKey()
66+
.filter(b -> b.length == UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH)
67+
.orElseThrow(IllegalArgumentException::new))
68+
.reduce(new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH],
69+
(a, b) -> {
70+
final byte[] xor = new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH];
71+
IntStream.range(0, UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH).forEach(i -> xor[i] = (byte) (a[i] ^ b[i]));
72+
return xor;
73+
});
74+
}
3475
}

0 commit comments

Comments
 (0)