Search in sources :

Example 11 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Pix-Art-Messenger by kriztan.

the class AxolotlService method getReceivingSession.

private XmppAxolotlSession getReceivingSession(XmppAxolotlMessage message) {
    SignalProtocolAddress senderAddress = new SignalProtocolAddress(message.getFrom().toPreppedString(), message.getSenderDeviceId());
    XmppAxolotlSession session = sessions.get(senderAddress);
    if (session == null) {
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Account: " + account.getJid() + " No axolotl session found while parsing received message " + message);
        session = recreateUncachedSession(senderAddress);
        if (session == null) {
            session = new XmppAxolotlSession(account, axolotlStore, senderAddress);
        }
    }
    return session;
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 12 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project toshi-android-client by toshiapp.

the class SignalSessionStore method migrateSessions.

public void migrateSessions() {
    synchronized (FILE_LOCK) {
        File directory = getSessionDirectory();
        for (File session : directory.listFiles()) {
            if (session.isFile()) {
                SignalProtocolAddress address = getAddressName(session);
                if (address != null) {
                    SessionRecord sessionRecord = loadSession(address);
                    storeSession(address, sessionRecord);
                }
            }
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord)

Example 13 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Conversations by siacs.

the class AxolotlService method createSessionsIfNeededActual.

private boolean createSessionsIfNeededActual(final Conversation conversation) {
    Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Creating axolotl sessions if needed...");
    boolean newSessions = false;
    Set<SignalProtocolAddress> addresses = findDevicesWithoutSession(conversation);
    for (SignalProtocolAddress address : addresses) {
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Processing device: " + address.toString());
        FetchStatus status = fetchStatusMap.get(address);
        if (status == null || status == FetchStatus.TIMEOUT) {
            fetchStatusMap.put(address, FetchStatus.PENDING);
            this.buildSessionFromPEP(address);
            newSessions = true;
        } else if (status == FetchStatus.PENDING) {
            newSessions = true;
        } else {
            Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Already fetching bundle for " + address.toString());
        }
    }
    return newSessions;
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 14 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Conversations by siacs.

the class AxolotlService method findOwnSessions.

public Collection<XmppAxolotlSession> findOwnSessions() {
    SignalProtocolAddress ownAddress = getAddressForJid(account.getJid().asBareJid());
    ArrayList<XmppAxolotlSession> s = new ArrayList<>(this.sessions.getAll(ownAddress.getName()).values());
    Collections.sort(s);
    return s;
}
Also used : ArrayList(java.util.ArrayList) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 15 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Conversations by siacs.

the class AxolotlService method registerDevices.

public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
    final int hash = deviceIds.hashCode();
    final boolean me = jid.asBareJid().equals(account.getJid().asBareJid());
    if (me) {
        if (hash != 0 && hash == this.lastDeviceListNotificationHash) {
            Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring duplicate own device id list");
            return;
        }
        this.lastDeviceListNotificationHash = hash;
    }
    boolean needsPublishing = me && !deviceIds.contains(getOwnDeviceId());
    if (me) {
        deviceIds.remove(getOwnDeviceId());
    }
    Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.asBareJid().toString()));
    expiredDevices.removeAll(deviceIds);
    for (Integer deviceId : expiredDevices) {
        SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId);
        XmppAxolotlSession session = sessions.get(address);
        if (session != null && session.getFingerprint() != null) {
            if (session.getTrust().isActive()) {
                session.setTrust(session.getTrust().toInactive());
            }
        }
    }
    Set<Integer> newDevices = new HashSet<>(deviceIds);
    for (Integer deviceId : newDevices) {
        SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId);
        XmppAxolotlSession session = sessions.get(address);
        if (session != null && session.getFingerprint() != null) {
            if (!session.getTrust().isActive()) {
                Log.d(Config.LOGTAG, "reactivating device with fingerprint " + session.getFingerprint());
                session.setTrust(session.getTrust().toActive());
            }
        }
    }
    if (me) {
        if (Config.OMEMO_AUTO_EXPIRY != 0) {
            needsPublishing |= deviceIds.removeAll(getExpiredDevices());
        }
        needsPublishing |= this.changeAccessMode.get();
        for (Integer deviceId : deviceIds) {
            SignalProtocolAddress ownDeviceAddress = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId);
            if (sessions.get(ownDeviceAddress) == null) {
                FetchStatus status = fetchStatusMap.get(ownDeviceAddress);
                if (status == null || status == FetchStatus.TIMEOUT) {
                    fetchStatusMap.put(ownDeviceAddress, FetchStatus.PENDING);
                    this.buildSessionFromPEP(ownDeviceAddress);
                }
            }
        }
        if (needsPublishing) {
            publishOwnDeviceId(deviceIds);
        }
    }
    final Set<Integer> oldSet = this.deviceIds.get(jid);
    final boolean changed = oldSet == null || oldSet.hashCode() != hash;
    this.deviceIds.put(jid, deviceIds);
    if (changed) {
        // update the lock icon
        mXmppConnectionService.updateConversationUi();
        mXmppConnectionService.keyStatusUpdated(null);
        if (me) {
            mXmppConnectionService.updateAccountUi();
        }
    } else {
        Log.d(Config.LOGTAG, "skipped device list update because it hasn't changed");
    }
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) HashSet(java.util.HashSet)

Aggregations

SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)77 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)14 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)11 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)11 ArrayList (java.util.ArrayList)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 IOException (java.io.IOException)9 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)9 Optional (org.whispersystems.libsignal.util.guava.Optional)9 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 ContentHint (org.whispersystems.signalservice.api.crypto.ContentHint)8 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)8 NonNull (androidx.annotation.NonNull)6 LinkedList (java.util.LinkedList)6 Collectors (java.util.stream.Collectors)6 SenderKeyDistributionMessage (org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage)6 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)6