diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-04-19 11:25:57 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-04-19 11:25:57 +0200 |
| commit | 1511b095853a3da3912a4c2dffe49cbab9501e91 (patch) | |
| tree | 5f9ffddd772bca7ac3c3402cad6d6591e35e6892 | |
| parent | 88a193b71cf8f15867d92829c00ae2d7eb470e59 (diff) | |
| parent | 2764b20a7c3044b3552e3f291b5bb01d990e9188 (diff) | |
| download | mullvadvpn-1511b095853a3da3912a4c2dffe49cbab9501e91.tar.xz mullvadvpn-1511b095853a3da3912a4c2dffe49cbab9501e91.zip | |
Merge branch 'persist-next-key'
| -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) } } } |
