Search in sources :

Example 81 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class AxolotlService method publishBundlesIfNeeded.

public void publishBundlesIfNeeded(final boolean announce, final boolean wipe) {
    if (pepBroken) {
        Log.d(Config.LOGTAG, getLogprefix(account) + "publishBundlesIfNeeded called, but PEP is broken. Ignoring... ");
        return;
    }
    if (account.getXmppConnection().getFeatures().pepPublishOptions()) {
        this.changeAccessMode.set(account.isOptionSet(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE));
    } else {
        if (account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE, true)) {
            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server doesn’t support publish-options. setting for later access mode change");
            mXmppConnectionService.databaseBackend.updateAccount(account);
        }
    }
    if (this.changeAccessMode.get()) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server gained publish-options capabilities. changing access model");
    }
    IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(account.getJid().toBareJid(), getOwnDeviceId());
    mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                // ignore timeout. do nothing
                return;
            }
            if (packet.getType() == IqPacket.TYPE.ERROR) {
                Element error = packet.findChild("error");
                if (error == null || !error.hasChild("item-not-found")) {
                    pepBroken = true;
                    Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "request for device bundles came back with something other than item-not-found" + packet);
                    return;
                }
            }
            PreKeyBundle bundle = mXmppConnectionService.getIqParser().bundle(packet);
            Map<Integer, ECPublicKey> keys = mXmppConnectionService.getIqParser().preKeyPublics(packet);
            boolean flush = false;
            if (bundle == null) {
                Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received invalid bundle:" + packet);
                bundle = new PreKeyBundle(-1, -1, -1, null, -1, null, null, null);
                flush = true;
            }
            if (keys == null) {
                Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received invalid prekeys:" + packet);
            }
            try {
                boolean changed = false;
                // Validate IdentityKey
                IdentityKeyPair identityKeyPair = axolotlStore.getIdentityKeyPair();
                if (flush || !identityKeyPair.getPublicKey().equals(bundle.getIdentityKey())) {
                    Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding own IdentityKey " + identityKeyPair.getPublicKey() + " to PEP.");
                    changed = true;
                }
                // Validate signedPreKeyRecord + ID
                SignedPreKeyRecord signedPreKeyRecord;
                int numSignedPreKeys = axolotlStore.getSignedPreKeysCount();
                try {
                    signedPreKeyRecord = axolotlStore.loadSignedPreKey(bundle.getSignedPreKeyId());
                    if (flush || !bundle.getSignedPreKey().equals(signedPreKeyRecord.getKeyPair().getPublicKey()) || !Arrays.equals(bundle.getSignedPreKeySignature(), signedPreKeyRecord.getSignature())) {
                        Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding new signedPreKey with ID " + (numSignedPreKeys + 1) + " to PEP.");
                        signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKeyPair, numSignedPreKeys + 1);
                        axolotlStore.storeSignedPreKey(signedPreKeyRecord.getId(), signedPreKeyRecord);
                        changed = true;
                    }
                } catch (InvalidKeyIdException e) {
                    Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding new signedPreKey with ID " + (numSignedPreKeys + 1) + " to PEP.");
                    signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKeyPair, numSignedPreKeys + 1);
                    axolotlStore.storeSignedPreKey(signedPreKeyRecord.getId(), signedPreKeyRecord);
                    changed = true;
                }
                // Validate PreKeys
                Set<PreKeyRecord> preKeyRecords = new HashSet<>();
                if (keys != null) {
                    for (Integer id : keys.keySet()) {
                        try {
                            PreKeyRecord preKeyRecord = axolotlStore.loadPreKey(id);
                            if (preKeyRecord.getKeyPair().getPublicKey().equals(keys.get(id))) {
                                preKeyRecords.add(preKeyRecord);
                            }
                        } catch (InvalidKeyIdException ignored) {
                        }
                    }
                }
                int newKeys = NUM_KEYS_TO_PUBLISH - preKeyRecords.size();
                if (newKeys > 0) {
                    List<PreKeyRecord> newRecords = KeyHelper.generatePreKeys(axolotlStore.getCurrentPreKeyId() + 1, newKeys);
                    preKeyRecords.addAll(newRecords);
                    for (PreKeyRecord record : newRecords) {
                        axolotlStore.storePreKey(record.getId(), record);
                    }
                    changed = true;
                    Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding " + newKeys + " new preKeys to PEP.");
                }
                if (changed || changeAccessMode.get()) {
                    if (account.getPrivateKeyAlias() != null && Config.X509_VERIFICATION) {
                        mXmppConnectionService.publishDisplayName(account);
                        publishDeviceVerificationAndBundle(signedPreKeyRecord, preKeyRecords, announce, wipe);
                    } else {
                        publishDeviceBundle(signedPreKeyRecord, preKeyRecords, announce, wipe);
                    }
                } else {
                    Log.d(Config.LOGTAG, getLogprefix(account) + "Bundle " + getOwnDeviceId() + " in PEP was current");
                    if (wipe) {
                        wipeOtherPepDevices();
                    } else if (announce) {
                        Log.d(Config.LOGTAG, getLogprefix(account) + "Announcing device " + getOwnDeviceId());
                        publishOwnDeviceIdIfNeeded();
                    }
                }
            } catch (InvalidKeyException e) {
                Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to publish bundle " + getOwnDeviceId() + ", reason: " + e.getMessage());
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Set(java.util.Set) HashSet(java.util.HashSet) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) PreKeyBundle(org.whispersystems.libsignal.state.PreKeyBundle) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) List(java.util.List) ArrayList(java.util.ArrayList) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Map(java.util.Map) HashMap(java.util.HashMap) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord)

