That fuck shit the fascists are using
1package org.tm.archive.crypto;
2
3import androidx.annotation.NonNull;
4
5import org.signal.libsignal.protocol.SignalProtocolAddress;
6import org.tm.archive.database.SignalDatabase;
7import org.tm.archive.dependencies.ApplicationDependencies;
8import org.tm.archive.keyvalue.SignalStore;
9import org.whispersystems.signalservice.api.SignalSessionLock;
10import org.whispersystems.signalservice.api.push.DistributionId;
11
12public final class SenderKeyUtil {
13 private SenderKeyUtil() {}
14
15 /**
16 * Clears the state for a sender key session we created. It will naturally get re-created when it is next needed, rotating the key.
17 */
18 public static void rotateOurKey(@NonNull DistributionId distributionId) {
19 try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
20 ApplicationDependencies.getProtocolStore().aci().senderKeys().deleteAllFor(SignalStore.account().requireAci().toString(), distributionId);
21 SignalDatabase.senderKeyShared().deleteAllFor(distributionId);
22 }
23 }
24
25 /**
26 * Gets when the sender key session was created, or -1 if it doesn't exist.
27 */
28 public static long getCreateTimeForOurKey(@NonNull DistributionId distributionId) {
29 SignalProtocolAddress address = new SignalProtocolAddress(SignalStore.account().requireAci().toString(), SignalStore.account().getDeviceId());
30 return SignalDatabase.senderKeys().getCreatedTime(address, distributionId);
31 }
32
33 /**
34 * Deletes all stored state around session keys. Should only really be used when the user is re-registering.
35 */
36 public static void clearAllState() {
37 try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
38 ApplicationDependencies.getProtocolStore().aci().senderKeys().deleteAll();
39 SignalDatabase.senderKeyShared().deleteAll();
40 }
41 }
42}