Search in sources :

Example 6 with SessionStore

use of org.whispersystems.libsignal.state.SessionStore in project Signal-Android by WhisperSystems.

the class IdentityUtil method getRemoteIdentityKey.

@UiThread
public static ListenableFuture<Optional<IdentityKey>> getRemoteIdentityKey(final Context context, final MasterSecret masterSecret, final Recipient recipient) {
    final SettableFuture<Optional<IdentityKey>> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Optional<IdentityKey>>() {

        @Override
        protected Optional<IdentityKey> doInBackground(Recipient... recipient) {
            SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
            SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(recipient[0].getNumber(), SignalServiceAddress.DEFAULT_DEVICE_ID);
            SessionRecord record = sessionStore.loadSession(axolotlAddress);
            if (record == null) {
                return Optional.absent();
            }
            return Optional.fromNullable(record.getSessionState().getRemoteIdentityKey());
        }

        @Override
        protected void onPostExecute(Optional<IdentityKey> result) {
            future.set(result);
        }
    }.execute(recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) IdentityKey(org.whispersystems.libsignal.IdentityKey) Optional(org.whispersystems.libsignal.util.guava.Optional) Recipient(org.thoughtcrime.securesms.recipients.Recipient) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord) UiThread(android.support.annotation.UiThread)

Example 7 with SessionStore

use of org.whispersystems.libsignal.state.SessionStore in project Signal-Android by signalapp.

the class PushDecryptJob method handleSynchronizeSentEndSessionMessage.

private long handleSynchronizeSentEndSessionMessage(@NonNull SentTranscriptMessage message) {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    Recipient recipient = getSyncMessageDestination(message);
    OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, "", -1);
    OutgoingEndSessionMessage outgoingEndSessionMessage = new OutgoingEndSessionMessage(outgoingTextMessage);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    if (!recipient.isGroupRecipient()) {
        SessionStore sessionStore = new TextSecureSessionStore(context);
        sessionStore.deleteAllSessions(recipient.getAddress().toPhoneString());
        SecurityEvent.broadcastSecurityUpdateEvent(context);
        long messageId = database.insertMessageOutbox(threadId, outgoingEndSessionMessage, false, message.getTimestamp(), null);
        database.markAsSent(messageId, true);
    }
    return threadId;
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingEndSessionMessage(org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 8 with SessionStore

use of org.whispersystems.libsignal.state.SessionStore in project Signal-Android by WhisperSystems.

the class IdentityUtil method saveIdentity.

public static void saveIdentity(String user, IdentityKey identityKey) {
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        SessionStore sessionStore = ApplicationDependencies.getProtocolStore().aci();
        SignalProtocolAddress address = new SignalProtocolAddress(user, SignalServiceAddress.DEFAULT_DEVICE_ID);
        if (ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(address, identityKey)) {
            if (sessionStore.containsSession(address)) {
                SessionRecord sessionRecord = sessionStore.loadSession(address);
                sessionRecord.archiveCurrentState();
                sessionStore.storeSession(address, sessionRecord);
            }
        }
    }
}
Also used : SessionStore(org.whispersystems.libsignal.state.SessionStore) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord)

Example 9 with SessionStore

use of org.whispersystems.libsignal.state.SessionStore in project Signal-Android by signalapp.

the class IdentityUtil method saveIdentity.

public static void saveIdentity(String user, IdentityKey identityKey) {
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        SessionStore sessionStore = ApplicationDependencies.getProtocolStore().aci();
        SignalProtocolAddress address = new SignalProtocolAddress(user, SignalServiceAddress.DEFAULT_DEVICE_ID);
        if (ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(address, identityKey)) {
            if (sessionStore.containsSession(address)) {
                SessionRecord sessionRecord = sessionStore.loadSession(address);
                sessionRecord.archiveCurrentState();
                sessionStore.storeSession(address, sessionRecord);
            }
        }
    }
}
Also used : SessionStore(org.whispersystems.libsignal.state.SessionStore) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord)

Aggregations

SessionStore (org.whispersystems.libsignal.state.SessionStore)9 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)7 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)5 SessionRecord (org.whispersystems.libsignal.state.SessionRecord)3 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)2 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 IncomingEndSessionMessage (org.thoughtcrime.securesms.sms.IncomingEndSessionMessage)2 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)2 OutgoingEndSessionMessage (org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage)2 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)2 SignalSessionLock (org.whispersystems.signalservice.api.SignalSessionLock)2 UiThread (android.support.annotation.UiThread)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)1 IdentityKey (org.whispersystems.libsignal.IdentityKey)1 Optional (org.whispersystems.libsignal.util.guava.Optional)1