diff options
| -rw-r--r-- | ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/TunnelManager/RotateKeyOperation.swift | 24 |
2 files changed, 18 insertions, 10 deletions
diff --git a/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift b/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift index a305839bb9..87fe59833e 100644 --- a/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift +++ b/ios/MullvadVPN/SettingsManager/TunnelSettingsV2.swift @@ -119,6 +119,10 @@ struct StoredWgKeyData: Codable, Equatable { /// Private key. var privateKey: PrivateKey + + /// Next private key we're trying to rotate to. + /// Added in 2023.3 + var nextPrivateKey: PrivateKey? } extension StoredWgKeyData { diff --git a/ios/MullvadVPN/TunnelManager/RotateKeyOperation.swift b/ios/MullvadVPN/TunnelManager/RotateKeyOperation.swift index e6059c5320..555c3d9ea0 100644 --- a/ios/MullvadVPN/TunnelManager/RotateKeyOperation.swift +++ b/ios/MullvadVPN/TunnelManager/RotateKeyOperation.swift @@ -32,11 +32,7 @@ class RotateKeyOperation: ResultOperation<Bool> { self.devicesProxy = devicesProxy self.keyRotationConfiguration = keyRotationConfiguration - super.init( - dispatchQueue: dispatchQueue, - completionQueue: nil, - completionHandler: nil - ) + super.init(dispatchQueue: dispatchQueue, completionQueue: nil, completionHandler: nil) } override func main() { @@ -60,7 +56,18 @@ class RotateKeyOperation: ResultOperation<Bool> { logger.debug("Replacing old key with new key on server...") - let newPrivateKey = PrivateKey() + let newPrivateKey: PrivateKey + if let nextPrivateKey = deviceData.wgKeyData.nextPrivateKey { + logger.debug("Next private key is already stored in Keychain. Using it.") + + newPrivateKey = nextPrivateKey + } else { + logger.debug("Create next private key and store it in Keychain.") + + newPrivateKey = PrivateKey() + deviceData.wgKeyData.nextPrivateKey = newPrivateKey + interactor.setDeviceState(.loggedIn(accountData, deviceData), persist: true) + } task = devicesProxy.rotateDeviceKey( accountNumber: accountData.number, @@ -69,10 +76,7 @@ class RotateKeyOperation: ResultOperation<Bool> { retryStrategy: .default ) { result in self.dispatchQueue.async { - self.didRotateKey( - newPrivateKey: newPrivateKey, - result: result - ) + self.didRotateKey(newPrivateKey: newPrivateKey, result: result) } } } |
