Search in sources :

Example 61 with Jid

use of de.pixart.messenger.xmpp.jid.Jid 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 62 with Jid

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

the class UriHandlerActivity method handleUri.

private void handleUri(Uri uri) {
    final Intent intent;
    final XmppUri xmppUri = new XmppUri(uri);
    // TODO only look at enabled accounts
    final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids();
    if (accounts.size() == 0) {
        intent = new Intent(getApplicationContext(), WelcomeActivity.class);
        WelcomeActivity.addInviteUri(intent, xmppUri);
        startActivity(intent);
        return;
    }
    if (xmppUri.isAction(XmppUri.ACTION_MESSAGE)) {
        final Jid jid = xmppUri.getJid();
        final String body = xmppUri.getBody();
        if (jid != null) {
            intent = new Intent(getApplicationContext(), ShareViaAccountActivity.class);
            intent.putExtra(ShareViaAccountActivity.EXTRA_CONTACT, jid.toString());
            intent.putExtra(ShareViaAccountActivity.EXTRA_BODY, body);
        } else {
            intent = new Intent(getApplicationContext(), ShareWithActivity.class);
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, body);
        }
    } else if (accounts.contains(xmppUri.getJid())) {
        intent = new Intent(getApplicationContext(), EditAccountActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.putExtra("jid", xmppUri.getJid().toBareJid().toString());
        intent.setData(uri);
    } else if (xmppUri.isJidValid()) {
        intent = new Intent(getApplicationContext(), StartConversationActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.setData(uri);
    } else {
        Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
        return;
    }
    startActivity(intent);
}
Also used : XmppUri(de.pixart.messenger.utils.XmppUri) Jid(de.pixart.messenger.xmpp.jid.Jid) Intent(android.content.Intent)

Example 63 with Jid

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

the class MagicCreateActivity method afterTextChanged.

@Override
public void afterTextChanged(Editable s) {
    if (s.toString().trim().length() > 0) {
        try {
            mFullJidDisplay.setVisibility(View.VISIBLE);
            Jid jid = Jid.fromParts(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
            mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString()));
        } catch (InvalidJidException e) {
            mFullJidDisplay.setVisibility(View.INVISIBLE);
        }
    } else {
        mFullJidDisplay.setVisibility(View.INVISIBLE);
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException)

Example 64 with Jid

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

the class ConversationFragment method sendMessage.

private void sendMessage() {
    final String body = binding.textinput.getText().toString();
    final Conversation conversation = this.conversation;
    if (body.length() == 0 || conversation == null) {
        return;
    }
    final Message message;
    if (conversation.getCorrectingMessage() == null) {
        message = new Message(conversation, body, conversation.getNextEncryption());
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            final Jid nextCounterpart = conversation.getNextCounterpart();
            if (nextCounterpart != null) {
                message.setCounterpart(nextCounterpart);
                message.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(nextCounterpart));
                message.setType(Message.TYPE_PRIVATE);
            }
        }
    } else {
        message = conversation.getCorrectingMessage();
        message.setBody(body);
        message.setEdited(message.getUuid());
        message.setUuid(UUID.randomUUID().toString());
    }
    switch(message.getConversation().getNextEncryption()) {
        case Message.ENCRYPTION_OTR:
            sendOtrMessage(message);
            break;
        case Message.ENCRYPTION_PGP:
            sendPgpMessage(message);
            break;
        case Message.ENCRYPTION_AXOLOTL:
            if (!trustKeysIfNeeded(REQUEST_TRUST_KEYS_TEXT)) {
                sendAxolotlMessage(message);
            }
            break;
        default:
            sendPlainTextMessage(message);
    }
}
Also used : EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) Jid(de.pixart.messenger.xmpp.jid.Jid) Conversation(de.pixart.messenger.entities.Conversation)

Example 65 with Jid

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

the class MagicCreateActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    if (getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.magic_create);
    mFullJidDisplay = findViewById(R.id.full_jid);
    mUsername = findViewById(R.id.username);
    mRandom = new SecureRandom();
    Button next = findViewById(R.id.create_account);
    next.setOnClickListener(v -> {
        String username = mUsername.getText().toString();
        if (username.contains("@") || username.length() < 3) {
            mUsername.setError(getString(R.string.invalid_username));
            mUsername.requestFocus();
        } else {
            mUsername.setError(null);
            try {
                Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
                Account account = xmppConnectionService.findAccountByJid(jid);
                if (account == null) {
                    account = new Account(jid, createPassword());
                    account.setOption(Account.OPTION_REGISTER, true);
                    account.setOption(Account.OPTION_DISABLED, true);
                    account.setOption(Account.OPTION_MAGIC_CREATE, true);
                    xmppConnectionService.createAccount(account);
                }
                Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
                intent.putExtra("jid", account.getJid().toBareJid().toString());
                intent.putExtra("init", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
                WelcomeActivity.addInviteUri(intent, getIntent());
                startActivity(intent);
            } catch (InvalidJidException e) {
                mUsername.setError(getString(R.string.invalid_username));
                mUsername.requestFocus();
            }
        }
    });
    mUsername.addTextChangedListener(this);
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Button(android.widget.Button) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) SecureRandom(java.security.SecureRandom) Intent(android.content.Intent)

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