1
0
Fork 1

verify hostname is valid before letting user save it

(cherry picked from commit 129f43a34991ea85c64f14e4874879fe7ddb1738)
This commit is contained in:
Daniel Gultsch 2020-08-01 15:03:20 +02:00 committed by Christian Schneppe
parent 738486fff0
commit a092514140
2 changed files with 17 additions and 6 deletions

View file

@ -32,10 +32,10 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import com.google.android.material.textfield.TextInputLayout;
import com.google.common.base.CharMatcher;
import org.openintents.openpgp.util.OpenPgpUtils;
@ -73,13 +73,13 @@ import eu.siacs.conversations.utils.TorServiceUtils;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.XmppConnection.Features;
import eu.siacs.conversations.xmpp.forms.Data;
import eu.siacs.conversations.xmpp.pep.Avatar;
import eu.siacs.conversations.xmpp.Jid;
import me.drakeet.support.toast.ToastCompat;
import static eu.siacs.conversations.utils.PermissionUtils.allGranted;
@ -201,12 +201,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
removeErrorsOnAllBut(binding.accountJidLayout);
return;
}
String hostname = null;
final String hostname;
int numericPort = 5222;
if (mShowOptions) {
hostname = binding.hostname.getText().toString().replaceAll("\\s", "");
final String port = binding.port.getText().toString().replaceAll("\\s", "");
if (hostname.contains(" ")) {
hostname = CharMatcher.whitespace().removeFrom(binding.hostname.getText());
final String port = CharMatcher.whitespace().removeFrom(binding.port.getText());
if (Resolver.invalidHostname(hostname)) {
binding.hostnameLayout.setError(getString(R.string.not_valid_hostname));
binding.hostname.requestFocus();
removeErrorsOnAllBut(binding.hostnameLayout);
@ -228,6 +228,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
return;
}
}
} else {
hostname = null;
}
if (jid.getLocal() == null) {

View file

@ -93,6 +93,15 @@ public class Resolver {
return happyEyeball(resolveNoSrvRecords(DNSName.from(hostname), port, true));
}
public static boolean invalidHostname(final String hostname) {
try {
DNSName.from(hostname);
return false;
} catch (IllegalArgumentException e) {
return true;
}
}
public static boolean useDirectTls(final int port) {
return port == 443 || port == 5223;