@@ -4,6 +4,7 @@ import KeychainAccess
44import NetworkExtension
55import os
66import SwiftUI
7+ import VPNLib
78
89@MainActor
910class AppState : ObservableObject {
@@ -70,6 +71,14 @@ class AppState: ObservableObject {
7071 }
7172 }
7273
74+ @Published var useSoftNetIsolation : Bool = UserDefaults . standard. bool ( forKey: Keys . useSoftNetIsolation) {
75+ didSet {
76+ reconfigure ( )
77+ guard persistent else { return }
78+ UserDefaults . standard. set ( useSoftNetIsolation, forKey: Keys . useSoftNetIsolation)
79+ }
80+ }
81+
7382 @Published var skipHiddenIconAlert : Bool = UserDefaults . standard. bool ( forKey: Keys . skipHiddenIconAlert) {
7483 didSet {
7584 guard persistent else { return }
@@ -81,11 +90,18 @@ class AppState: ObservableObject {
8190 if !hasSession { return nil }
8291 let proto = NETunnelProviderProtocol ( )
8392 proto. providerBundleIdentifier = " \( appId) .VPN "
84- // HACK: We can't write to the system keychain, and the user keychain
85- // isn't accessible, so we'll use providerConfiguration, which is over XPC.
86- proto. providerConfiguration = [ " token " : sessionToken!]
87- if useLiteralHeaders, let headers = try ? JSONEncoder ( ) . encode ( literalHeaders) {
88- proto. providerConfiguration ? [ " literalHeaders " ] = headers
93+
94+ proto. providerConfiguration = [
95+ // HACK: We can't write to the system keychain, and the user keychain
96+ // isn't accessible, so we'll use providerConfiguration, which
97+ // writes to disk.
98+ VPNConfigurationKeys . token: sessionToken!,
99+ VPNConfigurationKeys . useSoftNetIsolation: useSoftNetIsolation,
100+ ]
101+ if useLiteralHeaders {
102+ proto. providerConfiguration ? [
103+ VPNConfigurationKeys . literalHeaders
104+ ] = literalHeaders. map { ( $0. name, $0. value) }
89105 }
90106 proto. serverAddress = baseAccessURL!. absoluteString
91107 return proto
@@ -188,6 +204,7 @@ class AppState: ObservableObject {
188204 }
189205
190206 public func clearSession( ) {
207+ logger. info ( " clearing session " )
191208 hasSession = false
192209 sessionToken = nil
193210 refreshTask? . cancel ( )
@@ -216,6 +233,7 @@ class AppState: ObservableObject {
216233
217234 static let useLiteralHeaders = " UseLiteralHeaders "
218235 static let literalHeaders = " LiteralHeaders "
236+ static let useSoftNetIsolation = " UseSoftNetIsolation "
219237 static let stopVPNOnQuit = " StopVPNOnQuit "
220238 static let startVPNOnLaunch = " StartVPNOnLaunch "
221239
0 commit comments