Override masksPrivateData via AppExtension

Unmask in demo.

Fixes #62
This commit is contained in:
Davide De Rosa 2019-03-21 17:46:52 +01:00
parent f8a1ec0a5b
commit fad20668b0
5 changed files with 26 additions and 6 deletions

View File

@ -99,6 +99,7 @@ extension ViewController {
builder.endpointProtocols = [EndpointProtocol(socketType, port)] builder.endpointProtocols = [EndpointProtocol(socketType, port)]
builder.mtu = 1350 builder.mtu = 1350
builder.shouldDebug = true builder.shouldDebug = true
builder.masksPrivateData = false
let configuration = builder.build() let configuration = builder.build()
return try! configuration.generatedTunnelProtocol( return try! configuration.generatedTunnelProtocol(

View File

@ -100,6 +100,7 @@ extension ViewController {
builder.endpointProtocols = [EndpointProtocol(socketType, port)] builder.endpointProtocols = [EndpointProtocol(socketType, port)]
builder.mtu = 1350 builder.mtu = 1350
builder.shouldDebug = true builder.shouldDebug = true
builder.masksPrivateData = false
let configuration = builder.build() let configuration = builder.build()
return try! configuration.generatedTunnelProtocol( return try! configuration.generatedTunnelProtocol(

View File

@ -70,7 +70,8 @@ extension TunnelKitProvider {
dnsServers: nil dnsServers: nil
), ),
shouldDebug: false, shouldDebug: false,
debugLogFormat: nil debugLogFormat: nil,
masksPrivateData: true
) )
/// Prefers resolved addresses over DNS resolution. `resolvedAddresses` must be set and non-empty. Default is `false`. /// Prefers resolved addresses over DNS resolution. `resolvedAddresses` must be set and non-empty. Default is `false`.
@ -98,6 +99,9 @@ extension TunnelKitProvider {
/// Optional debug log format (SwiftyBeaver format). /// Optional debug log format (SwiftyBeaver format).
public var debugLogFormat: String? public var debugLogFormat: String?
/// Mask private data in debug log (default is `true`).
public var masksPrivateData: Bool
// MARK: Building // MARK: Building
/** /**
@ -113,6 +117,7 @@ extension TunnelKitProvider {
self.sessionConfiguration = sessionConfiguration self.sessionConfiguration = sessionConfiguration
shouldDebug = ConfigurationBuilder.defaults.shouldDebug shouldDebug = ConfigurationBuilder.defaults.shouldDebug
debugLogFormat = ConfigurationBuilder.defaults.debugLogFormat debugLogFormat = ConfigurationBuilder.defaults.debugLogFormat
masksPrivateData = ConfigurationBuilder.defaults.masksPrivateData
} }
fileprivate init(providerConfiguration: [String: Any]) throws { fileprivate init(providerConfiguration: [String: Any]) throws {
@ -187,10 +192,11 @@ extension TunnelKitProvider {
sessionConfigurationBuilder.dnsServers = providerConfiguration[S.dnsServers] as? [String] sessionConfigurationBuilder.dnsServers = providerConfiguration[S.dnsServers] as? [String]
sessionConfiguration = sessionConfigurationBuilder.build() sessionConfiguration = sessionConfigurationBuilder.build()
shouldDebug = providerConfiguration[S.debug] as? Bool ?? false shouldDebug = providerConfiguration[S.debug] as? Bool ?? ConfigurationBuilder.defaults.shouldDebug
if shouldDebug { if shouldDebug {
debugLogFormat = providerConfiguration[S.debugLogFormat] as? String debugLogFormat = providerConfiguration[S.debugLogFormat] as? String
} }
masksPrivateData = providerConfiguration[S.masksPrivateData] as? Bool ?? ConfigurationBuilder.defaults.masksPrivateData
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)]")
@ -210,7 +216,8 @@ extension TunnelKitProvider {
mtu: mtu, mtu: mtu,
sessionConfiguration: sessionConfiguration, sessionConfiguration: sessionConfiguration,
shouldDebug: shouldDebug, shouldDebug: shouldDebug,
debugLogFormat: shouldDebug ? debugLogFormat : nil debugLogFormat: shouldDebug ? debugLogFormat : nil,
masksPrivateData: masksPrivateData
) )
} }
} }
@ -259,6 +266,8 @@ extension TunnelKitProvider {
static let debug = "Debug" static let debug = "Debug"
static let debugLogFormat = "DebugLogFormat" static let debugLogFormat = "DebugLogFormat"
static let masksPrivateData = "MasksPrivateData"
} }
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.prefersResolvedAddresses` /// - Seealso: `TunnelKitProvider.ConfigurationBuilder.prefersResolvedAddresses`
@ -282,6 +291,9 @@ extension TunnelKitProvider {
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.debugLogFormat` /// - Seealso: `TunnelKitProvider.ConfigurationBuilder.debugLogFormat`
public let debugLogFormat: String? public let debugLogFormat: String?
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.masksPrivateData`
public let masksPrivateData: Bool
// MARK: Shortcuts // MARK: Shortcuts
static let debugLogFilename = "debug.log" static let debugLogFilename = "debug.log"
@ -384,7 +396,8 @@ extension TunnelKitProvider {
S.digestAlgorithm: sessionConfiguration.digest.rawValue, S.digestAlgorithm: sessionConfiguration.digest.rawValue,
S.ca: sessionConfiguration.ca.pem, S.ca: sessionConfiguration.ca.pem,
S.mtu: mtu, S.mtu: mtu,
S.debug: shouldDebug S.debug: shouldDebug,
S.masksPrivateData: masksPrivateData
] ]
if let clientCertificate = sessionConfiguration.clientCertificate { if let clientCertificate = sessionConfiguration.clientCertificate {
dict[S.clientCertificate] = clientCertificate.pem dict[S.clientCertificate] = clientCertificate.pem
@ -494,6 +507,7 @@ extension TunnelKitProvider {
log.info("\tCustom DNS servers: \(dnsServers.maskedDescription)") log.info("\tCustom DNS servers: \(dnsServers.maskedDescription)")
} }
log.info("\tDebug: \(shouldDebug)") log.info("\tDebug: \(shouldDebug)")
log.info("\tMasks private data: \(masksPrivateData)")
} }
} }
} }

View File

@ -176,6 +176,9 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
customFormat: cfg.debugLogFormat customFormat: cfg.debugLogFormat
) )
// override library configuration
CoreConfiguration.masksPrivateData = cfg.masksPrivateData
log.info("Starting tunnel...") log.info("Starting tunnel...")
cfg.clearLastError(in: appGroup) cfg.clearLastError(in: appGroup)

View File

@ -57,11 +57,12 @@ struct CoreConfiguration {
}() }()
// MARK: Session // MARK: Session
// configurable
static var masksPrivateData = true
static let logsSensitiveData = false static let logsSensitiveData = false
static let masksPrivateData = true
static let usesReplayProtection = true static let usesReplayProtection = true
static let tickInterval = 0.2 static let tickInterval = 0.2