Search in sources :

Example 1 with PNI

use of org.whispersystems.signalservice.api.push.PNI in project Signal-Android by WhisperSystems.

the class RegistrationRepository method registerAccountInternal.

@WorkerThread
private void registerAccountInternal(@NonNull RegistrationData registrationData, @NonNull VerifyAccountResponse response, @Nullable String pin, @Nullable KbsPinData kbsData) throws IOException {
    ACI aci = ACI.parseOrThrow(response.getUuid());
    PNI pni = PNI.parseOrThrow(response.getPni());
    boolean hasPin = response.isStorageCapable();
    SignalStore.account().setAci(aci);
    SignalStore.account().setPni(pni);
    ApplicationDependencies.getProtocolStore().aci().sessions().archiveAllSessions();
    ApplicationDependencies.getProtocolStore().pni().sessions().archiveAllSessions();
    SenderKeyUtil.clearAllState(context);
    SignalServiceAccountManager accountManager = AccountManagerFactory.createAuthenticated(context, aci, pni, registrationData.getE164(), SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.getPassword());
    SignalServiceAccountDataStoreImpl aciProtocolStore = ApplicationDependencies.getProtocolStore().aci();
    SignalServiceAccountDataStoreImpl pniProtocolStore = ApplicationDependencies.getProtocolStore().pni();
    generateAndRegisterPreKeys(ServiceIdType.ACI, accountManager, aciProtocolStore, SignalStore.account().aciPreKeys());
    generateAndRegisterPreKeys(ServiceIdType.PNI, accountManager, pniProtocolStore, SignalStore.account().pniPreKeys());
    if (registrationData.isFcm()) {
        accountManager.setGcmId(Optional.fromNullable(registrationData.getFcmToken()));
    }
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    RecipientId selfId = Recipient.externalPush(aci, registrationData.getE164(), true).getId();
    recipientDatabase.setProfileSharing(selfId, true);
    recipientDatabase.markRegisteredOrThrow(selfId, aci);
    recipientDatabase.setPni(selfId, pni);
    recipientDatabase.setProfileKey(selfId, registrationData.getProfileKey());
    ApplicationDependencies.getRecipientCache().clearSelf();
    SignalStore.account().setE164(registrationData.getE164());
    SignalStore.account().setFcmToken(registrationData.getFcmToken());
    SignalStore.account().setFcmEnabled(registrationData.isFcm());
    long now = System.currentTimeMillis();
    saveOwnIdentityKey(selfId, aciProtocolStore, now);
    saveOwnIdentityKey(selfId, pniProtocolStore, now);
    SignalStore.account().setServicePassword(registrationData.getPassword());
    SignalStore.account().setRegistered(true);
    TextSecurePreferences.setPromptedPushRegistration(context, true);
    TextSecurePreferences.setUnauthorizedReceived(context, false);
    PinState.onRegistration(context, kbsData, pin, hasPin);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ACI(org.whispersystems.signalservice.api.push.ACI) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) PNI(org.whispersystems.signalservice.api.push.PNI) SignalServiceAccountDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with PNI

use of org.whispersystems.signalservice.api.push.PNI in project Signal-Android by WhisperSystems.

the class RotateSignedPreKeyJob method onRun.

@Override
public void onRun() throws Exception {
    if (!SignalStore.account().isRegistered() || SignalStore.account().getAci() == null || SignalStore.account().getPni() == null) {
        Log.w(TAG, "Not registered. Skipping.");
        return;
    }
    Log.i(TAG, "Rotating signed prekey...");
    ACI aci = SignalStore.account().getAci();
    PNI pni = SignalStore.account().getPni();
    if (aci == null) {
        Log.w(TAG, "ACI is unset!");
        return;
    }
    if (pni == null) {
        Log.w(TAG, "PNI is unset!");
        return;
    }
    rotate(ServiceIdType.ACI, ApplicationDependencies.getProtocolStore().aci(), SignalStore.account().aciPreKeys());
    rotate(ServiceIdType.PNI, ApplicationDependencies.getProtocolStore().pni(), SignalStore.account().pniPreKeys());
}
Also used : ACI(org.whispersystems.signalservice.api.push.ACI) PNI(org.whispersystems.signalservice.api.push.PNI)

