mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +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) {
|
if (accountId == null) {
|
||||||
return;
|
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 oneTimePreKeys = generatePreKeys(serviceIdType);
|
||||||
final var signedPreKeyRecord = generateSignedPreKey(serviceIdType, identityKeyPair);
|
final var signedPreKeyRecord = generateSignedPreKey(serviceIdType, identityKeyPair);
|
||||||
|
|
||||||
|
|
|
@ -294,10 +294,8 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearAllPreKeys() {
|
private void clearAllPreKeys() {
|
||||||
this.aciPreKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
|
resetPreKeyOffsets(ServiceIdType.ACI);
|
||||||
this.aciNextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
|
resetPreKeyOffsets(ServiceIdType.PNI);
|
||||||
this.pniPreKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
|
|
||||||
this.pniNextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
|
|
||||||
this.getAciPreKeyStore().removeAllPreKeys();
|
this.getAciPreKeyStore().removeAllPreKeys();
|
||||||
this.getAciSignedPreKeyStore().removeAllSignedPreKeys();
|
this.getAciSignedPreKeyStore().removeAllSignedPreKeys();
|
||||||
this.getPniPreKeyStore().removeAllPreKeys();
|
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) {
|
public void addPreKeys(ServiceIdType serviceIdType, List<PreKeyRecord> records) {
|
||||||
if (serviceIdType.equals(ServiceIdType.ACI)) {
|
if (serviceIdType.equals(ServiceIdType.ACI)) {
|
||||||
addAciPreKeys(records);
|
addAciPreKeys(records);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue