Merge branch 'handle-server-restart'
This commit is contained in:
commit
ccd9e58062
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Index out of range during negotiation (Grivus). [#143](https://github.com/passepartoutvpn/tunnelkit/pull/143)
|
- Index out of range during negotiation (Grivus). [#143](https://github.com/passepartoutvpn/tunnelkit/pull/143)
|
||||||
|
- Handle server shutdown/restart (remote `--explicit-exit-notify`). [#131](https://github.com/passepartoutvpn/tunnelkit/issues/131)
|
||||||
|
|
||||||
## 2.2.1 (2019-12-14)
|
## 2.2.1 (2019-12-14)
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,9 @@ extension OpenVPNTunnelProvider {
|
||||||
/// Default gateway could not be attained.
|
/// Default gateway could not be attained.
|
||||||
case gatewayUnattainable
|
case gatewayUnattainable
|
||||||
|
|
||||||
|
/// Remove server has shut down.
|
||||||
|
case serverShutdown
|
||||||
|
|
||||||
/// The server replied in an unexpected way.
|
/// The server replied in an unexpected way.
|
||||||
case unexpectedReply
|
case unexpectedReply
|
||||||
}
|
}
|
||||||
|
|
|
@ -877,6 +877,9 @@ extension OpenVPNTunnelProvider {
|
||||||
case .noRouting:
|
case .noRouting:
|
||||||
return .routing
|
return .routing
|
||||||
|
|
||||||
|
case .serverShutdown:
|
||||||
|
return .serverShutdown
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return .unexpectedReply
|
return .unexpectedReply
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,9 @@ extension OpenVPN {
|
||||||
|
|
||||||
private(set) var serverRandom2: ZeroingData?
|
private(set) var serverRandom2: ZeroingData?
|
||||||
|
|
||||||
let username: ZeroingData?
|
private(set) var username: ZeroingData?
|
||||||
|
|
||||||
let password: ZeroingData?
|
private(set) var password: ZeroingData?
|
||||||
|
|
||||||
var withLocalOptions: Bool
|
var withLocalOptions: Bool
|
||||||
|
|
||||||
|
@ -87,6 +87,17 @@ extension OpenVPN {
|
||||||
controlBuffer = Z()
|
controlBuffer = Z()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reset() {
|
||||||
|
controlBuffer.zero()
|
||||||
|
preMaster.zero()
|
||||||
|
random1.zero()
|
||||||
|
random2.zero()
|
||||||
|
serverRandom1?.zero()
|
||||||
|
serverRandom2?.zero()
|
||||||
|
username = nil
|
||||||
|
password = nil
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Authentication request
|
// MARK: Authentication request
|
||||||
|
|
||||||
// Ruby: on_tls_connect
|
// Ruby: on_tls_connect
|
||||||
|
|
|
@ -77,4 +77,7 @@ public enum OpenVPNError: String, Error {
|
||||||
|
|
||||||
/// Missing routing information.
|
/// Missing routing information.
|
||||||
case noRouting
|
case noRouting
|
||||||
|
|
||||||
|
/// Remote server shut down (--explicit-exit-notify).
|
||||||
|
case serverShutdown
|
||||||
}
|
}
|
||||||
|
|
|
@ -745,7 +745,7 @@ public class OpenVPNSession: Session {
|
||||||
|
|
||||||
private func completeConnection() {
|
private func completeConnection() {
|
||||||
setupEncryption()
|
setupEncryption()
|
||||||
authenticator = nil
|
authenticator?.reset()
|
||||||
negotiationKey.controlState = .connected
|
negotiationKey.controlState = .connected
|
||||||
connectedDate = Date()
|
connectedDate = Date()
|
||||||
transitionKeys()
|
transitionKeys()
|
||||||
|
@ -907,6 +907,11 @@ public class OpenVPNSession: Session {
|
||||||
|
|
||||||
// Ruby: handle_ctrl_msg
|
// Ruby: handle_ctrl_msg
|
||||||
private func handleControlMessage(_ message: String) {
|
private func handleControlMessage(_ message: String) {
|
||||||
|
if CoreConfiguration.logsSensitiveData {
|
||||||
|
log.debug("Received control message: \"\(message)\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
// disconnect on authentication failure
|
||||||
guard !message.hasPrefix("AUTH_FAILED") else {
|
guard !message.hasPrefix("AUTH_FAILED") else {
|
||||||
|
|
||||||
// XXX: retry without client options
|
// XXX: retry without client options
|
||||||
|
@ -921,12 +926,16 @@ public class OpenVPNSession: Session {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard (negotiationKey.controlState == .preIfConfig) else {
|
// disconnect on remote server restart (--explicit-exit-notify)
|
||||||
|
guard !message.hasPrefix("RESTART") else {
|
||||||
|
log.debug("Disconnecting due to server shutdown")
|
||||||
|
deferStop(.shutdown, OpenVPNError.serverShutdown)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if CoreConfiguration.logsSensitiveData {
|
// handle authentication from now on
|
||||||
log.debug("Received control message: \"\(message)\"")
|
guard negotiationKey.controlState == .preIfConfig else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let completeMessage: String
|
let completeMessage: String
|
||||||
|
|
Loading…
Reference in New Issue