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.PackageManager;
import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Bundle;
import android.security.KeyChain;
import android.security.KeyChainAliasCallback;
@ -46,23 +47,27 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
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);
if (referrer != null) {
if ("xmpp".equalsIgnoreCase(referrer.getScheme())) {
final XmppUri xmppUri = new XmppUri(referrer);
runOnUiThread(() -> processXmppUri(xmppUri));
} else {
Log.i(Config.LOGTAG, "install referrer was not an XMPP uri");
}
}
private boolean processXmppUri(final XmppUri xmppUri) {
if (xmppUri.isValidJid()) {
final String preauth = xmppUri.getParameter("preauth");
private void processXmppUri(final XmppUri xmppUri) {
if (!xmppUri.isValidJid()) {
return;
}
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);
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 = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth);
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
} else {
intent = null;
@ -70,12 +75,10 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi
if (intent != null) {
startActivity(intent);
finish();
return true;
return;
}
this.inviteUri = xmppUri;
}
return false;
}
@Override
protected void refreshUiReal() {

View file

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