2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// OpenVPN+L10n.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/26/22.
|
2024-01-14 13:34:21 +00:00
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2023-07-02 10:51:50 +00:00
|
|
|
import PassepartoutLibrary
|
2022-04-12 13:09:14 +00:00
|
|
|
import TunnelKitOpenVPN
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension OpenVPN.Cipher: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-07-16 13:06:35 +00:00
|
|
|
description
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension OpenVPN.Digest: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-07-16 13:06:35 +00:00
|
|
|
description
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension OpenVPN.CompressionFraming: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
switch self {
|
|
|
|
case .disabled:
|
|
|
|
return L10n.Global.Strings.disabled
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .compLZO:
|
|
|
|
return Unlocalized.OpenVPN.compLZO
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .compress, .compressV2:
|
|
|
|
return Unlocalized.OpenVPN.compress
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension OpenVPN.CompressionAlgorithm: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
let V = L10n.Endpoint.Advanced.Openvpn.Items.self
|
|
|
|
switch self {
|
|
|
|
case .disabled:
|
|
|
|
return L10n.Global.Strings.disabled
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .LZO:
|
|
|
|
return Unlocalized.OpenVPN.lzo
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .other:
|
|
|
|
return V.CompressionAlgorithm.Value.other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
extension OpenVPN.XORMethod: StyledLocalizableEntity {
|
|
|
|
public enum Style {
|
|
|
|
case short
|
2022-11-06 17:08:41 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
case long
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(style: Style) -> String {
|
|
|
|
switch style {
|
|
|
|
case .short:
|
|
|
|
return shortDescription
|
|
|
|
|
|
|
|
case .long:
|
|
|
|
return longDescription
|
2022-11-06 17:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
private var shortDescription: String {
|
2022-11-06 17:08:41 +00:00
|
|
|
switch self {
|
|
|
|
case .xormask:
|
|
|
|
return Unlocalized.OpenVPN.XOR.xormask.rawValue
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-11-06 17:08:41 +00:00
|
|
|
case .xorptrpos:
|
|
|
|
return Unlocalized.OpenVPN.XOR.xorptrpos.rawValue
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-11-06 17:08:41 +00:00
|
|
|
case .reverse:
|
|
|
|
return Unlocalized.OpenVPN.XOR.reverse.rawValue
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-11-06 17:08:41 +00:00
|
|
|
case .obfuscate:
|
|
|
|
return Unlocalized.OpenVPN.XOR.obfuscate.rawValue
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
private var longDescription: String {
|
2022-11-06 17:08:41 +00:00
|
|
|
switch self {
|
|
|
|
case .xormask(let mask):
|
2023-07-05 15:18:33 +00:00
|
|
|
return "\(shortDescription) \(mask.toHex())"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-11-06 17:08:41 +00:00
|
|
|
case .obfuscate(let mask):
|
2023-07-05 15:18:33 +00:00
|
|
|
return "\(shortDescription) \(mask.toHex())"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-11-06 17:08:41 +00:00
|
|
|
default:
|
2023-07-05 15:18:33 +00:00
|
|
|
return shortDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension OpenVPN.PullMask: LocalizableEntity {
|
|
|
|
public var localizedDescription: String {
|
|
|
|
switch self {
|
|
|
|
case .routes:
|
|
|
|
return L10n.Endpoint.Advanced.Openvpn.Items.Route.caption
|
|
|
|
|
|
|
|
case .dns:
|
|
|
|
return Unlocalized.Network.dns
|
|
|
|
|
|
|
|
case .proxy:
|
|
|
|
return L10n.Global.Strings.proxy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension OpenVPN.ConfigurationBuilder: StyledLocalizableEntity {
|
|
|
|
public enum Style {
|
|
|
|
case tlsWrap
|
|
|
|
|
|
|
|
case eku
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(style: Style) -> String {
|
|
|
|
switch style {
|
|
|
|
case .tlsWrap:
|
|
|
|
return tlsWrap.tlsWrapDescription
|
|
|
|
|
|
|
|
case .eku:
|
|
|
|
return checksEKU.ekuDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension OpenVPN.Configuration: StyledOptionalLocalizableEntity {
|
|
|
|
public enum OptionalStyle {
|
|
|
|
case keepAlive
|
|
|
|
|
|
|
|
case renegotiatesAfter
|
|
|
|
|
|
|
|
case randomizeEndpoint
|
|
|
|
|
|
|
|
case randomizeHostnames
|
|
|
|
}
|
|
|
|
|
|
|
|
public func localizedDescription(optionalStyle: OptionalStyle) -> String? {
|
|
|
|
switch optionalStyle {
|
|
|
|
case .keepAlive:
|
|
|
|
return keepAliveInterval?.keepAliveDescription
|
|
|
|
|
|
|
|
case .renegotiatesAfter:
|
|
|
|
return renegotiatesAfter?.renegotiatesAfterDescription
|
|
|
|
|
|
|
|
case .randomizeEndpoint:
|
|
|
|
return randomizeEndpoint?.randomizeEndpointDescription
|
|
|
|
|
|
|
|
case .randomizeHostnames:
|
|
|
|
return randomizeHostnames?.randomizeHostnamesDescription
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension Optional where Wrapped == OpenVPN.TLSWrap {
|
|
|
|
var tlsWrapDescription: String {
|
|
|
|
guard let strategy = self?.strategy else {
|
|
|
|
return L10n.Global.Strings.disabled
|
|
|
|
}
|
|
|
|
let V = L10n.Endpoint.Advanced.Openvpn.Items.self
|
|
|
|
switch strategy {
|
|
|
|
case .auth:
|
|
|
|
return V.TlsWrapping.Value.auth
|
|
|
|
|
|
|
|
case .crypt:
|
|
|
|
return V.TlsWrapping.Value.crypt
|
2022-11-06 17:08:41 +00:00
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
private extension TimeInterval {
|
|
|
|
var keepAliveDescription: String {
|
|
|
|
let V = L10n.Endpoint.Advanced.Openvpn.Items.self
|
|
|
|
if self > 0 {
|
|
|
|
return V.KeepAlive.Value.seconds(Int(self))
|
|
|
|
} else {
|
|
|
|
return L10n.Global.Strings.disabled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension Optional where Wrapped == Bool {
|
|
|
|
var ekuDescription: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
let V = L10n.Global.Strings.self
|
|
|
|
return (self ?? false) ? V.enabled : V.disabled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
private extension TimeInterval {
|
|
|
|
var renegotiatesAfterDescription: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
let V = L10n.Endpoint.Advanced.Openvpn.Items.self
|
|
|
|
if self > 0 {
|
|
|
|
return V.RenegotiationSeconds.Value.after(TimeInterval(self).localizedDescription)
|
|
|
|
} else {
|
|
|
|
return L10n.Global.Strings.disabled
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
private extension Bool {
|
|
|
|
var randomizeEndpointDescription: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
let V = L10n.Global.Strings.self
|
|
|
|
return self ? V.enabled : V.disabled
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
var randomizeHostnamesDescription: String {
|
2022-10-16 12:19:36 +00:00
|
|
|
let V = L10n.Global.Strings.self
|
|
|
|
return self ? V.enabled : V.disabled
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-10-13 17:09:51 +00:00
|
|
|
|
2023-07-05 15:18:33 +00:00
|
|
|
// MARK: - Errors
|
2023-07-02 10:51:50 +00:00
|
|
|
|
|
|
|
extension TunnelKitOpenVPNError: LocalizedError {
|
|
|
|
public var errorDescription: String? {
|
|
|
|
let V = L10n.Tunnelkit.Errors.Vpn.self
|
|
|
|
switch self {
|
|
|
|
case .socketActivity, .timeout:
|
|
|
|
return V.timeout
|
|
|
|
|
|
|
|
case .dnsFailure:
|
|
|
|
return V.dns
|
|
|
|
|
|
|
|
case .tlsInitialization, .tlsServerVerification, .tlsHandshake:
|
|
|
|
return V.tls
|
|
|
|
|
|
|
|
case .authentication:
|
|
|
|
return V.auth
|
|
|
|
|
|
|
|
case .encryptionInitialization, .encryptionData:
|
|
|
|
return V.encryption
|
|
|
|
|
|
|
|
case .serverCompression, .lzo:
|
|
|
|
return V.compression
|
|
|
|
|
2024-01-05 22:54:16 +00:00
|
|
|
case .networkChanged:
|
2023-07-02 10:51:50 +00:00
|
|
|
return V.network
|
|
|
|
|
|
|
|
case .routing:
|
|
|
|
return V.routing
|
|
|
|
|
|
|
|
case .gatewayUnattainable:
|
|
|
|
return V.gateway
|
|
|
|
|
|
|
|
case .serverShutdown:
|
|
|
|
return V.shutdown
|
|
|
|
|
|
|
|
default:
|
2023-09-10 16:40:24 +00:00
|
|
|
return L10n.Global.Strings.unknown
|
2023-07-02 10:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension OpenVPN.ConfigurationError: LocalizedError {
|
|
|
|
public var errorDescription: String? {
|
|
|
|
let V = L10n.Tunnelkit.Errors.Openvpn.self
|
|
|
|
switch self {
|
|
|
|
case .encryptionPassphrase:
|
|
|
|
pp_log.error("Could not parse configuration URL: unable to decrypt, passphrase required")
|
|
|
|
return V.passphraseRequired
|
|
|
|
|
|
|
|
case .unableToDecrypt(let error):
|
|
|
|
pp_log.error("Could not parse configuration URL: unable to decrypt, \(error.localizedDescription)")
|
|
|
|
return V.decryption
|
|
|
|
|
|
|
|
case .malformed(let option):
|
|
|
|
pp_log.error("Could not parse configuration URL: malformed option, \(option)")
|
|
|
|
return V.malformed(option)
|
|
|
|
|
|
|
|
case .missingConfiguration(let option):
|
|
|
|
pp_log.error("Could not parse configuration URL: missing configuration, \(option)")
|
|
|
|
return V.requiredOption(option)
|
|
|
|
|
|
|
|
case .unsupportedConfiguration(var option):
|
|
|
|
if option.contains("external") {
|
|
|
|
option.append(" (see FAQ)")
|
|
|
|
}
|
|
|
|
pp_log.error("Could not parse configuration URL: unsupported configuration, \(option)")
|
|
|
|
return V.unsupportedOption(option)
|
|
|
|
|
|
|
|
case .continuationPushReply:
|
|
|
|
assertionFailure("This is a server-side configuration parsing error")
|
2023-09-10 15:15:40 +00:00
|
|
|
return L10n.Global.Strings.unknown
|
2023-07-02 10:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|