Skip to content

Commit 2b08742

Browse files
authored
Create separate key stores for different kinds of pre-keys
1 parent cac0414 commit 2b08742

34 files changed

+1482
-847
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ commercial, industrial or non-consumer uses, unless such uses represent
296296
the only significant mode of use of the product.
297297

298298
"Installation Information" for a User Product means any methods,
299-
procedures, authorization keys, or other information required to install
299+
procedures, authorization keysManager, or other information required to install
300300
and execute modified versions of a covered work in that User Product from
301301
a modified version of its Corresponding Source. The information must
302302
suffice to ensure that the continued functioning of the modified object

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
import org.whispersystems.textsecuregcm.storage.DeletedAccounts;
177177
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
178178
import org.whispersystems.textsecuregcm.storage.IssuedReceiptsManager;
179-
import org.whispersystems.textsecuregcm.storage.Keys;
179+
import org.whispersystems.textsecuregcm.storage.KeysManager;
180180
import org.whispersystems.textsecuregcm.storage.MessagePersister;
181181
import org.whispersystems.textsecuregcm.storage.MessagesCache;
182182
import org.whispersystems.textsecuregcm.storage.MessagesDynamoDb;
@@ -345,10 +345,11 @@ public void run(WhisperServerConfiguration config, Environment environment) thro
345345
config.getDynamoDbTables().getPhoneNumberIdentifiers().getTableName());
346346
Profiles profiles = new Profiles(dynamoDbClient, dynamoDbAsyncClient,
347347
config.getDynamoDbTables().getProfiles().getTableName());
348-
Keys keys = new Keys(dynamoDbClient,
348+
KeysManager keys = new KeysManager(
349+
dynamoDbAsyncClient,
349350
config.getDynamoDbTables().getEcKeys().getTableName(),
350-
config.getDynamoDbTables().getPqKeys().getTableName(),
351-
config.getDynamoDbTables().getPqLastResortKeys().getTableName());
351+
config.getDynamoDbTables().getKemKeys().getTableName(),
352+
config.getDynamoDbTables().getKemLastResortKeys().getTableName());
352353
MessagesDynamoDb messagesDynamoDb = new MessagesDynamoDb(dynamoDbClient, dynamoDbAsyncClient,
353354
config.getDynamoDbTables().getMessages().getTableName(),
354355
config.getDynamoDbTables().getMessages().getExpiration(),

service/src/main/java/org/whispersystems/textsecuregcm/configuration/DynamoDbTables.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public Duration getExpiration() {
5151
private final Table deletedAccountsLock;
5252
private final IssuedReceiptsTableConfiguration issuedReceipts;
5353
private final Table ecKeys;
54-
private final Table pqKeys;
55-
private final Table pqLastResortKeys;
54+
private final Table kemKeys;
55+
private final Table kemLastResortKeys;
5656
private final TableWithExpiration messages;
5757
private final Table pendingAccounts;
5858
private final Table pendingDevices;
@@ -72,8 +72,8 @@ public DynamoDbTables(
7272
@JsonProperty("deletedAccountsLock") final Table deletedAccountsLock,
7373
@JsonProperty("issuedReceipts") final IssuedReceiptsTableConfiguration issuedReceipts,
7474
@JsonProperty("ecKeys") final Table ecKeys,
75-
@JsonProperty("pqKeys") final Table pqKeys,
76-
@JsonProperty("pqLastResortKeys") final Table pqLastResortKeys,
75+
@JsonProperty("pqKeys") final Table kemKeys,
76+
@JsonProperty("pqLastResortKeys") final Table kemLastResortKeys,
7777
@JsonProperty("messages") final TableWithExpiration messages,
7878
@JsonProperty("pendingAccounts") final Table pendingAccounts,
7979
@JsonProperty("pendingDevices") final Table pendingDevices,
@@ -92,8 +92,8 @@ public DynamoDbTables(
9292
this.deletedAccountsLock = deletedAccountsLock;
9393
this.issuedReceipts = issuedReceipts;
9494
this.ecKeys = ecKeys;
95-
this.pqKeys = pqKeys;
96-
this.pqLastResortKeys = pqLastResortKeys;
95+
this.kemKeys = kemKeys;
96+
this.kemLastResortKeys = kemLastResortKeys;
9797
this.messages = messages;
9898
this.pendingAccounts = pendingAccounts;
9999
this.pendingDevices = pendingDevices;
@@ -140,14 +140,14 @@ public Table getEcKeys() {
140140

141141
@NotNull
142142
@Valid
143-
public Table getPqKeys() {
144-
return pqKeys;
143+
public Table getKemKeys() {
144+
return kemKeys;
145145
}
146146

147147
@NotNull
148148
@Valid
149-
public Table getPqLastResortKeys() {
150-
return pqLastResortKeys;
149+
public Table getKemLastResortKeys() {
150+
return kemLastResortKeys;
151151
}
152152

153153
@NotNull

service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import org.whispersystems.textsecuregcm.storage.AccountsManager;
5252
import org.whispersystems.textsecuregcm.storage.Device;
5353
import org.whispersystems.textsecuregcm.storage.Device.DeviceCapabilities;
54-
import org.whispersystems.textsecuregcm.storage.Keys;
54+
import org.whispersystems.textsecuregcm.storage.KeysManager;
5555
import org.whispersystems.textsecuregcm.storage.MessagesManager;
5656
import org.whispersystems.textsecuregcm.storage.StoredVerificationCodeManager;
5757
import org.whispersystems.textsecuregcm.util.Pair;
@@ -67,14 +67,14 @@ public class DeviceController {
6767
private final StoredVerificationCodeManager pendingDevices;
6868
private final AccountsManager accounts;
6969
private final MessagesManager messages;
70-
private final Keys keys;
70+
private final KeysManager keys;
7171
private final RateLimiters rateLimiters;
7272
private final Map<String, Integer> maxDeviceConfiguration;
7373

7474
public DeviceController(StoredVerificationCodeManager pendingDevices,
7575
AccountsManager accounts,
7676
MessagesManager messages,
77-
Keys keys,
77+
KeysManager keys,
7878
RateLimiters rateLimiters,
7979
Map<String, Integer> maxDeviceConfiguration) {
8080
this.pendingDevices = pendingDevices;

service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
import org.whispersystems.textsecuregcm.storage.Account;
5454
import org.whispersystems.textsecuregcm.storage.AccountsManager;
5555
import org.whispersystems.textsecuregcm.storage.Device;
56-
import org.whispersystems.textsecuregcm.storage.Keys;
56+
import org.whispersystems.textsecuregcm.storage.KeysManager;
5757

5858
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
5959
@Path("/v2/keys")
6060
@Tag(name = "Keys")
6161
public class KeysController {
6262

6363
private final RateLimiters rateLimiters;
64-
private final Keys keys;
64+
private final KeysManager keys;
6565
private final AccountsManager accounts;
6666

6767
private static final String IDENTITY_KEY_CHANGE_COUNTER_NAME = name(KeysController.class, "identityKeyChange");
@@ -70,7 +70,7 @@ public class KeysController {
7070
private static final String IDENTITY_TYPE_TAG_NAME = "identityType";
7171
private static final String HAS_IDENTITY_KEY_TAG_NAME = "hasIdentityKey";
7272

73-
public KeysController(RateLimiters rateLimiters, Keys keys, AccountsManager accounts) {
73+
public KeysController(RateLimiters rateLimiters, KeysManager keys, AccountsManager accounts) {
7474
this.rateLimiters = rateLimiters;
7575
this.keys = keys;
7676
this.accounts = accounts;

service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.whispersystems.textsecuregcm.storage.Account;
4949
import org.whispersystems.textsecuregcm.storage.AccountsManager;
5050
import org.whispersystems.textsecuregcm.storage.Device;
51-
import org.whispersystems.textsecuregcm.storage.Keys;
51+
import org.whispersystems.textsecuregcm.storage.KeysManager;
5252
import org.whispersystems.textsecuregcm.util.HeaderUtils;
5353
import org.whispersystems.textsecuregcm.util.Util;
5454

@@ -74,18 +74,18 @@ public class RegistrationController {
7474
private final AccountsManager accounts;
7575
private final PhoneVerificationTokenManager phoneVerificationTokenManager;
7676
private final RegistrationLockVerificationManager registrationLockVerificationManager;
77-
private final Keys keys;
77+
private final KeysManager keysManager;
7878
private final RateLimiters rateLimiters;
7979

8080
public RegistrationController(final AccountsManager accounts,
8181
final PhoneVerificationTokenManager phoneVerificationTokenManager,
8282
final RegistrationLockVerificationManager registrationLockVerificationManager,
83-
final Keys keys,
83+
final KeysManager keysManager,
8484
final RateLimiters rateLimiters) {
8585
this.accounts = accounts;
8686
this.phoneVerificationTokenManager = phoneVerificationTokenManager;
8787
this.registrationLockVerificationManager = registrationLockVerificationManager;
88-
this.keys = keys;
88+
this.keysManager = keysManager;
8989
this.rateLimiters = rateLimiters;
9090
}
9191

@@ -176,8 +176,8 @@ public AccountIdentityResponse register(
176176
registrationRequest.deviceActivationRequest().gcmToken().ifPresent(gcmRegistrationId ->
177177
device.setGcmId(gcmRegistrationId.gcmRegistrationId()));
178178

179-
keys.storePqLastResort(a.getUuid(), Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().aciPqLastResortPreKey().get()));
180-
keys.storePqLastResort(a.getPhoneNumberIdentifier(), Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().pniPqLastResortPreKey().get()));
179+
keysManager.storePqLastResort(a.getUuid(), Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().aciPqLastResortPreKey().get()));
180+
keysManager.storePqLastResort(a.getPhoneNumberIdentifier(), Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().pniPqLastResortPreKey().get()));
181181
});
182182
}
183183

service/src/main/java/org/whispersystems/textsecuregcm/entities/ChangeNumberRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public record ChangeNumberRequest(
4343
@NotEmpty byte[] pniIdentityKey,
4444

4545
@Schema(description="""
46-
A list of synchronization messages to send to companion devices to supply the private keys
46+
A list of synchronization messages to send to companion devices to supply the private keysManager
4747
associated with the new identity key and their new prekeys.
4848
Exactly one message must be supplied for each enabled device other than the sending (primary) device.""")
4949
@NotNull @Valid List<@NotNull @Valid IncomingMessage> deviceMessages,

service/src/main/java/org/whispersystems/textsecuregcm/entities/ChangePhoneNumberRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public record ChangePhoneNumberRequest(
3636
@Nullable byte[] pniIdentityKey,
3737

3838
@Schema(description="""
39-
A list of synchronization messages to send to companion devices to supply the private keys
39+
A list of synchronization messages to send to companion devices to supply the private keysManager
4040
associated with the new identity key and their new prekeys.
4141
Exactly one message must be supplied for each enabled device other than the sending (primary) device.""")
4242
@Nullable List<IncomingMessage> deviceMessages,

service/src/main/java/org/whispersystems/textsecuregcm/entities/PhoneNumberIdentityKeyDistributionRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public record PhoneNumberIdentityKeyDistributionRequest(
3030
@NotNull
3131
@Valid
3232
@Schema(description="""
33-
A list of synchronization messages to send to companion devices to supply the private keys
33+
A list of synchronization messages to send to companion devices to supply the private keysManager
3434
associated with the new identity key and their new prekeys.
3535
Exactly one message must be supplied for each enabled device other than the sending (primary) device.""")
3636
List<@NotNull @Valid IncomingMessage> deviceMessages,

service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class AccountsManager {
9090
private final FaultTolerantRedisCluster cacheCluster;
9191
private final AccountLockManager accountLockManager;
9292
private final DeletedAccounts deletedAccounts;
93-
private final Keys keys;
93+
private final KeysManager keysManager;
9494
private final MessagesManager messagesManager;
9595
private final ProfilesManager profilesManager;
9696
private final StoredVerificationCodeManager pendingAccounts;
@@ -134,7 +134,7 @@ public AccountsManager(final Accounts accounts,
134134
final FaultTolerantRedisCluster cacheCluster,
135135
final AccountLockManager accountLockManager,
136136
final DeletedAccounts deletedAccounts,
137-
final Keys keys,
137+
final KeysManager keysManager,
138138
final MessagesManager messagesManager,
139139
final ProfilesManager profilesManager,
140140
final StoredVerificationCodeManager pendingAccounts,
@@ -150,7 +150,7 @@ public AccountsManager(final Accounts accounts,
150150
this.cacheCluster = cacheCluster;
151151
this.accountLockManager = accountLockManager;
152152
this.deletedAccounts = deletedAccounts;
153-
this.keys = keys;
153+
this.keysManager = keysManager;
154154
this.messagesManager = messagesManager;
155155
this.profilesManager = profilesManager;
156156
this.pendingAccounts = pendingAccounts;
@@ -223,8 +223,8 @@ public Account create(final String number,
223223
// account and need to clear out messages and keys that may have been stored for the old account.
224224
if (!originalUuid.equals(actualUuid)) {
225225
messagesManager.clear(actualUuid);
226-
keys.delete(actualUuid);
227-
keys.delete(account.getPhoneNumberIdentifier());
226+
keysManager.delete(actualUuid);
227+
keysManager.delete(account.getPhoneNumberIdentifier());
228228
profilesManager.deleteAll(actualUuid);
229229
clientPresenceManager.disconnectAllPresencesForUuid(actualUuid);
230230
}
@@ -315,13 +315,13 @@ public Account changeNumber(final Account account,
315315

316316
updatedAccount.set(numberChangedAccount);
317317

318-
keys.delete(phoneNumberIdentifier);
319-
keys.delete(originalPhoneNumberIdentifier);
318+
keysManager.delete(phoneNumberIdentifier);
319+
keysManager.delete(originalPhoneNumberIdentifier);
320320

321321
if (pniPqLastResortPreKeys != null) {
322-
keys.storePqLastResort(
322+
keysManager.storePqLastResort(
323323
phoneNumberIdentifier,
324-
keys.getPqEnabledDevices(uuid).stream().collect(
324+
keysManager.getPqEnabledDevices(uuid).stream().collect(
325325
Collectors.toMap(
326326
Function.identity(),
327327
pniPqLastResortPreKeys::get)));
@@ -356,10 +356,10 @@ public Account updatePniKeys(final Account account,
356356
final UUID pni = account.getPhoneNumberIdentifier();
357357
final Account updatedAccount = update(account, a -> { return setPniKeys(a, pniIdentityKey, pniSignedPreKeys, pniRegistrationIds); });
358358

359-
final List<Long> pqEnabledDeviceIDs = keys.getPqEnabledDevices(pni);
360-
keys.delete(pni);
359+
final List<Long> pqEnabledDeviceIDs = keysManager.getPqEnabledDevices(pni);
360+
keysManager.delete(pni);
361361
if (pniPqLastResortPreKeys != null) {
362-
keys.storePqLastResort(pni, pqEnabledDeviceIDs.stream().collect(Collectors.toMap(Function.identity(), pniPqLastResortPreKeys::get)));
362+
keysManager.storePqLastResort(pni, pqEnabledDeviceIDs.stream().collect(Collectors.toMap(Function.identity(), pniPqLastResortPreKeys::get)));
363363
}
364364

365365
return updatedAccount;
@@ -740,8 +740,8 @@ private void delete(final Account account) {
740740
account.getUuid());
741741

742742
profilesManager.deleteAll(account.getUuid());
743-
keys.delete(account.getUuid());
744-
keys.delete(account.getPhoneNumberIdentifier());
743+
keysManager.delete(account.getUuid());
744+
keysManager.delete(account.getPhoneNumberIdentifier());
745745
messagesManager.clear(account.getUuid());
746746
messagesManager.clear(account.getPhoneNumberIdentifier());
747747
registrationRecoveryPasswordsManager.removeForNumber(account.getNumber());

0 commit comments

Comments
 (0)