diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-01-24 17:08:30 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-01-24 17:08:30 +0100 |
commit | 6d74698aec0a2728ac1a88d27b3eb0aa7904e4c9 (patch) | |
tree | 25e7ba81c3fb8bcce0c46adbb44e7c553c8cecff /src/main/java/de/pixart/messenger/xmpp | |
parent | f4a207e859999b49603efcea548f4a09546bb569 (diff) |
support registration via pars tokens
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp')
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 617a2e3ad..b8cddc170 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -114,6 +114,7 @@ public class XmppConnection implements Runnable { public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { 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); } else { final List<String> PASSWORD_TOO_WEAK_MSGS = Arrays.asList( @@ -876,7 +877,7 @@ public class XmppConnection implements Runnable { sendStartTLS(); } else if (this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { if (isSecure) { - sendRegistryRequest(); + register(); } else { 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); @@ -950,6 +951,25 @@ public class XmppConnection implements Runnable { 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() { final IqPacket register = new IqPacket(IqPacket.TYPE.GET); register.query(Namespace.REGISTER); @@ -1899,6 +1919,10 @@ public class XmppConnection implements Runnable { return hasDiscoFeature(Jid.of(account.getServer()), Namespace.REGISTER); } + public boolean invite() { + return connection.streamFeatures != null && connection.streamFeatures.hasChild("register", Namespace.INVITE); + } + public boolean sm() { return streamId != null || (connection.streamFeatures != null && connection.streamFeatures.hasChild("sm")); |