Prefix top-level entities with OpenVPN*

This commit is contained in:
Davide De Rosa 2019-05-19 14:19:23 +02:00
parent 9c7ae47679
commit c4a84a5ade
11 changed files with 70 additions and 73 deletions

View File

@ -27,9 +27,9 @@ custom_categories:
- name: OpenVPN
children:
- OpenVPN
- SessionError
- SessionProxy
- SessionProxyDelegate
- OpenVPNError
- OpenVPNSession
- OpenVPNSessionDelegate
- name: AppExtension
children:
- TunnelKitProvider

View File

@ -33,8 +33,8 @@
0E0B20412278A85C007A3CB9 /* RoutingTableEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E0B203E2278A85B007A3CB9 /* RoutingTableEntry.h */; };
0E0B20422278A85C007A3CB9 /* RoutingTableEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B203F2278A85B007A3CB9 /* RoutingTableEntry.m */; };
0E0B20432278A85C007A3CB9 /* RoutingTableEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E0B203F2278A85B007A3CB9 /* RoutingTableEntry.m */; };
0E0C2125212ED29D008AB282 /* SessionError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C2123212ED29D008AB282 /* SessionError.swift */; };
0E0C2126212ED29D008AB282 /* SessionError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C2123212ED29D008AB282 /* SessionError.swift */; };
0E0C2125212ED29D008AB282 /* OpenVPNError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C2123212ED29D008AB282 /* OpenVPNError.swift */; };
0E0C2126212ED29D008AB282 /* OpenVPNError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C2123212ED29D008AB282 /* OpenVPNError.swift */; };
0E0C2127212ED29D008AB282 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C2124212ED29D008AB282 /* Configuration.swift */; };
0E0C2128212ED29D008AB282 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0C2124212ED29D008AB282 /* Configuration.swift */; };
0E11089F1F77B9E800A92462 /* TunnelKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E17D7F91F730D9F009EE129 /* TunnelKit.framework */; };
@ -96,8 +96,8 @@
0E58BF5722411F3E006FB157 /* LZO.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF5522411F37006FB157 /* LZO.h */; };
0E58BF5922411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; };
0E58BF5A22411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; };
0E749F5F2178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */; };
0E749F602178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */; };
0E749F5F2178885500BB2701 /* OpenVPNSession+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* OpenVPNSession+PIA.swift */; };
0E749F602178885500BB2701 /* OpenVPNSession+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* OpenVPNSession+PIA.swift */; };
0E749F622178911D00BB2701 /* pia-2048.pem in Resources */ = {isa = PBXBuildFile; fileRef = 0E749F612178911C00BB2701 /* pia-2048.pem */; };
0E9379C91F819A4300CE91B6 /* TunnelKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E17D7F91F730D9F009EE129 /* TunnelKit.framework */; };
0EA82A282190B220007960EB /* TunnelKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E3251C51F95770D00C108D9 /* TunnelKit.framework */; };
@ -158,7 +158,7 @@
0EFEB4642006D3C800F81029 /* ReplayProtector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EFEB4392006D3C800F81029 /* ReplayProtector.h */; };
0EFEB4652006D3C800F81029 /* Authenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43A2006D3C800F81029 /* Authenticator.swift */; };
0EFEB4662006D3C800F81029 /* ZeroingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43B2006D3C800F81029 /* ZeroingData.swift */; };
0EFEB4672006D3C800F81029 /* SessionProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43C2006D3C800F81029 /* SessionProxy.swift */; };
0EFEB4672006D3C800F81029 /* OpenVPNSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43C2006D3C800F81029 /* OpenVPNSession.swift */; };
0EFEB4682006D3C800F81029 /* MSS.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43D2006D3C800F81029 /* MSS.m */; };
0EFEB4692006D3C800F81029 /* Packet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43E2006D3C800F81029 /* Packet.swift */; };
0EFEB46B2006D3C800F81029 /* CryptoBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EFEB4402006D3C800F81029 /* CryptoBox.h */; };
@ -182,7 +182,7 @@
0EFEB4962006D7F300F81029 /* ProtocolMacros.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB4382006D3C800F81029 /* ProtocolMacros.swift */; };
0EFEB4972006D7F300F81029 /* Authenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43A2006D3C800F81029 /* Authenticator.swift */; };
0EFEB4982006D7F300F81029 /* ZeroingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43B2006D3C800F81029 /* ZeroingData.swift */; };
0EFEB4992006D7F300F81029 /* SessionProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43C2006D3C800F81029 /* SessionProxy.swift */; };
0EFEB4992006D7F300F81029 /* OpenVPNSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43C2006D3C800F81029 /* OpenVPNSession.swift */; };
0EFEB49A2006D7F300F81029 /* MSS.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43D2006D3C800F81029 /* MSS.m */; };
0EFEB49B2006D7F300F81029 /* Packet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB43E2006D3C800F81029 /* Packet.swift */; };
0EFEB49C2006D7F300F81029 /* Data+Manipulation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EFEB4432006D3C800F81029 /* Data+Manipulation.swift */; };
@ -244,7 +244,7 @@
0E07597D20F0060E00F38FD8 /* CryptoAEAD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CryptoAEAD.m; sourceTree = "<group>"; };
0E0B203E2278A85B007A3CB9 /* RoutingTableEntry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoutingTableEntry.h; sourceTree = "<group>"; };
0E0B203F2278A85B007A3CB9 /* RoutingTableEntry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoutingTableEntry.m; sourceTree = "<group>"; };
0E0C2123212ED29D008AB282 /* SessionError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionError.swift; sourceTree = "<group>"; };
0E0C2123212ED29D008AB282 /* OpenVPNError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenVPNError.swift; sourceTree = "<group>"; };
0E0C2124212ED29D008AB282 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
0E11089A1F77B9E800A92462 /* TunnelKitTests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "TunnelKitTests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
0E11089E1F77B9E800A92462 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -287,7 +287,7 @@
0E58BF5822411FEF006FB157 /* LZO.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LZO.m; sourceTree = "<group>"; };
0E6479DD212EAC96008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0E6479E0212EACD6008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+PIA.swift"; sourceTree = "<group>"; };
0E749F5E2178885500BB2701 /* OpenVPNSession+PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OpenVPNSession+PIA.swift"; sourceTree = "<group>"; };
0E749F612178911C00BB2701 /* pia-2048.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = "pia-2048.pem"; sourceTree = "<group>"; };
0E85A25B202CCA3D0059E9F9 /* TunnelKitHost.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TunnelKitHost.entitlements; sourceTree = "<group>"; };
0EA82A232190B220007960EB /* TunnelKitTests-macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "TunnelKitTests-macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
@ -326,7 +326,7 @@
0EFEB4392006D3C800F81029 /* ReplayProtector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReplayProtector.h; sourceTree = "<group>"; };
0EFEB43A2006D3C800F81029 /* Authenticator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Authenticator.swift; sourceTree = "<group>"; };
0EFEB43B2006D3C800F81029 /* ZeroingData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZeroingData.swift; sourceTree = "<group>"; };
0EFEB43C2006D3C800F81029 /* SessionProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionProxy.swift; sourceTree = "<group>"; };
0EFEB43C2006D3C800F81029 /* OpenVPNSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenVPNSession.swift; sourceTree = "<group>"; };
0EFEB43D2006D3C800F81029 /* MSS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSS.m; sourceTree = "<group>"; };
0EFEB43E2006D3C800F81029 /* Packet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Packet.swift; sourceTree = "<group>"; };
0EFEB4402006D3C800F81029 /* CryptoBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoBox.h; sourceTree = "<group>"; };
@ -564,6 +564,9 @@
0EFEB42D2006D3C800F81029 /* MSS.h */,
0EFEB43D2006D3C800F81029 /* MSS.m */,
0EE2F97622916A5D00F56F49 /* OpenVPN.swift */,
0E0C2123212ED29D008AB282 /* OpenVPNError.swift */,
0EFEB43C2006D3C800F81029 /* OpenVPNSession.swift */,
0E749F5E2178885500BB2701 /* OpenVPNSession+PIA.swift */,
0EFEB43E2006D3C800F81029 /* Packet.swift */,
0EE7A79420F61EDC00B42E6A /* PacketMacros.h */,
0EE7A79720F6296F00B42E6A /* PacketMacros.m */,
@ -573,10 +576,7 @@
0E3E0F202108A8CC00B371C1 /* PushReply.swift */,
0EFEB4392006D3C800F81029 /* ReplayProtector.h */,
0EFEB4482006D3C800F81029 /* ReplayProtector.m */,
0E0C2123212ED29D008AB282 /* SessionError.swift */,
0EFEB42B2006D3C800F81029 /* SessionKey.swift */,
0EFEB43C2006D3C800F81029 /* SessionProxy.swift */,
0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */,
0EE3B3E321471C3A0027AB17 /* StaticKey.swift */,
0EFEB4442006D3C800F81029 /* TLSBox.h */,
0EFEB4302006D3C800F81029 /* TLSBox.m */,
@ -1104,13 +1104,13 @@
0E0B20422278A85C007A3CB9 /* RoutingTableEntry.m in Sources */,
0E58BF5922411FEF006FB157 /* LZO.m in Sources */,
0E12B29E21449ADB00B4BAE9 /* NSRegularExpression+Shortcuts.swift in Sources */,
0E749F5F2178885500BB2701 /* SessionProxy+PIA.swift in Sources */,
0E749F5F2178885500BB2701 /* OpenVPNSession+PIA.swift in Sources */,
0EE3B3E421471C3A0027AB17 /* StaticKey.swift in Sources */,
0EFEB4622006D3C800F81029 /* SecureRandom.swift in Sources */,
0EFEB45D2006D3C800F81029 /* CryptoBox.m in Sources */,
0E3B15C92152B05E00984B17 /* CryptoCTR.m in Sources */,
0E011F7D2196D97200BA59EE /* EndpointProtocol.swift in Sources */,
0E0C2125212ED29D008AB282 /* SessionError.swift in Sources */,
0E0C2125212ED29D008AB282 /* OpenVPNError.swift in Sources */,
0E12B2A821456C0200B4BAE9 /* ControlChannel.swift in Sources */,
0EFEB4552006D3C800F81029 /* EncryptionBridge.swift in Sources */,
0EFEB45C2006D3C800F81029 /* ZeroingData.m in Sources */,
@ -1136,7 +1136,7 @@
0E58BF3922405410006FB157 /* minilzo.c in Sources */,
0EFEB4702006D3C800F81029 /* Allocation.m in Sources */,
0E041D092152E6FE0025FE3C /* TLSWrap.swift in Sources */,
0EFEB4672006D3C800F81029 /* SessionProxy.swift in Sources */,
0EFEB4672006D3C800F81029 /* OpenVPNSession.swift in Sources */,
0ED9C8642138139000621BA3 /* CompressionFraming.swift in Sources */,
0EFEB4722006D3C800F81029 /* ReplayProtector.m in Sources */,
0E3E0F212108A8CC00B371C1 /* PushReply.swift in Sources */,
@ -1165,13 +1165,13 @@
0E58BF5A22411FEF006FB157 /* LZO.m in Sources */,
0E12B29F21449ADB00B4BAE9 /* NSRegularExpression+Shortcuts.swift in Sources */,
0EFEB4A02006D7F300F81029 /* ReplayProtector.m in Sources */,
0E749F602178885500BB2701 /* SessionProxy+PIA.swift in Sources */,
0EFEB4992006D7F300F81029 /* SessionProxy.swift in Sources */,
0E749F602178885500BB2701 /* OpenVPNSession+PIA.swift in Sources */,
0EFEB4992006D7F300F81029 /* OpenVPNSession.swift in Sources */,
0EE3B3E521471C3A0027AB17 /* StaticKey.swift in Sources */,
0EFEB4962006D7F300F81029 /* ProtocolMacros.swift in Sources */,
0E3B15CA2152B05E00984B17 /* CryptoCTR.m in Sources */,
0E011F7E2196D97200BA59EE /* EndpointProtocol.swift in Sources */,
0E0C2126212ED29D008AB282 /* SessionError.swift in Sources */,
0E0C2126212ED29D008AB282 /* OpenVPNError.swift in Sources */,
0E12B2A921456C0200B4BAE9 /* ControlChannel.swift in Sources */,
0EFEB4982006D7F300F81029 /* ZeroingData.swift in Sources */,
0EFEB4A32006D7F300F81029 /* Errors.m in Sources */,

