From 74ed3cb4cd0d2aa6ab2c13889f2aa81b340ce0b6 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 11 Jun 2020 16:32:31 +0200 Subject: [PATCH] Move some initialization after logging configuration Logging and masking were not configured at Credentials and ConnectionStrategy initialization time, hence the missing log entries from e.g. ConnectionStrategy.init(). --- .../AppExtension/OpenVPNTunnelProvider.swift | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift index 43e6606..3e11702 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift @@ -179,18 +179,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { return } - // optional credentials - let credentials: OpenVPN.Credentials? - if let username = protocolConfiguration.username, let passwordReference = protocolConfiguration.passwordReference, - let password = try? Keychain.password(for: username, reference: passwordReference) { - - credentials = OpenVPN.Credentials(username, password) - } else { - credentials = nil - } - - strategy = ConnectionStrategy(configuration: cfg) - + // prepare for logging (append) if let content = cfg.existingLog(in: appGroup) { var existingLog = content.components(separatedBy: "\n") if let i = existingLog.firstIndex(of: logSeparator) { @@ -202,17 +191,28 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { existingLog.append("") memoryLog.start(with: existingLog) } - configureLogging( debug: cfg.shouldDebug, customFormat: cfg.debugLogFormat ) + // logging only ACTIVE from now on + // override library configuration if let masksPrivateData = cfg.masksPrivateData { CoreConfiguration.masksPrivateData = masksPrivateData } + // optional credentials + let credentials: OpenVPN.Credentials? + if let username = protocolConfiguration.username, let passwordReference = protocolConfiguration.passwordReference, + let password = try? Keychain.password(for: username, reference: passwordReference) { + + credentials = OpenVPN.Credentials(username, password) + } else { + credentials = nil + } + log.info("Starting tunnel...") cfg.clearLastError(in: appGroup) @@ -222,7 +222,10 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider { } cfg.print(appVersion: appVersion) - + + // prepare to pick endpoints + strategy = ConnectionStrategy(configuration: cfg) + let session: OpenVPNSession do { session = try OpenVPNSession(queue: tunnelQueue, configuration: cfg.sessionConfiguration, cachesURL: cachesURL)