mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Warn users if they're about to send their recovery phrase to someone
This commit is contained in:
parent
2b97959f45
commit
0131bc171a
@ -71,8 +71,10 @@ import org.session.libsession.utilities.TextSecurePreferences
|
|||||||
import org.session.libsession.utilities.concurrent.SimpleTask
|
import org.session.libsession.utilities.concurrent.SimpleTask
|
||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.session.libsession.utilities.recipients.RecipientModifiedListener
|
import org.session.libsession.utilities.recipients.RecipientModifiedListener
|
||||||
|
import org.session.libsignal.crypto.MnemonicCodec
|
||||||
import org.session.libsignal.utilities.ListenableFuture
|
import org.session.libsignal.utilities.ListenableFuture
|
||||||
import org.session.libsignal.utilities.guava.Optional
|
import org.session.libsignal.utilities.guava.Optional
|
||||||
|
import org.session.libsignal.utilities.hexEncodedPrivateKey
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.audio.AudioRecorder
|
import org.thoughtcrime.securesms.audio.AudioRecorder
|
||||||
@ -94,6 +96,8 @@ import org.thoughtcrime.securesms.conversation.v2.utilities.AttachmentManager
|
|||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities
|
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities
|
||||||
import org.thoughtcrime.securesms.conversation.v2.utilities.ResendMessageUtilities
|
import org.thoughtcrime.securesms.conversation.v2.utilities.ResendMessageUtilities
|
||||||
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||||
|
import org.thoughtcrime.securesms.crypto.MnemonicUtilities
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.database.DraftDatabase
|
import org.thoughtcrime.securesms.database.DraftDatabase
|
||||||
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts
|
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts
|
||||||
@ -153,6 +157,17 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
private val layoutManager: LinearLayoutManager
|
private val layoutManager: LinearLayoutManager
|
||||||
get() { return conversationRecyclerView.layoutManager as LinearLayoutManager }
|
get() { return conversationRecyclerView.layoutManager as LinearLayoutManager }
|
||||||
|
|
||||||
|
private val seed by lazy {
|
||||||
|
var hexEncodedSeed = IdentityKeyUtil.retrieve(this, IdentityKeyUtil.LOKI_SEED)
|
||||||
|
if (hexEncodedSeed == null) {
|
||||||
|
hexEncodedSeed = IdentityKeyUtil.getIdentityKeyPair(this).hexEncodedPrivateKey // Legacy account
|
||||||
|
}
|
||||||
|
val loadFileContents: (String) -> String = { fileName ->
|
||||||
|
MnemonicUtilities.loadFileContents(this, fileName)
|
||||||
|
}
|
||||||
|
MnemonicCodec(loadFileContents).encode(hexEncodedSeed!!, MnemonicCodec.Language.Configuration.english)
|
||||||
|
}
|
||||||
|
|
||||||
private val adapter by lazy {
|
private val adapter by lazy {
|
||||||
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
|
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
|
||||||
val adapter = ConversationAdapter(
|
val adapter = ConversationAdapter(
|
||||||
@ -889,11 +904,18 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
startActivityForResult(MediaSendActivity.buildEditorIntent(this, listOf( media ), thread, getMessageBody()), ConversationActivityV2.PICK_FROM_LIBRARY)
|
startActivityForResult(MediaSendActivity.buildEditorIntent(this, listOf( media ), thread, getMessageBody()), ConversationActivityV2.PICK_FROM_LIBRARY)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendTextOnlyMessage() {
|
private fun sendTextOnlyMessage(hasPermissionToSendSeed: Boolean = false) {
|
||||||
|
val text = getMessageBody()
|
||||||
|
val userPublicKey = TextSecurePreferences.getLocalNumber(this)
|
||||||
|
val isNoteToSelf = (thread.isContactRecipient && thread.address.toString() == userPublicKey)
|
||||||
|
if (text.contains(seed) && !isNoteToSelf && !hasPermissionToSendSeed) {
|
||||||
|
val dialog = SendSeedDialog { sendTextOnlyMessage(true) }
|
||||||
|
return dialog.show(supportFragmentManager, "Send Seed Dialog")
|
||||||
|
}
|
||||||
// Create the message
|
// Create the message
|
||||||
val message = VisibleMessage()
|
val message = VisibleMessage()
|
||||||
message.sentTimestamp = System.currentTimeMillis()
|
message.sentTimestamp = System.currentTimeMillis()
|
||||||
message.text = getMessageBody()
|
message.text = text
|
||||||
val outgoingTextMessage = OutgoingTextMessage.from(message, thread)
|
val outgoingTextMessage = OutgoingTextMessage.from(message, thread)
|
||||||
// Clear the input bar
|
// Clear the input bar
|
||||||
inputBar.text = ""
|
inputBar.text = ""
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package org.thoughtcrime.securesms.conversation.v2.dialogs
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import kotlinx.android.synthetic.main.dialog_send_seed.view.*
|
||||||
|
import network.loki.messenger.R
|
||||||
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
||||||
|
|
||||||
|
/** Shown if the user is about to send their recovery phrase to someone. */
|
||||||
|
class SendSeedDialog(private val proceed: (() -> Unit)? = null) : BaseDialog() {
|
||||||
|
|
||||||
|
override fun setContentView(builder: AlertDialog.Builder) {
|
||||||
|
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_send_seed, null)
|
||||||
|
contentView.cancelButton.setOnClickListener { dismiss() }
|
||||||
|
contentView.sendSeedButton.setOnClickListener { send() }
|
||||||
|
builder.setView(contentView)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun send() {
|
||||||
|
proceed?.invoke()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
57
app/src/main/res/layout/dialog_send_seed.xml
Normal file
57
app/src/main/res/layout/dialog_send_seed.xml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/default_dialog_background_inset"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:elevation="4dp"
|
||||||
|
android:padding="32dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/openURLTitleTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dialog_send_seed_title"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="@dimen/large_font_size" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/openURLExplanationTextView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/large_spacing"
|
||||||
|
android:text="@string/dialog_send_seed_explanation"
|
||||||
|
android:paddingHorizontal="@dimen/medium_spacing"
|
||||||
|
android:textColor="@color/text"
|
||||||
|
android:textSize="@dimen/small_font_size"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/large_spacing"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/Widget.Session.Button.Dialog.Unimportant"
|
||||||
|
android:id="@+id/cancelButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="@dimen/small_button_height"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/cancel" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/Widget.Session.Button.Dialog.Destructive"
|
||||||
|
android:id="@+id/sendSeedButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="@dimen/small_button_height"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginStart="@dimen/medium_spacing"
|
||||||
|
android:text="@string/dialog_send_seed_send_button_title" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -884,4 +884,8 @@
|
|||||||
<string name="media">Media</string>
|
<string name="media">Media</string>
|
||||||
<string name="UntrustedAttachmentView_download_attachment">Tap to download %s</string>
|
<string name="UntrustedAttachmentView_download_attachment">Tap to download %s</string>
|
||||||
<string name="message_details_header__error">Error</string>
|
<string name="message_details_header__error">Error</string>
|
||||||
|
|
||||||
|
<string name="dialog_send_seed_title">Warning</string>
|
||||||
|
<string name="dialog_send_seed_explanation">This is your recovery phrase. If you send it to someone they\'ll have full access to your account.</string>
|
||||||
|
<string name="dialog_send_seed_send_button_title">Send</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user