Make IV_UI_VER flag overridable

This commit is contained in:
Kirill Pahnev 2020-06-29 16:31:20 +03:00
parent 7d2184d205
commit 014f8aabbd
4 changed files with 28 additions and 6 deletions

View File

@ -56,6 +56,8 @@ class CoreConfiguration {
// configurable // configurable
static var masksPrivateData = true static var masksPrivateData = true
static var versionIdentifier: String?
static let logsSensitiveData = false static let logsSensitiveData = false
} }

View File

@ -55,7 +55,8 @@ extension OpenVPNTunnelProvider {
mtu: 1250, mtu: 1250,
shouldDebug: false, shouldDebug: false,
debugLogFormat: nil, debugLogFormat: nil,
masksPrivateData: true masksPrivateData: true,
versionIdentifier: nil
) )
/// The session configuration. /// The session configuration.
@ -71,7 +72,10 @@ extension OpenVPNTunnelProvider {
/// The MTU of the link. /// The MTU of the link.
public var mtu: Int public var mtu: Int
/// Optional version identifier about the client pushed to server in peer-info as `IV_UI_VER`.
public var versionIdentifier: String?
// MARK: Debugging // MARK: Debugging
/// Enables debugging. /// Enables debugging.
@ -98,6 +102,7 @@ extension OpenVPNTunnelProvider {
shouldDebug = ConfigurationBuilder.defaults.shouldDebug shouldDebug = ConfigurationBuilder.defaults.shouldDebug
debugLogFormat = ConfigurationBuilder.defaults.debugLogFormat debugLogFormat = ConfigurationBuilder.defaults.debugLogFormat
masksPrivateData = ConfigurationBuilder.defaults.masksPrivateData masksPrivateData = ConfigurationBuilder.defaults.masksPrivateData
versionIdentifier = ConfigurationBuilder.defaults.versionIdentifier
} }
fileprivate init(providerConfiguration: [String: Any]) throws { fileprivate init(providerConfiguration: [String: Any]) throws {
@ -112,6 +117,7 @@ extension OpenVPNTunnelProvider {
debugLogFormat = providerConfiguration[S.debugLogFormat] as? String debugLogFormat = providerConfiguration[S.debugLogFormat] as? String
} }
masksPrivateData = providerConfiguration[S.masksPrivateData] as? Bool ?? ConfigurationBuilder.defaults.masksPrivateData masksPrivateData = providerConfiguration[S.masksPrivateData] as? Bool ?? ConfigurationBuilder.defaults.masksPrivateData
versionIdentifier = providerConfiguration[S.versionIdentifier] as? String ?? ConfigurationBuilder.defaults.versionIdentifier
guard !prefersResolvedAddresses || !(resolvedAddresses?.isEmpty ?? true) else { guard !prefersResolvedAddresses || !(resolvedAddresses?.isEmpty ?? true) else {
throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.prefersResolvedAddresses)] is true but no [\(S.resolvedAddresses)]") throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.prefersResolvedAddresses)] is true but no [\(S.resolvedAddresses)]")
@ -131,7 +137,8 @@ extension OpenVPNTunnelProvider {
mtu: mtu, mtu: mtu,
shouldDebug: shouldDebug, shouldDebug: shouldDebug,
debugLogFormat: shouldDebug ? debugLogFormat : nil, debugLogFormat: shouldDebug ? debugLogFormat : nil,
masksPrivateData: masksPrivateData masksPrivateData: masksPrivateData,
versionIdentifier: versionIdentifier
) )
} }
} }
@ -140,7 +147,9 @@ extension OpenVPNTunnelProvider {
public struct Configuration: Codable { public struct Configuration: Codable {
struct Keys { struct Keys {
static let appGroup = "AppGroup" static let appGroup = "AppGroup"
static let versionIdentifier = "VersionIdentifier"
// MARK: SessionConfiguration // MARK: SessionConfiguration
static let cipherAlgorithm = "CipherAlgorithm" static let cipherAlgorithm = "CipherAlgorithm"
@ -230,7 +239,10 @@ extension OpenVPNTunnelProvider {
/// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.masksPrivateData` /// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.masksPrivateData`
public let masksPrivateData: Bool? public let masksPrivateData: Bool?
/// - Seealso: `OpenVPNTunnelProvider.ConfigurationBuilder.versionIdentifier`
public let versionIdentifier: String?
// MARK: Shortcuts // MARK: Shortcuts
static let debugLogFilename = "debug.log" static let debugLogFilename = "debug.log"
@ -368,6 +380,9 @@ extension OpenVPNTunnelProvider {
if let masksPrivateData = masksPrivateData { if let masksPrivateData = masksPrivateData {
dict[S.masksPrivateData] = masksPrivateData dict[S.masksPrivateData] = masksPrivateData
} }
if let versionIdentifier = versionIdentifier {
dict[S.versionIdentifier] = versionIdentifier
}
return dict return dict
} }
@ -429,6 +444,7 @@ extension OpenVPNTunnelProvider.Configuration {
builder.shouldDebug = shouldDebug builder.shouldDebug = shouldDebug
builder.debugLogFormat = debugLogFormat builder.debugLogFormat = debugLogFormat
builder.masksPrivateData = masksPrivateData builder.masksPrivateData = masksPrivateData
builder.versionIdentifier = versionIdentifier
return builder return builder
} }
} }

View File

@ -203,6 +203,9 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
if let masksPrivateData = cfg.masksPrivateData { if let masksPrivateData = cfg.masksPrivateData {
CoreConfiguration.masksPrivateData = masksPrivateData CoreConfiguration.masksPrivateData = masksPrivateData
} }
if let versionIdentifier = cfg.versionIdentifier {
CoreConfiguration.versionIdentifier = versionIdentifier
}
// optional credentials // optional credentials
let credentials: OpenVPN.Credentials? let credentials: OpenVPN.Credentials?

View File

@ -70,10 +70,11 @@ extension CoreConfiguration {
#else #else
platform = "mac" platform = "mac"
#endif #endif
let uiVersion = versionIdentifier ?? "\(identifier) \(version)"
var info = [ var info = [
"IV_VER=2.4", "IV_VER=2.4",
"IV_PLAT=\(platform)", "IV_PLAT=\(platform)",
"IV_UI_VER=\(identifier) \(version)", "IV_UI_VER=\(uiVersion)",
"IV_PROTO=2", "IV_PROTO=2",
"IV_NCP=2", "IV_NCP=2",
"IV_SSL=\(CryptoBox.version())", "IV_SSL=\(CryptoBox.version())",