Search in sources :

Example 11 with AxolotlService

use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.

the class Account method initAccountServices.

public void initAccountServices(final XmppConnectionService context) {
    this.mOtrService = new OtrService(context, this);
    this.axolotlService = new AxolotlService(this, context);
    this.pgpDecryptionService = new PgpDecryptionService(context);
    if (xmppConnection != null) {
        xmppConnection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
}
Also used : AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) OtrService(de.pixart.messenger.crypto.OtrService) PgpDecryptionService(de.pixart.messenger.crypto.PgpDecryptionService)

Example 12 with AxolotlService

use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.

the class TrustKeysActivity method reloadFingerprints.

private boolean reloadFingerprints() {
    List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
    ownKeysToTrust.clear();
    AxolotlService service = this.mAccount.getAxolotlService();
    Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided());
    for (final IdentityKey identityKey : ownKeysSet) {
        final String fingerprint = CryptoHelper.bytesToHex(identityKey.getPublicKey().serialize());
        if (!ownKeysToTrust.containsKey(fingerprint)) {
            ownKeysToTrust.put(fingerprint, false);
        }
    }
    synchronized (this.foreignKeysToTrust) {
        foreignKeysToTrust.clear();
        for (Jid jid : contactJids) {
            Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), jid);
            if (hasNoOtherTrustedKeys(jid) && ownKeysSet.size() == 0) {
                foreignKeysSet.addAll(service.getKeysWithTrust(FingerprintStatus.createActive(false), jid));
            }
            Map<String, Boolean> foreignFingerprints = new HashMap<>();
            for (final IdentityKey identityKey : foreignKeysSet) {
                final String fingerprint = CryptoHelper.bytesToHex(identityKey.getPublicKey().serialize());
                if (!foreignFingerprints.containsKey(fingerprint)) {
                    foreignFingerprints.put(fingerprint, false);
                }
            }
            if (foreignFingerprints.size() > 0 || !acceptedTargets.contains(jid)) {
                foreignKeysToTrust.put(jid, foreignFingerprints);
            }
        }
    }
    return ownKeysSet.size() + foreignKeysToTrust.size() > 0;
}
Also used : AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) IdentityKey(org.whispersystems.libsignal.IdentityKey) Jid(de.pixart.messenger.xmpp.jid.Jid) HashMap(java.util.HashMap) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 13 with AxolotlService

use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method updateSnackBar.

private void updateSnackBar(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final XmppConnection connection = account.getXmppConnection();
    final Contact contact = conversation.getContact();
    final int mode = conversation.getMode();
    if (account.getStatus() == Account.State.DISABLED) {
        showSnackbar(R.string.this_account_is_disabled, R.string.enable, this.mEnableAccountListener);
    } else if (conversation.isBlocked()) {
        showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
    } else if (contact != null && !contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
        showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener, this.mLongPressBlockListener);
    } else if (contact != null && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
        showSnackbar(R.string.contact_asks_for_presence_subscription, R.string.allow, this.mAllowPresenceSubscription, this.mLongPressBlockListener);
    } else if (mode == Conversation.MODE_MULTI && !conversation.getMucOptions().online() && account.getStatus() == Account.State.ONLINE) {
        switch(conversation.getMucOptions().getError()) {
            case NICK_IN_USE:
                showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
                break;
            case NO_RESPONSE:
                showSnackbar(R.string.joining_conference, 0, null);
                break;
            case SERVER_NOT_FOUND:
                if (conversation.receivedMessagesCount() > 0) {
                    showSnackbar(R.string.remote_server_not_found, R.string.try_again, joinMuc);
                } else {
                    showSnackbar(R.string.remote_server_not_found, R.string.leave, leaveMuc);
                }
                break;
            case PASSWORD_REQUIRED:
                showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
                break;
            case BANNED:
                showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
                break;
            case MEMBERS_ONLY:
                showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
                break;
            case KICKED:
                showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
                break;
            case UNKNOWN:
                showSnackbar(R.string.conference_unknown_error, R.string.leave, leaveMuc);
                break;
            case INVALID_NICK:
                showSnackbar(R.string.invalid_muc_nick, R.string.edit, clickToMuc);
            case SHUTDOWN:
                showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc);
                break;
            default:
                hideSnackbar();
                break;
        }
    } else if ((mode == Conversation.MODE_MULTI && !conversation.getMucOptions().participating())) {
        showSnackbar(R.string.no_write_access_in_public_muc, R.string.ok, clickToMuc);
    } else if (account.hasPendingPgpIntent(conversation)) {
        showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
    } else if (mode == Conversation.MODE_SINGLE && conversation.smpRequested()) {
        showSnackbar(R.string.smp_requested, R.string.verify, this.mAnswerSmpClickListener);
    } else if (mode == Conversation.MODE_SINGLE && conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!conversation.isOtrFingerprintVerified())) {
        showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
    } else if (connection != null && connection.getFeatures().blocking() && conversation.countMessages() != 0 && !conversation.isBlocked() && conversation.isWithStranger()) {
        showSnackbar(R.string.received_message_from_stranger, R.string.block, mBlockClickListener);
    } else if (activity.xmppConnectionService.warnUnecryptedChat()) {
        AxolotlService axolotlService = account.getAxolotlService();
        if ((mode == Conversation.MODE_SINGLE) && (conversation.getNextEncryption() == Message.ENCRYPTION_NONE && ((Config.supportOmemo() && axolotlService != null && conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) || (Config.supportOpenPgp() && account.isPgpDecryptionServiceConnected()) || Config.supportOtr()))) {
            if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomainpart())) {
                hideSnackbar();
            } else {
                showSnackbar(R.string.conversation_unencrypted_hint, R.string.ok, mHideUnencryptionHint, null);
            }
        } else if ((mode == Conversation.MODE_MULTI && conversation.getMucOptions().membersOnly() && conversation.getMucOptions().nonanonymous()) && (conversation.getNextEncryption() == Message.ENCRYPTION_NONE && ((Config.supportOmemo() && axolotlService != null && conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) || (Config.supportOpenPgp() && account.isPgpDecryptionServiceConnected())))) {
            if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomainpart())) {
                Log.d(Config.LOGTAG, "Don't show unencrypted warning because " + conversation.getJid().toString() + " is on exception list");
                hideSnackbar();
            } else {
                showSnackbar(R.string.conversation_unencrypted_hint, R.string.ok, mHideUnencryptionHint, null);
            }
        } else {
            hideSnackbar();
        }
    } else {
        hideSnackbar();
    }
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) Account(de.pixart.messenger.entities.Account) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) SuppressLint(android.annotation.SuppressLint) Contact(de.pixart.messenger.entities.Contact)

