Search in sources :

Example 1 with AxolotlAddress

use of org.whispersystems.libaxolotl.AxolotlAddress in project Conversations by siacs.

the class AxolotlService method createSessionsIfNeeded.

public boolean createSessionsIfNeeded(final Conversation conversation) {
    Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Creating axolotl sessions if needed...");
    boolean newSessions = false;
    Set<AxolotlAddress> addresses = findDevicesWithoutSession(conversation);
    for (AxolotlAddress 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 : AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress)

Example 2 with AxolotlAddress

use of org.whispersystems.libaxolotl.AxolotlAddress in project Conversations by siacs.

the class AxolotlService method findOwnSessions.

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

Example 3 with AxolotlAddress

use of org.whispersystems.libaxolotl.AxolotlAddress in project Conversations by siacs.

the class AxolotlService method registerDevices.

public void registerDevices(final Jid jid, @NonNull final Set<Integer> deviceIds) {
    boolean me = jid.toBareJid().equals(account.getJid().toBareJid());
    if (me && ownPushPending.getAndSet(false)) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ignoring own device update because of pending push");
        return;
    }
    boolean needsPublishing = me && !deviceIds.contains(getOwnDeviceId());
    if (me) {
        deviceIds.remove(getOwnDeviceId());
    }
    Set<Integer> expiredDevices = new HashSet<>(axolotlStore.getSubDeviceSessions(jid.toBareJid().toPreppedString()));
    expiredDevices.removeAll(deviceIds);
    for (Integer deviceId : expiredDevices) {
        AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toPreppedString(), 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) {
        AxolotlAddress address = new AxolotlAddress(jid.toBareJid().toPreppedString(), 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());
        }
        for (Integer deviceId : deviceIds) {
            AxolotlAddress ownDeviceAddress = new AxolotlAddress(jid.toBareJid().toPreppedString(), 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);
        }
    }
    this.deviceIds.put(jid, deviceIds);
    //update the lock icon
    mXmppConnectionService.updateConversationUi();
    mXmppConnectionService.keyStatusUpdated(null);
}
Also used : AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress) HashSet(java.util.HashSet)

Example 4 with AxolotlAddress

use of org.whispersystems.libaxolotl.AxolotlAddress in project Conversations by siacs.

the class AxolotlService method getReceivingSession.

private XmppAxolotlSession getReceivingSession(XmppAxolotlMessage message) {
    AxolotlAddress senderAddress = new AxolotlAddress(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 : AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress)

Example 5 with AxolotlAddress

use of org.whispersystems.libaxolotl.AxolotlAddress in project Conversations by siacs.

the class AxolotlService method finishBuildingSessionsFromPEP.

private void finishBuildingSessionsFromPEP(final AxolotlAddress address) {
    AxolotlAddress ownAddress = new AxolotlAddress(account.getJid().toBareJid().toPreppedString(), 0);
    Map<Integer, FetchStatus> own = fetchStatusMap.getAll(ownAddress);
    Map<Integer, FetchStatus> remote = fetchStatusMap.getAll(address);
    if (!own.containsValue(FetchStatus.PENDING) && !remote.containsValue(FetchStatus.PENDING)) {
        FetchStatus report = null;
        if (own.containsValue(FetchStatus.SUCCESS) || remote.containsValue(FetchStatus.SUCCESS)) {
            report = FetchStatus.SUCCESS;
        } else if (own.containsValue(FetchStatus.SUCCESS_VERIFIED) || remote.containsValue(FetchStatus.SUCCESS_VERIFIED)) {
            report = FetchStatus.SUCCESS_VERIFIED;
        } else if (own.containsValue(FetchStatus.SUCCESS_TRUSTED) || remote.containsValue(FetchStatus.SUCCESS_TRUSTED)) {
            report = FetchStatus.SUCCESS_TRUSTED;
        } else if (own.containsValue(FetchStatus.ERROR) || remote.containsValue(FetchStatus.ERROR)) {
            report = FetchStatus.ERROR;
        }
        mXmppConnectionService.keyStatusUpdated(report);
    }
    if (Config.REMOVE_BROKEN_DEVICES) {
        Set<Integer> ownDeviceIds = new HashSet<>(getOwnDeviceIds());
        boolean publish = false;
        for (Map.Entry<Integer, FetchStatus> entry : own.entrySet()) {
            int id = entry.getKey();
            if (entry.getValue() == FetchStatus.ERROR && PREVIOUSLY_REMOVED_FROM_ANNOUNCEMENT.add(id) && ownDeviceIds.remove(id)) {
                publish = true;
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error fetching own device with id " + id + ". removing from announcement");
            }
        }
        if (publish) {
            publishOwnDeviceId(ownDeviceIds);
        }
    }
}
Also used : AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

AxolotlAddress (org.whispersystems.libaxolotl.AxolotlAddress)10 HashSet (java.util.HashSet)3 Account (eu.siacs.conversations.entities.Account)2 Jid (eu.siacs.conversations.xmpp.jid.Jid)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IdentityKey (org.whispersystems.libaxolotl.IdentityKey)2 IdentityKeyPair (org.whispersystems.libaxolotl.IdentityKeyPair)2 ContentValues (android.content.ContentValues)1 Bundle (android.os.Bundle)1 Pair (android.util.Pair)1 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)1 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)1 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)1 File (java.io.File)1 Signature (java.security.Signature)1 X509Certificate (java.security.cert.X509Certificate)1 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)1 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)1