2015-07-19 16:36:28 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2016-11-22 11:03:21 +00:00
|
|
|
import android.app.ActionBar;
|
2015-07-19 16:36:28 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2016-11-22 11:03:21 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2015-07-19 16:36:28 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
2015-10-16 21:48:42 +00:00
|
|
|
import android.widget.Toast;
|
2015-07-19 16:36:28 +00:00
|
|
|
|
2016-11-22 11:03:21 +00:00
|
|
|
import com.google.zxing.integration.android.IntentIntegrator;
|
|
|
|
|
2017-06-18 14:35:30 +00:00
|
|
|
import org.whispersystems.libsignal.IdentityKey;
|
2015-07-19 16:36:28 +00:00
|
|
|
|
2016-02-29 12:18:07 +00:00
|
|
|
import java.util.ArrayList;
|
2016-11-23 10:01:58 +00:00
|
|
|
import java.util.Arrays;
|
2015-07-19 16:36:28 +00:00
|
|
|
import java.util.HashMap;
|
2016-02-29 12:18:07 +00:00
|
|
|
import java.util.List;
|
2015-07-19 16:36:28 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2017-06-29 12:01:12 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2015-07-19 16:36:28 +00:00
|
|
|
|
2016-11-17 19:09:42 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2015-07-19 16:36:28 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2015-10-16 21:48:42 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
2016-11-14 21:27:41 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
2015-07-19 16:36:28 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2016-03-01 10:26:59 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2017-06-25 16:18:13 +00:00
|
|
|
import eu.siacs.conversations.utils.CryptoHelper;
|
2016-11-22 11:03:21 +00:00
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2015-07-21 12:18:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
|
2015-07-19 16:36:28 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
|
|
|
|
2016-11-15 19:00:52 +00:00
|
|
|
public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdated {
|
2016-02-29 12:18:07 +00:00
|
|
|
private List<Jid> contactJids;
|
2015-10-16 21:48:42 +00:00
|
|
|
|
|
|
|
private Account mAccount;
|
2016-03-01 10:26:59 +00:00
|
|
|
private Conversation mConversation;
|
2015-08-15 16:52:47 +00:00
|
|
|
private TextView keyErrorMessage;
|
|
|
|
private LinearLayout keyErrorMessageCard;
|
2015-07-19 16:36:28 +00:00
|
|
|
private TextView ownKeysTitle;
|
|
|
|
private LinearLayout ownKeys;
|
|
|
|
private LinearLayout ownKeysCard;
|
|
|
|
private LinearLayout foreignKeys;
|
|
|
|
private Button mSaveButton;
|
|
|
|
private Button mCancelButton;
|
|
|
|
|
2017-06-29 12:01:12 +00:00
|
|
|
private AtomicBoolean mUseCameraHintShown = new AtomicBoolean(false);
|
|
|
|
|
2016-01-13 11:19:56 +00:00
|
|
|
private AxolotlService.FetchStatus lastFetchReport = AxolotlService.FetchStatus.SUCCESS;
|
|
|
|
|
2015-09-06 13:08:42 +00:00
|
|
|
private final Map<String, Boolean> ownKeysToTrust = new HashMap<>();
|
2016-02-29 12:18:07 +00:00
|
|
|
private final Map<Jid,Map<String, Boolean>> foreignKeysToTrust = new HashMap<>();
|
2015-07-19 16:36:28 +00:00
|
|
|
|
|
|
|
private final OnClickListener mSaveButtonListener = new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
commitTrusts();
|
2015-10-16 21:48:42 +00:00
|
|
|
finishOk();
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private final OnClickListener mCancelButtonListener = new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
setResult(RESULT_CANCELED);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
};
|
2016-11-23 09:42:27 +00:00
|
|
|
private Toast mUseCameraHintToast = null;
|
2015-07-19 16:36:28 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
populateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_trust_keys);
|
2016-02-29 12:18:07 +00:00
|
|
|
this.contactJids = new ArrayList<>();
|
|
|
|
for(String jid : getIntent().getStringArrayExtra("contacts")) {
|
|
|
|
try {
|
|
|
|
this.contactJids.add(Jid.fromString(jid));
|
|
|
|
} catch (InvalidJidException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
|
2015-08-15 16:52:47 +00:00
|
|
|
keyErrorMessageCard = (LinearLayout) findViewById(R.id.key_error_message_card);
|
|
|
|
keyErrorMessage = (TextView) findViewById(R.id.key_error_message);
|
2015-07-19 16:36:28 +00:00
|
|
|
ownKeysTitle = (TextView) findViewById(R.id.own_keys_title);
|
|
|
|
ownKeys = (LinearLayout) findViewById(R.id.own_keys_details);
|
|
|
|
ownKeysCard = (LinearLayout) findViewById(R.id.own_keys_card);
|
2016-02-29 12:18:07 +00:00
|
|
|
foreignKeys = (LinearLayout) findViewById(R.id.foreign_keys);
|
2015-07-19 16:36:28 +00:00
|
|
|
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
|
|
|
mCancelButton.setOnClickListener(mCancelButtonListener);
|
|
|
|
mSaveButton = (Button) findViewById(R.id.save_button);
|
|
|
|
mSaveButton.setOnClickListener(mSaveButtonListener);
|
|
|
|
|
|
|
|
|
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setHomeButtonEnabled(true);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
2017-06-29 18:23:28 +00:00
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
mUseCameraHintShown.set(savedInstanceState.getBoolean("camera_hint_shown",false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
|
|
|
savedInstanceState.putBoolean("camera_hint_shown", mUseCameraHintShown.get());
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 11:03:21 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.trust_keys, menu);
|
2017-06-29 12:01:12 +00:00
|
|
|
MenuItem scanQrCode = menu.findItem(R.id.action_scan_qr_code);
|
|
|
|
scanQrCode.setVisible(ownKeysToTrust.size() > 0 || foreignActuallyHasKeys());
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showCameraToast() {
|
2016-11-23 09:42:27 +00:00
|
|
|
mUseCameraHintToast = Toast.makeText(this,R.string.use_camera_icon_to_scan_barcode,Toast.LENGTH_LONG);
|
2016-11-22 11:03:21 +00:00
|
|
|
ActionBar actionBar = getActionBar();
|
2016-11-23 09:42:27 +00:00
|
|
|
mUseCameraHintToast.setGravity(Gravity.TOP | Gravity.END, 0 ,actionBar == null ? 0 : actionBar.getHeight());
|
|
|
|
mUseCameraHintToast.show();
|
2016-11-22 11:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_scan_qr_code:
|
|
|
|
if (hasPendingKeyFetches()) {
|
|
|
|
Toast.makeText(this, R.string.please_wait_for_keys_to_be_fetched, Toast.LENGTH_SHORT).show();
|
|
|
|
} else {
|
2016-11-23 10:01:58 +00:00
|
|
|
new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC","QR_CODE"));
|
2016-11-22 11:03:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-28 14:11:44 +00:00
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
if (mUseCameraHintToast != null) {
|
|
|
|
mUseCameraHintToast.cancel();
|
2016-11-22 11:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 14:11:44 +00:00
|
|
|
@Override
|
|
|
|
protected void processFingerprintVerification(XmppUri uri) {
|
2016-11-22 11:03:21 +00:00
|
|
|
if (mConversation != null
|
|
|
|
&& mAccount != null
|
|
|
|
&& uri.hasFingerprints()
|
|
|
|
&& mAccount.getAxolotlService().getCryptoTargets(mConversation).contains(uri.getJid())) {
|
|
|
|
boolean performedVerification = xmppConnectionService.verifyFingerprints(mAccount.getRoster().getContact(uri.getJid()),uri.getFingerprints());
|
|
|
|
boolean keys = reloadFingerprints();
|
|
|
|
if (performedVerification && !keys && !hasNoOtherTrustedKeys() && !hasPendingKeyFetches()) {
|
|
|
|
Toast.makeText(this,R.string.all_omemo_keys_have_been_verified, Toast.LENGTH_SHORT).show();
|
|
|
|
finishOk();
|
2016-11-28 14:11:44 +00:00
|
|
|
return;
|
2016-11-22 11:03:21 +00:00
|
|
|
} else if (performedVerification) {
|
|
|
|
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-28 14:11:44 +00:00
|
|
|
reloadFingerprints();
|
2016-11-22 11:03:21 +00:00
|
|
|
Log.d(Config.LOGTAG,"xmpp uri was: "+uri.getJid()+" has Fingerprints: "+Boolean.toString(uri.hasFingerprints()));
|
|
|
|
Toast.makeText(this,R.string.barcode_does_not_contain_fingerprints_for_this_conversation,Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2016-11-28 14:11:44 +00:00
|
|
|
populateView();
|
2016-11-22 11:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-07-19 16:36:28 +00:00
|
|
|
private void populateView() {
|
2015-08-08 11:29:21 +00:00
|
|
|
setTitle(getString(R.string.trust_omemo_fingerprints));
|
2015-07-19 16:36:28 +00:00
|
|
|
ownKeys.removeAllViews();
|
|
|
|
foreignKeys.removeAllViews();
|
|
|
|
boolean hasOwnKeys = false;
|
|
|
|
boolean hasForeignKeys = false;
|
2015-09-06 13:08:42 +00:00
|
|
|
for(final String fingerprint : ownKeysToTrust.keySet()) {
|
2015-07-19 16:36:28 +00:00
|
|
|
hasOwnKeys = true;
|
2016-02-29 12:18:07 +00:00
|
|
|
addFingerprintRowWithListeners(ownKeys, mAccount, fingerprint, false,
|
2016-11-15 19:00:52 +00:00
|
|
|
FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)), false, false,
|
2015-07-19 16:36:28 +00:00
|
|
|
new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
2015-09-06 13:08:42 +00:00
|
|
|
ownKeysToTrust.put(fingerprint, isChecked);
|
2015-08-05 20:22:37 +00:00
|
|
|
// own fingerprints have no impact on locked status.
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
2016-11-15 19:00:52 +00:00
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-29 12:18:07 +00:00
|
|
|
synchronized (this.foreignKeysToTrust) {
|
|
|
|
for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
|
2016-03-01 10:26:59 +00:00
|
|
|
hasForeignKeys = true;
|
2016-02-29 12:18:07 +00:00
|
|
|
final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.keys_card, foreignKeys, false);
|
2016-03-01 10:26:59 +00:00
|
|
|
final Jid jid = entry.getKey();
|
2016-02-29 12:18:07 +00:00
|
|
|
final TextView header = (TextView) layout.findViewById(R.id.foreign_keys_title);
|
|
|
|
final LinearLayout keysContainer = (LinearLayout) layout.findViewById(R.id.foreign_keys_details);
|
2016-03-01 10:26:59 +00:00
|
|
|
final TextView informNoKeys = (TextView) layout.findViewById(R.id.no_keys_to_accept);
|
|
|
|
header.setText(jid.toString());
|
2017-08-24 08:09:16 +00:00
|
|
|
header.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
switchToContactDetails(mAccount.getRoster().getContact(jid));
|
|
|
|
}
|
|
|
|
});
|
2016-02-29 12:18:07 +00:00
|
|
|
final Map<String, Boolean> fingerprints = entry.getValue();
|
|
|
|
for (final String fingerprint : fingerprints.keySet()) {
|
|
|
|
addFingerprintRowWithListeners(keysContainer, mAccount, fingerprint, false,
|
2016-11-15 19:00:52 +00:00
|
|
|
FingerprintStatus.createActive(fingerprints.get(fingerprint)), false, false,
|
2016-02-29 12:18:07 +00:00
|
|
|
new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
fingerprints.put(fingerprint, isChecked);
|
|
|
|
lockOrUnlockAsNeeded();
|
|
|
|
}
|
2016-11-15 19:00:52 +00:00
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
);
|
|
|
|
}
|
2016-03-01 10:26:59 +00:00
|
|
|
if (fingerprints.size() == 0) {
|
|
|
|
informNoKeys.setVisibility(View.VISIBLE);
|
2017-08-21 12:08:20 +00:00
|
|
|
if (hasNoOtherTrustedKeys(jid)) {
|
|
|
|
if (!mAccount.getRoster().getContact(jid).mutualPresenceSubscription()) {
|
|
|
|
informNoKeys.setText(R.string.error_no_keys_to_trust_presence);
|
|
|
|
} else {
|
|
|
|
informNoKeys.setText(R.string.error_no_keys_to_trust_server_error);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
informNoKeys.setText(getString(R.string.no_keys_just_confirm, mAccount.getRoster().getContact(jid).getDisplayName()));
|
|
|
|
}
|
2016-03-01 10:26:59 +00:00
|
|
|
} else {
|
|
|
|
informNoKeys.setVisibility(View.GONE);
|
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
foreignKeys.addView(layout);
|
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
|
2017-06-29 12:01:12 +00:00
|
|
|
if ((hasOwnKeys || foreignActuallyHasKeys()) && mUseCameraHintShown.compareAndSet(false,true)) {
|
|
|
|
showCameraToast();
|
|
|
|
}
|
|
|
|
|
2016-03-01 10:26:59 +00:00
|
|
|
ownKeysTitle.setText(mAccount.getJid().toBareJid().toString());
|
2016-02-29 12:18:07 +00:00
|
|
|
ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE);
|
|
|
|
foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE);
|
2015-10-16 21:48:42 +00:00
|
|
|
if(hasPendingKeyFetches()) {
|
2015-07-20 12:56:41 +00:00
|
|
|
setFetching();
|
|
|
|
lock();
|
|
|
|
} else {
|
2015-10-16 21:48:42 +00:00
|
|
|
if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
|
2015-08-15 16:52:47 +00:00
|
|
|
keyErrorMessageCard.setVisibility(View.VISIBLE);
|
2016-01-23 10:39:02 +00:00
|
|
|
if (lastFetchReport == AxolotlService.FetchStatus.ERROR
|
2016-02-29 12:18:07 +00:00
|
|
|
|| mAccount.getAxolotlService().fetchMapHasErrors(contactJids)) {
|
2017-08-21 12:08:20 +00:00
|
|
|
if (anyWithoutMutualPresenceSubscription(contactJids)) {
|
|
|
|
keyErrorMessage.setText(R.string.error_no_keys_to_trust_presence);
|
|
|
|
} else {
|
|
|
|
keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error);
|
|
|
|
}
|
2016-01-13 11:19:56 +00:00
|
|
|
} else {
|
|
|
|
keyErrorMessage.setText(R.string.error_no_keys_to_trust);
|
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
ownKeys.removeAllViews();
|
|
|
|
ownKeysCard.setVisibility(View.GONE);
|
|
|
|
foreignKeys.removeAllViews();
|
|
|
|
foreignKeys.setVisibility(View.GONE);
|
2015-08-15 16:52:47 +00:00
|
|
|
}
|
2015-08-05 20:22:37 +00:00
|
|
|
lockOrUnlockAsNeeded();
|
2015-07-20 12:56:41 +00:00
|
|
|
setDone();
|
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 12:08:20 +00:00
|
|
|
private boolean anyWithoutMutualPresenceSubscription(List<Jid> contactJids){
|
|
|
|
for(Jid jid : contactJids) {
|
|
|
|
if (!mAccount.getRoster().getContact(jid).mutualPresenceSubscription()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-29 12:01:12 +00:00
|
|
|
private boolean foreignActuallyHasKeys() {
|
|
|
|
synchronized (this.foreignKeysToTrust) {
|
|
|
|
for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
|
|
|
|
if (entry.getValue().size() > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-16 21:48:42 +00:00
|
|
|
private boolean reloadFingerprints() {
|
2016-03-01 10:26:59 +00:00
|
|
|
List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
|
2015-10-17 12:09:26 +00:00
|
|
|
ownKeysToTrust.clear();
|
2015-10-16 21:48:42 +00:00
|
|
|
AxolotlService service = this.mAccount.getAxolotlService();
|
2016-11-14 21:27:41 +00:00
|
|
|
Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided());
|
2015-07-19 16:36:28 +00:00
|
|
|
for(final IdentityKey identityKey : ownKeysSet) {
|
2017-06-25 16:18:13 +00:00
|
|
|
final String fingerprint = CryptoHelper.bytesToHex(identityKey.getPublicKey().serialize());
|
|
|
|
if(!ownKeysToTrust.containsKey(fingerprint)) {
|
|
|
|
ownKeysToTrust.put(fingerprint, false);
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
synchronized (this.foreignKeysToTrust) {
|
|
|
|
foreignKeysToTrust.clear();
|
|
|
|
for (Jid jid : contactJids) {
|
2016-11-14 21:27:41 +00:00
|
|
|
Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), jid);
|
2016-02-29 12:18:07 +00:00
|
|
|
if (hasNoOtherTrustedKeys(jid) && ownKeysSet.size() == 0) {
|
2016-11-14 21:27:41 +00:00
|
|
|
foreignKeysSet.addAll(service.getKeysWithTrust(FingerprintStatus.createActive(false), jid));
|
2016-02-29 12:18:07 +00:00
|
|
|
}
|
|
|
|
Map<String, Boolean> foreignFingerprints = new HashMap<>();
|
|
|
|
for (final IdentityKey identityKey : foreignKeysSet) {
|
2017-06-25 16:18:13 +00:00
|
|
|
final String fingerprint = CryptoHelper.bytesToHex(identityKey.getPublicKey().serialize());
|
|
|
|
if (!foreignFingerprints.containsKey(fingerprint)) {
|
|
|
|
foreignFingerprints.put(fingerprint, false);
|
2016-02-29 12:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-01 10:26:59 +00:00
|
|
|
if (foreignFingerprints.size() > 0 || !acceptedTargets.contains(jid)) {
|
2016-02-29 12:18:07 +00:00
|
|
|
foreignKeysToTrust.put(jid, foreignFingerprints);
|
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
return ownKeysSet.size() + foreignKeysToTrust.size() > 0;
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onBackendConnected() {
|
2016-03-01 10:26:59 +00:00
|
|
|
Intent intent = getIntent();
|
|
|
|
this.mAccount = extractAccount(intent);
|
|
|
|
if (this.mAccount != null && intent != null) {
|
|
|
|
String uuid = intent.getStringExtra("conversation");
|
|
|
|
this.mConversation = xmppConnectionService.findConversationByUuid(uuid);
|
2016-11-22 11:03:21 +00:00
|
|
|
if (this.mPendingFingerprintVerificationUri != null) {
|
|
|
|
processFingerprintVerification(this.mPendingFingerprintVerificationUri);
|
|
|
|
this.mPendingFingerprintVerificationUri = null;
|
2016-11-28 14:11:44 +00:00
|
|
|
} else {
|
|
|
|
reloadFingerprints();
|
|
|
|
populateView();
|
2017-06-29 18:23:28 +00:00
|
|
|
invalidateOptionsMenu();
|
2016-11-22 11:03:21 +00:00
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 21:48:42 +00:00
|
|
|
private boolean hasNoOtherTrustedKeys() {
|
2016-02-29 12:18:07 +00:00
|
|
|
return mAccount == null || mAccount.getAxolotlService().anyTargetHasNoTrustedKeys(contactJids);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasNoOtherTrustedKeys(Jid contact) {
|
2015-10-16 21:48:42 +00:00
|
|
|
return mAccount == null || mAccount.getAxolotlService().getNumTrustedKeys(contact) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasPendingKeyFetches() {
|
2016-02-29 12:18:07 +00:00
|
|
|
return mAccount != null && mAccount.getAxolotlService().hasPendingKeyFetches(mAccount, contactJids);
|
2015-10-16 21:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-19 16:36:28 +00:00
|
|
|
@Override
|
2015-10-17 12:09:26 +00:00
|
|
|
public void onKeyStatusUpdated(final AxolotlService.FetchStatus report) {
|
2016-11-23 09:42:27 +00:00
|
|
|
final boolean keysToTrust = reloadFingerprints();
|
2015-10-17 12:09:26 +00:00
|
|
|
if (report != null) {
|
2016-01-13 11:19:56 +00:00
|
|
|
lastFetchReport = report;
|
2015-10-17 12:09:26 +00:00
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-11-23 09:42:27 +00:00
|
|
|
if (mUseCameraHintToast != null && !keysToTrust) {
|
|
|
|
mUseCameraHintToast.cancel();
|
|
|
|
}
|
2015-10-17 12:09:26 +00:00
|
|
|
switch (report) {
|
|
|
|
case ERROR:
|
|
|
|
Toast.makeText(TrustKeysActivity.this,R.string.error_fetching_omemo_key,Toast.LENGTH_SHORT).show();
|
|
|
|
break;
|
2016-11-23 09:42:27 +00:00
|
|
|
case SUCCESS_TRUSTED:
|
|
|
|
Toast.makeText(TrustKeysActivity.this,R.string.blindly_trusted_omemo_keys,Toast.LENGTH_LONG).show();
|
|
|
|
break;
|
2015-10-17 12:09:26 +00:00
|
|
|
case SUCCESS_VERIFIED:
|
2016-11-17 19:09:42 +00:00
|
|
|
Toast.makeText(TrustKeysActivity.this,
|
|
|
|
Config.X509_VERIFICATION ? R.string.verified_omemo_key_with_certificate : R.string.all_omemo_keys_have_been_verified,
|
|
|
|
Toast.LENGTH_LONG).show();
|
2015-10-17 12:09:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2015-10-16 21:48:42 +00:00
|
|
|
if (keysToTrust || hasPendingKeyFetches() || hasNoOtherTrustedKeys()) {
|
|
|
|
refreshUi();
|
|
|
|
} else {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
finishOk();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void finishOk() {
|
|
|
|
Intent data = new Intent();
|
|
|
|
data.putExtra("choice", getIntent().getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID));
|
|
|
|
setResult(RESULT_OK, data);
|
|
|
|
finish();
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void commitTrusts() {
|
2015-09-06 13:08:42 +00:00
|
|
|
for(final String fingerprint :ownKeysToTrust.keySet()) {
|
2016-02-29 12:18:07 +00:00
|
|
|
mAccount.getAxolotlService().setFingerprintTrust(
|
2015-09-06 13:08:42 +00:00
|
|
|
fingerprint,
|
2016-11-14 21:27:41 +00:00
|
|
|
FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)));
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
2016-03-01 10:26:59 +00:00
|
|
|
List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
|
2016-02-29 12:18:07 +00:00
|
|
|
synchronized (this.foreignKeysToTrust) {
|
2016-03-01 10:26:59 +00:00
|
|
|
for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
|
|
|
|
Jid jid = entry.getKey();
|
|
|
|
Map<String, Boolean> value = entry.getValue();
|
|
|
|
if (!acceptedTargets.contains(jid)) {
|
|
|
|
acceptedTargets.add(jid);
|
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
for (final String fingerprint : value.keySet()) {
|
|
|
|
mAccount.getAxolotlService().setFingerprintTrust(
|
|
|
|
fingerprint,
|
2016-11-14 21:27:41 +00:00
|
|
|
FingerprintStatus.createActive(value.get(fingerprint)));
|
2016-02-29 12:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
2016-03-01 10:26:59 +00:00
|
|
|
if (mConversation != null && mConversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
mConversation.setAcceptedCryptoTargets(acceptedTargets);
|
2016-03-01 11:22:20 +00:00
|
|
|
xmppConnectionService.updateConversation(mConversation);
|
2016-03-01 10:26:59 +00:00
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void unlock() {
|
|
|
|
mSaveButton.setEnabled(true);
|
|
|
|
mSaveButton.setTextColor(getPrimaryTextColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void lock() {
|
|
|
|
mSaveButton.setEnabled(false);
|
|
|
|
mSaveButton.setTextColor(getSecondaryTextColor());
|
|
|
|
}
|
2015-07-20 12:56:41 +00:00
|
|
|
|
2015-08-05 20:22:37 +00:00
|
|
|
private void lockOrUnlockAsNeeded() {
|
2016-02-29 12:18:07 +00:00
|
|
|
synchronized (this.foreignKeysToTrust) {
|
|
|
|
for (Jid jid : contactJids) {
|
|
|
|
Map<String, Boolean> fingerprints = foreignKeysToTrust.get(jid);
|
|
|
|
if (hasNoOtherTrustedKeys(jid) && (fingerprints == null || !fingerprints.values().contains(true))) {
|
|
|
|
lock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 20:22:37 +00:00
|
|
|
}
|
2016-02-29 12:18:07 +00:00
|
|
|
unlock();
|
|
|
|
|
2015-08-05 20:22:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 12:56:41 +00:00
|
|
|
private void setDone() {
|
|
|
|
mSaveButton.setText(getString(R.string.done));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setFetching() {
|
|
|
|
mSaveButton.setText(getString(R.string.fetching_keys));
|
|
|
|
}
|
2015-07-19 16:36:28 +00:00
|
|
|
}
|