Search in sources :

Example 56 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class OtrService method verify.

@Override
public void verify(SessionID id, String fingerprint, boolean approved) {
    Log.d(Config.LOGTAG, "OtrService.verify(" + id.toString() + "," + fingerprint + "," + String.valueOf(approved) + ")");
    try {
        final Jid jid = Jid.fromSessionID(id);
        Conversation conversation = this.mXmppConnectionService.find(this.account, jid);
        if (conversation != null) {
            if (approved) {
                conversation.getContact().addOtrFingerprint(fingerprint);
            }
            conversation.smp().hint = null;
            conversation.smp().status = Conversation.Smp.STATUS_VERIFIED;
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.syncRosterToDisk(conversation.getAccount());
        }
    } catch (final InvalidJidException ignored) {
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation)

Example 57 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class AxolotlService method createSessionsIfNeeded.

public boolean createSessionsIfNeeded(final Conversation conversation) {
    final List<Jid> jidsWithEmptyDeviceList = getCryptoTargets(conversation);
    for (Iterator<Jid> iterator = jidsWithEmptyDeviceList.iterator(); iterator.hasNext(); ) {
        final Jid jid = iterator.next();
        if (!hasEmptyDeviceList(jid)) {
            iterator.remove();
        }
    }
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": createSessionsIfNeeded() - jids with empty device list: " + jidsWithEmptyDeviceList);
    if (jidsWithEmptyDeviceList.size() > 0) {
        fetchDeviceIds(jidsWithEmptyDeviceList, new OnMultipleDeviceIdFetched() {

            @Override
            public void fetched() {
                createSessionsIfNeededActual(conversation);
            }
        });
        return true;
    } else {
        return createSessionsIfNeededActual(conversation);
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid)

Example 58 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class AxolotlService method completeSession.

private void completeSession(XmppAxolotlSession session) {
    final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().toBareJid(), getOwnDeviceId());
    axolotlMessage.addDevice(session);
    try {
        Jid jid = Jid.fromString(session.getRemoteAddress().getName());
        MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateKeyTransportMessage(jid, axolotlMessage);
        mXmppConnectionService.sendMessagePacket(account, packet);
    } catch (InvalidJidException e) {
        throw new Error("Remote addresses are created from jid and should convert back to jid", e);
    }
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException)

Example 59 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class TrustKeysActivity method commitTrusts.

