if (accountId == null) {
return;
}
+ try {
+ refreshPreKeys(serviceIdType, identityKeyPair);
+ } catch (Exception e) {
+ logger.warn("Failed to store new pre keys, resetting preKey id offset", e);
+ account.resetPreKeyOffsets(serviceIdType);
+ refreshPreKeys(serviceIdType, identityKeyPair);
+ }
+ }
+
+ private void refreshPreKeys(
+ final ServiceIdType serviceIdType, final IdentityKeyPair identityKeyPair
+ ) throws IOException {
final var oneTimePreKeys = generatePreKeys(serviceIdType);
final var signedPreKeyRecord = generateSignedPreKey(serviceIdType, identityKeyPair);
}
private void clearAllPreKeys() {
- this.aciPreKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
- this.aciNextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
- this.pniPreKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
- this.pniNextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
+ resetPreKeyOffsets(ServiceIdType.ACI);
+ resetPreKeyOffsets(ServiceIdType.PNI);
this.getAciPreKeyStore().removeAllPreKeys();
this.getAciSignedPreKeyStore().removeAllSignedPreKeys();
this.getPniPreKeyStore().removeAllPreKeys();
}
}
+ public void resetPreKeyOffsets(final ServiceIdType serviceIdType) {
+ if (serviceIdType.equals(ServiceIdType.ACI)) {
+ this.aciPreKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
+ this.aciNextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
+ } else {
+ this.pniPreKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
+ this.pniNextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
+ }
+ save();
+ }
+
public void addPreKeys(ServiceIdType serviceIdType, List<PreKeyRecord> records) {
if (serviceIdType.equals(ServiceIdType.ACI)) {
addAciPreKeys(records);