diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-04-29 13:22:11 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-05-05 10:05:38 +0200 |
| commit | 6b1c792b0d73995897f3c81e34f231bbe1f7bed7 (patch) | |
| tree | 3a68208cd0314b7b7be9b1fd9e215ce98d17474c | |
| parent | 5deb33e9beed61acfdd10c70aa7b00d7b3d8fde8 (diff) | |
| download | mullvadvpn-6b1c792b0d73995897f3c81e34f231bbe1f7bed7.tar.xz mullvadvpn-6b1c792b0d73995897f3c81e34f231bbe1f7bed7.zip | |
Do not store pubkey in device.json
| -rw-r--r-- | mullvad-daemon/src/device/mod.rs | 5 | ||||
| -rw-r--r-- | mullvad-daemon/src/device/service.rs | 6 | ||||
| -rw-r--r-- | mullvad-daemon/src/migrations/device.rs | 8 | ||||
| -rw-r--r-- | mullvad-types/src/device.rs | 36 |
4 files changed, 39 insertions, 16 deletions
diff --git a/mullvad-daemon/src/device/mod.rs b/mullvad-daemon/src/device/mod.rs index 1b79b46853..3935436f2a 100644 --- a/mullvad-daemon/src/device/mod.rs +++ b/mullvad-daemon/src/device/mod.rs @@ -7,7 +7,7 @@ use futures::{ use mullvad_api::{availability::ApiAvailabilityHandle, rest}; use mullvad_types::{ account::AccountToken, - device::{Device, DeviceData, DeviceEvent}, + device::{Device, DeviceData, DeviceEvent, InnerDevice}, wireguard::{RotationInterval, WireguardData}, }; use std::{ @@ -418,7 +418,7 @@ impl AccountManager { let current_pubkey = current_data.wg_data.private_key.public_key(); if new_device_data.pubkey == current_pubkey { let new_data = DeviceData { - device: new_device_data, + device: InnerDevice::from(new_device_data), ..current_data.clone() }; @@ -471,7 +471,6 @@ impl AccountManager { match api_result { Ok(wg_data) => { - device_data.device.pubkey = wg_data.private_key.public_key(); device_data.wg_data = wg_data; match self.set(InnerDeviceEvent::RotatedKey(device_data)).await { Ok(_) => { diff --git a/mullvad-daemon/src/device/service.rs b/mullvad-daemon/src/device/service.rs index 36ea48ea86..7f39bfc145 100644 --- a/mullvad-daemon/src/device/service.rs +++ b/mullvad-daemon/src/device/service.rs @@ -4,7 +4,7 @@ use chrono::{DateTime, Utc}; use futures::future::{abortable, AbortHandle}; use mullvad_types::{ account::{AccountToken, VoucherSubmission}, - device::{Device, DeviceData, DeviceId}, + device::{Device, DeviceData, DeviceId, InnerDevice}, wireguard::WireguardData, }; use talpid_types::net::wireguard::PrivateKey; @@ -62,7 +62,7 @@ impl DeviceService { Ok(DeviceData { token, - device, + device: InnerDevice::from(device), wg_data: WireguardData { private_key, addresses, @@ -92,7 +92,7 @@ impl DeviceService { Ok(DeviceData { token, - device, + device: InnerDevice::from(device), wg_data: WireguardData { private_key, addresses, diff --git a/mullvad-daemon/src/migrations/device.rs b/mullvad-daemon/src/migrations/device.rs index dd9ac8e94e..6420d5df51 100644 --- a/mullvad-daemon/src/migrations/device.rs +++ b/mullvad-daemon/src/migrations/device.rs @@ -11,7 +11,11 @@ use crate::{ device::{self, DeviceService}, DaemonEventSender, InternalDaemonEvent, }; -use mullvad_types::{account::AccountToken, device::DeviceData, wireguard::WireguardData}; +use mullvad_types::{ + account::AccountToken, + device::{DeviceData, InnerDevice}, + wireguard::WireguardData, +}; use std::time::Duration; use talpid_core::mpsc::Sender; use talpid_types::ErrorExt; @@ -78,7 +82,7 @@ async fn cache_from_wireguard_key( if device.pubkey == wg_data.private_key.public_key() { return Ok(DeviceData { token, - device, + device: InnerDevice::from(device), wg_data, }); } diff --git a/mullvad-types/src/device.rs b/mullvad-types/src/device.rs index 4b0123e6a9..0a0dd4d91d 100644 --- a/mullvad-types/src/device.rs +++ b/mullvad-types/src/device.rs @@ -65,13 +65,36 @@ impl fmt::Display for DevicePort { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct DeviceData { pub token: AccountToken, - pub device: Device, + pub device: InnerDevice, pub wg_data: wireguard::WireguardData, } impl From<DeviceData> for Device { fn from(data: DeviceData) -> Device { - data.device + Device { + id: data.device.id, + name: data.device.name, + pubkey: data.wg_data.private_key.public_key(), + ports: data.device.ports, + } + } +} + +/// Device data used by [DeviceData]. +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] +pub struct InnerDevice { + pub id: DeviceId, + pub name: DeviceName, + pub ports: Vec<DevicePort>, +} + +impl From<Device> for InnerDevice { + fn from(device: Device) -> Self { + InnerDevice { + id: device.id, + name: device.name, + ports: device.ports, + } } } @@ -87,8 +110,8 @@ pub struct DeviceConfig { impl From<DeviceData> for DeviceConfig { fn from(data: DeviceData) -> DeviceConfig { DeviceConfig { - token: data.token, - device: data.device, + token: data.token.clone(), + device: Device::from(data), } } } @@ -114,10 +137,7 @@ impl DeviceEvent { pub fn from_device(data: DeviceData, remote: bool) -> DeviceEvent { DeviceEvent { - device: Some(DeviceConfig { - token: data.token, - device: data.device, - }), + device: Some(DeviceConfig::from(data)), remote, } } |
