Warn users if they're about to send their recovery phrase to someone

This commit is contained in:
Niels Andriesse 2021-07-19 13:15:02 +10:00
parent 5fca1de866
commit 6d2044f230
25 changed files with 153 additions and 1 deletions

View File

@ -237,6 +237,7 @@
B8AE75A425A6C6A6001A84D2 /* Data+Trimming.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */; };
B8AE760B25ABFB5A001A84D2 /* GeneralUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = B8AE760A25ABFB5A001A84D2 /* GeneralUtilities.m */; };
B8AE761425ABFBB9001A84D2 /* GeneralUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = B8AE760925ABFB00001A84D2 /* GeneralUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
B8AF4BB426A5204600583500 /* SendSeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8AF4BB326A5204600583500 /* SendSeedModal.swift */; };
B8B32021258B1A650020074B /* Contact.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B32020258B1A650020074B /* Contact.swift */; };
B8B32033258B235D0020074B /* Storage+Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B32032258B235D0020074B /* Storage+Contacts.swift */; };
B8B3204E258C15C80020074B /* ContactsMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B32044258C117C0020074B /* ContactsMigration.swift */; };
@ -1197,6 +1198,7 @@
B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Trimming.swift"; sourceTree = "<group>"; };
B8AE760925ABFB00001A84D2 /* GeneralUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneralUtilities.h; sourceTree = "<group>"; };
B8AE760A25ABFB5A001A84D2 /* GeneralUtilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GeneralUtilities.m; sourceTree = "<group>"; };
B8AF4BB326A5204600583500 /* SendSeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendSeedModal.swift; sourceTree = "<group>"; };
B8B32020258B1A650020074B /* Contact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contact.swift; sourceTree = "<group>"; };
B8B32032258B235D0020074B /* Storage+Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+Contacts.swift"; sourceTree = "<group>"; };
B8B32044258C117C0020074B /* ContactsMigration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsMigration.swift; sourceTree = "<group>"; };
@ -2109,6 +2111,7 @@
B8F5F72225F1B4CA003BF8D4 /* DownloadAttachmentModal.swift */,
C3A76A8C25DB83F90074CB90 /* PermissionMissingModal.swift */,
B821494525D4D6FF009C0F2A /* URLModal.swift */,
B8AF4BB326A5204600583500 /* SendSeedModal.swift */,
B8758859264503A6000E60D0 /* JoinOpenGroupModal.swift */,
B821494E25D4E163009C0F2A /* BodyTextView.swift */,
B82149B725D60393009C0F2A /* BlockedModal.swift */,
@ -4820,6 +4823,7 @@
B82B408E239DC00D00A248E7 /* DisplayNameVC.swift in Sources */,
B8214A2B25D63EB9009C0F2A /* MessagesTableView.swift in Sources */,
B835246E25C38ABF0089A44F /* ConversationVC.swift in Sources */,
B8AF4BB426A5204600583500 /* SendSeedModal.swift in Sources */,
B821494625D4D6FF009C0F2A /* URLModal.swift in Sources */,
C374EEEB25DA3CA70073A857 /* ConversationTitleView.swift in Sources */,
B88FA7F2260C3EB10049422F /* OpenGroupSuggestionGrid.swift in Sources */,

View File

