fixed some issues with jid escaping

This commit is contained in:
Daniel Gultsch 2018-03-11 18:32:16 +01:00
parent b2a9c63568
commit 72388e37f5
4 changed files with 15 additions and 16 deletions

View File

@ -58,14 +58,14 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
mRandom = new SecureRandom(); mRandom = new SecureRandom();
Button next = findViewById(R.id.create_account); Button next = findViewById(R.id.create_account);
next.setOnClickListener(v -> { next.setOnClickListener(v -> {
String username = mUsername.getText().toString(); try {
if (username.contains("@") || username.length() < 3) { String username = mUsername.getText().toString();
mUsername.setError(getString(R.string.invalid_username)); Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
mUsername.requestFocus(); if (!jid.getEscapedLocal().equals(jid.getLocal())|| username.length() < 3) {
} else { mUsername.setError(getString(R.string.invalid_username));
mUsername.setError(null); mUsername.requestFocus();
try { } else {
Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); mUsername.setError(null);
Account account = xmppConnectionService.findAccountByJid(jid); Account account = xmppConnectionService.findAccountByJid(jid);
if (account == null) { if (account == null) {
account = new Account(jid, createPassword()); 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(); Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
WelcomeActivity.addInviteUri(intent, getIntent()); WelcomeActivity.addInviteUri(intent, getIntent());
startActivity(intent); 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); mUsername.addTextChangedListener(this);
@ -114,7 +114,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
try { try {
mFullJidDisplay.setVisibility(View.VISIBLE); mFullJidDisplay.setVisibility(View.VISIBLE);
Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); 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) { } catch (IllegalArgumentException e) {
mFullJidDisplay.setVisibility(View.INVISIBLE); mFullJidDisplay.setVisibility(View.INVISIBLE);
} }

View File

@ -369,7 +369,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Bookmark bookmark = (Bookmark) conferences.get(position); Bookmark bookmark = (Bookmark) conferences.get(position);
Intent shareIntent = new Intent(); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND); 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"); shareIntent.setType("text/plain");
try { try {
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with))); startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));

View File

@ -151,9 +151,8 @@ public class Element {
final String jid = this.getAttribute(name); final String jid = this.getAttribute(name);
if (jid != null && !jid.isEmpty()) { if (jid != null && !jid.isEmpty()) {
try { try {
return Jid.of(jid); return Jid.ofEscaped(jid);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
Log.e(Config.LOGTAG, "could not parse jid " + jid);
return null; return null;
} }
} }

View File

@ -1020,7 +1020,7 @@ public class XmppConnection implements Runnable {
final Element jid = bind.findChild("jid"); final Element jid = bind.findChild("jid");
if (jid != null && jid.getContent() != null) { if (jid != null && jid.getContent() != null) {
try { try {
Jid assignedJid = Jid.of(jid.getContent()); Jid assignedJid = Jid.ofEscaped(jid.getContent());
if (!account.getJid().getDomain().equals(assignedJid.getDomain())) { if (!account.getJid().getDomain().equals(assignedJid.getDomain())) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": server tried to re-assign domain to "+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); throw new StateChangingError(Account.State.BIND_FAILURE);