validate install referrer beforing accepting it as xmpp uri

This commit is contained in:
Daniel Gultsch 2020-06-18 10:15:51 +02:00
parent 7bcb29c482
commit fe68aff23c
2 changed files with 32 additions and 24 deletions

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.security.KeyChain; import android.security.KeyChain;
import android.security.KeyChainAliasCallback; import android.security.KeyChainAliasCallback;
@ -46,35 +47,37 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
activity.overridePendingTransition(0, 0); activity.overridePendingTransition(0, 0);
} }
public void onInstallReferrerDiscovered(final String referrer) { public void onInstallReferrerDiscovered(final Uri referrer) {
Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer); Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer);
if (referrer != null) { if ("xmpp".equalsIgnoreCase(referrer.getScheme())) {
final XmppUri xmppUri = new XmppUri(referrer); final XmppUri xmppUri = new XmppUri(referrer);
runOnUiThread(() -> processXmppUri(xmppUri)); runOnUiThread(() -> processXmppUri(xmppUri));
} else {
Log.i(Config.LOGTAG, "install referrer was not an XMPP uri");
} }
} }
private boolean processXmppUri(final XmppUri xmppUri) { private void processXmppUri(final XmppUri xmppUri) {
if (xmppUri.isValidJid()) { if (!xmppUri.isValidJid()) {
final String preauth = xmppUri.getParameter("preauth"); return;
final Jid jid = xmppUri.getJid();
final Intent intent;
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
intent = SignupUtils.getTokenRegistrationIntent(this, jid, preauth);
} else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) {
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preauth);
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
} else {
intent = null;
}
if (intent != null) {
startActivity(intent);
finish();
return true;
}
this.inviteUri = xmppUri;
} }
return false; final String preAuth = xmppUri.getParameter("preauth");
final Jid jid = xmppUri.getJid();
final Intent intent;
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
intent = SignupUtils.getTokenRegistrationIntent(this, jid, preAuth);
} else if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter("ibr"))) {
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth);
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
} else {
intent = null;
}
if (intent != null) {
startActivity(intent);
finish();
return;
}
this.inviteUri = xmppUri;
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package eu.siacs.conversations.utils;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
@ -9,6 +10,7 @@ import android.util.Log;
import com.android.installreferrer.api.InstallReferrerClient; import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener; import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails; import com.android.installreferrer.api.ReferrerDetails;
import com.google.common.base.Strings;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.ui.WelcomeActivity; import eu.siacs.conversations.ui.WelcomeActivity;
@ -49,8 +51,11 @@ public class InstallReferrerUtils implements InstallReferrerStateListener {
try { try {
final ReferrerDetails referrerDetails = installReferrerClient.getInstallReferrer(); final ReferrerDetails referrerDetails = installReferrerClient.getInstallReferrer();
final String referrer = referrerDetails.getInstallReferrer(); final String referrer = referrerDetails.getInstallReferrer();
welcomeActivity.onInstallReferrerDiscovered(referrer); if (Strings.isNullOrEmpty(referrer)) {
} catch (final RemoteException e) { return;
}
welcomeActivity.onInstallReferrerDiscovered(Uri.parse(referrer));
} catch (final RemoteException | IllegalArgumentException e) {
Log.d(Config.LOGTAG, "unable to get install referrer", e); Log.d(Config.LOGTAG, "unable to get install referrer", e);
} }
} else { } else {