Global: fix up strings

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-11-01 18:59:58 +01:00
parent 196daccdde
commit c2d76b9c45
8 changed files with 43 additions and 53 deletions

View File

@ -39,7 +39,7 @@ struct PeerConfiguration: Codable {
var preSharedKey: Data? {
didSet(value) {
if let value = value {
if (value.count != 32) { fatalError("Invalid pre-shared key") }
if (value.count != 32) { fatalError("Invalid preshared key") }
}
}
}

View File

@ -22,9 +22,9 @@ class TunnelViewModel {
enum PeerField: String {
case publicKey = "Public key"
case preSharedKey = "Pre-shared key"
case preSharedKey = "Preshared key"
case endpoint = "Endpoint"
case persistentKeepAlive = "Persistent Keepalive"
case persistentKeepAlive = "Persistent keepalive"
case allowedIPs = "Allowed IPs"
case excludePrivateIPs = "Exclude private IPs"
case deletePeer = "Delete peer"
@ -107,7 +107,7 @@ class TunnelViewModel {
}
guard let privateKey = Data(base64Encoded: privateKeyString), privateKey.count == 32 else {
fieldsWithError.insert(.privateKey)
return .error("Interface's private key should be a 32-byte key in base64 encoding")
return .error("Interface's private key must be a 32-byte key in base64 encoding")
}
var config = InterfaceConfiguration(name: name, privateKey: privateKey)
var errorMessages: [String] = []
@ -119,7 +119,7 @@ class TunnelViewModel {
addresses.append(address)
} else {
fieldsWithError.insert(.addresses)
errorMessages.append("Interface addresses should be a list of comma-separated IP addresses")
errorMessages.append("Interface addresses must be a list of comma-separated IP addresses, optionally in CIDR notation")
}
}
config.addresses = addresses
@ -129,15 +129,15 @@ class TunnelViewModel {
config.listenPort = listenPort
} else {
fieldsWithError.insert(.listenPort)
errorMessages.append("Interface's listen port should be a 16-bit integer (0 to 65535)")
errorMessages.append("Interface's listen port must be between 0 and 65535, or unspecified")
}
}
if let mtuString = scratchpad[.mtu] {
if let mtu = UInt16(mtuString) {
if let mtu = UInt16(mtuString), mtu >= 576 {
config.mtu = mtu
} else {
fieldsWithError.insert(.mtu)
errorMessages.append("Interface's MTU should be a 16-bit integer (0 to 65535)")
errorMessages.append("Interface's MTU must be between 576 and 65535, or unspecified")
}
}
if let dnsString = scratchpad[.dns] {
@ -148,7 +148,7 @@ class TunnelViewModel {
dnsServers.append(dnsServer)
} else {
fieldsWithError.insert(.dns)
errorMessages.append("Interface's DNS should be a list of comma-separated IP addresses")
errorMessages.append("Interface's DNS servers must be a list of comma-separated IP addresses")
}
}
config.dns = dnsServers
@ -243,7 +243,7 @@ class TunnelViewModel {
}
guard let publicKey = Data(base64Encoded: publicKeyString), publicKey.count == 32 else {
fieldsWithError.insert(.publicKey)
return .error("Peer's public key should be a 32-byte key in base64 encoding")
return .error("Peer's public key must be a 32-byte key in base64 encoding")
}
var config = PeerConfiguration(publicKey: publicKey)
var errorMessages: [String] = []
@ -252,7 +252,7 @@ class TunnelViewModel {
config.preSharedKey = preSharedKey
} else {
fieldsWithError.insert(.preSharedKey)
errorMessages.append("Peer's pre-shared key should be a 32-byte key in base64 encoding")
errorMessages.append("Peer's preshared key must be a 32-byte key in base64 encoding")
}
}
if let allowedIPsString = scratchpad[.allowedIPs] {
@ -263,7 +263,7 @@ class TunnelViewModel {
allowedIPs.append(allowedIP)
} else {
fieldsWithError.insert(.allowedIPs)
errorMessages.append("Peer's allowedIPs should be a list of comma-separated IP addresses in CIDR notation")
errorMessages.append("Peer's allowed IPs must be a list of comma-separated IP addresses, optionally in CIDR notation")
}
}
config.allowedIPs = allowedIPs
@ -273,7 +273,7 @@ class TunnelViewModel {
config.endpoint = endpoint
} else {
fieldsWithError.insert(.endpoint)
errorMessages.append("Peer's endpoint should be of the form 'host:port' or '[host]:port'")
errorMessages.append("Peer's endpoint must be of the form 'host:port' or '[host]:port'")
}
}
if let persistentKeepAliveString = scratchpad[.persistentKeepAlive] {
@ -281,7 +281,7 @@ class TunnelViewModel {
config.persistentKeepAlive = persistentKeepAlive
} else {
fieldsWithError.insert(.persistentKeepAlive)
errorMessages.append("Peer's persistent keepalive should be a 16-bit integer (0 to 65535)")
errorMessages.append("Peer's persistent keepalive must be between 0 to 65535, or unspecified")
}
}

