From d8ed0c7d41dafa6e5e8311d49a566326b8ce462c Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 1 Mar 2021 13:11:51 +0530 Subject: [PATCH] Cleanup cached PEMs at the end of a Session --- .../Sources/Protocols/OpenVPN/OpenVPNSession.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift b/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift index 8070618..bf86863 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift @@ -243,11 +243,7 @@ public class OpenVPNSession: Session { /// :nodoc: deinit { cleanup() - - let fm = FileManager.default - for url in [caURL, clientCertificateURL, clientKeyURL] { - try? fm.removeItem(at: url) - } + cleanupCache() } // MARK: Session @@ -358,6 +354,13 @@ public class OpenVPNSession: Session { stopError = nil } + func cleanupCache() { + let fm = FileManager.default + for url in [caURL, clientCertificateURL, clientKeyURL] { + try? fm.removeItem(at: url) + } + } + // MARK: Loop // Ruby: start @@ -1249,6 +1252,7 @@ public class OpenVPNSession: Session { switch method { case .shutdown: self?.doShutdown(error: error) + self?.cleanupCache() case .reconnect: self?.doReconnect(error: error)