allow verification of own omemo keys via uri

This commit is contained in:
Daniel Gultsch 2022-02-13 10:22:31 +01:00
parent fecc34431c
commit 12463911f1
4 changed files with 47 additions and 13 deletions

View file

@ -194,6 +194,7 @@
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<activity <activity
android:name=".ui.EditAccountActivity" android:name=".ui.EditAccountActivity"
android:exported="false"
android:launchMode="singleTop" android:launchMode="singleTop"
android:windowSoftInputMode="stateHidden|adjustResize" /> android:windowSoftInputMode="stateHidden|adjustResize" />
<activity <activity

View file

@ -164,16 +164,16 @@ public class FileBackend {
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + app + "/Backup/"; return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + app + "/Backup/";
} }
private static Bitmap rotate(Bitmap bitmap, int degree) { private static Bitmap rotate(final Bitmap bitmap, final int degree) {
if (degree == 0) { if (degree == 0) {
return bitmap; return bitmap;
} }
int w = bitmap.getWidth(); final int w = bitmap.getWidth();
int h = bitmap.getHeight(); final int h = bitmap.getHeight();
Matrix mtx = new Matrix(); final Matrix matrix = new Matrix();
mtx.postRotate(degree); matrix.postRotate(degree);
Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); final Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
if (bitmap != null && !bitmap.isRecycled()) { if (!bitmap.isRecycled()) {
bitmap.recycle(); bitmap.recycle();
} }
return result; return result;

View file

@ -23,11 +23,14 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder; import androidx.appcompat.app.AlertDialog.Builder;
@ -693,12 +696,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} catch (final IllegalArgumentException | NullPointerException ignored) { } catch (final IllegalArgumentException | NullPointerException ignored) {
this.jidToEdit = null; this.jidToEdit = null;
} }
if (jidToEdit != null && intent.getData() != null && intent.getBooleanExtra("scanned", false)) { final Uri data = intent.getData();
final XmppUri uri = new XmppUri(intent.getData()); final XmppUri xmppUri = data == null ? null : new XmppUri(data);
if (xmppConnectionServiceBound) { final boolean scanned = intent.getBooleanExtra("scanned", false);
processFingerprintVerification(uri, false); if (jidToEdit != null && xmppUri != null && xmppUri.hasFingerprints()) {
if (scanned) {
if (xmppConnectionServiceBound) {
processFingerprintVerification(xmppUri, false);
} else {
this.pendingUri = xmppUri;
}
} else { } else {
this.pendingUri = uri; displayVerificationWarningDialog(xmppUri);
} }
} }
boolean init = intent.getBooleanExtra("init", false); boolean init = intent.getBooleanExtra("init", false);
@ -735,6 +744,28 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
} }
private void displayVerificationWarningDialog(final XmppUri xmppUri) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.verify_omemo_keys);
View view = getLayoutInflater().inflate(R.layout.dialog_verify_fingerprints, null);
final CheckBox isTrustedSource = view.findViewById(R.id.trusted_source);
TextView warning = view.findViewById(R.id.warning);
warning.setText(R.string.verifying_omemo_keys_trusted_source_account);
builder.setView(view);
builder.setPositiveButton(R.string.continue_btn, (dialog, which) -> {
if (isTrustedSource.isChecked()) {
processFingerprintVerification(xmppUri, false);
} else {
finish();
}
});
builder.setNegativeButton(R.string.cancel, (dialog, which) -> finish());
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.setOnCancelListener(d -> finish());
dialog.show();
}
@Override @Override
public void onNewIntent(final Intent intent) { public void onNewIntent(final Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
@ -749,7 +780,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
@Override @Override
public void onSaveInstanceState(final Bundle savedInstanceState) { public void onSaveInstanceState(@NonNull final Bundle savedInstanceState) {
if (mAccount != null) { if (mAccount != null) {
savedInstanceState.putString("account", mAccount.getJid().asBareJid().toEscapedString()); savedInstanceState.putString("account", mAccount.getJid().asBareJid().toEscapedString());
savedInstanceState.putBoolean("initMode", mInitMode); savedInstanceState.putBoolean("initMode", mInitMode);

View file

@ -622,6 +622,8 @@
<string name="pref_clean_private_storage_summary">Clean private storage where files are kept (They can be re-downloaded from the server)</string> <string name="pref_clean_private_storage_summary">Clean private storage where files are kept (They can be re-downloaded from the server)</string>
<string name="i_followed_this_link_from_a_trusted_source">I followed this link from a trusted source</string> <string name="i_followed_this_link_from_a_trusted_source">I followed this link from a trusted source</string>
<string name="verifying_omemo_keys_trusted_source">You are about to verify the OMEMO keys of %1$s after clicking a link. This is only secure if you followed this link from a trusted source where only %2$s could have published this link.</string> <string name="verifying_omemo_keys_trusted_source">You are about to verify the OMEMO keys of %1$s after clicking a link. This is only secure if you followed this link from a trusted source where only %2$s could have published this link.</string>
<string name="verifying_omemo_keys_trusted_source_account">You are about to verify the OMEMO keys of your own account. This is only secure if you followed this link from a trusted source where only you could have published this link.</string>
<string name="continue_btn">Continue</string>
<string name="verify_omemo_keys">Verify OMEMO keys</string> <string name="verify_omemo_keys">Verify OMEMO keys</string>
<string name="show_inactive_devices">Show inactive</string> <string name="show_inactive_devices">Show inactive</string>
<string name="hide_inactive_devices">Hide inactive</string> <string name="hide_inactive_devices">Hide inactive</string>