Merge pull request #43 from keeshux/save-log-to-group-file

Save log snapshot to file in app group
This commit is contained in:
Davide De Rosa 2018-10-25 07:23:36 +02:00 committed by GitHub
commit e97b1d9164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 32 deletions

View File

@ -7,20 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Changed
- Debug log is saved to group container rather than `UserDefaults`. [#43](https://github.com/keeshux/tunnelkit/pull/43)
### Fixed
- Handle server-initiated renegotiation. [#41](https://github.com/keeshux/tunnelkit/pull/41)
- Potentially private data (e.g. Internet addresses) is now masked in debug log. [#42](https://github.com/keeshux/tunnelkit/pull/42)
## 1.2.1 (2018-10-24)
### Added
- Configuration key `lastErrorKey` for reporting errors to host app. [#40](https://github.com/keeshux/tunnelkit/pull/40)
- Server extended key usage validation (EKU). [#27](https://github.com/keeshux/tunnelkit/issues/27)
### Changed
- Potentially private data (e.g. Internet addresses) is now masked in debug log. [#42](https://github.com/keeshux/tunnelkit/pull/42)
### Fixed
- CA file was not closed after MD5 calculation when using PIA patches.
- Mitigated an issue with MTU in TCP mode during negotiation. [#39](https://github.com/keeshux/tunnelkit/issues/39)
- Handle server-initiated renegotiation. [#41](https://github.com/keeshux/tunnelkit/pull/41)
## 1.2.0 (2018-10-20)

View File

@ -1,13 +1,13 @@
PODS:
- OpenSSL-Apple (1.1.0i-v2)
- SwiftyBeaver (1.6.1)
- TunnelKit (1.1.2):
- TunnelKit/AppExtension (= 1.1.2)
- TunnelKit/Core (= 1.1.2)
- TunnelKit/AppExtension (1.1.2):
- TunnelKit (1.2.2):
- TunnelKit/AppExtension (= 1.2.2)
- TunnelKit/Core (= 1.2.2)
- TunnelKit/AppExtension (1.2.2):
- SwiftyBeaver
- TunnelKit/Core
- TunnelKit/Core (1.1.2):
- TunnelKit/Core (1.2.2):
- OpenSSL-Apple (~> 1.1.0h)
- SwiftyBeaver
@ -26,8 +26,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
OpenSSL-Apple: a93b8f2eec8783ff40d9a9304de180ab68bb647c
SwiftyBeaver: ccfcdf85a04d429f1633f668650b0ce8020bda3a
TunnelKit: 392e78dd45cded30a6f814200b8334c33901f677
TunnelKit: 15c88f0cef7b926883566a9455e912a1e55f4048
PODFILE CHECKSUM: f66dfaaa92a8d04ab2743f3caeab0ac9f9f25859
COCOAPODS: 1.6.0.beta.1
COCOAPODS: 1.6.0.beta.2

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "TunnelKit"
s.version = "1.2.1"
s.version = "1.2.2"
s.summary = "Non-official OpenVPN client for Apple platforms."
s.homepage = "https://github.com/keeshux/tunnelkit"

View File

@ -1144,7 +1144,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 245;
CURRENT_PROJECT_VERSION = 273;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@ -1208,7 +1208,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 245;
CURRENT_PROJECT_VERSION = 273;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
@ -1241,7 +1241,7 @@
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 245;
DYLIB_CURRENT_VERSION = 273;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/TunnelKit-iOS/Info.plist";
@ -1264,7 +1264,7 @@
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 245;
DYLIB_CURRENT_VERSION = 273;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/TunnelKit-iOS/Info.plist";
@ -1287,7 +1287,7 @@
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 245;
DYLIB_CURRENT_VERSION = 273;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "$(SRCROOT)/TunnelKit-macOS/Info.plist";
@ -1310,7 +1310,7 @@
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 245;
DYLIB_CURRENT_VERSION = 273;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "$(SRCROOT)/TunnelKit-macOS/Info.plist";

View File

@ -54,11 +54,11 @@ class MemoryDestination: BaseDestination, CustomStringConvertible {
}
}
func flush(to: UserDefaults, with key: String) {
func flush(to url: URL) {
execute(synchronously: true) {
to.set(self.buffer, forKey: key)
let content = self.buffer.joined(separator: "\n")
try? content.write(to: url, atomically: true, encoding: .utf8)
}
to.synchronize()
}
var description: String {

View File

@ -159,7 +159,7 @@ extension TunnelKitProvider {
/// Enables debugging. If `true`, then `debugLogKey` is a mandatory field.
public var shouldDebug: Bool
/// The key in `defaults` where the latest debug log snapshot is stored. Ignored if `shouldDebug` is `false`.
/// The filename in group container where the latest debug log snapshot is stored. Ignored if `shouldDebug` is `false`.
public var debugLogKey: String?
/// Optional debug log format (SwiftyBeaver format).
@ -403,12 +403,34 @@ extension TunnelKitProvider {
public let lastErrorKey: String?
// MARK: Shortcuts
/**
Returns the URL of the latest debug log.
func existingLog(in defaults: UserDefaults) -> [String]? {
- Parameter in: The app group where to locate the log file.
- Returns: The URL of the debug log, if any.
*/
public func urlForLog(in appGroup: String) -> URL? {
guard shouldDebug, let key = debugLogKey else {
return nil
}
return defaults.array(forKey: key) as? [String]
guard let parentURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else {
return nil
}
return parentURL.appendingPathComponent("\(key).log")
}
/**
Returns the content of the latest debug log.
- Parameter in: The app group where to locate the log file.
- Returns: The content of the debug log, if any.
*/
public func existingLog(in appGroup: String) -> String? {
guard let url = urlForLog(in: appGroup) else {
return nil
}
return try? String(contentsOf: url)
}
// MARK: API

View File

@ -94,12 +94,12 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
private var appGroup: String!
private lazy var defaults = UserDefaults(suiteName: appGroup)
private var cfg: Configuration!
private var strategy: ConnectionStrategy!
private lazy var defaults = UserDefaults(suiteName: appGroup)
// MARK: Internal state
private var proxy: SessionProxy?
@ -157,7 +157,8 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
strategy = ConnectionStrategy(hostname: hostname, configuration: cfg)
if let defaults = defaults, var existingLog = cfg.existingLog(in: defaults) {
if let content = cfg.existingLog(in: appGroup) {
var existingLog = content.components(separatedBy: "\n")
if let i = existingLog.index(of: logSeparator) {
existingLog.removeFirst(i + 2)
}
@ -595,8 +596,8 @@ extension TunnelKitProvider {
private func flushLog() {
log.debug("Flushing log...")
if let defaults = defaults, let key = cfg.debugLogKey {
memoryLog.flush(to: defaults, with: key)
if let url = cfg.urlForLog(in: appGroup) {
memoryLog.flush(to: url)
}
}

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<string>1.2.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<string>1.2.2</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>