From 72388e37f564a61870647b48c42ce01210219210 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 11 Mar 2018 18:32:16 +0100 Subject: [PATCH] fixed some issues with jid escaping --- .../conversations/ui/MagicCreateActivity.java | 24 +++++++++---------- .../ui/StartConversationActivity.java | 2 +- .../eu/siacs/conversations/xml/Element.java | 3 +-- .../conversations/xmpp/XmppConnection.java | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java index 0c5e6cd39..532719053 100644 --- a/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java @@ -58,14 +58,14 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { 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.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + try { + String username = mUsername.getText().toString(); + Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + if (!jid.getEscapedLocal().equals(jid.getLocal())|| username.length() < 3) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); + } else { + mUsername.setError(null); Account account = xmppConnectionService.findAccountByJid(jid); if (account == null) { account = new Account(jid, createPassword()); @@ -81,10 +81,10 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show(); WelcomeActivity.addInviteUri(intent, getIntent()); startActivity(intent); - } catch (IllegalArgumentException e) { - mUsername.setError(getString(R.string.invalid_username)); - mUsername.requestFocus(); } + } catch (IllegalArgumentException e) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); } }); mUsername.addTextChangedListener(this); @@ -114,7 +114,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { try { mFullJidDisplay.setVisibility(View.VISIBLE); Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); - mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString())); + mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString())); } catch (IllegalArgumentException e) { mFullJidDisplay.setVisibility(View.INVISIBLE); } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 3836f6015..a01265ef4 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -369,7 +369,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU Bookmark bookmark = (Bookmark) conferences.get(position); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); - shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toString() + "?join"); + shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toEscapedString() + "?join"); shareIntent.setType("text/plain"); try { startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with))); diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index 1e4c2be1c..94ff6c564 100644 --- a/src/main/java/eu/siacs/conversations/xml/Element.java +++ b/src/main/java/eu/siacs/conversations/xml/Element.java @@ -151,9 +151,8 @@ public class Element { final String jid = this.getAttribute(name); if (jid != null && !jid.isEmpty()) { try { - return Jid.of(jid); + return Jid.ofEscaped(jid); } catch (final IllegalArgumentException e) { - Log.e(Config.LOGTAG, "could not parse jid " + jid); return null; } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 6617ae982..e9cee23fe 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1020,7 +1020,7 @@ public class XmppConnection implements Runnable { final Element jid = bind.findChild("jid"); if (jid != null && jid.getContent() != null) { try { - Jid assignedJid = Jid.of(jid.getContent()); + Jid assignedJid = Jid.ofEscaped(jid.getContent()); if (!account.getJid().getDomain().equals(assignedJid.getDomain())) { Log.d(Config.LOGTAG,account.getJid().asBareJid()+": server tried to re-assign domain to "+assignedJid.getDomain()); throw new StateChangingError(Account.State.BIND_FAILURE);