datatheorem / TrustKit

Easy SSL pinning validation and reporting for iOS, macOS, tvOS and watchOS.
MIT License
2k stars 360 forks source link

restore iOS 12 support #297

Closed aj-dt closed 1 year ago

aj-dt commented 1 year ago

restore runtime support for iOS 12, tvOS 12, watchOS 4 and macOS 10.13.

Adds OS-sensitive versions for copying keys (copyKey()) and evaluating server trust (evaluateCertificateChainTrust()).

copyKey() calls SecTrustCopyKey() on iOS 14+ and SecTrustCopyPublicKey() on earlier OSs.

evaluateCertificateChainTrust() calls SecTrustEvaluateWithError() on iOS 12+ and SecTrustEvaluate() on earlier OSs.

Note that macOS, tvOS, watchOS have slightly different version thresholds.

One subtlety in the implementation lies in evaluateCertificateChainTrust() which effectively "returns" three values: the bool return value and the referenced parameters TrustResult and the NSError. Since SecTrustEvaluateWithError() and SecTrustEvaluate() return slightly different sets of these three values for the various possible scenarios, interpretation of these results is delicate and requires if conditions evaluating combinations of these values. I consider this complexity acceptable given that consumers of TrustKit are shielded from it. For validation of the current code we rely on the unit tests (which all pass).

Note that with these changes support for running on iOS 12 and iOS 13 is restored, however building with old versions of Xcode may fail. In particular, the use of @available(iOS 14.0) likely introduces a requirement to build with Xcode >= 12 (the earliest Xcode to ship with iOS 14, see here)

JuhaO81 commented 1 year ago

Thx for adding the support back! Much needed here :)

aj-dt commented 1 year ago

@nabla-c0d3 removed the bool return value from evaluateCertificateChainTrust() following your suggestion. It turned out to be redundant with the error parameter, so now there is less opportunity to cofuse that return value as a signal that the cert is trusted and one must examine the trust result to know the details.