iOS/Sources/Shared/API/Webhook/Networking/CustomServerTrustManager.swift
Zac West 662eec4c64
Allow trusting otherwise-invalid TLS certificates during onboarding (#2131)
## Summary
During onboarding, allow trusting an invalid certificate chain for most features of the app.

## Screenshots
<img src="https://user-images.githubusercontent.com/74188/170773293-14eeb3fb-2e54-42a5-b6c6-8b07c792ea24.png" width="300">

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
Future changes necessary:
- Trusting certificates if an error occurs while the app is running
- Trusting certificates when configuring internal/external URLs
2022-05-27 23:15:14 +00:00

24 lines
641 B
Swift

import Alamofire
final class CustomServerTrustManager: ServerTrustManager, ServerTrustEvaluating {
let exceptions: () -> SecurityExceptions
init(server: Server) {
self.exceptions = { server.info.connection.securityExceptions }
super.init(evaluators: [:])
}
init(exceptions: SecurityExceptions) {
self.exceptions = { exceptions }
super.init(evaluators: [:])
}
override func serverTrustEvaluator(forHost host: String) -> ServerTrustEvaluating? {
self
}
func evaluate(_ trust: SecTrust, forHost host: String) throws {
try exceptions().evaluate(trust)
}
}