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().
This commit is contained in:
Davide De Rosa 2020-06-11 16:32:31 +02:00
parent 1ff936895f
commit 74ed3cb4cd
1 changed files with 17 additions and 14 deletions

View File

@ -179,18 +179,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
return return
} }
// optional credentials // prepare for logging (append)
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)
if let content = cfg.existingLog(in: appGroup) { if let content = cfg.existingLog(in: appGroup) {
var existingLog = content.components(separatedBy: "\n") var existingLog = content.components(separatedBy: "\n")
if let i = existingLog.firstIndex(of: logSeparator) { if let i = existingLog.firstIndex(of: logSeparator) {
@ -202,17 +191,28 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
existingLog.append("") existingLog.append("")
memoryLog.start(with: existingLog) memoryLog.start(with: existingLog)
} }
configureLogging( configureLogging(
debug: cfg.shouldDebug, debug: cfg.shouldDebug,
customFormat: cfg.debugLogFormat customFormat: cfg.debugLogFormat
) )
// logging only ACTIVE from now on
// override library configuration // override library configuration
if let masksPrivateData = cfg.masksPrivateData { if let masksPrivateData = cfg.masksPrivateData {
CoreConfiguration.masksPrivateData = 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...") log.info("Starting tunnel...")
cfg.clearLastError(in: appGroup) cfg.clearLastError(in: appGroup)
@ -223,6 +223,9 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
cfg.print(appVersion: appVersion) cfg.print(appVersion: appVersion)
// prepare to pick endpoints
strategy = ConnectionStrategy(configuration: cfg)
let session: OpenVPNSession let session: OpenVPNSession
do { do {
session = try OpenVPNSession(queue: tunnelQueue, configuration: cfg.sessionConfiguration, cachesURL: cachesURL) session = try OpenVPNSession(queue: tunnelQueue, configuration: cfg.sessionConfiguration, cachesURL: cachesURL)