mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
parent
266129c61b
commit
228713ebb5
2 changed files with 25 additions and 4 deletions
|
@ -53,6 +53,18 @@ public class PreKeyHelper {
|
|||
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);
|
||||
|
||||
|
|
|
@ -294,10 +294,8 @@ public class SignalAccount implements Closeable {
|
|||
}
|
||||
|
||||
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();
|
||||
|
@ -998,6 +996,17 @@ public class SignalAccount implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue