Skip to content

Commit

Permalink
add device owner verification for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Oct 19, 2024
1 parent 2f09291 commit dd396c6
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit
import DcCore
import Intents
import LocalAuthentication

internal final class ChatsAndMediaViewController: UITableViewController {

Expand Down Expand Up @@ -157,7 +158,7 @@ internal final class ChatsAndMediaViewController: UITableViewController {
case .mediaQuality: showMediaQuality()
case .downloadOnDemand: showDownloadOnDemand()
case .receiptConfirmation: break
case .exportBackup: createBackup()
case .exportBackup: authenticateAndCreateBackup()
}
}

Expand All @@ -171,6 +172,27 @@ internal final class ChatsAndMediaViewController: UITableViewController {

// MARK: - actions

private func authenticateAndCreateBackup() {
let localAuthenticationContext = LAContext()
var error: NSError?
if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
let reason = String.localized("pref_backup_explain")
localAuthenticationContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { [weak self] success, error in
DispatchQueue.main.async {
guard let self = self else { return }
if success {
self.createBackup()
} else {
logger.info("local authentication aborted: \(String(describing: error))")
}
}
}
} else {
logger.info("local authentication unavailable: \(String(describing: error))")
createBackup()
}
}

private func createBackup() {
let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { [weak self] _ in
Expand Down

0 comments on commit dd396c6

Please sign in to comment.