From 950399a20be7234e859eadf7203877fd77a9f24c Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 4 Feb 2021 16:17:50 +0100 Subject: [PATCH] Fix reset configuration not working when encrypted --- Passepartout/App/iOS/CHANGELOG.md | 3 +- .../Scenes/ConfigurationViewController.swift | 30 +++++++++++++++++-- Passepartout/App/macOS/CHANGELOG.md | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Passepartout/App/iOS/CHANGELOG.md b/Passepartout/App/iOS/CHANGELOG.md index eaeb2bc2..65d12947 100644 --- a/Passepartout/App/iOS/CHANGELOG.md +++ b/Passepartout/App/iOS/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 1.15.0 Beta 2564 (2021-01-30) +## Unreleased ### Added @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Redundant keychain items. - Keyboard not dismissed in "Network settings". +- "Reset configuration" not working with encrypted configuration files. ## 1.14.0 (2021-01-07) diff --git a/Passepartout/App/iOS/Scenes/ConfigurationViewController.swift b/Passepartout/App/iOS/Scenes/ConfigurationViewController.swift index fd527b12..b0c30ffa 100644 --- a/Passepartout/App/iOS/Scenes/ConfigurationViewController.swift +++ b/Passepartout/App/iOS/Scenes/ConfigurationViewController.swift @@ -165,14 +165,24 @@ class ConfigurationViewController: UIViewController, StrongTableHost { // MARK: Actions - private func resetOriginalConfiguration() { + private func resetOriginalConfiguration(passphrase: String? = nil) { guard let originalURL = originalConfigurationURL else { log.warning("Resetting with no original configuration set? Bad table model?") return } let parsingResult: OpenVPN.ConfigurationParser.Result do { - parsingResult = try OpenVPN.ConfigurationParser.parsed(fromURL: originalURL) + parsingResult = try OpenVPN.ConfigurationParser.parsed(fromURL: originalURL, passphrase: passphrase) + } catch let e as ConfigurationError { + switch e { + case .encryptionPassphrase: + log.warning("Configuration is encrypted, ask for passphrase") + askForResetConfigurationWithPassphrase(originalURL) + + default: + log.error("Could not parse original configuration: \(e)") + } + return } catch let e { log.error("Could not parse original configuration: \(e)") return @@ -184,6 +194,22 @@ class ConfigurationViewController: UIViewController, StrongTableHost { delegate?.configuration(didUpdate: initialConfiguration) } + + private func askForResetConfigurationWithPassphrase(_ originalURL: URL) { + let alert = UIAlertController.asAlert(nil, L10n.Core.ParsedFile.Alerts.EncryptionPassphrase.message) + alert.addTextField { (field) in + field.isSecureTextEntry = true + } + alert.addPreferredAction(L10n.Core.Global.ok) { + guard let passphrase = alert.textFields?.first?.text else { + return + } + self.resetOriginalConfiguration(passphrase: passphrase) + } + alert.addCancelAction(L10n.Core.Global.cancel) { + } + present(alert, animated: true, completion: nil) + } @IBAction private func refresh() { guard isEditable else { diff --git a/Passepartout/App/macOS/CHANGELOG.md b/Passepartout/App/macOS/CHANGELOG.md index 689f32c1..7f3e9651 100644 --- a/Passepartout/App/macOS/CHANGELOG.md +++ b/Passepartout/App/macOS/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 1.15.0 Beta 2564 (2021-01-30) +## Unreleased ### Added