Search in sources :

Example 1 with Fingerprint

use of org.whispersystems.libsignal.fingerprint.Fingerprint in project Signal-Android by WhisperSystems.

the class VerifyDisplayFragment method initializeFingerprint.

private void initializeFingerprint() {
    RecipientId recipientId = getArguments().getParcelable(RECIPIENT_ID);
    IdentityKeyParcelable localIdentityParcelable = getArguments().getParcelable(LOCAL_IDENTITY);
    IdentityKeyParcelable remoteIdentityParcelable = getArguments().getParcelable(REMOTE_IDENTITY);
    this.localIdentity = localIdentityParcelable.get();
    this.recipient = Recipient.live(recipientId);
    this.remoteIdentity = remoteIdentityParcelable.get();
    int version;
    byte[] localId;
    byte[] remoteId;
    // noinspection WrongThread
    Recipient resolved = recipient.resolve();
    if (FeatureFlags.verifyV2() && resolved.getServiceId().isPresent()) {
        Log.i(TAG, "Using UUID (version 2).");
        version = 2;
        localId = Recipient.self().requireServiceId().toByteArray();
        remoteId = resolved.requireServiceId().toByteArray();
    } else if (!FeatureFlags.verifyV2() && resolved.getE164().isPresent()) {
        Log.i(TAG, "Using E164 (version 1).");
        version = 1;
        localId = Recipient.self().requireE164().getBytes();
        remoteId = resolved.requireE164().getBytes();
    } else {
        Log.w(TAG, String.format(Locale.ENGLISH, "Could not show proper verification! verifyV2: %s, hasUuid: %s, hasE164: %s", FeatureFlags.verifyV2(), resolved.getServiceId().isPresent(), resolved.getE164().isPresent()));
        new MaterialAlertDialogBuilder(requireContext()).setMessage(getString(R.string.VerifyIdentityActivity_you_must_first_exchange_messages_in_order_to_view, resolved.getDisplayName(requireContext()))).setPositiveButton(android.R.string.ok, (dialog, which) -> requireActivity().finish()).setOnDismissListener(dialog -> {
            requireActivity().finish();
            dialog.dismiss();
        }).show();
        return;
    }
    this.recipient.observe(this, this::setRecipientText);
    SimpleTask.run(() -> new NumericFingerprintGenerator(5200).createFor(version, localId, localIdentity, remoteId, remoteIdentity), fingerprint -> {
        if (getActivity() == null)
            return;
        VerifyDisplayFragment.this.fingerprint = fingerprint;
        setFingerprintViews(fingerprint, true);
        initializeOptionsMenu();
    });
}
Also used : ScaleAnimation(android.view.animation.ScaleAnimation) AnticipateInterpolator(android.view.animation.AnticipateInterpolator) Bundle(android.os.Bundle) ReentrantSessionLock(org.thoughtcrime.securesms.crypto.ReentrantSessionLock) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint) LinkMovementMethod(android.text.method.LinkMovementMethod) DrawableRes(androidx.annotation.DrawableRes) R(org.thoughtcrime.securesms.R) NumericFingerprintGenerator(org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator) TypeEvaluator(android.animation.TypeEvaluator) MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) Canvas(android.graphics.Canvas) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ThreadUtil(org.signal.core.util.ThreadUtil) ViewGroup(android.view.ViewGroup) IdentityKey(org.whispersystems.libsignal.IdentityKey) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) Toolbar(androidx.appcompat.widget.Toolbar) Context(android.content.Context) ContextMenu(android.view.ContextMenu) Util(org.thoughtcrime.securesms.util.Util) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) MenuItem(android.view.MenuItem) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) FingerprintVersionMismatchException(org.whispersystems.libsignal.fingerprint.FingerprintVersionMismatchException) Charset(java.nio.charset.Charset) MenuInflater(android.view.MenuInflater) QrCode(org.thoughtcrime.securesms.qr.QrCode) Toast(android.widget.Toast) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityUtil(org.thoughtcrime.securesms.util.IdentityUtil) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) TextSwitcher(android.widget.TextSwitcher) ViewTreeObserver(android.view.ViewTreeObserver) ValueAnimator(android.animation.ValueAnimator) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) NumericFingerprintGenerator(org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint)

Example 2 with Fingerprint

use of org.whispersystems.libsignal.fingerprint.Fingerprint in project Signal-Android by WhisperSystems.

the class VerifyDisplayFragment method getFormattedSafetyNumbers.

@NonNull
private String getFormattedSafetyNumbers(@NonNull Fingerprint fingerprint, int segmentCount) {
    String[] segments = getSegments(fingerprint, segmentCount);
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < segments.length; i++) {
        result.append(segments[i]);
        if (i != segments.length - 1) {
            if (((i + 1) % 4) == 0)
                result.append('\n');
            else
                result.append(' ');
        }
    }
    return result.toString();
}
Also used : Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint) NonNull(androidx.annotation.NonNull)

Example 3 with Fingerprint

use of org.whispersystems.libsignal.fingerprint.Fingerprint in project Signal-Android by signalapp.

the class VerifyDisplayFragment method initializeFingerprint.

