From 71b6492d61f818e49337bd224c18d70e01824a23 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 30 Oct 2023 13:06:04 +0100 Subject: [PATCH] show unverified devices warning in contact and account details --- .../crypto/axolotl/AxolotlService.java | 6 +- .../crypto/axolotl/FingerprintStatus.java | 4 + .../ui/ContactDetailsActivity.java | 8 +- .../conversations/ui/EditAccountActivity.java | 13 +- .../siacs/conversations/ui/OmemoActivity.java | 1 + .../res/layout/activity_contact_details.xml | 13 + src/main/res/layout/activity_edit_account.xml | 227 +++++++++++------- src/main/res/values/strings.xml | 2 + 8 files changed, 178 insertions(+), 96 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 05ffdbdca..9cf3d9091 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -736,8 +736,12 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { return axolotlStore.getFingerprintCertificate(fingerprint); } - public void setFingerprintTrust(String fingerprint, FingerprintStatus status) { + public void setFingerprintTrust(final String fingerprint, final FingerprintStatus status) { axolotlStore.setFingerprintStatus(fingerprint, status); + // TODO we decided to call this after a fingerprint gets toggled to update the 'your contact + // is using unverified devices text'; however this means the entire screen gets redrawn + // after a toggle which might be annoying or cause other weird UI glitches + mXmppConnectionService.updateAccountUi(); } private ListenableFuture verifySessionWithPEP(final XmppAxolotlSession session) { diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/FingerprintStatus.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/FingerprintStatus.java index 2f1856d09..dffde90a1 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/FingerprintStatus.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/FingerprintStatus.java @@ -97,6 +97,10 @@ public class FingerprintStatus implements Comparable { return trust == Trust.TRUSTED || isVerified(); } + public boolean isUnverified() { + return trust == Trust.TRUSTED; + } + public boolean isVerified() { return trust == Trust.VERIFIED || trust == Trust.VERIFIED_X509; } diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 7c1d08643..f1556df6e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -455,6 +455,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } boolean skippedInactive = false; boolean showsInactive = false; + boolean showUnverifiedWarning = false; for (final XmppAxolotlSession session : sessions) { final FingerprintStatus trust = session.getTrust(); hasKeys |= !trust.isCompromised(); @@ -470,7 +471,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp boolean highlight = session.getFingerprint().equals(messageFingerprint); addFingerprintRow(binding.detailsContactKeys, session, highlight); } + if (trust.isUnverified()) { + showUnverifiedWarning = true; + } } + binding.unverifiedWarning.setVisibility(showUnverifiedWarning ? View.VISIBLE : View.GONE); if (showsInactive || skippedInactive) { binding.showInactiveDevices.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices); binding.showInactiveDevices.setVisibility(View.VISIBLE); @@ -480,7 +485,8 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } else { binding.showInactiveDevices.setVisibility(View.GONE); } - binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable() ? View.VISIBLE : View.GONE); + final boolean isCameraFeatureAvailable = isCameraFeatureAvailable(); + binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable ? View.VISIBLE : View.GONE); if (hasKeys) { binding.scanButton.setOnClickListener((v) -> ScanActivity.scan(this)); } diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 4011f1e2f..42335048a 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -49,6 +49,7 @@ import java.util.concurrent.atomic.AtomicInteger; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.AxolotlService; +import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.databinding.ActivityEditAccountBinding; import eu.siacs.conversations.databinding.DialogPresenceBinding; @@ -630,6 +631,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.accountRegisterNew.setVisibility(View.GONE); } this.binding.actionEditYourName.setOnClickListener(this::onEditYourNameClicked); + this.binding.scanButton.setOnClickListener((v) -> ScanActivity.scan(this)); } private void onEditYourNameClicked(View view) { @@ -1166,13 +1168,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.axolotlFingerprintBox.setVisibility(View.GONE); } boolean hasKeys = false; + boolean showUnverifiedWarning = false; binding.otherDeviceKeys.removeAllViews(); - for (XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) { - if (!session.getTrust().isCompromised()) { + for (final XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) { + final FingerprintStatus trust = session.getTrust(); + if (!trust.isCompromised()) { boolean highlight = session.getFingerprint().equals(messageFingerprint); addFingerprintRow(binding.otherDeviceKeys, session, highlight); hasKeys = true; } + if (trust.isUnverified()) { + showUnverifiedWarning = true; + } } if (hasKeys && Config.supportOmemo()) { //TODO: either the button should be visible if we print an active device or the device list should be fed with reactived devices this.binding.otherDeviceKeysCard.setVisibility(View.VISIBLE); @@ -1182,6 +1189,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } else { binding.clearDevices.setVisibility(View.VISIBLE); } + binding.unverifiedWarning.setVisibility(showUnverifiedWarning ? View.VISIBLE : View.GONE); + binding.scanButton.setVisibility(showUnverifiedWarning ? View.VISIBLE : View.GONE); } else { this.binding.otherDeviceKeysCard.setVisibility(View.GONE); } diff --git a/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java b/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java index 89fdae333..44af0d0b2 100644 --- a/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java @@ -205,6 +205,7 @@ public abstract class OmemoActivity extends XmppActivity { @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); } } diff --git a/src/main/res/layout/activity_contact_details.xml b/src/main/res/layout/activity_contact_details.xml index a7d569a4a..fc7219ee1 100644 --- a/src/main/res/layout/activity_contact_details.xml +++ b/src/main/res/layout/activity_contact_details.xml @@ -186,6 +186,19 @@ android:orientation="vertical" android:padding="@dimen/card_padding_list"/> + + + + + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> - + android:layout_marginBottom="@dimen/activity_vertical_margin"> + app:riv_corner_radius="8dp" /> + app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error" + app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint"> + android:textColor="?attr/edit_text_color" /> @@ -76,21 +77,21 @@ android:id="@+id/account_password_layout" android:layout_width="match_parent" android:layout_height="wrap_content" + app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error" + app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint" app:passwordToggleDrawable="@drawable/visibility_toggle_drawable" app:passwordToggleEnabled="true" - app:passwordToggleTint="?android:textColorSecondary" - app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint" - app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error"> + app:passwordToggleTint="?android:textColorSecondary"> + android:textColor="?attr/edit_text_color" /> + app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error" + app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint"> + android:inputType="textWebEmailAddress" /> @@ -135,16 +136,16 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/account_settings_port" - app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint" - app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error"> + app:errorTextAppearance="@style/TextAppearance.Conversations.Design.Error" + app:hintTextAppearance="@style/TextAppearance.Conversations.Design.Hint"> + android:maxLength="5" /> @@ -155,7 +156,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:text="@string/register_account"/> + android:text="@string/register_account" /> @@ -164,10 +165,10 @@ android:id="@+id/os_optimization" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" - android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" + android:layout_marginRight="@dimen/activity_horizontal_margin" + android:layout_marginBottom="@dimen/activity_vertical_margin" android:visibility="gone"> + android:textAppearance="@style/TextAppearance.Conversations.Title" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + android:textColor="?colorAccent" /> @@ -222,10 +223,10 @@ android:id="@+id/stats" android:layout_width="fill_parent" android:layout_height="fill_parent" - android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" - android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" + android:layout_marginRight="@dimen/activity_horizontal_margin" + android:layout_marginBottom="@dimen/activity_vertical_margin" android:visibility="gone"> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> @@ -282,7 +283,7 @@ android:ellipsize="end" android:singleLine="true" android:text="@string/server_info_pep" - android:textAppearance="@style/TextAppearance.Conversations.Body1"/> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + tools:ignore="RtlHardcoded" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> @@ -512,14 +513,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_name_set_instructions" - android:textAppearance="@style/TextAppearance.Conversations.Body1.Tertiary"/> + android:textAppearance="@style/TextAppearance.Conversations.Body1.Tertiary" /> + android:textAppearance="@style/TextAppearance.Conversations.Caption" /> + android:visibility="visible" /> + android:textAppearance="@style/TextAppearance.Conversations.Fingerprint" /> + android:textAppearance="@style/TextAppearance.Conversations.Caption" /> + android:visibility="visible" /> + android:textAppearance="@style/TextAppearance.Conversations.Fingerprint" /> + android:textAppearance="@style/TextAppearance.Conversations.Caption" /> + android:visibility="visible" /> + android:visibility="gone" /> @@ -642,41 +643,83 @@ android:id="@+id/other_device_keys_card" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" - android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" + android:layout_marginRight="@dimen/activity_horizontal_margin" + android:layout_marginBottom="@dimen/activity_vertical_margin" android:visibility="gone"> - - + android:orientation="vertical"> + android:orientation="vertical" + android:padding="@dimen/card_padding_list"> -