Search in sources :

Example 6 with PreKeyMetadataStore

use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by WhisperSystems.

the class PniAccountInitializationMigrationJob method performMigration.

@Override
public void performMigration() throws IOException {
    PNI pni = SignalStore.account().getPni();
    if (pni == null || SignalStore.account().getAci() == null || !Recipient.self().isRegistered()) {
        Log.w(TAG, "Not yet registered! No need to perform this migration.");
        return;
    }
    if (!SignalStore.account().hasPniIdentityKey()) {
        Log.i(TAG, "Generating PNI identity.");
        SignalStore.account().generatePniIdentityKeyIfNecessary();
    } else {
        Log.w(TAG, "Already generated the PNI identity. Skipping this step.");
    }
    SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
    SignalProtocolStore protocolStore = ApplicationDependencies.getProtocolStore().pni();
    PreKeyMetadataStore metadataStore = SignalStore.account().pniPreKeys();
    if (!metadataStore.isSignedPreKeyRegistered()) {
        Log.i(TAG, "Uploading signed prekey for PNI.");
        SignedPreKeyRecord signedPreKey = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, true);
        List<PreKeyRecord> oneTimePreKeys = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore);
        accountManager.setPreKeys(ServiceIdType.PNI, protocolStore.getIdentityKeyPair().getPublicKey(), signedPreKey, oneTimePreKeys);
        metadataStore.setSignedPreKeyRegistered(true);
    } else {
        Log.w(TAG, "Already uploaded signed prekey for PNI. Skipping this step.");
    }
}
Also used : SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) PNI(org.whispersystems.signalservice.api.push.PNI) PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 7 with PreKeyMetadataStore

use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by WhisperSystems.

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 8 with PreKeyMetadataStore

use of org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore in project Signal-Android by signalapp.

the class PniAccountInitializationMigrationJob method performMigration.

@Override
public void performMigration() throws IOException {
    PNI pni = SignalStore.account().getPni();
    if (pni == null || SignalStore.account().getAci() == null || !Recipient.self().isRegistered()) {
        Log.w(TAG, "Not yet registered! No need to perform this migration.");
        return;
    }
    if (!SignalStore.account().hasPniIdentityKey()) {
        Log.i(TAG, "Generating PNI identity.");
        SignalStore.account().generatePniIdentityKeyIfNecessary();
    } else {
        Log.w(TAG, "Already generated the PNI identity. Skipping this step.");
    }
    SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
    SignalProtocolStore protocolStore = ApplicationDependencies.getProtocolStore().pni();
    PreKeyMetadataStore metadataStore = SignalStore.account().pniPreKeys();
    if (!metadataStore.isSignedPreKeyRegistered()) {
        Log.i(TAG, "Uploading signed prekey for PNI.");
        SignedPreKeyRecord signedPreKey = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, true);
        List<PreKeyRecord> oneTimePreKeys = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore);
        accountManager.setPreKeys(ServiceIdType.PNI, protocolStore.getIdentityKeyPair().getPublicKey(), signedPreKey, oneTimePreKeys);
        metadataStore.setSignedPreKeyRegistered(true);
    } else {
        Log.w(TAG, "Already uploaded signed prekey for PNI. Skipping this step.");
    }
}
Also used : SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) PNI(org.whispersystems.signalservice.api.push.PNI) PreKeyMetadataStore(org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

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