support registration via pars tokens

This commit is contained in:
Daniel Gultsch 2020-01-09 14:13:05 +01:00
parent 387e32cf8e
commit d039c4870f
11 changed files with 280 additions and 165 deletions

View File

@ -2,7 +2,9 @@ package eu.siacs.conversations.ui;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.View; import android.view.View;
@ -15,14 +17,19 @@ import java.security.SecureRandom;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.MagicCreateBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class MagicCreateActivity extends XmppActivity implements TextWatcher { public class MagicCreateActivity extends XmppActivity implements TextWatcher {
private TextView mFullJidDisplay; public static final String EXTRA_DOMAIN = "domain";
private EditText mUsername; public static final String EXTRA_PRE_AUTH = "pre_auth";
private MagicCreateBinding binding;
private String domain;
private String preAuth;
@Override @Override
protected void refreshUiReal() { protected void refreshUiReal() {
@ -45,31 +52,43 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
final Intent data = getIntent();
this.domain = data == null ? null : data.getStringExtra(EXTRA_DOMAIN);
this.preAuth = data == null ? null : data.getStringExtra(EXTRA_PRE_AUTH);
if (getResources().getBoolean(R.bool.portrait_only)) { if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.magic_create); this.binding = DataBindingUtil.setContentView(this, R.layout.magic_create);
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar((Toolbar) this.binding.toolbar);
configureActionBar(getSupportActionBar()); configureActionBar(getSupportActionBar(), this.domain == null);
mFullJidDisplay = findViewById(R.id.full_jid); if (domain != null) {
mUsername = findViewById(R.id.username); binding.instructions.setText(getString(R.string.magic_create_text_on_x, domain));
Button next = findViewById(R.id.create_account); binding.finePrint.setVisibility(View.INVISIBLE);
next.setOnClickListener(v -> { }
binding.createAccount.setOnClickListener(v -> {
try { try {
String username = mUsername.getText().toString(); final String username = binding.username.getText().toString();
Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); final Jid jid;
if (!jid.getEscapedLocal().equals(jid.getLocal())|| username.length() < 3) { if (this.domain == null) {
mUsername.setError(getString(R.string.invalid_username)); jid = Jid.ofLocalAndDomain(username, Config.MAGIC_CREATE_DOMAIN);
mUsername.requestFocus();
} else { } else {
mUsername.setError(null); jid = Jid.ofLocalAndDomain(username, this.domain);
}
if (!jid.getEscapedLocal().equals(jid.getLocal()) || username.length() < 3) {
binding.username.setError(getString(R.string.invalid_username));
binding.username.requestFocus();
} else {
binding.username.setError(null);
Account account = xmppConnectionService.findAccountByJid(jid); Account account = xmppConnectionService.findAccountByJid(jid);
if (account == null) { if (account == null) {
account = new Account(jid, CryptoHelper.createPassword(new SecureRandom())); account = new Account(jid, CryptoHelper.createPassword(new SecureRandom()));
account.setOption(Account.OPTION_REGISTER, true); account.setOption(Account.OPTION_REGISTER, true);
account.setOption(Account.OPTION_DISABLED, true); account.setOption(Account.OPTION_DISABLED, true);
account.setOption(Account.OPTION_MAGIC_CREATE, true); account.setOption(Account.OPTION_MAGIC_CREATE, true);
if (this.preAuth != null) {
account.setKey(Account.PRE_AUTH_REGISTRATION_TOKEN, this.preAuth);
}
xmppConnectionService.createAccount(account); xmppConnectionService.createAccount(account);
} }
Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class); Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
@ -81,11 +100,11 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
startActivity(intent); startActivity(intent);
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
mUsername.setError(getString(R.string.invalid_username)); binding.username.setError(getString(R.string.invalid_username));
mUsername.requestFocus(); binding.username.requestFocus();
} }
}); });
mUsername.addTextChangedListener(this); binding.username.addTextChangedListener(this);
} }
@Override @Override
@ -102,15 +121,20 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (s.toString().trim().length() > 0) { if (s.toString().trim().length() > 0) {
try { try {
mFullJidDisplay.setVisibility(View.VISIBLE); binding.fullJid.setVisibility(View.VISIBLE);
Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); final Jid jid;
mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString())); if (this.domain == null) {
jid = Jid.ofLocalAndDomain(s.toString(), Config.MAGIC_CREATE_DOMAIN);
} else {
jid = Jid.ofLocalAndDomain(s.toString(), this.domain);
}
binding.fullJid.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
mFullJidDisplay.setVisibility(View.INVISIBLE); binding.fullJid.setVisibility(View.INVISIBLE);
} }
} else { } else {
mFullJidDisplay.setVisibility(View.INVISIBLE); binding.fullJid.setVisibility(View.INVISIBLE);
} }
} }
} }