Example 82 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppActivity method inviteUser.

private void inviteUser() {
    Account mAccount = xmppConnectionService.getAccounts().get(0);
    String user = mAccount.getJid().getLocalpart().toString();
    String domain = mAccount.getJid().getDomainpart().toString();
    String inviteURL = Config.inviteUserURL + user + "/" + domain;
    String inviteText = getString(R.string.InviteText, user);
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, user + " " + getString(R.string.inviteUser_Subject) + " " + getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_TEXT, inviteText + "\n\n" + inviteURL);
    startActivity(Intent.createChooser(intent, getString(R.string.invite_contact)));
}
Also used : Account(de.pixart.messenger.entities.Account) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 83 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_invite_user:
            inviteUser();
            break;
        case R.id.action_create_issue:
            createIssue();
            break;
        case R.id.action_settings:
            startActivity(new Intent(this, SettingsActivity.class));
            break;
        case R.id.action_accounts:
            if (xmppConnectionService.getAccounts().size() == 1 && !xmppConnectionService.multipleAccounts()) {
                final Intent intent = new Intent(getApplicationContext(), EditAccountActivity.class);
                Account mAccount = xmppConnectionService.getAccounts().get(0);
                intent.putExtra("jid", mAccount.getJid().toBareJid().toString());
                intent.putExtra("init", false);
                startActivity(intent);
            } else {
                final Intent intent = new Intent(getApplicationContext(), ManageAccountActivity.class);
                startActivity(intent);
            }
            break;
        case android.R.id.home:
            finish();
            break;
        case R.id.action_show_qr_code:
            showQrCode();
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : Account(de.pixart.messenger.entities.Account) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 84 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class OmemoActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Object account = v.getTag(R.id.TAG_ACCOUNT);
    Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
    Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
    if (account != null && fingerprint != null && account instanceof Account && fingerprintStatus != null && fingerprint instanceof String && fingerprintStatus instanceof FingerprintStatus) {
        getMenuInflater().inflate(R.menu.omemo_key_context, menu);
        MenuItem distrust = menu.findItem(R.id.distrust_key);
        MenuItem verifyScan = menu.findItem(R.id.verify_scan);
        if (this instanceof TrustKeysActivity) {
            distrust.setVisible(false);
            verifyScan.setVisible(false);
        } else {
            FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
            if (!status.isActive() || status.isVerified()) {
                verifyScan.setVisible(false);
            }
            distrust.setVisible(status.isVerified() || (!status.isActive() && status.isTrusted()));
        }
        this.mSelectedAccount = (Account) account;
        this.mSelectedFingerprint = (String) fingerprint;
    }
}
Also used : Account(de.pixart.messenger.entities.Account) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) MenuItem(android.view.MenuItem)

Example 85 with Account

use of de.pixart.messenger.entities.Account 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)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6