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.");
}
}
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);
}
}
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.");
}
}
Aggregations