Search in sources :

Example 1 with PreKeyMetadataStore

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.");
}
Also used : SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore)

Example 2 with PreKeyMetadataStore

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);
    }
}
Also used : SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) NonNull(androidx.annotation.NonNull) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) Medium(org.whispersystems.libsignal.util.Medium) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) Curve(org.whispersystems.libsignal.ecc.Curve) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 3 with PreKeyMetadataStore

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);
}
Also used : PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore)

Example 4 with PreKeyMetadataStore

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.");
}
Also used : SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore)

Example 5 with PreKeyMetadataStore

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);
}
Also used : PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore)

Aggregations

PreKeyMetadataStore (org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore)8 SignalProtocolStore (org.whispersystems.libsignal.state.SignalProtocolStore)6 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)4 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)4 NonNull (androidx.annotation.NonNull)2 Comparator (java.util.Comparator)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Log (org.signal.core.util.logging.Log)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)2 Curve (org.whispersystems.libsignal.ecc.Curve)2 ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)2 Medium (org.whispersystems.libsignal.util.Medium)2 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)2 PNI (org.whispersystems.signalservice.api.push.PNI)2