Fix reset configuration not working when encrypted

This commit is contained in:
Davide De Rosa 2021-02-04 16:17:50 +01:00
parent c1d02d8edb
commit 950399a20b
3 changed files with 31 additions and 4 deletions

View File

@ -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/), 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). 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 ### Added
@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Redundant keychain items. - Redundant keychain items.
- Keyboard not dismissed in "Network settings". - Keyboard not dismissed in "Network settings".
- "Reset configuration" not working with encrypted configuration files.
## 1.14.0 (2021-01-07) ## 1.14.0 (2021-01-07)

View File

@ -165,14 +165,24 @@ class ConfigurationViewController: UIViewController, StrongTableHost {
// MARK: Actions // MARK: Actions
private func resetOriginalConfiguration() { private func resetOriginalConfiguration(passphrase: String? = nil) {
guard let originalURL = originalConfigurationURL else { guard let originalURL = originalConfigurationURL else {
log.warning("Resetting with no original configuration set? Bad table model?") log.warning("Resetting with no original configuration set? Bad table model?")
return return
} }
let parsingResult: OpenVPN.ConfigurationParser.Result let parsingResult: OpenVPN.ConfigurationParser.Result
do { 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 { } catch let e {
log.error("Could not parse original configuration: \(e)") log.error("Could not parse original configuration: \(e)")
return return
@ -184,6 +194,22 @@ class ConfigurationViewController: UIViewController, StrongTableHost {
delegate?.configuration(didUpdate: initialConfiguration) 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() { @IBAction private func refresh() {
guard isEditable else { guard isEditable else {

View File

@ -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/), 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). 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 ### Added