use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by WhisperSystems.
the class RefreshPreKeysJob method onRun.
@Override
public void onRun() throws IOException {
if (!SignalStore.account().isRegistered() || SignalStore.account().getAci() == null || SignalStore.account().getPni() == null) {
Log.w(TAG, "Not registered. Skipping.");
return;
}
SignalProtocolStore aciProtocolStore = ApplicationDependencies.getProtocolStore().aci();
PreKeyMetadataStore aciPreKeyStore = SignalStore.account().aciPreKeys();
SignalProtocolStore pniProtocolStore = ApplicationDependencies.getProtocolStore().pni();
PreKeyMetadataStore pniPreKeyStore = SignalStore.account().pniPreKeys();
if (refreshKeys(ServiceIdType.ACI, aciProtocolStore, aciPreKeyStore)) {
PreKeyUtil.cleanSignedPreKeys(aciProtocolStore, aciPreKeyStore);
}
if (refreshKeys(ServiceIdType.PNI, pniProtocolStore, pniPreKeyStore)) {
PreKeyUtil.cleanSignedPreKeys(pniProtocolStore, pniPreKeyStore);
}
SignalStore.misc().setLastPrekeyRefreshTime(System.currentTimeMillis());
Log.i(TAG, "Successfully refreshed prekeys.");
}
use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by signalapp.
the class PreKeyUtil method cleanSignedPreKeys.
/**
* Finds all of the signed prekeys that are older than the archive age, and archive all but the youngest of those.
*/
public static synchronized void cleanSignedPreKeys(@NonNull SignalProtocolStore protocolStore, @NonNull PreKeyMetadataStore metadataStore) {
Log.i(TAG, "Cleaning signed prekeys...");
int activeSignedPreKeyId = metadataStore.getActiveSignedPreKeyId();
if (activeSignedPreKeyId < 0) {
return;
}
try {
long now = System.currentTimeMillis();
SignedPreKeyRecord currentRecord = protocolStore.loadSignedPreKey(activeSignedPreKeyId);
List<SignedPreKeyRecord> allRecords = protocolStore.loadSignedPreKeys();
allRecords.stream().filter(r -> r.getId() != currentRecord.getId()).filter(r -> (now - r.getTimestamp()) > ARCHIVE_AGE).sorted(Comparator.comparingLong(SignedPreKeyRecord::getTimestamp).reversed()).skip(1).forEach(record -> {
Log.i(TAG, "Removing signed prekey record: " + record.getId() + " with timestamp: " + record.getTimestamp());
protocolStore.removeSignedPreKey(record.getId());
});
} catch (InvalidKeyIdException e) {
Log.w(TAG, e);
}
}
use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by signalapp.
the class RotateSignedPreKeyJob method onFailure.
@Override
public void onFailure() {
PreKeyMetadataStore aciStore = SignalStore.account().aciPreKeys();
PreKeyMetadataStore pniStore = SignalStore.account().pniPreKeys();
aciStore.setSignedPreKeyFailureCount(aciStore.getSignedPreKeyFailureCount() + 1);
pniStore.setSignedPreKeyFailureCount(pniStore.getSignedPreKeyFailureCount() + 1);
}
use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by signalapp.
the class RefreshPreKeysJob method onRun.
@Override
public void onRun() throws IOException {
if (!SignalStore.account().isRegistered() || SignalStore.account().getAci() == null || SignalStore.account().getPni() == null) {
Log.w(TAG, "Not registered. Skipping.");
return;
}
SignalProtocolStore aciProtocolStore = ApplicationDependencies.getProtocolStore().aci();
PreKeyMetadataStore aciPreKeyStore = SignalStore.account().aciPreKeys();
SignalProtocolStore pniProtocolStore = ApplicationDependencies.getProtocolStore().pni();
PreKeyMetadataStore pniPreKeyStore = SignalStore.account().pniPreKeys();
if (refreshKeys(ServiceIdType.ACI, aciProtocolStore, aciPreKeyStore)) {
PreKeyUtil.cleanSignedPreKeys(aciProtocolStore, aciPreKeyStore);
}
if (refreshKeys(ServiceIdType.PNI, pniProtocolStore, pniPreKeyStore)) {
PreKeyUtil.cleanSignedPreKeys(pniProtocolStore, pniPreKeyStore);
}
SignalStore.misc().setLastPrekeyRefreshTime(System.currentTimeMillis());
Log.i(TAG, "Successfully refreshed prekeys.");
}
use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by WhisperSystems.
the class RotateSignedPreKeyJob method onFailure.
@Override
public void onFailure() {
PreKeyMetadataStore aciStore = SignalStore.account().aciPreKeys();
PreKeyMetadataStore pniStore = SignalStore.account().pniPreKeys();
aciStore.setSignedPreKeyFailureCount(aciStore.getSignedPreKeyFailureCount() + 1);
pniStore.setSignedPreKeyFailureCount(pniStore.getSignedPreKeyFailureCount() + 1);
}
Aggregations