private void initializeFingerprint() {
    RecipientId recipientId = getArguments().getParcelable(RECIPIENT_ID);
    IdentityKeyParcelable localIdentityParcelable = getArguments().getParcelable(LOCAL_IDENTITY);
    IdentityKeyParcelable remoteIdentityParcelable = getArguments().getParcelable(REMOTE_IDENTITY);
    this.localIdentity = localIdentityParcelable.get();
    this.recipient = Recipient.live(recipientId);
    this.remoteIdentity = remoteIdentityParcelable.get();
    int version;
    byte[] localId;
    byte[] remoteId;
    // noinspection WrongThread
    Recipient resolved = recipient.resolve();
    if (FeatureFlags.verifyV2() && resolved.getServiceId().isPresent()) {
        Log.i(TAG, "Using UUID (version 2).");
        version = 2;
        localId = Recipient.self().requireServiceId().toByteArray();
        remoteId = resolved.requireServiceId().toByteArray();
    } else if (!FeatureFlags.verifyV2() && resolved.getE164().isPresent()) {
        Log.i(TAG, "Using E164 (version 1).");
        version = 1;
        localId = Recipient.self().requireE164().getBytes();
        remoteId = resolved.requireE164().getBytes();
    } else {
        Log.w(TAG, String.format(Locale.ENGLISH, "Could not show proper verification! verifyV2: %s, hasUuid: %s, hasE164: %s", FeatureFlags.verifyV2(), resolved.getServiceId().isPresent(), resolved.getE164().isPresent()));
        new MaterialAlertDialogBuilder(requireContext()).setMessage(getString(R.string.VerifyIdentityActivity_you_must_first_exchange_messages_in_order_to_view, resolved.getDisplayName(requireContext()))).setPositiveButton(android.R.string.ok, (dialog, which) -> requireActivity().finish()).setOnDismissListener(dialog -> {
            requireActivity().finish();
            dialog.dismiss();
        }).show();
        return;
    }
    this.recipient.observe(this, this::setRecipientText);
    SimpleTask.run(() -> new NumericFingerprintGenerator(5200).createFor(version, localId, localIdentity, remoteId, remoteIdentity), fingerprint -> {
        if (getActivity() == null)
            return;
        VerifyDisplayFragment.this.fingerprint = fingerprint;
        setFingerprintViews(fingerprint, true);
        initializeOptionsMenu();
    });
}
Also used : ScaleAnimation(android.view.animation.ScaleAnimation) AnticipateInterpolator(android.view.animation.AnticipateInterpolator) Bundle(android.os.Bundle) ReentrantSessionLock(org.thoughtcrime.securesms.crypto.ReentrantSessionLock) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint) LinkMovementMethod(android.text.method.LinkMovementMethod) DrawableRes(androidx.annotation.DrawableRes) R(org.thoughtcrime.securesms.R) NumericFingerprintGenerator(org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator) TypeEvaluator(android.animation.TypeEvaluator) MultiDeviceVerifiedUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) Canvas(android.graphics.Canvas) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ThreadUtil(org.signal.core.util.ThreadUtil) ViewGroup(android.view.ViewGroup) IdentityKey(org.whispersystems.libsignal.IdentityKey) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) Toolbar(androidx.appcompat.widget.Toolbar) Context(android.content.Context) ContextMenu(android.view.ContextMenu) Util(org.thoughtcrime.securesms.util.Util) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) MenuItem(android.view.MenuItem) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) FingerprintVersionMismatchException(org.whispersystems.libsignal.fingerprint.FingerprintVersionMismatchException) Charset(java.nio.charset.Charset) MenuInflater(android.view.MenuInflater) QrCode(org.thoughtcrime.securesms.qr.QrCode) Toast(android.widget.Toast) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityUtil(org.thoughtcrime.securesms.util.IdentityUtil) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) TextSwitcher(android.widget.TextSwitcher) ViewTreeObserver(android.view.ViewTreeObserver) ValueAnimator(android.animation.ValueAnimator) IdentityKeyParcelable(org.thoughtcrime.securesms.crypto.IdentityKeyParcelable) NumericFingerprintGenerator(org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint)

Example 4 with Fingerprint

use of org.whispersystems.libsignal.fingerprint.Fingerprint in project Signal-Android by signalapp.

the class VerifyDisplayFragment method getSegments.

private String[] getSegments(Fingerprint fingerprint, int segmentCount) {
    String[] segments = new String[segmentCount];
    String digits = fingerprint.getDisplayableFingerprint().getDisplayText();
    int partSize = digits.length() / segmentCount;
    for (int i = 0; i < segmentCount; i++) {
        segments[i] = digits.substring(i * partSize, (i * partSize) + partSize);
    }
    return segments;
}
Also used : Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint)

Example 5 with Fingerprint

use of org.whispersystems.libsignal.fingerprint.Fingerprint in project Signal-Android by WhisperSystems.

the class VerifyDisplayFragment method getSegments.

private String[] getSegments(Fingerprint fingerprint, int segmentCount) {
    String[] segments = new String[segmentCount];
    String digits = fingerprint.getDisplayableFingerprint().getDisplayText();
    int partSize = digits.length() / segmentCount;
    for (int i = 0; i < segmentCount; i++) {
        segments[i] = digits.substring(i * partSize, (i * partSize) + partSize);
    }
    return segments;
}
Also used : Fingerprint(org.whispersystems.libsignal.fingerprint.Fingerprint)

Aggregations

Fingerprint (org.whispersystems.libsignal.fingerprint.Fingerprint)8 Bitmap (android.graphics.Bitmap)4 NonNull (androidx.annotation.NonNull)4 TypeEvaluator (android.animation.TypeEvaluator)2 ValueAnimator (android.animation.ValueAnimator)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Context (android.content.Context)2 Intent (android.content.Intent)2 BitmapFactory (android.graphics.BitmapFactory)2 Canvas (android.graphics.Canvas)2 PorterDuff (android.graphics.PorterDuff)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Bundle (android.os.Bundle)2 Html (android.text.Html)2 TextUtils (android.text.TextUtils)2 LinkMovementMethod (android.text.method.LinkMovementMethod)2 ContextMenu (android.view.ContextMenu)2 LayoutInflater (android.view.LayoutInflater)2 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2