View File

@ -10,21 +10,21 @@ class ErrorPresenter {
// TunnelManagementError
case TunnelManagementError.tunnelAlreadyExistsWithThatName:
return ("Name already in use", "A tunnel with that name already exists. Please pick a different name.")
return ("Name already exists", "A tunnel with that name already exists. Please choose a different name.")
case TunnelManagementError.vpnSystemErrorOnAddTunnel:
return ("Could not create tunnel", "Internal error")
return ("Unable to create tunnel", "Internal error")
case TunnelManagementError.vpnSystemErrorOnModifyTunnel:
return ("Could not modify tunnel", "Internal error")
return ("Unable to modify tunnel", "Internal error")
case TunnelManagementError.vpnSystemErrorOnRemoveTunnel:
return ("Could not remove tunnel", "Internal error")
return ("Unable to remove tunnel", "Internal error")
// TunnelActivationError
case TunnelActivationError.noEndpoint:
return ("Endpoint missing", "There must be at least one peer with an endpoint")
case TunnelActivationError.dnsResolutionFailed:
return ("DNS Failure", "One or more endpoint domains could not be resolved")
return ("DNS resolution failure", "One or more endpoint domains could not be resolved")
case TunnelActivationError.tunnelActivationFailed:
return ("Activation failed", "The tunnel could not be activated because of an internal error")
return ("Activation failure", "The tunnel could not be activated due to an internal error")
case TunnelActivationError.attemptingActivationWhenAnotherTunnelIsBusy(let otherTunnelStatus):
let statusString: String = {
switch (otherTunnelStatus) {
@ -41,7 +41,7 @@ class ErrorPresenter {
fatalError()
}
}()
return ("Activation failed", "Another tunnel is currently \(statusString). Only one tunnel can be in operation at a time.")
return ("Activation failure", "Another tunnel is currently \(statusString). Only one tunnel may be in operation at a time.")
default:
os_log("ErrorPresenter: Error not presented: %{public}@", log: OSLog.default, type: .error, "\(error)")

View File

@ -40,7 +40,7 @@ class QRScanViewController: UIViewController {
let captureSession = captureSession,
captureSession.canAddInput(videoInput),
captureSession.canAddOutput(metadataOutput) else {
scanDidEncounterError(title: "Scanning Not Supported", message: "This device does not have the ability to scan QR codes.")
scanDidEncounterError(title: "Camera Unsupported", message: "This device is not able to scan QR codes.")
return
}
@ -108,11 +108,11 @@ class QRScanViewController: UIViewController {
func scanDidComplete(withCode code: String) {
let scannedTunnelConfiguration = try? WgQuickConfigFileParser.parse(code, name: "Scanned")
guard let tunnelConfiguration = scannedTunnelConfiguration else {
scanDidEncounterError(title: "Invalid Code", message: "The scanned code is not a valid WireGuard config file.")
scanDidEncounterError(title: "Invalid QR Code", message: "The scanned QR code is not a valid WireGuard configuration.")
return
}
let alert = UIAlertController(title: NSLocalizedString("Enter a title for new tunnel", comment: ""), message: nil, preferredStyle: .alert)
let alert = UIAlertController(title: NSLocalizedString("Please name the scanned tunnel", comment: ""), message: nil, preferredStyle: .alert)
alert.addTextField(configurationHandler: nil)
alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: NSLocalizedString("Save", comment: ""), style: .default, handler: { [weak self] _ in

View File

@ -46,7 +46,7 @@ class SettingsTableViewController: UITableViewController {
func exportConfigurationsAsZipFile(sourceView: UIView) {
guard let tunnelsManager = tunnelsManager, tunnelsManager.numberOfTunnels() > 0 else {
showErrorAlert(title: "Nothing to export", message: "There are no tunnel configurations to export")
showErrorAlert(title: "Nothing to export", message: "There are no tunnels to export")
return
}
var inputsToArchiver: [(fileName: String, contents: Data)] = []
@ -76,21 +76,15 @@ class SettingsTableViewController: UITableViewController {
os_log("Failed to delete file: %{public}@ : %{public}@", log: OSLog.default, type: .error, destinationURL.absoluteString, error.localizedDescription)
}
var ok = false
do {
try ZipArchive.archive(inputs: inputsToArchiver, to: destinationURL)
ok = true
} catch {
os_log("Failed to create archive: %{public}@ : %{public}@", log: OSLog.default, type: .error, destinationURL.absoluteString)
}
if (ok) {
let activityVC = UIActivityViewController(activityItems: [destinationURL], applicationActivities: nil)
// popoverPresentationController shall be non-nil on the iPad
activityVC.popoverPresentationController?.sourceView = sourceView
present(activityVC, animated: true)
} else {
showErrorAlert(title: "Could not export", message: "There was an error creating the tunnel configuration archive")
} catch (let error) {
showErrorAlert(title: "Unable to export", message: "There was an error exporting the tunnel configuration archive: \(String(describing: error))")
}
}

View File

@ -42,15 +42,13 @@ class TunnelsListTableViewController: UITableViewController {
}
@objc func addButtonTapped(sender: UIBarButtonItem!) {
let alert = UIAlertController(title: "",
message: "Add a tunnel",
preferredStyle: .actionSheet)
let importFileAction = UIAlertAction(title: "Import file or archive", style: .default) { [weak self] (action) in
let alert = UIAlertController(title: "", message: "Add a new WireGuard tunnel", preferredStyle: .actionSheet)
let importFileAction = UIAlertAction(title: "Create from file or archive", style: .default) { [weak self] (action) in
self?.presentViewControllerForFileImport()
}
alert.addAction(importFileAction)
let scanQRCodeAction = UIAlertAction(title: "Scan QR code", style: .default) { [weak self] (action) in
let scanQRCodeAction = UIAlertAction(title: "Create from QR code", style: .default) { [weak self] (action) in
self?.presentViewControllerForScanningQRCode()
}
alert.addAction(scanQRCodeAction)
@ -83,8 +81,8 @@ class TunnelsListTableViewController: UITableViewController {
do {
let fileContents = try String(contentsOf: configFileURL)
try tunnelConfiguration = WgQuickConfigFileParser.parse(fileContents, name: name)
} catch {
showErrorAlert(title: "Could not import config", message: "There was an error importing the config file")
} catch (let error) {
showErrorAlert(title: "Unable to import tunnel", message: "An error occured when importing the tunnel configuration: \(String(describing: error))")
return
}
tunnelConfiguration?.interface.name = name
@ -140,18 +138,18 @@ class TunnelsListTableViewController: UITableViewController {
}
}
} else {
showErrorAlert(title: "Could not import", message: "The config file contained errors")
showErrorAlert(title: "Unable to import tunnel", message: "An error occured when importing the tunnel configuration.")
}
} else if (url.pathExtension == "zip") {
var unarchivedFiles: [(fileName: String, contents: Data)] = []
do {
unarchivedFiles = try ZipArchive.unarchive(url: url, requiredFileExtensions: ["conf"])
} catch ZipArchiveError.cantOpenInputZipFile {
showErrorAlert(title: "Cannot read zip archive", message: "The zip file couldn't be read")
showErrorAlert(title: "Unable to read zip archive", message: "The zip archive could not be read")
} catch ZipArchiveError.badArchive {
showErrorAlert(title: "Cannot read zip archive", message: "Bad archive")
showErrorAlert(title: "Unable to read zip archive", message: "Bad or corrupt zip archive")
} catch (let error) {
print("Error opening zip archive: \(error)")
showErrorAlert(title: "Unable to read zip archive", message: "Unexpected error: \(String(describing: error))")
}
var numberOfConfigFilesWithErrors = 0
var tunnelConfigurationsToAdd: [TunnelConfiguration] = []
@ -167,7 +165,7 @@ class TunnelsListTableViewController: UITableViewController {
}
}
guard (tunnelConfigurationsToAdd.count > 0) else {
showErrorAlert(title: "No configurations found", message: "Zip archive doesn't contain any valid .conf files")
showErrorAlert(title: "No configurations found", message: "Zip archive does not contain any valid .conf files")
return
}
var numberOfTunnelsRemainingAfterError = 0
@ -179,8 +177,8 @@ class TunnelsListTableViewController: UITableViewController {
}
}
if (numberOfConfigFilesWithErrors > 0) {
showErrorAlert(title: "Could not import \(numberOfConfigFilesWithErrors + numberOfTunnelsRemainingAfterError) files",
message: "\(numberOfConfigFilesWithErrors) of \(unarchivedFiles.count) files contained errors or duplicate names and were not imported")
showErrorAlert(title: "Created \(unarchivedFiles.count) tunnels",
message: "Created \(numberOfTunnelsRemainingAfterError) of \(unarchivedFiles.count) tunnels from files in zip archive")
}
}
}
@ -254,8 +252,8 @@ extension TunnelsListTableViewController {
}
}
} else {
tunnelsManager.startDeactivation(of: tunnel) { error in
print("Error while deactivating: \(String(describing: error))")
tunnelsManager.startDeactivation(of: tunnel) { [weak s] error in
s?.showErrorAlert(title: "Deactivation error", message: "Error while bringing down tunnel: \(String(describing: error))")
}
}
}

View File

@ -95,8 +95,6 @@
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
#endif
const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
#define SIZEDATA_INDATABLOCK (4096-(4*4))

View File

@ -29,7 +29,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
guard let options = options else {
os_log("Starting tunnel failed: No options passed. Possible connection request from preferences.", log: OSLog.default, type: .error)
// displayMessage is deprecated API
displayMessage("Please use the WireGuard app to start up WireGuard VPN configurations.") { (_) in
displayMessage("Please use the WireGuard app to start WireGuard tunnels.") { (_) in
startTunnelCompletionHandler(PacketTunnelProviderError.invalidOptions)
}
return