Merge branch 'trusted-via-location'

This commit is contained in:
Davide De Rosa 2019-10-21 00:38:21 +02:00
commit 38d1527b39
5 changed files with 84 additions and 21 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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.9.0 Beta 2039 (2019-10-11)
## Unreleased
### Changed
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Cannot enter IP addresses in some localizations. [#103](https://github.com/passepartoutvpn/passepartout-ios/issues/103)
- Cannot easily trust Wi-Fi networks in iOS 13. [#100](https://github.com/passepartoutvpn/passepartout-ios/issues/100)
## 1.8.1 (2019-09-15)

View File

@ -75,6 +75,18 @@ internal enum L10n {
}
}
internal enum Service {
internal enum Alerts {
internal enum Location {
internal enum Button {
/// Settings
internal static let settings = L10n.tr("App", "service.alerts.location.button.settings")
}
internal enum Message {
/// You must allow location access to trust this Wi-Fi network. Go to iOS settings and review your location permissions for Passepartout.
internal static let denied = L10n.tr("App", "service.alerts.location.message.denied")
}
}
}
internal enum Cells {
internal enum Host {
internal enum Parameters {

View File

@ -40,6 +40,8 @@
"service.cells.provider.refresh.caption" = "Refresh infrastructure";
"service.cells.host.parameters.caption" = "Parameters";
"service.cells.trusted_add_wifi.caption" = "Add current Wi-Fi";
"service.alerts.location.message.denied" = "You must allow location access to trust this Wi-Fi network. Go to iOS settings and review your location permissions for Passepartout.";
"service.alerts.location.button.settings" = "Settings";
"account.sections.credentials.header" = "Credentials";

View File

@ -11,15 +11,15 @@
<dict>
<key>CFBundleTypeName</key>
<string>All files</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.content</string>
<string>public.data</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleExecutable</key>
@ -42,6 +42,8 @@
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Trusted networks</string>
<key>NSUserActivityTypes</key>
<array>
<string>ConnectVPNIntent</string>
@ -82,10 +84,10 @@
<false/>
<key>com.algoritmico.Passepartout.config</key>
<dict>
<key>group_id</key>
<string>group.$(CFG_GROUP_ID)</string>
<key>appstore_id</key>
<string>$(CFG_APPSTORE_ID)</string>
<key>group_id</key>
<string>group.$(CFG_GROUP_ID)</string>
</dict>
</dict>
</plist>

View File

@ -26,6 +26,7 @@
import UIKit
import NetworkExtension
import MBProgressHUD
import CoreLocation
import TunnelKit
import PassepartoutCore
import Convenience
@ -39,6 +40,10 @@ class ServiceViewController: UIViewController, StrongTableHost {
@IBOutlet private weak var itemEdit: UIBarButtonItem!
private let locationManager = CLLocationManager()
private var isPendingTrustedWiFi = false
private let downloader = FileDownloader(
temporaryURL: GroupConstants.App.cachesURL.appendingPathComponent("downloaded.tmp"),
timeout: AppConstants.Web.timeout
@ -338,6 +343,50 @@ class ServiceViewController: UIViewController, StrongTableHost {
}
}
private func trustCurrentWiFi() {
if #available(iOS 13, *) {
let auth = CLLocationManager.authorizationStatus()
switch auth {
case .authorizedAlways, .authorizedWhenInUse:
break
case .denied:
isPendingTrustedWiFi = false
let alert = UIAlertController.asAlert(
L10n.App.Service.Cells.TrustedAddWifi.caption,
L10n.App.Service.Alerts.Location.Message.denied
)
alert.addCancelAction(L10n.Core.Global.ok)
alert.addPreferredAction(L10n.App.Service.Alerts.Location.Button.settings) {
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
}
present(alert, animated: true, completion: nil)
return
default:
isPendingTrustedWiFi = true
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
return
}
}
if #available(iOS 12, *) {
IntentDispatcher.donateTrustCurrentNetwork()
IntentDispatcher.donateUntrustCurrentNetwork()
}
guard trustedNetworks.addCurrentWifi() else {
let alert = UIAlertController.asAlert(
L10n.Core.Service.Sections.Trusted.header,
L10n.Core.Service.Alerts.Trusted.NoNetwork.message
)
alert.addCancelAction(L10n.Core.Global.ok)
present(alert, animated: true, completion: nil)
return
}
}
private func toggleTrustedConnectionPolicy(_ isOn: Bool, sender: ToggleTableViewCell) {
let completionHandler: () -> Void = {
self.service.preferences.trustPolicy = isOn ? .disconnect : .ignore
@ -931,20 +980,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
return true
case .trustedAddCurrentWiFi:
if #available(iOS 12, *) {
IntentDispatcher.donateTrustCurrentNetwork()
IntentDispatcher.donateUntrustCurrentNetwork()
}
guard trustedNetworks.addCurrentWifi() else {
let alert = UIAlertController.asAlert(
L10n.Core.Service.Sections.Trusted.header,
L10n.Core.Service.Alerts.Trusted.NoNetwork.message
)
alert.addCancelAction(L10n.Core.Global.ok)
present(alert, animated: true, completion: nil)
return false
}
trustCurrentWiFi()
case .testConnectivity:
testInternetConnectivity()
@ -1293,6 +1329,16 @@ extension ServiceViewController: ProviderPresetViewControllerDelegate {
}
}
extension ServiceViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
guard isPendingTrustedWiFi else {
return
}
isPendingTrustedWiFi = false
trustCurrentWiFi()
}
}
// MARK: -
private extension ServiceViewController {