diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-12-16 15:34:25 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-12-16 16:08:58 +0100 |
| commit | 28f0e4a42fe753a4fb772e46f085033f083021a3 (patch) | |
| tree | 7c24ba7615d71489fc87e51b6dcba5d51ab7af44 | |
| parent | 05c2d5fedf8ca4715df1f012f79c8c8dffd06fbd (diff) | |
| download | mullvadvpn-28f0e4a42fe753a4fb772e46f085033f083021a3.tar.xz mullvadvpn-28f0e4a42fe753a4fb772e46f085033f083021a3.zip | |
Migration v1 -> v2: Log out user but migrate settings when we cannot match the pubkey with device
| -rw-r--r-- | ios/MullvadVPN/SettingsManager/Migrations/MigrationFromV1ToV2.swift | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/ios/MullvadVPN/SettingsManager/Migrations/MigrationFromV1ToV2.swift b/ios/MullvadVPN/SettingsManager/Migrations/MigrationFromV1ToV2.swift index 34956cd1e0..cea71d5924 100644 --- a/ios/MullvadVPN/SettingsManager/Migrations/MigrationFromV1ToV2.swift +++ b/ios/MullvadVPN/SettingsManager/Migrations/MigrationFromV1ToV2.swift @@ -12,7 +12,7 @@ import MullvadREST import MullvadTypes import Operations -class MigrationFromV1ToV2: Migration { +final class MigrationFromV1ToV2: Migration { private let accountsProxy: REST.AccountsProxy private let devicesProxy: REST.DevicesProxy @@ -108,45 +108,50 @@ class MigrationFromV1ToV2: Migration { device.pubkey == interfaceData.nextPrivateKey?.publicKey } - guard let device = device else { - logger.debug( - "Failed to match legacy settings against available devices." - ) - return - } - - logger.debug("Found device matching public key stored in legacy settings.") + let newDeviceState: DeviceState + if let device = device { + logger.debug("Found device matching public key stored in legacy settings.") - // Match private key. - let privateKeyWithMetadata: PrivateKeyWithMetadata - if let nextKey = interfaceData.nextPrivateKey, nextKey.publicKey == device.pubkey { - privateKeyWithMetadata = nextKey - } else { - privateKeyWithMetadata = interfaceData.privateKey - } + // Match private key. + let privateKeyWithMetadata: PrivateKeyWithMetadata + if let nextKey = interfaceData.nextPrivateKey, nextKey.publicKey == device.pubkey { + privateKeyWithMetadata = nextKey + } else { + privateKeyWithMetadata = interfaceData.privateKey + } - logger.debug("Store new settings...") + logger.debug("Store new settings...") - // Create new settings. - let newDeviceState = DeviceState.loggedIn( - StoredAccountData( - identifier: accountData.id, - number: settings.accountNumber, - expiry: accountData.expiry - ), - StoredDeviceData( - creationDate: device.created, - identifier: device.id, - name: device.name, - hijackDNS: device.hijackDNS, - ipv4Address: device.ipv4Address, - ipv6Address: device.ipv6Address, - wgKeyData: StoredWgKeyData( - creationDate: privateKeyWithMetadata.creationDate, - privateKey: privateKeyWithMetadata.privateKey + // Create new settings. + newDeviceState = DeviceState.loggedIn( + StoredAccountData( + identifier: accountData.id, + number: settings.accountNumber, + expiry: accountData.expiry + ), + StoredDeviceData( + creationDate: device.created, + identifier: device.id, + name: device.name, + hijackDNS: device.hijackDNS, + ipv4Address: device.ipv4Address, + ipv6Address: device.ipv6Address, + wgKeyData: StoredWgKeyData( + creationDate: privateKeyWithMetadata.creationDate, + privateKey: privateKeyWithMetadata.privateKey + ) ) ) - ) + } else { + logger.debug( + """ + Failed to find a device matching public key from legacy settings. \ + Set device state to logged out. + """ + ) + + newDeviceState = .loggedOut + } let newSettings = TunnelSettingsV2( relayConstraints: tunnelSettings.relayConstraints, |
