use of org.whispersystems.libsignal.state.PreKeyRecord in project Signal-Android by signalapp.
the class RegistrationRepository method generateAndRegisterPreKeys.
private void generateAndRegisterPreKeys(@NonNull ServiceIdType serviceIdType, @NonNull SignalServiceAccountManager accountManager, @NonNull SignalProtocolStore protocolStore, @NonNull PreKeyMetadataStore metadataStore) throws IOException {
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, true);
List<PreKeyRecord> oneTimePreKeys = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore);
accountManager.setPreKeys(serviceIdType, protocolStore.getIdentityKeyPair().getPublicKey(), signedPreKey, oneTimePreKeys);
metadataStore.setSignedPreKeyRegistered(true);
}
use of org.whispersystems.libsignal.state.PreKeyRecord 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.");
}
}
use of org.whispersystems.libsignal.state.PreKeyRecord in project Signal-Android by signalapp.
the class PushServiceSocket method registerPreKeys.
public void registerPreKeys(ServiceIdType serviceIdType, IdentityKey identityKey, SignedPreKeyRecord signedPreKey, List<PreKeyRecord> records) throws IOException {
List<PreKeyEntity> entities = new LinkedList<>();
for (PreKeyRecord record : records) {
PreKeyEntity entity = new PreKeyEntity(record.getId(), record.getKeyPair().getPublicKey());
entities.add(entity);
}
SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(), signedPreKey.getKeyPair().getPublicKey(), signedPreKey.getSignature());
makeServiceRequest(String.format(Locale.US, PREKEY_PATH, "", serviceIdType.queryParam()), "PUT", JsonUtil.toJson(new PreKeyState(entities, signedPreKeyEntity, identityKey)));
}
use of org.whispersystems.libsignal.state.PreKeyRecord in project Signal-Android by signalapp.
the class RefreshPreKeysJob method refreshKeys.
/**
* @return True if we need to clean prekeys, otherwise false.
*/
private boolean refreshKeys(@NonNull ServiceIdType serviceIdType, @NonNull SignalProtocolStore protocolStore, @NonNull PreKeyMetadataStore metadataStore) throws IOException {
String logPrefix = "[" + serviceIdType + "] ";
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
int availableKeys = accountManager.getPreKeysCount(serviceIdType);
log(TAG, logPrefix + "Available keys: " + availableKeys);
if (availableKeys >= PREKEY_MINIMUM && metadataStore.isSignedPreKeyRegistered()) {
log(TAG, logPrefix + "Available keys sufficient.");
return false;
}
List<PreKeyRecord> preKeyRecords = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore);
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, false);
IdentityKeyPair identityKey = protocolStore.getIdentityKeyPair();
log(TAG, logPrefix + "Registering new prekeys...");
accountManager.setPreKeys(serviceIdType, identityKey.getPublicKey(), signedPreKeyRecord, preKeyRecords);
metadataStore.setActiveSignedPreKeyId(signedPreKeyRecord.getId());
metadataStore.setSignedPreKeyRegistered(true);
log(TAG, logPrefix + "Need to clean prekeys.");
return true;
}
Aggregations