datatheorem / datatheorem/TrustKit
TrustKit initialisation fully blocks the main thread in NotificationServiceExtension if its attempted before first unlock.
Nobody has claimed this yet.
- Dominant language
- Objective-C
- Stars
- 2.1k
- Forks
- 381
- PR merge metrics
- No merged PRs in 30d
Description
Problem description
TrustKit initialisation fully blocks the main thread ina NotificationServiceExtension if its attempted before first unlock BFU. This makes it impossible to use trustkit to pin network calls made from extensions which imo is a major issue.
Steps to reproduce
- Create an application with a NotificationServiceExtension.
- Either on the implementation of
UNNotificationServiceExtension.initorUNNotificationServiceExtension.didReceive(_:withContentHandler:)attempt to instantiate TrustKit viaTrustKit(configuration: someconfiguration). The configuration object seems irrelevant to reproduce the issue. - Install the app+extension on a real device, launch and make sure to grab the push notification token.
- Make sure to set a PIN/Password on your phone.
- Restart your phone. DO NOT UNLOCK IT
- Send a notification to the phone via your preferred method (I recommend APNS console which should just require the PN token from step 3.). The payload is not important aside from making sure it has an
aps.alertdictionary andaps.content-mutable: 1so that it gets processed by the service extension. - There should be an abnormal delay in the PN arriving.
- Perform a sysdiagnose. (I recommend using the trick with assistive touch mentioned in https://developer.apple.com/forums/thread/99634?answerId=354659022#354659022).
- Export the sysdiagnose to your computer and you should see something along these lines in the
system_logs.logarchivefile:
default 2023-10-04 13:16:30.938216 +0100 NotificationExtension Hello, I'm launching as euid = 501, uid = 501, personaid = 1000, type = DEFAULT, name = <private>
default 2023-10-04 13:16:30.980808 +0100 NotificationExtension Will initialize TrustKit <- I added this log line
error 2023-10-04 13:16:31.073940 +0100 NotificationExtension Attempting to create a background session before first device unlock!
default 2023-10-04 13:16:31.073976 +0100 NotificationExtension Waiting for first unlock
default 2023-10-04 13:16:31.074028 +0100 NotificationExtension Device is locked - waiting
error 2023-10-04 13:17:00.605212 +0100 SpringBoard [your.extension.bundle.id] Extension will be killed because it used its runtime in starting up
Explanation:
TrustKit.initcreates aTSKBackgroundReporterregardless of reporting flags in the configuration: https://github.com/datatheorem/TrustKit/blob/master/TrustKit/TrustKit.m#L156TSKBackgroundReporter.initcreates aNSURLSessionwith background configuration.- This blocks the calling thread until the phone is first unlocked (don't ask me why, its apple'd behavior.)
Expected Results:
Initialising trustKit should still be possible from a BFU context. Failing that, we should at least throw an error or have some warnings in the docs that it cannot be used by extensions reliably. (Save the next guy the insane amount of time it took me to diag this.)
Kindly,
Caio
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in TrustKit/TrustKit.m around the TSKBackgroundReporter creation at line 156, then inspect TSKBackgroundReporter.init and its background NSURLSession configuration. Reproduce initialization in a NotificationServiceExtension before first unlock and determine a safe failure or initialization path; done means TrustKit no longer blocks the extension startup, or clearly reports the limitation and documents it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, objective-c
- Domain
- mobile-dev, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100