mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 09:32:52 +02:00
Complete security: Handle incoming SAS transaction.
This commit is contained in:
+5
@@ -60,10 +60,15 @@ final class KeyVerificationSelfVerifyWaitCoordinator: KeyVerificationSelfVerifyW
|
||||
|
||||
// MARK: - KeyVerificationSelfVerifyWaitViewModelCoordinatorDelegate
|
||||
extension KeyVerificationSelfVerifyWaitCoordinator: KeyVerificationSelfVerifyWaitViewModelCoordinatorDelegate {
|
||||
|
||||
func keyVerificationSelfVerifyWaitViewModel(_ viewModel: KeyVerificationSelfVerifyWaitViewModelType, didAcceptKeyVerificationRequest keyVerificationRequest: MXKeyVerificationRequest) {
|
||||
self.delegate?.keyVerificationSelfVerifyWaitCoordinator(self, didAcceptKeyVerificationRequest: keyVerificationRequest)
|
||||
}
|
||||
|
||||
func keyVerificationSelfVerifyWaitViewModel(_ viewModel: KeyVerificationSelfVerifyWaitViewModelType, didAcceptIncomingSASTransaction incomingSASTransaction: MXIncomingSASTransaction) {
|
||||
self.delegate?.keyVerificationSelfVerifyWaitCoordinator(self, didAcceptIncomingSASTransaction: incomingSASTransaction)
|
||||
}
|
||||
|
||||
func keyVerificationSelfVerifyWaitViewModelDidCancel(_ viewModel: KeyVerificationSelfVerifyWaitViewModelType) {
|
||||
self.delegate?.keyVerificationSelfVerifyWaitCoordinatorDidCancel(self)
|
||||
}
|
||||
|
||||
+1
@@ -20,6 +20,7 @@ import Foundation
|
||||
|
||||
protocol KeyVerificationSelfVerifyWaitCoordinatorDelegate: class {
|
||||
func keyVerificationSelfVerifyWaitCoordinator(_ coordinator: KeyVerificationSelfVerifyWaitCoordinatorType, didAcceptKeyVerificationRequest keyVerificationRequest: MXKeyVerificationRequest)
|
||||
func keyVerificationSelfVerifyWaitCoordinator(_ coordinator: KeyVerificationSelfVerifyWaitCoordinatorType, didAcceptIncomingSASTransaction incomingSASTransaction: MXIncomingSASTransaction)
|
||||
func keyVerificationSelfVerifyWaitCoordinatorDidCancel(_ coordinator: KeyVerificationSelfVerifyWaitCoordinatorType)
|
||||
}
|
||||
|
||||
|
||||
+24
@@ -134,6 +134,10 @@ final class KeyVerificationSelfVerifyWaitViewController: UIViewController {
|
||||
self.renderLoading()
|
||||
case .loaded(let isNewSignIn):
|
||||
self.renderLoaded(isNewSignIn: isNewSignIn)
|
||||
case .cancelled(let reason):
|
||||
self.renderCancelled(reason: reason)
|
||||
case .cancelledByMe(let reason):
|
||||
self.renderCancelledByMe(reason: reason)
|
||||
case .error(let error):
|
||||
self.render(error: error)
|
||||
}
|
||||
@@ -150,6 +154,26 @@ final class KeyVerificationSelfVerifyWaitViewController: UIViewController {
|
||||
self.cancelBarButtonItem?.title = isNewSignIn ? VectorL10n.skip : VectorL10n.cancel
|
||||
}
|
||||
|
||||
private func renderCancelled(reason: MXTransactionCancelCode) {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
|
||||
self.errorPresenter.presentError(from: self, title: "", message: VectorL10n.deviceVerificationCancelled, animated: true) {
|
||||
self.viewModel.process(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
|
||||
private func renderCancelledByMe(reason: MXTransactionCancelCode) {
|
||||
if reason.value != MXTransactionCancelCode.user().value {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
|
||||
self.errorPresenter.presentError(from: self, title: "", message: VectorL10n.deviceVerificationCancelledByMe(reason.humanReadable), animated: true) {
|
||||
self.viewModel.process(viewAction: .cancel)
|
||||
}
|
||||
} else {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
private func render(error: Error) {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
self.errorPresenter.presentError(from: self, forError: error, animated: true, handler: nil)
|
||||
|
||||
+47
@@ -65,6 +65,7 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai
|
||||
private func loadData() {
|
||||
self.registerKeyVerificationManagerNewRequestNotification(for: self.verificationManager)
|
||||
self.update(viewState: .loaded(self.isNewSignIn))
|
||||
self.registerTransactionDidStateChangeNotification()
|
||||
}
|
||||
|
||||
private func cancel() {
|
||||
@@ -88,6 +89,7 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai
|
||||
return
|
||||
}
|
||||
|
||||
self.unregisterKeyVerificationManagerNewRequestNotification()
|
||||
self.coordinatorDelegate?.keyVerificationSelfVerifyWaitViewModel(self, didAcceptKeyVerificationRequest: keyVerificationRequest)
|
||||
|
||||
}, failure: { [weak self] (error) in
|
||||
@@ -122,6 +124,51 @@ final class KeyVerificationSelfVerifyWaitViewModel: KeyVerificationSelfVerifyWai
|
||||
return
|
||||
}
|
||||
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.acceptKeyVerificationRequest(keyVerificationRequest)
|
||||
}
|
||||
|
||||
// MARK: MXKeyVerificationTransactionDidChange
|
||||
|
||||
private func registerTransactionDidStateChangeNotification() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(transactionDidStateChange(notification:)), name: .MXKeyVerificationTransactionDidChange, object: nil)
|
||||
}
|
||||
|
||||
private func unregisterTransactionDidStateChangeNotification() {
|
||||
NotificationCenter.default.removeObserver(self, name: .MXKeyVerificationTransactionDidChange, object: nil)
|
||||
}
|
||||
|
||||
@objc private func transactionDidStateChange(notification: Notification) {
|
||||
guard let sasTransaction = notification.object as? MXIncomingSASTransaction,
|
||||
sasTransaction.otherUserId == self.session.myUserId else {
|
||||
return
|
||||
}
|
||||
self.sasTransactionDidStateChange(sasTransaction)
|
||||
}
|
||||
|
||||
private func sasTransactionDidStateChange(_ transaction: MXIncomingSASTransaction) {
|
||||
switch transaction.state {
|
||||
case MXSASTransactionStateIncomingShowAccept:
|
||||
// Stop listening for incoming request
|
||||
self.unregisterKeyVerificationManagerNewRequestNotification()
|
||||
transaction.accept()
|
||||
case MXSASTransactionStateShowSAS:
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.coordinatorDelegate?.keyVerificationSelfVerifyWaitViewModel(self, didAcceptIncomingSASTransaction: transaction)
|
||||
case MXSASTransactionStateCancelled:
|
||||
guard let reason = transaction.reasonCancelCode else {
|
||||
return
|
||||
}
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.update(viewState: .cancelled(reason))
|
||||
case MXSASTransactionStateCancelledByMe:
|
||||
guard let reason = transaction.reasonCancelCode else {
|
||||
return
|
||||
}
|
||||
self.unregisterTransactionDidStateChangeNotification()
|
||||
self.update(viewState: .cancelledByMe(reason))
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ protocol KeyVerificationSelfVerifyWaitViewModelViewDelegate: class {
|
||||
|
||||
protocol KeyVerificationSelfVerifyWaitViewModelCoordinatorDelegate: class {
|
||||
func keyVerificationSelfVerifyWaitViewModel(_ viewModel: KeyVerificationSelfVerifyWaitViewModelType, didAcceptKeyVerificationRequest keyVerificationRequest: MXKeyVerificationRequest)
|
||||
func keyVerificationSelfVerifyWaitViewModel(_ viewModel: KeyVerificationSelfVerifyWaitViewModelType, didAcceptIncomingSASTransaction incomingSASTransaction: MXIncomingSASTransaction)
|
||||
func keyVerificationSelfVerifyWaitViewModelDidCancel(_ viewModel: KeyVerificationSelfVerifyWaitViewModelType)
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -22,5 +22,7 @@ import Foundation
|
||||
enum KeyVerificationSelfVerifyWaitViewState {
|
||||
case loading
|
||||
case loaded(_ isNewSignIn: Bool)
|
||||
case cancelled(MXTransactionCancelCode)
|
||||
case cancelledByMe(MXTransactionCancelCode)
|
||||
case error(Error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user