View File

@ -8,6 +8,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.ConversationsActivity; import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.ui.EditAccountActivity; import eu.siacs.conversations.ui.EditAccountActivity;
import eu.siacs.conversations.ui.MagicCreateActivity;
import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.ManageAccountActivity;
import eu.siacs.conversations.ui.PickServerActivity; import eu.siacs.conversations.ui.PickServerActivity;
import eu.siacs.conversations.ui.StartConversationActivity; import eu.siacs.conversations.ui.StartConversationActivity;
@ -15,6 +16,17 @@ import eu.siacs.conversations.ui.WelcomeActivity;
public class SignupUtils { public class SignupUtils {
public static boolean isSupportTokenRegistry() {
return true;
}
public static Intent getTokenRegistrationIntent(final Activity activity, String domain, String preauth) {
final Intent intent = new Intent(activity, MagicCreateActivity.class);
intent.putExtra(MagicCreateActivity.EXTRA_DOMAIN, domain);
intent.putExtra(MagicCreateActivity.EXTRA_PRE_AUTH, preauth);
return intent;
}
public static Intent getSignUpIntent(final Activity activity) { public static Intent getSignUpIntent(final Activity activity) {
return getSignUpIntent(activity, false); return getSignUpIntent(activity, false);
} }

View File

@ -1,55 +1,64 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <layout xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/toolbar" /> <include layout="@layout/toolbar" android:id="@+id/toolbar"/>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fillViewport="true"> android:fillViewport="true">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:background="?attr/color_background_primary"> android:background="?attr/color_background_primary">
<LinearLayout <LinearLayout
android:id="@+id/linearLayout" android:id="@+id/linearLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:minHeight="256dp" android:minHeight="256dp"
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp"> android:paddingRight="16dp"
android:paddingBottom="10dp">
<Space <Space
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"/> android:layout_weight="1" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/pick_your_username" android:text="@string/pick_your_username"
android:textAppearance="@style/TextAppearance.Conversations.Title"/> android:textAppearance="@style/TextAppearance.Conversations.Title" />
<TextView <TextView
android:id="@+id/instructions"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/magic_create_text" android:text="@string/magic_create_text"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/> android:textAppearance="@style/TextAppearance.Conversations.Body1" />
<EditText <EditText
android:id="@+id/username" android:id="@+id/username"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:hint="@string/username_hint" android:hint="@string/username_hint"
android:inputType="textNoSuggestions"/> android:inputType="textNoSuggestions" />
<TextView <TextView
android:id="@+id/full_jid" android:id="@+id/full_jid"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -57,7 +66,8 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/your_full_jid_will_be" android:text="@string/your_full_jid_will_be"
android:textAppearance="@style/TextAppearance.Conversations.Caption" android:textAppearance="@style/TextAppearance.Conversations.Caption"
android:visibility="invisible"/> android:visibility="invisible" />
<Button <Button
android:id="@+id/create_account" android:id="@+id/create_account"
style="@style/Widget.Conversations.Button.Borderless" style="@style/Widget.Conversations.Button.Borderless"
@ -65,33 +75,38 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="right"
android:text="@string/next" android:text="@string/next"
android:textColor="?colorAccent"/> android:textColor="?colorAccent" />
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@+id/linearLayout" android:layout_above="@+id/linearLayout"
android:layout_alignParentLeft="true" android:layout_alignParentStart="true"
android:layout_alignParentStart="true"> android:layout_alignParentLeft="true">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/main_logo"/> android:src="@drawable/main_logo" />
</RelativeLayout> </RelativeLayout>
<TextView <TextView
android:paddingLeft="8dp" android:id="@+id/fine_print"
android:paddingRight="8dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:textColor="?android:textColorSecondary" android:layout_centerHorizontal="true"
android:textSize="@dimen/fineprint_size"
android:maxLines="1" android:maxLines="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/free_for_six_month" android:text="@string/free_for_six_month"
android:layout_centerHorizontal="true"/> android:textColor="?android:textColorSecondary"
android:textSize="@dimen/fineprint_size" />
</RelativeLayout> </RelativeLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>
</layout>

View File

@ -5,5 +5,5 @@
<string name="create_new_account">Create new account</string> <string name="create_new_account">Create new account</string>
<string name="do_you_have_an_account">Do you already have an XMPP account? This might be the case if you are already using a different XMPP client or have used Conversations before. If not you can create a new XMPP account right now.\nHint: Some email providers also provide XMPP accounts.</string> <string name="do_you_have_an_account">Do you already have an XMPP account? This might be the case if you are already using a different XMPP client or have used Conversations before. If not you can create a new XMPP account right now.\nHint: Some email providers also provide XMPP accounts.</string>
<string name="server_select_text">XMPP is a provider independent instant messaging network. You can use this client with what ever XMPP server you choose.\nHowever for your convenience we made it easy to create an account on conversations.im¹; a provider specially suited for the use with Conversations.</string> <string name="server_select_text">XMPP is a provider independent instant messaging network. You can use this client with what ever XMPP server you choose.\nHowever for your convenience we made it easy to create an account on conversations.im¹; a provider specially suited for the use with Conversations.</string>
<string name="magic_create_text_on_x">You have been invited to %1$s. We will guide you through the process of creating an account.\nWhen picking %1$s as a provider you will be able to communicate with users of other providers by giving them your full XMPP address.</string>
</resources> </resources>

View File

@ -50,6 +50,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
public static final String RESOURCE = "resource"; public static final String RESOURCE = "resource";
public static final String PINNED_MECHANISM_KEY = "pinned_mechanism"; public static final String PINNED_MECHANISM_KEY = "pinned_mechanism";
public static final String PRE_AUTH_REGISTRATION_TOKEN = "pre_auth_registration";
public static final int OPTION_USETLS = 0; public static final int OPTION_USETLS = 0;
public static final int OPTION_DISABLED = 1; public static final int OPTION_DISABLED = 1;
@ -619,6 +620,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
REGISTRATION_CONFLICT(true, false), REGISTRATION_CONFLICT(true, false),
REGISTRATION_NOT_SUPPORTED(true, false), REGISTRATION_NOT_SUPPORTED(true, false),
REGISTRATION_PLEASE_WAIT(true, false), REGISTRATION_PLEASE_WAIT(true, false),
REGISTRATION_INVALID_TOKEN(true,false),
REGISTRATION_PASSWORD_TOO_WEAK(true, false), REGISTRATION_PASSWORD_TOO_WEAK(true, false),
TLS_ERROR, TLS_ERROR,
INCOMPATIBLE_SERVER, INCOMPATIBLE_SERVER,
@ -683,6 +685,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
return R.string.account_status_regis_success; return R.string.account_status_regis_success;
case REGISTRATION_NOT_SUPPORTED: case REGISTRATION_NOT_SUPPORTED:
return R.string.account_status_regis_not_sup; return R.string.account_status_regis_not_sup;
case REGISTRATION_INVALID_TOKEN:
return R.string.account_status_regis_invalid_token;
case TLS_ERROR: case TLS_ERROR:
return R.string.account_status_tls_error; return R.string.account_status_tls_error;
case INCOMPATIBLE_SERVER: case INCOMPATIBLE_SERVER:

View File

@ -403,6 +403,16 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
xmppConnectionService.deleteAccount(mAccount); xmppConnectionService.deleteAccount(mAccount);
} }
final boolean magicCreate = mAccount != null && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
final Jid jid = mAccount == null ? null : mAccount.getJid();
if (SignupUtils.isSupportTokenRegistry() && jid != null && magicCreate && !jid.getDomain().equals(Config.MAGIC_CREATE_DOMAIN)) {
final Intent intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), mAccount.getKey(Account.PRE_AUTH_REGISTRATION_TOKEN));
startActivity(intent);
return;
}
if (xmppConnectionService.getAccounts().size() == 0 && Config.MAGIC_CREATE_DOMAIN != null) { if (xmppConnectionService.getAccounts().size() == 0 && Config.MAGIC_CREATE_DOMAIN != null) {
Intent intent = SignupUtils.getSignUpIntent(this, mForceRegister != null && mForceRegister); Intent intent = SignupUtils.getSignUpIntent(this, mForceRegister != null && mForceRegister);
startActivity(intent); startActivity(intent);
@ -816,6 +826,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
return false; return false;
} }
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home:
deleteAccountAndReturnIfNecessary();
break;
case R.id.action_show_block_list: case R.id.action_show_block_list:
final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class); final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString()); showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());

