Skip to content

Revert "Replace NSCoding with NSSecureCoding"#7863

Merged
charlotteliang merged 1 commit intomasterfrom
revert-7831-fm-secure-token
Apr 8, 2021
Merged

Revert "Replace NSCoding with NSSecureCoding"#7863
charlotteliang merged 1 commit intomasterfrom
revert-7831-fm-secure-token

Conversation

@charlotteliang
Copy link
Copy Markdown
Member

@charlotteliang charlotteliang commented Apr 8, 2021

Reverts #7831

Looks like this is the one breaks the Encoding/Decoding as the GULSecureCoding doesn't offer overwriting the class. Considering the code change is significant, it's less risk to revert this change and fix the secure coding on top of the original implementation. (preferably after breaking change and let the large refactor of token code settle for a while)

@charlotteliang charlotteliang requested review from maksymmalyhin and paulb777 and removed request for maksymmalyhin April 8, 2021 01:25
Copy link
Copy Markdown
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing a test that would have caught the regression?

@charlotteliang
Copy link
Copy Markdown
Member Author

The unit test didn't capture this. So we change Messaging from read/write to IIDTokenInfo to MessagingTokenInfo. We need a test like IID call deleteToken and then Messaging try to read the token.

Copy link
Copy Markdown
Contributor

@maksymmalyhin maksymmalyhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
BTW, I just realized that if we bump minimum supported macOS version to 10.13 then we don't need to use GULSecureCoding as modern NSKeyedUnarchiver API will be available for all supported OS (iOS, tvOS and watchOS versions already support the API).

Never mind, the NSKeyedUnarchiver API actually requires iOS 11+ (I misread the code) , so using GULSecureCoding is still a cleaner solution. We can consider extending GULSecureCoding to support setting the class for an unarchiver instance if we want to avoid global class override.

Copy link
Copy Markdown
Contributor

@maksymmalyhin maksymmalyhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed one potential issue(see the comment). In either way I would suggest changes to the PR. Would you mind discussing before proceeding.

@"Could not parse raw APNS Info while parsing unarchived token info: %@", error);
// TODO(chliangGoogle: Use the new API and secureCoding protocol.
@try {
[NSKeyedUnarchiver setClass:[FIRMessagingAPNSInfo class]
Copy link
Copy Markdown
Contributor

@maksymmalyhin maksymmalyhin Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we override the class globally then:

  • we can still use GULSecureCoding since the override will affect it as well
  • if the FCM version is used with IID then FIRInstanceIDAPNSInfo archives will be unarchived to FIRMessagingAPNSInfo in IID as well. It will probably not cause any issue as long as the classes are identical due to Objective-C dynamic nature, but it looks a bit risky and not clean.

I think we should modify it either:

  1. override the class only for an NSKeyedUnarchiver instance, not globally. It's a safer option.
  2. if we are fine with the global override, then the revert is not required. Just appending the global [NSKeyedUnarchiver setClass:...] will be enough. It's simpler to implement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we made the change after I/O breaking change because Messaging already had significant amount of code change and at this point we want to ensure no unnecessary changes in so we can fully tested all the complicated scenarios with IID and Messaging.

Copy link
Copy Markdown
Contributor

@maksymmalyhin maksymmalyhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline:

  • the PR is a clean revert to the tested version, so it should be safe to do
  • we will most likely postpone the NSSecureCoding update until after Firebase 8 to reduce risks
  • Firebase 8 is going to include code to make sure IID and FCM are not installed in the app together, so setting the class globally will not be an issue
  • A version after Firebase 8 will include NSSecureCoding change based on existing GULSecureCoding API

@charlotteliang charlotteliang merged commit b245611 into master Apr 8, 2021
@charlotteliang charlotteliang deleted the revert-7831-fm-secure-token branch April 8, 2021 17:25
@google-oss-bot
Copy link
Copy Markdown
Collaborator

Coverage Report

Affected SDKs

  • FirebaseMessaging-iOS-FirebaseMessaging.framework

    SDK overall coverage changed from 65.74% (aeeb015) to 65.94% (843cec5) by +0.19%.

    Filename Base (aeeb015) Head (843cec5) Diff
    FIRMessagingAPNSInfo.m 88.00% 87.23% -0.77%
    FIRMessagingCheckinService.m 91.76% 89.80% -1.96%
    FIRMessagingTokenInfo.m 77.18% 82.78% +5.60%
    FIRMessagingTokenStore.m 58.93% 68.42% +9.49%

Test Logs

@firebase firebase locked and limited conversation to collaborators May 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants