datatheorem / TrustKit

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

Fix deprecation warnings #294

Closed aj-dt closed 1 year ago

aj-dt commented 1 year ago

Fixes deprecation warnings for

The deprecation warnings are fixed by delegating the same tasks to new functions in pinning_utils.m, which use if (@available(...)) to call the correct functions based on platform version, e.g. SecTrustCopyPublicKey on iOS < 14 and SecTrustCopyKey on iOS >= 14.

The replcaements for SecTrustCopyPublicKey and SecTrustGetCertificateAtIndex are straightforward.

The replacement for SecTrustEvaluate is more subtle, because SecTrustEvaluate and its replacement SecTrustEvaluateWithError behave differently: SecTrustEvaluate will return success even when the certificate is not trusted (e.g. for trustResult = kSecTrustResultRecoverableTrustFailure). But SecTrustEvaluateWithError will return failure when the certificate is not trusted (e.g. for kSecTrustResultRecoverableTrustFailure). This means that beyond just replacing SecTrustEvaluate() -> evaluateTrust(), it was necessary to adjust the if statements evaluating the result to reflect this change.

The changes were evaluated by running the unit tests after setting the minimum deployment target successively to iOS 11 and iOS 15.

aj-dt commented 1 year ago

Several additional changes made on subsequent commits: