Repository navigation
Introduce linting - #373
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
Static review identified no blocking defects in the lint integration, explicit imports, or behavior-preserving formatting changes.
No open issues 🎉
What changed in this PR
Introduces consistent Swift and Objective-C linting across TrustKit, its tests, and demo apps, with lint checks required before CI builds and tests.
Changes:
- Adds formatter configurations and a lint script supporting automatic fixes and check-only mode.
- Adds a CI lint job that gates tests, demo validation, and package builds.
- Applies formatting throughout the repository and adds explicit imports to the private validator header.
| File | Description |
|---|---|
| TrustKitTests/TSKSwizzlingTests.m | Formats swizzling tests and sorts imports. |
| TrustKitTests/TSKReportsRateLimiterTests.m | Formats rate-limiter tests. |
| TrustKitTests/TSKReporterTests.m | Formats reporting tests and sorts imports. |
| TrustKitTests/TSKPublicKeyAlgorithmTests.m | Formats key-extraction and cache tests. |
| TrustKitTests/TSKNSURLSessionTests.m | Formats session delegate tests. |
| TrustKitTests/TSKNSURLConnectionTests.m | Formats connection delegate tests. |
| TrustKitTests/TSKLoggerTests.m | Formats logging tests and sorts imports. |
| TrustKitTests/TSKEndToEndSwizzlingTests.m | Formats end-to-end swizzling tests. |
| TrustKitTests/TSKCertificateUtils.m | Formats certificate test helpers. |
| TrustKitTests/TSKCertificateUtils.h | Removes comment whitespace. |
| TrustKitDemo/TrustKitDemo-Swift/WebViewController.swift | Formats WebKit demo callbacks. |
| TrustKitDemo/TrustKitDemo-Swift/DTViewController.swift | Formats demo code and removes unused parameter names. |
| TrustKitDemo/TrustKitDemo-Swift/AppDelegate.swift | Formats startup configuration and comments. |
| TrustKitDemo/TrustKitDemo-ObjC/WebViewController.m | Formats WebKit demo methods. |
| TrustKitDemo/TrustKitDemo-ObjC/ViewController.m | Formats networking and UI methods. |
| TrustKitDemo/TrustKitDemo-ObjC/ViewController.h | Removes excess whitespace. |
| TrustKitDemo/TrustKitDemo-ObjC/main.m | Sorts imports and formats pointer spacing. |
| TrustKitDemo/TrustKitDemo-ObjC/AppDelegate.m | Formats pinning configuration and logging. |
| TrustKitDemo/TrustKitDemo-ObjC/AppDelegate.h | Removes excess whitespace. |
| TrustKit/TSKTrustKitConfig.m | Normalizes constant declaration spacing. |
| TrustKit/TSKPinningValidatorResult.m | Formats result initialization. |
| TrustKit/TSKPinningValidator.m | Formats validation logic and sorts imports. |
| TrustKit/TSKPinningValidator_Private.h | Adds explicit dependency imports. |
| TrustKit/TSKLog.h | Removes excess whitespace. |
| TrustKit/TrustKit.m | Formats initialization and reporting callbacks. |
| TrustKit/TrustKit-Bridging-Header.h | Removes a trailing blank line. |
| TrustKit/Swizzling/TSKNSURLSessionDelegateProxy.m | Formats session hooks and delegate forwarding. |
| TrustKit/Swizzling/TSKNSURLSessionDelegateProxy.h | Formats callback and method declarations. |
| TrustKit/Swizzling/TSKNSURLConnectionDelegateProxy.m | Formats connection hooks and forwarding. |
| TrustKit/Swizzling/TSKNSURLConnectionDelegateProxy.h | Normalizes interface spacing. |
| TrustKit/Swift/SubjectPublicKeyInfo.swift | Formats certificate parsing code and comments. |
| TrustKit/Reporting/vendor_identifier.m | Formats identifier helper. |
| TrustKit/Reporting/vendor_identifier.h | Removes comment whitespace. |
| TrustKit/Reporting/TSKReportsRateLimiter.m | Formats report-cache logic. |
| TrustKit/Reporting/TSKReportsRateLimiter.h | Normalizes declaration spacing. |
| TrustKit/Reporting/TSKPinFailureReport.m | Formats report construction and serialization. |
| TrustKit/Reporting/TSKPinFailureReport.h | Formats initializer declaration. |
| TrustKit/Reporting/TSKBackgroundReporter.m | Formats upload logic and sorts imports. |
| TrustKit/Reporting/TSKBackgroundReporter.h | Formats declarations and comment whitespace. |
| TrustKit/Reporting/reporting_utils.m | Formats certificate and pin conversion helpers. |
| TrustKit/Reporting/reporting_utils.h | Removes comment whitespace. |
| TrustKit/public/TrustKit/TSKTrustKitConfig.h | Formats declarations and documentation. |
| TrustKit/public/TrustKit/TSKTrustDecision.h | Formats enums and wraps documentation. |
| TrustKit/public/TrustKit/TSKPinningValidatorResult.h | Removes documentation whitespace. |
| TrustKit/public/TrustKit/TSKPinningValidatorCallback.h | Formats callback typedef and documentation spacing. |
| TrustKit/public/TrustKit/TSKPinningValidator.h | Formats methods and wraps documentation. |
| TrustKit/public/TrustKit/TrustKit.h | Sorts imports and formats public declarations. |
| TrustKit/Pinning/TSKSPKIHashCache.m | Formats hashing and persistence code. |
| TrustKit/Pinning/TSKSPKIHashCache.h | Normalizes declaration spacing. |
| TrustKit/Pinning/TSKPublicKeyAlgorithm.h | Formats enum declaration. |
| TrustKit/Pinning/ssl_pin_verifier.m | Formats verification logic and sorts imports. |
| TrustKit/Pinning/ssl_pin_verifier.h | Formats verifier declaration. |
| TrustKit/Pinning/pinning_utils.m | Formats trust-evaluation error handling. |
| TrustKit/Pinning/pinning_utils.h | Removes an extra blank line. |
| TrustKit/parse_configuration.m | Formats configuration parsing and error strings. |
| TrustKit/parse_configuration.h | Removes comment whitespace. |
| TrustKit/configuration_utils.m | Formats hostname and policy helpers. |
| TrustKit/configuration_utils.h | Normalizes declaration spacing. |
| scripts/lint.sh | Adds fix and check modes for Swift and Objective-C. |
| Package.swift | Normalizes manifest formatting. |
| .swiftlint.yml | Defines SwiftLint rules and exclusions. |
| .swift-format | Defines Swift formatting rules. |
| .github/workflows/ci.yml | Adds lint checks as a prerequisite for existing jobs. |
| .clang-format | Defines Objective-C formatting rules. |
Review effort: Balanced
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - run: brew install swiftlint clang-format | ||
| - run: ./scripts/lint.sh --check |
There was a problem hiding this comment.
🟡 (optional) Every CI run can go red with no code change once Homebrew ships a newer clang-format or SwiftLint, and that also skips all test jobs. The lint job runs brew install swiftlint clang-format with no version pin, while scripts/lint.sh --check fails on any formatting diff or strict-mode warning. Fix: pin both tools to the versions used for the reformat, e.g. a clang-format@<major> formula or a fixed SwiftLint release binary, and print their versions in the job log. Since test, demo, xcframework and swift-package all have needs: lint, one drift blocks the whole pipeline.
Why this was flagged
The lint job at .github/workflows/ci.yml:26 runs brew install swiftlint clang-format, which installs whatever version Homebrew currently has. scripts/lint.sh:30 runs clang-format --dry-run --Werror and scripts/lint.sh:29 runs swiftlint lint --strict, so the job fails on any output difference or new warning. clang-format output changes between LLVM major releases under the same .clang-format (WebKit base, InsertBraces, AlignAfterOpenBracket: BlockIndent). New SwiftLint releases add default-on rules, and --strict turns their warnings into errors. When Homebrew bumps either formula, lint fails on an unchanged tree. Because the test, demo, xcframework and swift-package jobs now have needs: lint, they are all skipped. On the base branch there is no lint job and these jobs run on every push. The only tool tied to the pinned DEVELOPER_DIR Xcode is xcrun swift format; the brew tools have no such pin.
Verification: The new lint job runs - run: brew install swiftlint clang-format with no version pin. That step is at .github/workflows/ci.yml line 25. scripts/lint.sh, which this diff adds, then fails on any difference. The diff also adds needs: lint to test, demo, xcframework and swift-package, so a lint failure caused only by a tool update skips all test and build jobs.
TrustKit 4.0 is a major release. It raises the minimum OS versions, drops CocoaPods, adds visionOS, logs through `os_log`, and accepts any domain name or IP address in the pinning configuration. Some of these changes affect which connections get pinned, so test this beta before you ship it. Please report problems in [Issues](https://github.com/datatheorem/TrustKit/issues). ## Breaking changes ### Requirements - Minimum OS versions are now iOS 15, macOS 12, Mac Catalyst 15, tvOS 15, watchOS 9 and visionOS 1. They were iOS 12, macOS 10.13, tvOS 12 and watchOS 4. - Swift Package Manager needs Xcode 16 or later (`swift-tools-version:6.0`). So does building from the Xcode project, which now uses the Xcode 16 project format. TrustKit itself is built and tested with Xcode 27. - **CocoaPods is no longer supported.** TrustKit 4.0 and later aren't published to CocoaPods, but 3.x is still available there. Use Swift Package Manager, or the static XCFramework (`TrustKit-static.zip`) attached to each release. - The `TrustKit_Static` Xcode target is removed. Use `TrustKit-static.zip` instead. ### Removed APIs - `+[TrustKit setLoggerBlock:]` is removed. TrustKit now logs through `os_log` (see [Logging](#logging)). To act on validation results in code, set `pinningValidatorCallback`. - `kTSKPublicKeyAlgorithms`, `TSKSupportedAlgorithm`, `kTSKAlgorithmRsa2048`, `kTSKAlgorithmRsa4096`, `kTSKAlgorithmEcDsaSecp256r1` and `kTSKAlgorithmEcDsaSecp384r1` are removed. They have been deprecated since 1.6.0, so remove them from your code. A configuration or Info.plist that still sets `TSKPublicKeyAlgorithms` keeps working, because the key is ignored. ### macOS-only symbols no longer compile on other platforms `kTSKIgnorePinningForUserDefinedTrustAnchors` and `TSKTrustEvaluationFailedUserDefinedTrustAnchor` are now marked unavailable on iOS, Mac Catalyst, tvOS, watchOS and visionOS. Using them there is a compile error. In code shared across platforms, wrap them in `#if TARGET_OS_OSX` (Objective-C) or `#if os(macOS)` (Swift). ### Header location The public headers moved to `TrustKit/public/TrustKit/`. `#import <TrustKit/TrustKit.h>` and `@import TrustKit;` now work the same way with Swift Package Manager and with the framework. If you have header search paths pointing into a TrustKit checkout, update them. ### Static XCFramework in apps without Swift Part of TrustKit is now written in Swift. This is internal only, and the public API hasn't changed. If your app has no Swift code of its own and targets an OS earlier than iOS 16, tvOS 16, Mac Catalyst 16 or macOS 13, linking the XCFramework fails with `Undefined symbols … __swift_FORCE_LOAD_$_swiftCompatibility56`. To fix it, add an empty Swift file to your app target. ### Swift contributions Starting with 4.0, TrustKit accepts contributions in Swift. This release ships TrustKit's first Swift code. Over time we plan to move the Objective-C classes to Swift that Objective-C can still call, so existing apps keep working unchanged. - Put new Swift files in `TrustKit/Swift/` and add them to each framework target in `TrustKit.xcodeproj`. - Swift code builds in Swift 6 language mode, with strict concurrency checking. `scripts/lint.sh` runs swift-format and SwiftLint, and CI fails if lint fails. - For now, Swift code is internal only. Swift Package Manager builds it as a separate target, which doesn't support public Swift API yet. Open an issue before you add a public Swift type. ## Pinning configuration (#333, #341) These changes affect which connections are pinned, so review your configuration when you upgrade. - **Any domain name or IP address can be pinned.** This includes internal names such as `api.internal` or `localhost`, and IPv4 or IPv6 addresses. 3.x rejected names that didn't end in an entry of its bundled public suffix list. That list is now removed. - **Keys that can never match now throw an exception at startup.** Examples are `*.example.com`, or any key containing `:`, `/`, `@` or a space. 3.x loaded these keys, and the domain silently stayed unpinned. Like any other configuration error, this raises an `NSException` from `initSharedInstanceWithConfiguration:`. If your app downloads its configuration at runtime, validate it before you pass it to TrustKit. - **Matching now ignores case and a trailing dot.** IPv6 addresses match with or without brackets, and in any notation. In 3.x, a key such as `API.example.com` never matched, and the host stayed unpinned without any warning. In 4.0 that key matches and the host is pinned. - **`kTSKIncludeSubdomains` now uses plain suffix matching.** It throws for an IP address or a single-label domain such as `com`. Otherwise it is allowed on any domain, including public suffixes such as `co.uk` or `appspot.com`, which 3.x rejected. ## Any key type can be pinned TrustKit now hashes each certificate's Subject Public Key Info exactly as it is encoded in the certificate. Before, it rebuilt the Subject Public Key Info, and that only worked for a fixed list of key types. - Key types that 3.x couldn't handle now work, ECDSA P-521 for example. In 3.x, those certificates failed with `TSKTrustEvaluationErrorCouldNotGenerateSpkiHash`, and the connection was blocked. - Pins for standard RSA 2048, 3072 and 4096 keys and for ECDSA P-256 and P-384 keys are unchanged. If a certificate encodes its key in a non-standard way, its 4.0 pin can differ from its 3.x pin. Regenerate the pin to check. - `get_pin_from_certificate.sh` replaces the Python script. It computes pins the same way TrustKit does, and takes a PEM or DER file: `./get_pin_from_certificate.sh ca.pem`. Don't re-encode the key first, for example with `openssl pkey`. For some certificates that changes the bytes, and the pin won't match. ## Logging TrustKit logs through the unified logging system (#128), under the subsystem `com.datatheorem.trustkit` and the category `TrustKit`. - Validation failures and other errors are logged at the error level. Successful validations are logged at the info level, and the detail of each step at the debug level. - **Release builds now log too.** 3.x didn't log anything in Release builds. Pinned hostnames are logged as public data, so they appear in device logs. - To watch the logs, run `log stream --level debug --predicate 'subsystem == "com.datatheorem.trustkit"'`. For the simulator, put `xcrun simctl spawn booted` in front of it. ## Pin failure reports The `app-platform` field now reports `VISIONOS` for visionOS apps, `MAC_CATALYST` for Mac Catalyst apps, and `IOS_ON_MAC` for iPhone or iPad apps running on a Mac. 3.x reported the last two as `IOS`. If your report server filters on this field, update it. The other report fields haven't changed. ## New platforms - **visionOS** is supported through Swift Package Manager, the Xcode project and the static XCFramework. - **Mac Catalyst** is now officially supported. It is declared in `Package.swift`, tested in CI and has its own slice in the XCFramework. - The static XCFramework now also includes `arm64e` slices. ## Docs and demos - In the getting started guide, the `UIWebView` section is replaced by a `WKWebView` example in Objective-C and Swift. The example validates off the main thread, and both demo apps include it. - The demo apps now use TrustKit as a local Swift package and use the UIScene lifecycle. ## For contributors - CI runs the unit tests on macOS, Mac Catalyst, and the iOS, tvOS and visionOS simulators. It also runs UI tests for both demo apps. watchOS is turned off for now, until a runner image issue is fixed. - `scripts/lint.sh` runs swift-format, SwiftLint and clang-format, and CI fails when lint fails. - OCMock now comes from Swift Package Manager instead of bundled binaries. ## What's Changed * [Issue #365] Move to Xcode 27 builds; align minOS to Apple min on Xcode 27; Drop Cocoapods support; Add visionOS support by @alexanderdibenedetto in #366 * Cleanup code comments and add wkwebview example by @alexanderdibenedetto in #367 * Replace TSKLog and +setLoggerBlock: with os_log (#128) by @alexanderdibenedetto in #368 * Allow any domain name or IP address in the pinning configuration (#333, #341) by @alexanderdibenedetto in #371 * Hash each certificate's SPKI as encoded instead of rebuilding it by @alexanderdibenedetto in #372 * Introduce linting by @alexanderdibenedetto in #373 * Remove the deprecated public key algorithm API by @alexanderdibenedetto in #375 * Set the version to 4.0.0 by @alexanderdibenedetto in #376 * Rename SPKICacheDictionnary to SPKICacheDictionary by @uroboro in #377 **Full Changelog**: 3.0.8...4.0.0-beta.1
No description provided.