Example 14 with AxolotlService

use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method fetchConferenceMembers.

private void fetchConferenceMembers(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final AxolotlService axolotlService = account.getAxolotlService();
    final String[] affiliations = { "member", "admin", "owner" };
    OnIqPacketReceived callback = new OnIqPacketReceived() {

        private int i = 0;

        private boolean success = true;

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element query = packet.query("http://jabber.org/protocol/muc#admin");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                for (Element child : query.getChildren()) {
                    if ("item".equals(child.getName())) {
                        MucOptions.User user = AbstractParser.parseItem(conversation, child);
                        if (!user.realJidMatchesAccount()) {
                            boolean isNew = conversation.getMucOptions().updateUser(user);
                            Contact contact = user.getContact();
                            if (isNew && user.getRealJid() != null && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
                                axolotlService.fetchDeviceIds(user.getRealJid());
                            }
                        }
                    }
                }
            } else {
                success = false;
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().toBareJid());
            }
            ++i;
            if (i >= affiliations.length) {
                List<Jid> members = conversation.getMucOptions().getMembers();
                if (success) {
                    List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
                    boolean changed = false;
                    for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
                        Jid jid = iterator.next();
                        if (!members.contains(jid)) {
                            iterator.remove();
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
                            changed = true;
                        }
                    }
                    if (changed) {
                        conversation.setAcceptedCryptoTargets(cryptoTargets);
                        updateConversation(conversation);
                    }
                }
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved members for " + conversation.getJid().toBareJid() + ": " + conversation.getMucOptions().getMembers());
                getAvatarService().clear(conversation);
                updateMucRosterUi();
                updateConversationUi();
            }
        }
    };
    for (String affiliation : affiliations) {
        sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
    }
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching members for " + conversation.getName());
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Contact(de.pixart.messenger.entities.Contact) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) MucOptions(de.pixart.messenger.entities.MucOptions)

Example 15 with AxolotlService

use of de.pixart.messenger.crypto.axolotl.AxolotlService in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method createConnection.

public XmppConnection createConnection(final Account account) {
    final XmppConnection connection = new XmppConnection(account, this);
    connection.setOnMessagePacketReceivedListener(this.mMessageParser);
    connection.setOnStatusChangedListener(this.statusListener);
    connection.setOnPresencePacketReceivedListener(this.mPresenceParser);
    connection.setOnUnregisteredIqPacketReceivedListener(this.mIqParser);
    connection.setOnJinglePacketReceivedListener(this.jingleListener);
    connection.setOnBindListener(this.mOnBindListener);
    connection.setOnMessageAcknowledgeListener(this.mOnMessageAcknowledgedListener);
    connection.addOnAdvancedStreamFeaturesAvailableListener(this.mMessageArchiveService);
    connection.addOnAdvancedStreamFeaturesAvailableListener(this.mAvatarService);
    AxolotlService axolotlService = account.getAxolotlService();
    if (axolotlService != null) {
        connection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
    return connection;
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService)

Aggregations

AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)17 Jid (de.pixart.messenger.xmpp.jid.Jid)7 Element (de.pixart.messenger.xml.Element)5 Contact (de.pixart.messenger.entities.Contact)4 XmppUri (de.pixart.messenger.utils.XmppUri)3 XmppConnection (de.pixart.messenger.xmpp.XmppConnection)3 Avatar (de.pixart.messenger.xmpp.pep.Avatar)3 SuppressLint (android.annotation.SuppressLint)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 ActionBar (android.support.v7.app.ActionBar)2 AlertDialog (android.support.v7.app.AlertDialog)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageButton (android.widget.ImageButton)2 FingerprintStatus (de.pixart.messenger.crypto.axolotl.FingerprintStatus)2 Account (de.pixart.messenger.entities.Account)2 Activity (android.app.Activity)1 Builder (android.app.AlertDialog.Builder)1