Add a certificate validator hook. (#3069)

* Add a certificate validator hook.

* General tidy up of AppHooks.

* Don't worry about the generic call links.
This commit is contained in:
Doug
2024-07-19 17:05:54 +01:00
committed by GitHub
parent 74907d321f
commit cdd763efd4
21 changed files with 227 additions and 104 deletions
@@ -25,6 +25,7 @@ struct CallScreenCoordinatorParameters {
let elementCallBaseURL: URL
let elementCallBaseURLOverride: URL?
let colorScheme: ColorScheme
let appHooks: AppHooks
}
enum CallScreenCoordinatorAction {
@@ -47,7 +48,8 @@ final class CallScreenCoordinator: CoordinatorProtocol {
clientID: parameters.clientID,
elementCallBaseURL: parameters.elementCallBaseURL,
elementCallBaseURLOverride: parameters.elementCallBaseURLOverride,
colorScheme: parameters.colorScheme)
colorScheme: parameters.colorScheme,
appHooks: parameters.appHooks)
}
func start() {
@@ -24,6 +24,9 @@ struct CallScreenViewState: BindableState {
let messageHandler: String
let script: String?
var url: URL?
let certificateValidator: CertificateValidatorHookProtocol
var bindings = Bindings()
}
@@ -43,7 +43,8 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
clientID: String,
elementCallBaseURL: URL,
elementCallBaseURLOverride: URL?,
colorScheme: ColorScheme) {
colorScheme: ColorScheme,
appHooks: AppHooks) {
guard let deviceID = clientProxy.deviceID else { fatalError("Missing device ID for the call.") }
self.elementCallService = elementCallService
@@ -52,7 +53,8 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol
widgetDriver = roomProxy.elementCallWidgetDriver(deviceID: deviceID)
super.init(initialViewState: CallScreenViewState(messageHandler: Self.eventHandlerName,
script: Self.eventHandlerInjectionScript))
script: Self.eventHandlerInjectionScript,
certificateValidator: appHooks.certificateValidatorHook))
state.bindings.javaScriptMessageHandler = { [weak self] message in
guard let self,
@@ -54,6 +54,7 @@ private struct WebView: UIViewRepresentable {
@MainActor
class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate {
private weak var viewModelContext: CallScreenViewModel.Context?
private let certificateValidator: CertificateValidatorHookProtocol
private(set) var webView: WKWebView!
@@ -61,6 +62,7 @@ private struct WebView: UIViewRepresentable {
init(viewModelContext: CallScreenViewModel.Context) {
self.viewModelContext = viewModelContext
certificateValidator = viewModelContext.viewState.certificateValidator
super.init()
@@ -131,6 +133,10 @@ private struct WebView: UIViewRepresentable {
// MARK: - WKNavigationDelegate
func webView(_ webView: WKWebView, respondTo challenge: URLAuthenticationChallenge) async -> (URLSession.AuthChallengeDisposition, URLCredential?) {
await certificateValidator.respondTo(challenge)
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
// Allow any content from the main URL.
if navigationAction.request.url?.host == url.host {
@@ -193,7 +199,8 @@ struct CallScreen_Previews: PreviewProvider {
clientID: "io.element.elementx",
elementCallBaseURL: "https://call.element.io",
elementCallBaseURLOverride: nil,
colorScheme: .light)
colorScheme: .light,
appHooks: AppHooks())
}()
static var previews: some View {