scanned results are always a trusted source

This commit is contained in:
Daniel Gultsch 2018-03-13 16:55:25 +01:00
parent 0c58e7cc30
commit f21fda1421
2 changed files with 14 additions and 9 deletions

View File

@ -273,7 +273,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
try { try {
Jid jid = Jid.of(searchString); Jid jid = Jid.of(searchString);
if (jid.getLocal() != null && jid.isBareJid() && jid.getDomain().contains(".")) { if (jid.getLocal() != null && jid.isBareJid() && jid.getDomain().contains(".")) {
showCreateContactDialog(jid.toString(),null); showCreateContactDialog(jid.toString(), null);
return; return;
} }
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
@ -475,7 +475,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else if (contact.showInRoster()) { } else if (contact.showInRoster()) {
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists)); throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
} else { } else {
xmppConnectionService.createContact(contact,true); xmppConnectionService.createContact(contact, true);
if (invite != null && invite.hasFingerprints()) { if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints()); xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
} }
@ -494,7 +494,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null); final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
final Spinner spinner = dialogView.findViewById(R.id.account); final Spinner spinner = dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid); final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid);
DelayedHintHelper.setHint(R.string.conference_address_example,jid); DelayedHintHelper.setHint(R.string.conference_address_example, jid);
jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts)); jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
if (prefilledJid != null) { if (prefilledJid != null) {
jid.append(prefilledJid); jid.append(prefilledJid);
@ -752,7 +752,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if (grantResults.length > 0) if (grantResults.length > 0)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
ScanActivity.onRequestPermissionResult(this,requestCode,grantResults); ScanActivity.onRequestPermissionResult(this, requestCode, grantResults);
if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) { if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
xmppConnectionService.loadPhoneContacts(); xmppConnectionService.loadPhoneContacts();
} }
@ -821,7 +821,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
case Intent.ACTION_VIEW: case Intent.ACTION_VIEW:
Uri uri = intent.getData(); Uri uri = intent.getData();
if (uri != null) { if (uri != null) {
Invite invite = new Invite(intent.getData(), false); Invite invite = new Invite(intent.getData(), intent.getBooleanExtra("scanned", false));
invite.account = intent.getStringExtra("account"); invite.account = intent.getStringExtra("account");
return invite.invite(); return invite.invite();
} else { } else {

View File

@ -53,7 +53,7 @@ public class UriHandlerActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.handled = savedInstanceState != null && savedInstanceState.getBoolean("handled",false); this.handled = savedInstanceState != null && savedInstanceState.getBoolean("handled", false);
} }
@Override @Override
@ -74,6 +74,10 @@ public class UriHandlerActivity extends AppCompatActivity {
} }
private void handleUri(Uri uri) { private void handleUri(Uri uri) {
handleUri(uri, false);
}
private void handleUri(Uri uri, final boolean scanned) {
final Intent intent; final Intent intent;
final XmppUri xmppUri = new XmppUri(uri); final XmppUri xmppUri = new XmppUri(uri);
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(); //TODO only look at enabled accounts final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(); //TODO only look at enabled accounts
@ -104,13 +108,14 @@ public class UriHandlerActivity extends AppCompatActivity {
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.putExtra("jid", xmppUri.getJid().asBareJid().toString()); intent.putExtra("jid", xmppUri.getJid().asBareJid().toString());
intent.setData(uri); intent.setData(uri);
} else if (xmppUri.isJidValid()){ } else if (xmppUri.isJidValid()) {
intent = new Intent(getApplicationContext(), StartConversationActivity.class); intent = new Intent(getApplicationContext(), StartConversationActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("scanned", scanned);
intent.setData(uri); intent.setData(uri);
} else { } else {
Toast.makeText(this,R.string.invalid_jid,Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
return; return;
} }
@ -149,7 +154,7 @@ public class UriHandlerActivity extends AppCompatActivity {
String result = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT); String result = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
if (result != null) { if (result != null) {
Uri uri = Uri.parse(result); Uri uri = Uri.parse(result);
handleUri(uri); handleUri(uri, true);
} }
} }
finish(); finish();