View File

@ -9,12 +9,14 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.utils.SignupUtils; import eu.siacs.conversations.utils.SignupUtils;
@ -87,6 +89,18 @@ public class UriHandlerActivity extends AppCompatActivity {
final XmppUri xmppUri = new XmppUri(uri); final XmppUri xmppUri = new XmppUri(uri);
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(true); final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(true);
if (SignupUtils.isSupportTokenRegistry() && xmppUri.isJidValid() && xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
final String preauth = xmppUri.getParamater("preauth");
final Jid jid = xmppUri.getJid();
if (jid.isDomainJid()) {
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preauth);
startActivity(intent);
return;
}
Log.d(Config.LOGTAG,"attempting to register on "+jid+" with preauth="+preauth);
return;
}
if (accounts.size() == 0) { if (accounts.size() == 0) {
if (xmppUri.isJidValid()) { if (xmppUri.isJidValid()) {
intent = SignupUtils.getSignUpIntent(this); intent = SignupUtils.getSignUpIntent(this);

View File

@ -28,6 +28,7 @@ public class XmppUri {
public static final String ACTION_JOIN = "join"; public static final String ACTION_JOIN = "join";
public static final String ACTION_MESSAGE = "message"; public static final String ACTION_MESSAGE = "message";
public static final String ACTION_REGISTER = "register";
public XmppUri(String uri) { public XmppUri(String uri) {
try { try {
@ -194,6 +195,10 @@ public class XmppUri {
return parameters.get("name"); return parameters.get("name");
} }
public String getParamater(String key) {
return this.parameters.get(key);
}
public List<Fingerprint> getFingerprints() { public List<Fingerprint> getFingerprints() {
return this.fingerprints; return this.fingerprints;
} }

View File

@ -37,4 +37,6 @@ public final class Namespace {
public static final String MUC_USER = "http://jabber.org/protocol/muc#user"; public static final String MUC_USER = "http://jabber.org/protocol/muc#user";
public static final String BOOKMARKS2 = "urn:xmpp:bookmarks:0"; public static final String BOOKMARKS2 = "urn:xmpp:bookmarks:0";
public static final String BOOKMARKS2_COMPAT = BOOKMARKS2+"#compat"; public static final String BOOKMARKS2_COMPAT = BOOKMARKS2+"#compat";
public static final String INVITE = "urn:xmpp:invite";
public static final String PARS = "urn:xmpp:pars:0";
} }

View File

@ -112,6 +112,7 @@ public class XmppConnection implements Runnable {
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) { if (packet.getType() == IqPacket.TYPE.RESULT) {
account.setOption(Account.OPTION_REGISTER, false); account.setOption(Account.OPTION_REGISTER, false);
Log.d(Config.LOGTAG, account.getJid().asBareJid()+": successfully registered new account on server");
throw new StateChangingError(Account.State.REGISTRATION_SUCCESSFUL); throw new StateChangingError(Account.State.REGISTRATION_SUCCESSFUL);
} else { } else {
final List<String> PASSWORD_TOO_WEAK_MSGS = Arrays.asList( final List<String> PASSWORD_TOO_WEAK_MSGS = Arrays.asList(
@ -838,7 +839,7 @@ public class XmppConnection implements Runnable {
sendStartTLS(); sendStartTLS();
} else if (this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { } else if (this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) {
if (isSecure) { if (isSecure) {
sendRegistryRequest(); register();
} else { } else {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": unable to find STARTTLS for registration process "+ XmlHelper.printElementNames(this.streamFeatures)); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": unable to find STARTTLS for registration process "+ XmlHelper.printElementNames(this.streamFeatures));
throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER); throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER);
@ -912,6 +913,26 @@ public class XmppConnection implements Runnable {
return mechanisms; return mechanisms;
} }
private void register() {
final String preAuth = account.getKey(Account.PRE_AUTH_REGISTRATION_TOKEN);
if (preAuth != null && features.invite()) {
final IqPacket preAuthRequest = new IqPacket(IqPacket.TYPE.SET);
preAuthRequest.addChild("preauth", Namespace.PARS).setAttribute("token", preAuth);
sendUnmodifiedIqPacket(preAuthRequest, (account, response) -> {
if (response.getType() == IqPacket.TYPE.RESULT) {
sendRegistryRequest();
} else {
final Element error = response.getError();
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": failed to pre auth. "+error);
throw new StateChangingError(Account.State.REGISTRATION_INVALID_TOKEN);
}
}, true);
} else {
sendRegistryRequest();
}
}
private void sendRegistryRequest() { private void sendRegistryRequest() {
final IqPacket register = new IqPacket(IqPacket.TYPE.GET); final IqPacket register = new IqPacket(IqPacket.TYPE.GET);
register.query(Namespace.REGISTER); register.query(Namespace.REGISTER);
@ -1776,6 +1797,10 @@ public class XmppConnection implements Runnable {
return hasDiscoFeature(Jid.of(account.getServer()), Namespace.REGISTER); return hasDiscoFeature(Jid.of(account.getServer()), Namespace.REGISTER);
} }
public boolean invite() {
return connection.streamFeatures != null && connection.streamFeatures.hasChild("register", Namespace.INVITE);
}
public boolean sm() { public boolean sm() {
return streamId != null return streamId != null
|| (connection.streamFeatures != null && connection.streamFeatures.hasChild("sm")); || (connection.streamFeatures != null && connection.streamFeatures.hasChild("sm"));

View File

@ -155,6 +155,7 @@
<string name="account_status_regis_conflict">Username already in use</string> <string name="account_status_regis_conflict">Username already in use</string>
<string name="account_status_regis_success">Registration completed</string> <string name="account_status_regis_success">Registration completed</string>
<string name="account_status_regis_not_sup">Server does not support registration</string> <string name="account_status_regis_not_sup">Server does not support registration</string>
<string name="account_status_regis_invalid_token">Invalid registration token</string>
<string name="account_status_tls_error">TLS negotiation failed</string> <string name="account_status_tls_error">TLS negotiation failed</string>
<string name="account_status_policy_violation">Policy violation</string> <string name="account_status_policy_violation">Policy violation</string>
<string name="account_status_incompatible_server">Incompatible server</string> <string name="account_status_incompatible_server">Incompatible server</string>