Skip to content

Configuration: added (internal for now) API to load public key#2215

Merged
NachoSoto merged 11 commits into
mainfrom
configuration-public-key
Feb 8, 2023
Merged

Configuration: added (internal for now) API to load public key#2215
NachoSoto merged 11 commits into
mainfrom
configuration-public-key

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Jan 14, 2023

Copy link
Copy Markdown
Contributor

Fixes CSDK-632.

Changes:

  • Created Signing to encapsulate new signing logic and types
  • Added abstractions like Signing.Certificate and Signing.PublicKey over Security C types
  • Created Configuration.EntitlementVerificationLevel and Signing.ResponseVerificationLevel (the logic for the name difference is that publicly this is used to validate entitlements, but the internal implementation works for any response).
  • Created Signing.loadPublicKey
  • Added tests for loading public key embedded in SDK
  • Added internal (for now) Configuration.with(entitlementVerificationLevel:)
  • Added SystemInfo.responseVerificationLevel with the loaded key, if enabled

For a future PR:

  • Make the Configuration.with(entitlementVerificationLevel:) public
  • Make Configuration.EntitlementVerificationLevel public
  • Add those 2 to APITesters
  • Improve documentation by adding a link to the docs
  • Verify certificate issuer in test

@NachoSoto NachoSoto added the pr:feat A new feature label Jan 14, 2023
@NachoSoto NachoSoto requested a review from a team January 14, 2023 01:25
@NachoSoto NachoSoto force-pushed the configuration-public-key branch 3 times, most recently from 8f1bc1a to 51a2635 Compare January 17, 2023 22:04
@aboedo

aboedo commented Jan 27, 2023

Copy link
Copy Markdown
Member

🤔 my thinking is that it would be useful for this to exist for testing purposes, but a customer would never need to override, right? What alternatives could we explore that don't modify the public API?
Perhaps we could have a file name where if the file exists, it overrides the key, and we use that for testing? Of course, that would mean that if the bundle is modified to include such file, it would override the key, which would make it a potential attack. Maybe we could have that only work in debug / sandbox?

@NachoSoto

Copy link
Copy Markdown
Contributor Author

Yeah when I did this I didn't have full context.
Should we make that Configuration method internal? (and DEBUG only?)

@NachoSoto NachoSoto force-pushed the configuration-public-key branch from 51a2635 to a4b1e3f Compare February 6, 2023 22:17
@NachoSoto NachoSoto changed the title Configuration: added ability to set a public key Configuration: added (internal for now) API to load public key Feb 6, 2023
@NachoSoto NachoSoto added refactor and removed blocked pr:feat A new feature labels Feb 6, 2023
@NachoSoto

Copy link
Copy Markdown
Contributor Author

This should be ready now, without any new public API.

@NachoSoto NachoSoto force-pushed the configuration-public-key branch from a4b1e3f to 2ea4a17 Compare February 6, 2023 22:23
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Hold on, I think we need to change the key loading code since it appears we're using a different type of key.

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple small things but looking good!


var publicKey: Signing.PublicKey? {
return self.systemInfo.responseVerificationLevel.publicKey
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this will be used in future tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh I moved these tests somewhere else, but let me add another one for Purchases.Configuration that uses this too.
I moved them out on a refactor and also when I made this internal, but they're still useful for when we make it public.

// everything in those classes will still be called by XCTest, and it will cause errors.
enum AvailabilityChecks {

static func iOS12APIAvailableOrSkipTest() throws {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also unused, but maybe you plan to use it for future tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh not anymore, since this feature is iOS 13 only, I'll remove it!

Comment thread Sources/Misc/SystemInfo.swift Outdated
operationDispatcher: OperationDispatcher = .default,
bundle: Bundle = .main,
storeKit2Setting: StoreKit2Setting = .default,
responseVerificationLevel: Signing.ResponseVerificationLevel = .disabled,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this use .default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes!! Great catch.

Comment thread Sources/Purchasing/Configuration.swift Outdated
private(set) var networkTimeout = Configuration.networkTimeoutDefault
private(set) var storeKit1Timeout = Configuration.storeKitRequestTimeoutDefault
private(set) var platformInfo: Purchases.PlatformInfo?
private(set) var responseVerificationLevel: Signing.ResponseVerificationLevel = .disabled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, should this be .default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Another good catch 👍🏻

@NachoSoto NachoSoto force-pushed the configuration-public-key branch from 415c083 to 4431f76 Compare February 8, 2023 16:42
@NachoSoto NachoSoto enabled auto-merge (squash) February 8, 2023 16:43
@NachoSoto NachoSoto merged commit 76dbf00 into main Feb 8, 2023
@NachoSoto NachoSoto deleted the configuration-public-key branch February 8, 2023 16:53
NachoSoto pushed a commit that referenced this pull request Feb 8, 2023
**This is an automatic release.**

### Dependency Updates
* Bump fastlane-plugin-revenuecat_internal from `738f255` to `9255366`
(#2264) via dependabot[bot] (@dependabot[bot])
* Update `Gemfile.lock` (#2254) via Cesar de la Vega (@vegaro)
### Other Changes
* `HTTPClient`: added support for sending `X-Nonce` (#2214) via
NachoSoto (@NachoSoto)
* `Configuration`: added (`internal` for now) API to load public key
(#2215) via NachoSoto (@NachoSoto)
* Replaced `Any` uses for workaround with `Box` (#2250) via NachoSoto
(@NachoSoto)
* `HTTPClientTests`: fixed failing test with missing assertions (#2262)
via NachoSoto (@NachoSoto)
* `HTTPClientTests`: refactored tests to use `waitUntil` (#2257) via
NachoSoto (@NachoSoto)
* PurchaseTester: Add Receipt Inspector UI (#2249) via Andy Boedo
(@aboedo)
* Adds dependabot (#2259) via Cesar de la Vega (@vegaro)
* `StoreKit1WrapperTests`: avoid using `Bool.random` to fix flaky code
coverage (#2258) via NachoSoto (@NachoSoto)
* `IntroEligibilityCalculator`: changed logic to handle products with no
subscription group (#2247) via NachoSoto (@NachoSoto)
NachoSoto added a commit that referenced this pull request Feb 16, 2023
…2267)

⚠️ 🎉 This also changes integration tests to use
`EntitlementVerificationLevel.enforced` so that integration tests fail
if signatures are invalid.

#### Depends on:
- https://github.com/RevenueCat/khepri/pull/5191
- https://github.com/RevenueCat/khepri/pull/5204
- #2214
- #2215 
- #2216
- #2272

_Marking this as `feat`ure because it contains a new error in
`PurchasesDiagnostics.Error`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants