diff --git a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift index 6c6e36e..198ce67 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider+Interaction.swift @@ -51,6 +51,11 @@ extension OpenVPNTunnelProvider { /// Data is 16 bytes: low 8 = received, high 8 = sent. public static let dataCount = Message(0xfe) + /// Requests the configuration pulled from the server (if connected and available). + /// + /// Data is JSON (Decodable). + public static let serverConfiguration = Message(0xfd) + /// The underlying raw message `Data` to forward to the tunnel via IPC. public let data: Data diff --git a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift index a9a7829..35a90b2 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift @@ -277,6 +277,12 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { response?.append(UInt64(dataCount.1)) // outbound } + case .serverConfiguration: + if let cfg = session?.serverConfiguration() { + let encoder = JSONEncoder() + response = try? encoder.encode(cfg) + } + default: break } diff --git a/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift b/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift index 343d0d9..6f53b89 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift @@ -308,6 +308,10 @@ public class OpenVPNSession: Session { return controlChannel.currentDataCount() } + public func serverConfiguration() -> OpenVPN.Configuration? { + return pushReply?.options + } + public func shutdown(error: Error?) { guard !isStopping else { log.warning("Ignore stop request, already stopping!")