Skip to content

Commit

Permalink
feat: evaluate key rotation as soon as VPN is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Nov 21, 2023
1 parent 2a255a0 commit 3376334
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions wireguard-tunnel-provider/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,23 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}

private func startKeyRegenerationMonitor(completion: @escaping (Error?) -> Void) {
evaluateKeyRotation(completion)
let timer = TimerManager(timeInterval: AppKeyManager.regenerationCheckInterval)
timer.eventHandler = {
if AppKeyManager.needToRegenerate() {
self.regenerateKeys { error in
completion(error)
}
}
self.evaluateKeyRotation(completion)
timer.proceed()
}
timer.resume()
}

private func evaluateKeyRotation(_ completion: @escaping (Error?) -> Void) {
if AppKeyManager.needToRegenerate() {
self.regenerateKeys { error in
completion(error)
}
}
}

private func regenerateKeys(completion: @escaping (Error?) -> Void) {
wg_log(.info, message: "Rotating keys")
AppKeyManager.shared.setNewKey { privateKey, ipAddress, presharedKey in
Expand Down

0 comments on commit 3376334

Please sign in to comment.