Example 3 with PNI

use of org.whispersystems.signalservice.api.push.PNI in project Signal-Android by WhisperSystems.

the class ApplicationDependencyProvider method provideProtocolStore.

@Override
@NonNull
public SignalServiceDataStoreImpl provideProtocolStore() {
    ACI localAci = SignalStore.account().getAci();
    PNI localPni = SignalStore.account().getPni();
    if (localAci == null) {
        throw new IllegalStateException("No ACI set!");
    }
    if (localPni == null) {
        throw new IllegalStateException("No PNI set!");
    }
    if (!SignalStore.account().hasPniIdentityKey()) {
        SignalStore.account().generatePniIdentityKeyIfNecessary();
        CreateSignedPreKeyJob.enqueueIfNeeded();
    }
    SignalBaseIdentityKeyStore baseIdentityStore = new SignalBaseIdentityKeyStore(context);
    SignalServiceAccountDataStoreImpl aciStore = new SignalServiceAccountDataStoreImpl(context, new TextSecurePreKeyStore(localAci), new SignalIdentityKeyStore(baseIdentityStore, () -> SignalStore.account().getAciIdentityKey()), new TextSecureSessionStore(localAci), new SignalSenderKeyStore(context));
    SignalServiceAccountDataStoreImpl pniStore = new SignalServiceAccountDataStoreImpl(context, new TextSecurePreKeyStore(localPni), new SignalIdentityKeyStore(baseIdentityStore, () -> SignalStore.account().getPniIdentityKey()), new TextSecureSessionStore(localPni), new SignalSenderKeyStore(context));
    return new SignalServiceDataStoreImpl(context, aciStore, pniStore);
}
Also used : TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) ACI(org.whispersystems.signalservice.api.push.ACI) SignalSenderKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore) PNI(org.whispersystems.signalservice.api.push.PNI) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) SignalBaseIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalBaseIdentityKeyStore) SignalServiceAccountDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl) SignalServiceDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceDataStoreImpl) NonNull(androidx.annotation.NonNull)

Example 4 with PNI

use of org.whispersystems.signalservice.api.push.PNI 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 5 with PNI

use of org.whispersystems.signalservice.api.push.PNI in project Signal-Android by WhisperSystems.

the class PniMigrationJob method performMigration.

@Override
void performMigration() throws Exception {
    if (!SignalStore.account().isRegistered() || SignalStore.account().getAci() == null) {
        Log.w(TAG, "Not registered! Skipping migration, as it wouldn't do anything.");
        return;
    }
    RecipientId self = Recipient.self().getId();
    PNI pni = PNI.parseOrNull(ApplicationDependencies.getSignalServiceAccountManager().getWhoAmI().getPni());
    if (pni == null) {
        throw new IOException("Invalid PNI!");
    }
    SignalDatabase.recipients().setPni(self, pni);
    SignalStore.account().setPni(pni);
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) PNI(org.whispersystems.signalservice.api.push.PNI) IOException(java.io.IOException)

Aggregations

PNI (org.whispersystems.signalservice.api.push.PNI)6 ACI (org.whispersystems.signalservice.api.push.ACI)4 SignalServiceAccountDataStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)2 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 PreKeyMetadataStore (org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore)1 SignalBaseIdentityKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalBaseIdentityKeyStore)1 SignalIdentityKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore)1 SignalSenderKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore)1 SignalServiceDataStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalServiceDataStoreImpl)1 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)1 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)1 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)1 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)1 SignalProtocolStore (org.whispersystems.libsignal.state.SignalProtocolStore)1 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)1