Catch WireGuard parsing errors properly (#279)

They could be reported as OpenVPN errors.
This commit is contained in:
Davide De Rosa 2023-04-03 08:48:18 +02:00 committed by GitHub
parent 7f9ae7c3bc
commit e050c0c8df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -51,7 +51,7 @@
"repositoryURL": "https://github.com/passepartoutvpn/tunnelkit", "repositoryURL": "https://github.com/passepartoutvpn/tunnelkit",
"state": { "state": {
"branch": null, "branch": null,
"revision": "7ce254be0293ba7e1eeda07a3701804de59f7490", "revision": "8f066a9e4821f041693c8262ba01ef49ab0084ae",
"version": null "version": null
} }
}, },
@ -61,7 +61,7 @@
"state": { "state": {
"branch": null, "branch": null,
"revision": "73d9152fa0cb661db0348a1ac11dbbf998422a50", "revision": "73d9152fa0cb661db0348a1ac11dbbf998422a50",
"version": null "version": "1.0.17"
} }
} }
] ]

View File

@ -179,13 +179,15 @@ extension Error {
extension Error { extension Error {
var localizedVPNParsingDescription: String? { var localizedVPNParsingDescription: String? {
if let ovpnError = self as? OpenVPN.ConfigurationError { if let ovpnError = self as? OpenVPN.ConfigurationError {
return ovpnErrorDescription(ovpnError) return ovpnConfigurationErrorDescription(ovpnError)
} else if let wgError = self as? WireGuard.ConfigurationError {
return wgConfigurationErrorDescription(wgError)
} }
pp_log.error("Could not parse configuration URL: \(localizedDescription)") pp_log.error("Could not parse configuration URL: \(localizedDescription)")
return L10n.Tunnelkit.Errors.parsing(localizedDescription) return L10n.Tunnelkit.Errors.parsing(localizedDescription)
} }
private func ovpnErrorDescription(_ error: OpenVPN.ConfigurationError) -> String { private func ovpnConfigurationErrorDescription(_ error: OpenVPN.ConfigurationError) -> String {
let V = L10n.Tunnelkit.Errors.Openvpn.self let V = L10n.Tunnelkit.Errors.Openvpn.self
switch error { switch error {
case .encryptionPassphrase: case .encryptionPassphrase:
@ -212,4 +214,8 @@ extension Error {
return V.unsupportedOption(option) return V.unsupportedOption(option)
} }
} }
private func wgConfigurationErrorDescription(_ error: WireGuard.ConfigurationError) -> String {
error.localizedDescription
}
} }

View File

@ -24,7 +24,7 @@ let package = Package(
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"), // .package(url: /* package url */, from: "1.0.0"),
// .package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", from: "5.0.0"), // .package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", from: "5.0.0"),
.package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", .revision("7ce254be0293ba7e1eeda07a3701804de59f7490")), .package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", .revision("8f066a9e4821f041693c8262ba01ef49ab0084ae")),
// .package(name: "TunnelKit", path: "../../tunnelkit"), // .package(name: "TunnelKit", path: "../../tunnelkit"),
.package(url: "https://github.com/zoul/generic-json-swift", from: "2.0.0"), .package(url: "https://github.com/zoul/generic-json-swift", from: "2.0.0"),
.package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver", from: "1.9.0") .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver", from: "1.9.0")

View File

@ -37,7 +37,7 @@ extension ProfileManager {
do { do {
let wg = try WireGuard.Configuration(wgQuickConfig: contents) let wg = try WireGuard.Configuration(wgQuickConfig: contents)
return Profile(header, configuration: wg) return Profile(header, configuration: wg)
} catch { } catch WireGuard.ConfigurationError.invalidLine {
throw ovpnError throw ovpnError
} }
} }