From 8d6f971c978f01c269604e46785b19110dea39e6 Mon Sep 17 00:00:00 2001 From: Tarik Eshaq Date: Fri, 26 Jan 2024 16:58:36 -0500 Subject: [PATCH] Add FXIOS-8314 [v124]: Removes all usages of apns in keychain --- .../Account/FxAPushMessageHandler.swift | 7 ++----- .../AppDelegate+PushNotifications.swift | 19 +------------------ firefox-ios/RustFxA/FxAWebViewModel.swift | 4 ---- .../RustFxA/PushNotificationSetup.swift | 4 ---- firefox-ios/RustFxA/RustFirefoxAccounts.swift | 4 ---- firefox-ios/Shared/AppConstants.swift | 4 ---- 6 files changed, 3 insertions(+), 39 deletions(-) diff --git a/firefox-ios/Account/FxAPushMessageHandler.swift b/firefox-ios/Account/FxAPushMessageHandler.swift index 993bfc5b0477..5a28c37da0a0 100644 --- a/firefox-ios/Account/FxAPushMessageHandler.swift +++ b/firefox-ios/Account/FxAPushMessageHandler.swift @@ -10,11 +10,8 @@ import Common let PendingAccountDisconnectedKey = "PendingAccountDisconnect" /// This class provides handles push messages from FxA. -/// For reference, the [message schema][0] and [Android implementation][1] are both useful resources. -/// [0]: https://github.com/mozilla/fxa-auth-server/blob/master/docs/pushpayloads.schema.json#L26 -/// [1]: https://dxr.mozilla.org/mozilla-central/source/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountPushHandler.java -/// The main entry points are `handle` methods, to accept the raw APNS `userInfo` and then to process -/// the resulting JSON. +/// The main entry point is the `handleDecryptedMessage` method to accept the decrypted push message and parse it into a +/// `PushMessage` class FxAPushMessageHandler { let profile: Profile private let logger: Logger diff --git a/firefox-ios/Client/Application/AppDelegate+PushNotifications.swift b/firefox-ios/Client/Application/AppDelegate+PushNotifications.swift index f67e6c139c7e..37546e90aefa 100644 --- a/firefox-ios/Client/Application/AppDelegate+PushNotifications.swift +++ b/firefox-ios/Client/Application/AppDelegate+PushNotifications.swift @@ -49,7 +49,7 @@ extension AppDelegate { } } - // If we see our local device with a pushEndpointExpired flag, clear the APNS token and re-register. + // If we see our local device with a pushEndpointExpired flag, try to re-register. NotificationCenter.default.addObserver( forName: .constellationStateUpdate, object: nil, @@ -57,29 +57,12 @@ extension AppDelegate { ) { notification in if let newState = notification.userInfo?["newState"] as? ConstellationState { if newState.localDevice?.pushEndpointExpired ?? false { - MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject( - forKey: KeychainKey.apnsToken, - withAccessibility: MZKeychainItemAccessibility.afterFirstUnlock - ) NotificationCenter.default.post(name: .RegisterForPushNotifications, object: nil) // Our endpoint expired, we should check for missed messages self.profile.pollCommands(forcePoll: true) } } } - - // Use sync event as a periodic check for the apnsToken. - // The notification service extension can clear this token if there is an error, - // and the main app can detect this and re-register. - NotificationCenter.default.addObserver(forName: .ProfileDidStartSyncing, object: nil, queue: .main) { _ in - let kc = MZKeychainWrapper.sharedClientAppContainerKeychain - if kc.string( - forKey: KeychainKey.apnsToken, - withAccessibility: MZKeychainItemAccessibility.afterFirstUnlock - ) == nil { - NotificationCenter.default.post(name: .RegisterForPushNotifications, object: nil) - } - } } } diff --git a/firefox-ios/RustFxA/FxAWebViewModel.swift b/firefox-ios/RustFxA/FxAWebViewModel.swift index 9304fb670825..ff9d7ccf3803 100644 --- a/firefox-ios/RustFxA/FxAWebViewModel.swift +++ b/firefox-ios/RustFxA/FxAWebViewModel.swift @@ -281,10 +281,6 @@ extension FxAWebViewModel { // or if the onboarding flow is missing the notifications card guard self.shouldAskForNotificationPermission else { return } - MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject( - forKey: KeychainKey.apnsToken, - withAccessibility: MZKeychainItemAccessibility.afterFirstUnlock - ) NotificationManager().requestAuthorization { granted, error in guard error == nil else { return } if granted { diff --git a/firefox-ios/RustFxA/PushNotificationSetup.swift b/firefox-ios/RustFxA/PushNotificationSetup.swift index f8a39a0e4b1c..357502b742fe 100644 --- a/firefox-ios/RustFxA/PushNotificationSetup.swift +++ b/firefox-ios/RustFxA/PushNotificationSetup.swift @@ -9,10 +9,6 @@ import MozillaAppServices open class PushNotificationSetup { /// Disables FxA push notifications for the user public func disableNotifications() { - MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject( - forKey: KeychainKey.apnsToken, - withAccessibility: .afterFirstUnlock - ) if let accountManager = RustFirefoxAccounts.shared.accountManager { let subscriptionEndpoint = accountManager.deviceConstellation()? .state()?.localDevice?.pushSubscription?.endpoint diff --git a/firefox-ios/RustFxA/RustFirefoxAccounts.swift b/firefox-ios/RustFxA/RustFirefoxAccounts.swift index 0a7fb7342dab..0712f63b3a26 100644 --- a/firefox-ios/RustFxA/RustFirefoxAccounts.swift +++ b/firefox-ios/RustFxA/RustFirefoxAccounts.swift @@ -235,10 +235,6 @@ open class RustFirefoxAccounts { prefs?.removeObjectForKey(prefKeyCachedUserProfile) prefs?.removeObjectForKey(PendingAccountDisconnectedKey) cachedUserProfile = nil - MZKeychainWrapper.sharedClientAppContainerKeychain.removeObject( - forKey: KeychainKey.apnsToken, - withAccessibility: .afterFirstUnlock - ) } public func hasAccount(completion: @escaping (Bool) -> Void) { diff --git a/firefox-ios/Shared/AppConstants.swift b/firefox-ios/Shared/AppConstants.swift index 69d8040d8b25..d903a961ff12 100644 --- a/firefox-ios/Shared/AppConstants.swift +++ b/firefox-ios/Shared/AppConstants.swift @@ -47,10 +47,6 @@ public enum KVOConstants: String { case contentSize } -public struct KeychainKey { - public static let apnsToken = "apnsToken" -} - public class AppConstants { // Any type of tests (UI and Unit) public static let isRunningTest = NSClassFromString("XCTestCase") != nil