-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix VPN rekeying #716
Fix VPN rekeying #716
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,15 +138,28 @@ public actor NetworkProtectionDeviceManager: NetworkProtectionDeviceManagement { | |
if regenerateKey { | ||
keyPair = keyStore.newKeyPair() | ||
} else { | ||
keyPair = keyStore.currentKeyPair() ?? keyStore.newKeyPair() | ||
// Temporary code added on 2024-03-12 to fix a previous issue where users had a really long | ||
// key expiration date. We should remove this after a month or so. | ||
if let existingKeyPair = keyStore.currentKeyPair(), | ||
existingKeyPair.expirationDate > Date().addingTimeInterval(TimeInterval.day) { | ||
|
||
keyPair = keyStore.newKeyPair() | ||
} else { | ||
// This is the regular code to restore when the above code is removed. | ||
keyPair = keyStore.currentKeyPair() ?? keyStore.newKeyPair() | ||
} | ||
} | ||
|
||
let (selectedServer, newExpiration) = try await register(keyPair: keyPair, selectionMethod: selectionMethod) | ||
os_log("Server registration successul", log: .networkProtection) | ||
|
||
keyStore.updateKeyPair(keyPair) | ||
|
||
if let newExpiration { | ||
// We only update the expiration date if it happens before our client-set expiration date. | ||
// This way we respect the client-set expiration date, unless the server has set an earlier | ||
// expiration for whatever reason (like if the subscription is known to expire). | ||
// | ||
if let newExpiration, newExpiration < keyPair.expirationDate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments are self-explanatory, never extend the local expiration, but always shorten it if the server considers that important. |
||
keyPair = KeyPair(privateKey: keyPair.privateKey, expirationDate: newExpiration) | ||
keyStore.updateKeyPair(keyPair) | ||
} | ||
|
@@ -224,9 +237,7 @@ public actor NetworkProtectionDeviceManager: NetworkProtectionDeviceManagement { | |
// If we're looking to exclude a server we should have a few other options available. If we can't find any | ||
// then it means theres an inconsistency in the server list that was returned. | ||
errorEvents?.fire(NetworkProtectionError.serverListInconsistency) | ||
|
||
let cachedServer = try cachedServer(registeredWith: keyPair) | ||
return (cachedServer, nil) | ||
throw NetworkProtectionError.serverListInconsistency | ||
} | ||
|
||
selectedServer = registeredServer | ||
|
@@ -238,9 +249,7 @@ public actor NetworkProtectionDeviceManager: NetworkProtectionDeviceManagement { | |
} | ||
|
||
handle(clientError: error) | ||
|
||
let cachedServer = try cachedServer(registeredWith: keyPair) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need more cleanup as this code isn't used anymore, but not in this hotfix. I'm removing this because:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good find, the |
||
return (cachedServer, nil) | ||
throw error | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -595,7 +595,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider { | |
serverSelectionMethod: currentServerSelectionMethod, | ||
includedRoutes: includedRoutes ?? [], | ||
excludedRoutes: settings.excludedRanges, | ||
regenerateKey: false) | ||
regenerateKey: true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always use a new key when starting up the tunnel. Why not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One downside here is that it'll make the NetP connection speed overall feel slower since it has to do extra work to get started. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure... after all we're not saving a call to register right now. |
||
startTunnel(with: tunnelConfiguration, onDemand: onDemand, completionHandler: completionHandler) | ||
os_log("🔵 Done generating tunnel config", log: .networkProtection, type: .info) | ||
} catch { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the expiration date is over a day from now, we create a new key pair. This is to fix users with long expiration dates... although this could be a good security measure in case users are manipulating expiration dates.