diff --git a/WireGuard.xcodeproj/project.pbxproj b/WireGuard.xcodeproj/project.pbxproj index 90a3150..15830f6 100644 --- a/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 48CF751B34E9703133F1B1AF /* Pods_WireGuard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 861983CAE8FDC13BC83E7E04 /* Pods_WireGuard.framework */; }; 4A430E802139DC8F0078172C /* icon_20pt@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A430E7F2139DC8F0078172C /* icon_20pt@3x.png */; }; 4A430E842139DCFB0078172C /* icon_60pt@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A430E832139DCFB0078172C /* icon_60pt@3x.png */; }; + 4A4349752151865E00EF92F8 /* libwg-go.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AD0900120DC4171000E9CF5 /* libwg-go.a */; }; 4A4351592124956200261999 /* Validators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4351582124956200261999 /* Validators.swift */; }; 4A43515A2124956200261999 /* Validators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4351582124956200261999 /* Validators.swift */; }; 4A43515C21249E5700261999 /* ValidatorsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A43515B21249E5700261999 /* ValidatorsTests.swift */; }; @@ -46,6 +47,7 @@ 4AD095C820DC4190000E9CF5 /* libwg-go.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AD0900120DC4171000E9CF5 /* libwg-go.a */; }; 4AEAC32920F14B3B007B67AB /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AEAC32820F14B3B007B67AB /* Log.swift */; }; 4AEAC32B20F14BA9007B67AB /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AEAC32A20F14BA9007B67AB /* Log.swift */; }; + 4AFB99C42150545500A745DA /* SetttingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AFB99C32150545500A745DA /* SetttingsTableViewController.swift */; }; 5FA1D4CB21249F7D00DBA2E6 /* Peer+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA1D4CA21249F7D00DBA2E6 /* Peer+Extension.swift */; }; 5FA1D4CD2124A05C00DBA2E6 /* Interface+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA1D4CC2124A05C00DBA2E6 /* Interface+Extension.swift */; }; 5FA1D5102124D80C00DBA2E6 /* String+Arrays.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA1D50F2124D80C00DBA2E6 /* String+Arrays.swift */; }; @@ -134,6 +136,7 @@ 4AD095C920DC42CD000E9CF5 /* WireGuardNetworkExtension-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WireGuardNetworkExtension-Bridging-Header.h"; sourceTree = ""; }; 4AEAC32820F14B3B007B67AB /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = ""; }; 4AEAC32A20F14BA9007B67AB /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = ""; }; + 4AFB99C32150545500A745DA /* SetttingsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetttingsTableViewController.swift; sourceTree = ""; }; 5FA1D4CA21249F7D00DBA2E6 /* Peer+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Peer+Extension.swift"; sourceTree = ""; }; 5FA1D4CC2124A05C00DBA2E6 /* Interface+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Interface+Extension.swift"; sourceTree = ""; }; 5FA1D50F2124D80C00DBA2E6 /* String+Arrays.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Arrays.swift"; sourceTree = ""; }; @@ -149,6 +152,7 @@ buildActionMask = 2147483647; files = ( 4ABFFEA3212D3C8300107136 /* Security.framework in Frameworks */, + 4A4349752151865E00EF92F8 /* libwg-go.a in Frameworks */, 48CF751B34E9703133F1B1AF /* Pods_WireGuard.framework in Frameworks */, 4A61D83520D98D25006C7A76 /* NetworkExtension.framework in Frameworks */, ); @@ -257,6 +261,7 @@ 4ABF718D214D8B0300A1E0BF /* TunnelInfoTableViewController.swift */, 4A4BA6D720B73CBA00223AB8 /* TunnelConfigurationTableViewController.swift */, 5FCC4342212B3092009A9C58 /* QRScanViewController.swift */, + 4AFB99C32150545500A745DA /* SetttingsTableViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -593,6 +598,7 @@ 5FA1D4CB21249F7D00DBA2E6 /* Peer+Extension.swift in Sources */, 5FA1D5122124DA6400DBA2E6 /* String+Base64.swift in Sources */, 4AC5462E2116306F00749D21 /* Tunnel+Extension.swift in Sources */, + 4AFB99C42150545500A745DA /* SetttingsTableViewController.swift in Sources */, 5FCC4343212B3092009A9C58 /* QRScanViewController.swift in Sources */, 4ABF718E214D8B0300A1E0BF /* TunnelInfoTableViewController.swift in Sources */, 4A4BAD0E20B5F6C300F12B28 /* Coordinator.swift in Sources */, @@ -796,6 +802,10 @@ "$(inherited)", "@executable_path/Frameworks", ); + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/wireguard-go-bridge", + ); PRODUCT_BUNDLE_IDENTIFIER = com.wireguard.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "WireGuard Development"; @@ -823,6 +833,10 @@ "$(inherited)", "@executable_path/Frameworks", ); + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/wireguard-go-bridge", + ); PRODUCT_BUNDLE_IDENTIFIER = com.wireguard.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "WireGuard Development"; diff --git a/WireGuard/Base.lproj/Main.storyboard b/WireGuard/Base.lproj/Main.storyboard index 5d8e3f5..bae91f9 100644 --- a/WireGuard/Base.lproj/Main.storyboard +++ b/WireGuard/Base.lproj/Main.storyboard @@ -89,16 +89,16 @@ + + + + + - - - - - @@ -548,27 +548,26 @@ + + + + + - - - - - - - + @@ -802,11 +801,18 @@ - - - - - + + + + + + + + + + + + @@ -815,7 +821,7 @@ - + @@ -845,7 +851,126 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WireGuard/Coordinators/AppCoordinator.swift b/WireGuard/Coordinators/AppCoordinator.swift index 8649c1d..9281907 100644 --- a/WireGuard/Coordinators/AppCoordinator.swift +++ b/WireGuard/Coordinators/AppCoordinator.swift @@ -137,7 +137,7 @@ class AppCoordinator: RootViewCoordinator { } // swiftlint:disable next function_body_length - func exportConfigs(barButtonItem: UIBarButtonItem) { + func exportConfigs(sourceView: UIView) { guard let path = FileManager.default .urls(for: .documentDirectory, in: .userDomainMask).first else { return @@ -196,7 +196,7 @@ class AppCoordinator: RootViewCoordinator { activityItems: [saveFileURL], applicationActivities: nil) if let popoverPresentationController = activityViewController.popoverPresentationController { - popoverPresentationController.barButtonItem = barButtonItem + popoverPresentationController.sourceView = sourceView } navigationController.present(activityViewController, animated: true) { } @@ -273,6 +273,14 @@ class AppCoordinator: RootViewCoordinator { self.navigationController.pushViewController(tunnelConfigurationViewController, animated: true) } + func showSettings() { + let settingsTableViewController = storyboard.instantiateViewController(type: SettingsTableViewController.self) + + settingsTableViewController.delegate = self + + self.navigationController.pushViewController(settingsTableViewController, animated: true) + } + public func showError(_ error: Error) { showAlert(title: NSLocalizedString("Error", comment: "Error alert title"), message: error.localizedDescription) } @@ -316,10 +324,6 @@ extension AppCoordinator: TunnelInfoTableViewControllerDelegate { } extension AppCoordinator: TunnelsTableViewControllerDelegate { - func exportTunnels(tunnelsTableViewController: TunnelsTableViewController, barButtonItem: UIBarButtonItem) { - self.exportConfigs(barButtonItem: barButtonItem) - } - func status(for tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) -> NEVPNStatus { let session = self.providerManager(for: tunnel)?.connection as? NETunnelProviderSession return session?.status ?? .invalid @@ -495,14 +499,9 @@ extension AppCoordinator: TunnelsTableViewControllerDelegate { } extension AppCoordinator: TunnelConfigurationTableViewControllerDelegate { - func export(tunnel: Tunnel, barButtonItem: UIBarButtonItem) { - exportConfig(tunnel: tunnel, barButtonItem: barButtonItem) - } - func didSave(tunnel: Tunnel, tunnelConfigurationTableViewController: TunnelConfigurationTableViewController) { saveTunnel(tunnel) } - } extension AppCoordinator: QRScanViewControllerDelegate { @@ -510,3 +509,9 @@ extension AppCoordinator: QRScanViewControllerDelegate { showTunnelConfigurationViewController(tunnel: tunnel, context: tunnel.managedObjectContext!) } } + +extension AppCoordinator: SettingsTableViewControllerDelegate { + func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) { + self.exportConfigs(sourceView: sourceView) + } +} diff --git a/WireGuard/ViewControllers/SetttingsTableViewController.swift b/WireGuard/ViewControllers/SetttingsTableViewController.swift new file mode 100644 index 0000000..a009403 --- /dev/null +++ b/WireGuard/ViewControllers/SetttingsTableViewController.swift @@ -0,0 +1,65 @@ +// +// Copyright © 2018 WireGuard LLC. All rights reserved. +// + +import UIKit + +protocol SettingsTableViewControllerDelegate: class { + func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) +} + +class SettingsTableViewController: UITableViewController { + + weak var delegate: SettingsTableViewControllerDelegate? + @IBOutlet weak var versionInfoCell: UITableViewCell! + @IBOutlet weak var goVersionInfoCell: UITableViewCell! + @IBOutlet weak var exportCell: UITableViewCell! + + @IBOutlet weak var versionInfoLabel: UILabel! + @IBOutlet weak var goVersionInfoLabel: UILabel! + + override func viewDidLoad() { + super.viewDidLoad() + versionInfoLabel.text = versionInformation + goVersionInfoLabel.text = goVersionInformation + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if let cell = tableView.cellForRow(at: indexPath) { + switch cell { + case versionInfoCell, goVersionInfoCell: + UIPasteboard.general.string = ["WireGuard for iOS:", versionInformation, "Go userspace backend:", goVersionInformation].joined(separator: "\n") + showCopyConfirmation() + case exportCell: + delegate?.exportTunnels(settingsTableViewController: self, sourceView: exportCell) + default: + () + } + tableView.deselectRow(at: indexPath, animated: true) + } + } + + var versionInformation: String { + var versionElements: [String] = [] + if let appBuildNumber = Bundle.main.infoDictionary!["CFBundleVersion"] as? String, let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String { + versionElements.append(appVersion) + versionElements.append("(\(appBuildNumber))") + } + + return versionElements.joined(separator: " ") + } + + var goVersionInformation: String { + return wgVersion().flatMap { String(cString: $0) } ?? "" + } + + private func showCopyConfirmation() { + let confirmationAlertController = UIAlertController(title: NSLocalizedString("Copied version information", comment: ""), message: UIPasteboard.general.string, preferredStyle: .alert) + confirmationAlertController.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: "Generic OK button"), style: .default, handler: nil)) + + present(confirmationAlertController, animated: true, completion: nil) + + } +} + +extension SettingsTableViewController: Identifyable {} diff --git a/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift b/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift index d5b0740..bf6ad14 100644 --- a/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift +++ b/WireGuard/ViewControllers/TunnelConfigurationTableViewController.swift @@ -9,13 +9,12 @@ import PromiseKit protocol TunnelConfigurationTableViewControllerDelegate: class { func didSave(tunnel: Tunnel, tunnelConfigurationTableViewController: TunnelConfigurationTableViewController) - func export(tunnel: Tunnel, barButtonItem: UIBarButtonItem) + func showSettings() } class TunnelConfigurationTableViewController: UITableViewController { @IBOutlet weak var saveButton: UIBarButtonItem! - @IBOutlet weak var exportButton: UIBarButtonItem! private var viewContext: NSManagedObjectContext! private weak var delegate: TunnelConfigurationTableViewControllerDelegate? @@ -41,6 +40,10 @@ class TunnelConfigurationTableViewController: UITableViewController { return tunnel } + @IBAction func showSettings(_ sender: Any) { + delegate?.showSettings() + } + @IBAction func addPeer(_ sender: Any) { if let moc = tunnel.managedObjectContext { tableView.beginUpdates() @@ -55,10 +58,6 @@ class TunnelConfigurationTableViewController: UITableViewController { } } - @IBAction func exportTunnel(_ sender: UIBarButtonItem) { - self.delegate?.export(tunnel: tunnel, barButtonItem: sender) - } - override func numberOfSections(in tableView: UITableView) -> Int { return 3 } diff --git a/WireGuard/ViewControllers/TunnelInfoTableViewController.swift b/WireGuard/ViewControllers/TunnelInfoTableViewController.swift index 094114a..cf1f05f 100644 --- a/WireGuard/ViewControllers/TunnelInfoTableViewController.swift +++ b/WireGuard/ViewControllers/TunnelInfoTableViewController.swift @@ -9,6 +9,7 @@ import PromiseKit protocol TunnelInfoTableViewControllerDelegate: class { func configure(tunnel: Tunnel, tunnelInfoTableViewController: TunnelInfoTableViewController) + func showSettings() } class TunnelInfoTableViewController: UITableViewController { @@ -63,6 +64,10 @@ class TunnelInfoTableViewController: UITableViewController { } } + @IBAction func showSettings(_ sender: Any) { + delegate?.showSettings() + } + @IBAction func editTunnelConfiguration(_ sender: Any) { delegate?.configure(tunnel: self.tunnel, tunnelInfoTableViewController: self) } diff --git a/WireGuard/ViewControllers/TunnelsTableViewController.swift b/WireGuard/ViewControllers/TunnelsTableViewController.swift index a66d3e3..8cc26e8 100644 --- a/WireGuard/ViewControllers/TunnelsTableViewController.swift +++ b/WireGuard/ViewControllers/TunnelsTableViewController.swift @@ -10,13 +10,13 @@ import BNRCoreDataStack import NetworkExtension protocol TunnelsTableViewControllerDelegate: class { - func exportTunnels(tunnelsTableViewController: TunnelsTableViewController, barButtonItem: UIBarButtonItem) func addProvider(tunnelsTableViewController: TunnelsTableViewController) func connect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) func disconnect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) func info(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) func delete(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) func status(for tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) -> NEVPNStatus + func showSettings() } class TunnelsTableViewController: UITableViewController { @@ -66,8 +66,8 @@ class TunnelsTableViewController: UITableViewController { tableView.tableFooterView = UIView(frame: CGRect.zero) } - @IBAction func exportTunnels(_ sender: UIBarButtonItem) { - delegate?.exportTunnels(tunnelsTableViewController: self, barButtonItem: sender) + @IBAction func showSettings(_ sender: Any) { + delegate?.showSettings() } @IBAction func addProvider(_ sender: UIBarButtonItem) { diff --git a/WireGuard/WireGuard-Bridging-Header.h b/WireGuard/WireGuard-Bridging-Header.h index 8c77009..95922cc 100644 --- a/WireGuard/WireGuard-Bridging-Header.h +++ b/WireGuard/WireGuard-Bridging-Header.h @@ -3,3 +3,4 @@ // #import "Crypto/x25519.h" +#import "../wireguard-go-bridge/wireguard.h" diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index f413eec..ee6493b 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -135,8 +135,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { private func connect(interfaceName: String, settings: String) -> Int32 { // swiftlint:disable:this cyclomatic_complexity return withStringsAsGoStrings(interfaceName, settings) { (nameGoStr, settingsGoStr) -> Int32 in return withUnsafeMutablePointer(to: &wgContext) { (wgCtxPtr) -> Int32 in - return wgTurnOn(nameGoStr, settingsGoStr, - { (wgCtxPtr, buf, len) -> Int in + return wgTurnOn(nameGoStr, settingsGoStr, { (wgCtxPtr, buf, len) -> Int in // read_fn: Read from the TUN interface and pass it on to WireGuard guard let wgCtxPtr = wgCtxPtr else { return 0 } guard let buf = buf else { return 0 } @@ -150,8 +149,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { return packetData.count } return 0 - }, - { (wgCtxPtr, buf, len) -> Int in + }, { (wgCtxPtr, buf, len) -> Int in // write_fn: Receive packets from WireGuard and write to the TUN interface guard let wgCtxPtr = wgCtxPtr else { return 0 } guard let buf = buf else { return 0 }