View File

@ -172,7 +172,7 @@ extension OpenVPN {
let prefix = controlBuffer.withOffset(0, count: prefixLength)
guard prefix.isEqual(to: ProtocolMacros.tlsPrefix) else {
throw SessionError.wrongControlDataPrefix
throw OpenVPNError.wrongControlDataPrefix
}
var offset = ProtocolMacros.tlsPrefix.count

View File

@ -167,7 +167,7 @@ extension OpenVPN {
static let compressionFraming: CompressionFraming = .disabled
}
/// The way to create a `Configuration` object for a `SessionProxy`.
/// The way to create a `Configuration` object for a `OpenVPNSession`.
public struct ConfigurationBuilder {
// MARK: General
@ -232,10 +232,10 @@ extension OpenVPN {
// MARK: Routing
/// The settings for IPv4. `SessionProxy` only evaluates this server-side.
/// The settings for IPv4. `OpenVPNSession` only evaluates this server-side.
public var ipv4: IPv4Settings?
/// The settings for IPv6. `SessionProxy` only evaluates this server-side.
/// The settings for IPv6. `OpenVPNSession` only evaluates this server-side.
public var ipv6: IPv6Settings?
/// The DNS servers.
@ -314,7 +314,7 @@ extension OpenVPN {
}
}
/// The immutable configuration for `SessionProxy`.
/// The immutable configuration for `OpenVPNSession`.
public struct Configuration: Codable {
/// - Seealso: `ConfigurationBuilder.cipher`

View File

@ -266,7 +266,7 @@ extension OpenVPN {
isContinuation = ($0.first == "2")
}
guard !isContinuation else {
throw SessionError.continuationPushReply
throw OpenVPNError.continuationPushReply
}
// MARK: Inline content

View File

@ -191,11 +191,11 @@ extension OpenVPN {
// Ruby: handle_acks
private func readAcks(_ packetIds: [UInt32], acksRemoteSessionId: Data) throws {
guard let sessionId = sessionId else {
throw SessionError.missingSessionId
throw OpenVPNError.missingSessionId
}
guard acksRemoteSessionId == sessionId else {
log.error("Control: Ack session mismatch (\(acksRemoteSessionId.toHex()) != \(sessionId.toHex()))")
throw SessionError.sessionMismatch
throw OpenVPNError.sessionMismatch
}
// drop queued out packets if ack-ed
@ -213,7 +213,7 @@ extension OpenVPN {
func writeAcks(withKey key: UInt8, ackPacketIds: [UInt32], ackRemoteSessionId: Data) throws -> Data {
guard let sessionId = sessionId else {
throw SessionError.missingSessionId
throw OpenVPNError.missingSessionId
}
let packet = ControlPacket(key: key, sessionId: sessionId, ackIds: ackPacketIds as [NSNumber], ackRemoteSessionId: ackRemoteSessionId)
log.debug("Control: Write ack packet \(packet)")

View File

@ -47,7 +47,7 @@ extension OpenVPN {
private let box: CryptoBox
/**
Initializes the PRNG. Must be issued before using `SessionProxy`.
Initializes the PRNG. Must be issued before using `OpenVPNSession`.
- Parameter seedLength: The length in bytes of the pseudorandom seed that will feed the PRNG.
*/

View File

@ -1,5 +1,5 @@
//
// SessionError.swift
// OpenVPNError.swift
// TunnelKit
//
// Created by Davide De Rosa on 8/23/18.
@ -37,8 +37,8 @@
import Foundation
import __TunnelKitCore
/// The possible errors raised/thrown during `SessionProxy` operation.
public enum SessionError: String, Error {
/// The possible errors raised/thrown during `OpenVPNSession` operation.
public enum OpenVPNError: String, Error {
/// The negotiation timed out.
case negotiationTimeout

View File

@ -1,5 +1,5 @@
//
// SessionProxy+PIA.swift
// OpenVPNSession+PIA.swift
// TunnelKit
//
// Created by Davide De Rosa on 10/18/18.
@ -36,7 +36,7 @@
import Foundation
extension SessionProxy {
extension OpenVPNSession {
struct PIAHardReset {
private static let obfuscationKeyLength = 3

View File

@ -1,5 +1,5 @@
//
// SessionProxy.swift
// OpenVPNSession.swift
// TunnelKit
//
// Created by Davide De Rosa on 2/3/17.
@ -41,8 +41,8 @@ import __TunnelKitOpenVPN
private let log = SwiftyBeaver.self
/// Observes major events notified by a `SessionProxy`.
public protocol SessionProxyDelegate: class {
/// Observes major events notified by a `OpenVPNSession`.
public protocol OpenVPNSessionDelegate: class {
/**
Called after starting a session.
@ -50,19 +50,19 @@ public protocol SessionProxyDelegate: class {
- Parameter remoteAddress: The address of the VPN server.
- Parameter options: The pulled tunnel settings.
*/
func sessionDidStart(_: SessionProxy, remoteAddress: String, options: OpenVPN.PushReply)
func sessionDidStart(_: OpenVPNSession, remoteAddress: String, options: OpenVPN.Configuration)
/**
Called after stopping a session.
- Parameter shouldReconnect: When `true`, the session can/should be restarted. Usually because the stop reason was recoverable.
- Seealso: `SessionProxy.reconnect(...)`
- Seealso: `OpenVPNSession.reconnect(...)`
*/
func sessionDidStop(_: SessionProxy, shouldReconnect: Bool)
func sessionDidStop(_: OpenVPNSession, shouldReconnect: Bool)
}
/// Provides methods to set up and maintain an OpenVPN session.
public class SessionProxy {
public class OpenVPNSession {
private enum StopMethod {
case shutdown
@ -97,8 +97,8 @@ public class SessionProxy {
return interval
}
/// An optional `SessionProxyDelegate` for receiving session events.
public weak var delegate: SessionProxyDelegate?
/// An optional `OpenVPNSessionDelegate` for receiving session events.
public weak var delegate: OpenVPNSessionDelegate?
// MARK: State
@ -341,10 +341,10 @@ public class SessionProxy {
}
/**
Shuts down the session with an optional `Error` reason and signals a reconnect flag to `SessionProxyDelegate.sessionDidStop(...)`. Does nothing if the session is already stopped or about to stop.
Shuts down the session with an optional `Error` reason and signals a reconnect flag to `OpenVPNSessionDelegate.sessionDidStop(...)`. Does nothing if the session is already stopped or about to stop.
- Parameter error: An optional `Error` being the reason of the shutdown.
- Seealso: `SessionProxyDelegate.sessionDidStop(...)`
- Seealso: `OpenVPNSessionDelegate.sessionDidStop(...)`
*/
public func reconnect(error: Error?) {
guard !isStopping else {
@ -402,11 +402,11 @@ public class SessionProxy {
}
guard !negotiationKey.didHardResetTimeOut(link: link) else {
doReconnect(error: SessionError.negotiationTimeout)
doReconnect(error: OpenVPNError.negotiationTimeout)
return
}
guard !negotiationKey.didNegotiationTimeOut(link: link) else {
doShutdown(error: SessionError.negotiationTimeout)
doShutdown(error: OpenVPNError.negotiationTimeout)
return
}
@ -499,7 +499,7 @@ public class SessionProxy {
let key = firstByte & 0b111
guard let _ = keys[key] else {
log.error("Key with id \(key) not found")
deferStop(.shutdown, SessionError.badKey)
deferStop(.shutdown, OpenVPNError.badKey)
return
}
@ -526,7 +526,7 @@ public class SessionProxy {
// return
}
if (code == .hardResetServerV2) && (negotiationKey.controlState == .connected) {
deferStop(.shutdown, SessionError.staleSession)
deferStop(.shutdown, OpenVPNError.staleSession)
return
} else if (code == .softResetV1) && !negotiationKey.softReset {
softReset(isServerInitiated: true)
@ -567,7 +567,7 @@ public class SessionProxy {
let now = Date()
guard (now.timeIntervalSince(lastPing.inbound) <= CoreConfiguration.OpenVPN.pingTimeout) else {
deferStop(.shutdown, SessionError.pingTimeout)
deferStop(.shutdown, OpenVPNError.pingTimeout)
return
}
@ -766,7 +766,7 @@ public class SessionProxy {
private func handleControlPacket(_ packet: ControlPacket) {
guard packet.key == negotiationKey.id else {
log.error("Bad key in control packet (\(packet.key) != \(negotiationKey.id))")
// deferStop(.shutdown, SessionError.badKey)
// deferStop(.shutdown, OpenVPNError.badKey)
return
}
@ -779,12 +779,12 @@ public class SessionProxy {
}
guard let remoteSessionId = controlChannel.remoteSessionId else {
log.error("No remote sessionId (never set)")
deferStop(.shutdown, SessionError.missingSessionId)
deferStop(.shutdown, OpenVPNError.missingSessionId)
return
}
guard packet.sessionId == remoteSessionId else {
log.error("Packet session mismatch (\(packet.sessionId.toHex()) != \(remoteSessionId.toHex()))")
deferStop(.shutdown, SessionError.sessionMismatch)
deferStop(.shutdown, OpenVPNError.sessionMismatch)
return
}
@ -829,12 +829,12 @@ public class SessionProxy {
else if ((packet.code == .controlV1) && (negotiationKey.state == .tls)) {
guard let remoteSessionId = controlChannel.remoteSessionId else {
log.error("No remote sessionId found in packet (control packets before server HARD_RESET)")
deferStop(.shutdown, SessionError.missingSessionId)
deferStop(.shutdown, OpenVPNError.missingSessionId)
return
}
guard packet.sessionId == remoteSessionId else {
log.error("Packet session mismatch (\(packet.sessionId.toHex()) != \(remoteSessionId.toHex()))")
deferStop(.shutdown, SessionError.sessionMismatch)
deferStop(.shutdown, OpenVPNError.sessionMismatch)
return
}
@ -921,11 +921,11 @@ public class SessionProxy {
if authenticator?.withLocalOptions ?? false {
log.warning("Authentication failure, retrying without local options")
withLocalOptions = false
deferStop(.reconnect, SessionError.badCredentials)
deferStop(.reconnect, OpenVPNError.badCredentials)
return
}
deferStop(.shutdown, SessionError.badCredentials)
deferStop(.shutdown, OpenVPNError.badCredentials)
return
}
@ -959,15 +959,15 @@ public class SessionProxy {
case .LZO:
if !LZOIsSupported() {
log.error("Server has LZO compression enabled and this was not built into the library (framing=\(framing))")
throw SessionError.serverCompression
throw OpenVPNError.serverCompression
}
case .other:
log.error("Server has non-LZO compression enabled and this is currently unsupported (framing=\(framing))")
throw SessionError.serverCompression
throw OpenVPNError.serverCompression
}
}
} catch SessionError.continuationPushReply {
} catch OpenVPNError.continuationPushReply {
continuatedPushReplyMessage = completeMessage.replacingOccurrences(of: "push-continuation", with: "")
// FIXME: strip "PUSH_REPLY" and "push-continuation 2"
return
@ -978,7 +978,7 @@ public class SessionProxy {
pushReply = reply
guard reply.options.ipv4 != nil || reply.options.ipv6 != nil else {
deferStop(.shutdown, SessionError.noRouting)
deferStop(.shutdown, OpenVPNError.noRouting)
return
}
@ -987,7 +987,7 @@ public class SessionProxy {
guard let remoteAddress = link?.remoteAddress else {
fatalError("Could not resolve link remote address")
}
delegate?.sessionDidStart(self, remoteAddress: remoteAddress, options: reply)
delegate?.sessionDidStart(self, remoteAddress: remoteAddress, options: reply.options)
scheduleNextPing()
}
@ -1039,7 +1039,7 @@ public class SessionProxy {
if let error = error {
self?.queue.sync {
log.error("Failed LINK write during control flush: \(error)")
self?.deferStop(.shutdown, SessionError.failedLinkWrite)
self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite)
}
return
}
@ -1169,7 +1169,7 @@ public class SessionProxy {
self?.queue.sync {
log.error("Data: Failed LINK write during send data: \(error)")
self?.deferStop(.shutdown, SessionError.failedLinkWrite)
self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite)
}
return
}
@ -1210,7 +1210,7 @@ public class SessionProxy {
if let error = error {
self?.queue.sync {
log.error("Failed LINK write during send ack for packetId \(controlPacket.packetId): \(error)")
self?.deferStop(.shutdown, SessionError.failedLinkWrite)
self?.deferStop(.shutdown, OpenVPNError.failedLinkWrite)
}
return
}

View File

@ -37,15 +37,12 @@
import Foundation
extension OpenVPN {
/// Groups the parsed reply of a successfully started session.
public struct PushReply: CustomStringConvertible {
struct PushReply: CustomStringConvertible {
private static let prefix = "PUSH_REPLY,"
private let original: String
/// The pushed options as a `Configuration` object.
public let options: Configuration
let options: Configuration
init?(message: String) throws {
guard message.hasPrefix(PushReply.prefix) else {
@ -63,7 +60,7 @@ extension OpenVPN {
// MARK: CustomStringConvertible
/// :nodoc:
public var description: String {
var description: String {
let stripped = NSMutableString(string: original)
ConfigurationParser.Regex.authToken.replaceMatches(
in: stripped,