@ -195,11 +195,19 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
sendMessage()
}
func sendMessage() {
func sendMessage(hasPermissionToSendSeed: Bool = false) {
guard !showBlockedModalIfNeeded() else { return }
let text = replaceMentions(in: snInputView.text.trimmingCharacters(in: .whitespacesAndNewlines))
let thread = self.thread
guard !text.isEmpty else { return }
if text.contains(mnemonic) && !thread.isNoteToSelf() && !hasPermissionToSendSeed {
// Warn the user if they're about to send their seed to someone
let modal = SendSeedModal()
modal.modalPresentationStyle = .overFullScreen
modal.modalTransitionStyle = .crossDissolve
modal.proceed = { self.sendMessage(hasPermissionToSendSeed: true) }
return present(modal, animated: true, completion: nil)
}
let message = VisibleMessage()
message.sentTimestamp = NSDate.millisecondTimestamp()
message.text = text

View File

@ -55,6 +55,16 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
return messagesTableView.contentSize.height - tableViewUnobscuredHeight
}
lazy var mnemonic: String = {
let identityManager = OWSIdentityManager.shared()
let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection
var hexEncodedSeed: String! = databaseConnection.object(forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) as! String?
if hexEncodedSeed == nil {
hexEncodedSeed = identityManager.identityKeyPair()!.hexEncodedPrivateKey // Legacy account
}
return Mnemonic.encode(hexEncodedString: hexEncodedSeed)
}()
lazy var viewModel = ConversationViewModel(thread: thread, focusMessageIdOnOpen: focusedMessageID, delegate: self)
lazy var mediaCache: NSCache<NSString, AnyObject> = {

View File

@ -0,0 +1,67 @@
final class SendSeedModal : Modal {
var proceed: (() -> Void)? = nil
private lazy var titleLabel: UILabel = {
let result = UILabel()
result.textColor = Colors.text
result.font = .boldSystemFont(ofSize: Values.largeFontSize)
result.text = NSLocalizedString("modal_send_seed_title", comment: "")
result.textAlignment = .center
return result
}()
private lazy var explanationLabel: UILabel = {
let result = UILabel()
result.textColor = Colors.text
result.font = .systemFont(ofSize: Values.smallFontSize)
result.text = NSLocalizedString("modal_send_seed_explanation", comment: "")
result.numberOfLines = 0
result.lineBreakMode = .byWordWrapping
result.textAlignment = .center
return result
}()
private lazy var sendSeedButton: UIButton = {
let result = UIButton()
result.set(.height, to: Values.mediumButtonHeight)
result.layer.cornerRadius = Modal.buttonCornerRadius
if isDarkMode {
result.backgroundColor = Colors.destructive
}
result.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
result.setTitleColor(isLightMode ? Colors.destructive : Colors.text, for: UIControl.State.normal)
result.setTitle(NSLocalizedString("modal_send_seed_send_button_title", comment: ""), for: UIControl.State.normal)
result.addTarget(self, action: #selector(sendSeed), for: UIControl.Event.touchUpInside)
return result
}()
private lazy var buttonStackView: UIStackView = {
let result = UIStackView(arrangedSubviews: [ cancelButton, sendSeedButton ])
result.axis = .horizontal
result.spacing = Values.mediumSpacing
result.distribution = .fillEqually
return result
}()
private lazy var mainStackView: UIStackView = {
let result = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, buttonStackView ])
result.axis = .vertical
result.spacing = Values.largeSpacing
return result
}()
override func populateContentView() {
contentView.addSubview(mainStackView)
mainStackView.pin(.leading, to: .leading, of: contentView, withInset: Values.largeSpacing)
mainStackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing)
contentView.pin(.trailing, to: .trailing, of: mainStackView, withInset: Values.largeSpacing)
contentView.pin(.bottom, to: .bottom, of: mainStackView, withInset: Values.largeSpacing)
}
// MARK: Interaction
@objc private func sendSeed() {
proceed?()
presentingViewController?.dismiss(animated: true, completion: nil)
}
}

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Gruppeneinladung öffnen";
"vc_conversation_settings_invite_button_title" = "Mitglieder hinzufügen";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Open group invitation";
"vc_conversation_settings_invite_button_title" = "Add Members";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Abrir invitación de grupo";
"vc_conversation_settings_invite_button_title" = "Añadir Miembros";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Open group invitation";
"vc_conversation_settings_invite_button_title" = "Add Members";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Avaa ryhmäkutsu";
"vc_conversation_settings_invite_button_title" = "Lisää jäseniä";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Invitation à un groupe ouvert";
"vc_conversation_settings_invite_button_title" = "Ajouter des membres";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "ग्रुप आमंत्रण खोलें";
"vc_conversation_settings_invite_button_title" = "सदस्य जोड़ें";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Otvori pozivnicu za grupu";
"vc_conversation_settings_invite_button_title" = "Dodaj članove";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Open group invitation";
"vc_conversation_settings_invite_button_title" = "Add Members";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Apri invito di gruppo";
"vc_conversation_settings_invite_button_title" = "Aggiungi membri";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "公開グループからの招待";
"vc_conversation_settings_invite_button_title" = "メンバーを追加する";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Open groepsuitnodiging";
"vc_conversation_settings_invite_button_title" = "Voeg deelnemers toe";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Otwórz zaproszenie do grupy";
"vc_conversation_settings_invite_button_title" = "Dodaj użytkowników";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Convite para grupo aberto";
"vc_conversation_settings_invite_button_title" = "Adicionar Membros";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Открыть приглашение в группу";
"vc_conversation_settings_invite_button_title" = "Добавить участников";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Otvoriť skupinovú pozvánku";
"vc_conversation_settings_invite_button_title" = "Pridať členov";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Öppen gruppinbjudan";
"vc_conversation_settings_invite_button_title" = "Lägg till medlemmar";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "การเชิญเข้าร่วมกลุ่ม";
"vc_conversation_settings_invite_button_title" = "เพิ่มสมาชิก";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "Open group invitation";
"vc_conversation_settings_invite_button_title" = "Add Members";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "打開群組邀請";
"vc_conversation_settings_invite_button_title" = "新增成員";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";

View File

@ -543,3 +543,6 @@
"view_open_group_invitation_description" = "打开群组邀请";
"vc_conversation_settings_invite_button_title" = "添加成员";
"vc_settings_faq_button_title" = "FAQ";
"modal_send_seed_title" = "Warning";
"modal_send_seed_explanation" = "This is your recovery phrase. If you send it to someone they'll have full access to your account.";
"modal_send_seed_send_button_title" = "Send";