From e4c1ea4def3625d75435bc8fdb421e5e721d5a63 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 21 Mar 2019 21:27:24 +0100 Subject: [PATCH] Delete log on masking change It may contain stale and either sensitive or irrelevant data. --- .../Scenes/ServiceViewController.swift | 25 ++++++++++++++++++- .../Sources/Model/ConnectionService.swift | 10 +++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 5919d04c..678cc592 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -48,6 +48,8 @@ class ServiceViewController: UIViewController, TableModelHost { private var lastInfrastructureUpdate: Date? + private var shouldDeleteLogOnDisconnection = false + // MARK: Table var model: TableModel = TableModel() @@ -401,6 +403,14 @@ class ServiceViewController: UIViewController, TableModelHost { private func togglePrivateDataMasking(cell: ToggleTableViewCell) { AppConstants.VPN.baseConfiguration.masksPrivateData = cell.isOn service.baseConfiguration = AppConstants.VPN.baseConfiguration.build() + + // for privacy, delete potentially unmasked data + if vpn.status != .disconnected { + shouldDeleteLogOnDisconnection = true + } else { + service.eraseVpnLog() + shouldDeleteLogOnDisconnection = false + } } private func postSupportRequest() { @@ -417,8 +427,21 @@ class ServiceViewController: UIViewController, TableModelHost { @objc private func vpnDidUpdate() { reloadVpnStatus() - if vpn.status == .connected { + guard let status = vpn.status else { + return + } + switch status { + case .connected: Reviewer.shared.reportEvent() + + case .disconnected: + if shouldDeleteLogOnDisconnection { + service.eraseVpnLog() + shouldDeleteLogOnDisconnection = false + } + + default: + break } } diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 45f0ec1e..a487375f 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -510,7 +510,11 @@ public class ConnectionService: Codable { baseConfiguration.clearLastError(in: appGroup) } -// public func eraseVpnLog() { -// defaults.removeObject(forKey: Keys.vpnLog) -// } + public func eraseVpnLog() { + log.info("Erasing VPN log...") + guard let url = baseConfiguration.urlForLog(in: appGroup) else { + return + } + try? FileManager.default.removeItem(at: url) + } }