diff --git a/Passepartout/Sources/Model/ConnectionProfile.swift b/Passepartout/Sources/Model/ConnectionProfile.swift index 313390ef..1ece6b5f 100644 --- a/Passepartout/Sources/Model/ConnectionProfile.swift +++ b/Passepartout/Sources/Model/ConnectionProfile.swift @@ -72,4 +72,11 @@ extension ConnectionProfile { } try keychain.set(password: password, for: key, label: key) } + + func removePassword(in keychain: Keychain) { + guard let key = passwordKey else { + return + } + keychain.removePassword(for: key) + } } diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 36f14328..9e9b5bc8 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -395,10 +395,11 @@ class ConnectionService: Codable { } func removeProfile(_ key: ProfileKey) { - guard let i = cache.index(forKey: key) else { + guard let profile = cache[key] else { return } - cache.remove(at: i) + cache.removeValue(forKey: key) + removeCredentials(for: profile) pendingRemoval.insert(key) if cache.isEmpty { activeProfileKey = nil @@ -458,6 +459,10 @@ class ConnectionService: Codable { try profile.setPassword(credentials?.password, in: keychain) } + func removeCredentials(for profile: ConnectionProfile) { + profile.removePassword(in: keychain) + } + // MARK: VPN func vpnConfiguration() throws -> NetworkExtensionVPNConfiguration {