private void commitTrusts() {
    for (final String fingerprint : ownKeysToTrust.keySet()) {
        mAccount.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)));
    }
    List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
    synchronized (this.foreignKeysToTrust) {
        for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
            Jid jid = entry.getKey();
            Map<String, Boolean> value = entry.getValue();
            if (!acceptedTargets.contains(jid)) {
                acceptedTargets.add(jid);
            }
            for (final String fingerprint : value.keySet()) {
                mAccount.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(value.get(fingerprint)));
            }
        }
    }
    if (mConversation != null && mConversation.getMode() == Conversation.MODE_MULTI) {
        mConversation.setAcceptedCryptoTargets(acceptedTargets);
        xmppConnectionService.updateConversation(mConversation);
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class TrustKeysActivity method populateView.

private void populateView() {
    setTitle(getString(R.string.trust_omemo_fingerprints));
    binding.ownKeysDetails.removeAllViews();
    binding.foreignKeys.removeAllViews();
    boolean hasOwnKeys = false;
    boolean hasForeignKeys = false;
    for (final String fingerprint : ownKeysToTrust.keySet()) {
        hasOwnKeys = true;
        addFingerprintRowWithListeners(binding.ownKeysDetails, mAccount, fingerprint, false, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)), false, false, new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                ownKeysToTrust.put(fingerprint, isChecked);
            // own fingerprints have no impact on locked status.
            }
        });
    }
    synchronized (this.foreignKeysToTrust) {
        for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
            hasForeignKeys = true;
            KeysCardBinding keysCardBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.keys_card, binding.foreignKeys, false);
            // final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.keys_card, foreignKeys, false);
            final Jid jid = entry.getKey();
            keysCardBinding.foreignKeysTitle.setText(jid.toString());
            keysCardBinding.foreignKeysTitle.setOnClickListener(v -> switchToContactDetails(mAccount.getRoster().getContact(jid)));
            final Map<String, Boolean> fingerprints = entry.getValue();
            for (final String fingerprint : fingerprints.keySet()) {
                addFingerprintRowWithListeners(keysCardBinding.foreignKeysDetails, mAccount, fingerprint, false, FingerprintStatus.createActive(fingerprints.get(fingerprint)), false, false, (buttonView, isChecked) -> {
                    fingerprints.put(fingerprint, isChecked);
                    lockOrUnlockAsNeeded();
                });
            }
            if (fingerprints.size() == 0) {
                keysCardBinding.noKeysToAccept.setVisibility(View.VISIBLE);
                if (hasNoOtherTrustedKeys(jid)) {
                    if (!mAccount.getRoster().getContact(jid).mutualPresenceSubscription()) {
                        keysCardBinding.noKeysToAccept.setText(R.string.error_no_keys_to_trust_presence);
                    } else {
                        keysCardBinding.noKeysToAccept.setText(R.string.error_no_keys_to_trust_server_error);
                    }
                } else {
                    keysCardBinding.noKeysToAccept.setText(getString(R.string.no_keys_just_confirm, mAccount.getRoster().getContact(jid).getDisplayName()));
                }
            } else {
                keysCardBinding.noKeysToAccept.setVisibility(View.GONE);
            }
            binding.foreignKeys.addView(keysCardBinding.foreignKeysCard);
        }
    }
    if ((hasOwnKeys || foreignActuallyHasKeys()) && mUseCameraHintShown.compareAndSet(false, true)) {
        showCameraToast();
    }
    binding.ownKeysTitle.setText(mAccount.getJid().toBareJid().toString());
    binding.ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE);
    binding.foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE);
    if (hasPendingKeyFetches()) {
        setFetching();
        lock();
    } else {
        if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
            binding.keyErrorMessageCard.setVisibility(View.VISIBLE);
            if (lastFetchReport == AxolotlService.FetchStatus.ERROR || mAccount.getAxolotlService().fetchMapHasErrors(contactJids)) {
                if (anyWithoutMutualPresenceSubscription(contactJids)) {
                    binding.keyErrorMessage.setText(R.string.error_no_keys_to_trust_presence);
                } else {
                    binding.keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error);
                }
            } else {
                binding.keyErrorMessage.setText(R.string.error_no_keys_to_trust);
            }
            binding.ownKeysDetails.removeAllViews();
            binding.ownKeysCard.setVisibility(View.GONE);
            binding.foreignKeys.removeAllViews();
            binding.foreignKeys.setVisibility(View.GONE);
        }
        lockOrUnlockAsNeeded();
        setDone();
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) KeysCardBinding(de.pixart.messenger.databinding.KeysCardBinding) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Map(java.util.Map) CompoundButton(android.widget.CompoundButton)

Aggregations

Jid (de.pixart.messenger.xmpp.jid.Jid)75 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)26 Account (de.pixart.messenger.entities.Account)24 Element (de.pixart.messenger.xml.Element)19 Conversation (de.pixart.messenger.entities.Conversation)18 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)15 Contact (de.pixart.messenger.entities.Contact)14 MucOptions (de.pixart.messenger.entities.MucOptions)11 ArrayList (java.util.ArrayList)11 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)8 Message (de.pixart.messenger.entities.Message)7 Intent (android.content.Intent)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)6 Bookmark (de.pixart.messenger.entities.Bookmark)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 AlertDialog (android.support.v7.app.AlertDialog)3 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)3 HashMap (java.util.HashMap)3