diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-08-30 09:53:34 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-09-05 10:46:54 +0100 |
| commit | ca928b4f734b589db3d315198b98c6e9fcc95353 (patch) | |
| tree | 76754957ca2735644c60af19aadeef4fd8b74711 | |
| parent | 58635659339cf5ed6f43debdf4c582510ffc60f7 (diff) | |
| download | mullvadvpn-ca928b4f734b589db3d315198b98c6e9fcc95353.tar.xz mullvadvpn-ca928b4f734b589db3d315198b98c6e9fcc95353.zip | |
Update public key structure to store publishing date
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 10 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 8 | ||||
| -rw-r--r-- | mullvad-types/src/wireguard.rs | 24 |
3 files changed, 29 insertions, 13 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index eed31fa2fc..59eac40ab4 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -795,7 +795,7 @@ where match result { Ok(data) => { - let public_key = data.private_key.public_key(); + let public_key = data.get_public_key(); let mut account_entry = self .account_history .get(&account) @@ -1256,7 +1256,7 @@ where .generate_key_sync(account_token.clone()) { Ok(new_data) => { - let public_key = new_data.private_key.public_key(); + let public_key = new_data.get_public_key(); account_entry.wireguard = Some(new_data.clone()); self.account_history.insert(account_entry).map_err(|e| { format!("Failed to add new wireguard key to account data: {}", e) @@ -1285,11 +1285,7 @@ where .settings .get_account_token() .and_then(|account| self.account_history.get(&account).ok()?) - .and_then(|account_entry| { - account_entry - .wireguard - .map(|wg| wg.private_key.public_key()) - }); + .and_then(|account_entry| account_entry.wireguard.map(|wg| wg.get_public_key())); Self::oneshot_send(tx, key, "get_wireguard_key response"); } diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 0940780ea3..e1b74f6185 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -19,7 +19,7 @@ use mullvad_types::{ relay_list::RelayList, settings::{self, Settings}, states::{TargetState, TunnelState}, - version, DaemonEvent, + version, wireguard, DaemonEvent, }; use parking_lot::{Mutex, RwLock}; use std::{ @@ -28,7 +28,7 @@ use std::{ }; use talpid_core::mpsc::IntoSender; use talpid_ipc; -use talpid_types::{net::wireguard, ErrorExt}; +use talpid_types::ErrorExt; use uuid; /// FIXME(linus): This is here just because the futures crate has deprecated it and jsonrpc_core @@ -133,7 +133,7 @@ build_rpc_trait! { /// Generates new wireguard key for current account #[rpc(meta, name = "generate_wireguard_key")] - fn generate_wireguard_key(&self, Self::Metadata) -> BoxFuture<mullvad_types::wireguard::KeygenEvent, Error>; + fn generate_wireguard_key(&self, Self::Metadata) -> BoxFuture<wireguard::KeygenEvent, Error>; /// Retrieve a public key for current account if the account has one. #[rpc(meta, name = "get_wireguard_key")] @@ -217,7 +217,7 @@ pub enum ManagementCommand { /// Get the daemon settings GetSettings(OneshotSender<Settings>), /// Generate new wireguard key - GenerateWireguardKey(OneshotSender<mullvad_types::wireguard::KeygenEvent>), + GenerateWireguardKey(OneshotSender<wireguard::KeygenEvent>), /// Return a public key of the currently set wireguard private key, if there is one GetWireguardKey(OneshotSender<Option<wireguard::PublicKey>>), /// Verify if the currently set wireguard key is valid. diff --git a/mullvad-types/src/wireguard.rs b/mullvad-types/src/wireguard.rs index 635bb7d7da..8675a6e845 100644 --- a/mullvad-types/src/wireguard.rs +++ b/mullvad-types/src/wireguard.rs @@ -1,3 +1,4 @@ +use chrono::{offset::Utc, DateTime}; use serde::{Deserialize, Serialize}; use std::fmt; use talpid_types::net::wireguard; @@ -7,6 +8,25 @@ use talpid_types::net::wireguard; pub struct WireguardData { pub private_key: wireguard::PrivateKey, pub addresses: AssociatedAddresses, + #[serde(default = "Utc::now")] + pub created: DateTime<Utc>, +} + +impl WireguardData { + /// Create a public key + pub fn get_public_key(&self) -> PublicKey { + PublicKey { + key: self.private_key.public_key(), + created: self.created, + } + } +} + +/// Represents a published public key +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct PublicKey { + pub key: wireguard::PublicKey, + pub created: DateTime<Utc>, } /// Contains a pair of local link addresses that are paired with a specific wireguard @@ -21,7 +41,7 @@ pub struct AssociatedAddresses { #[derive(Clone, Debug, Deserialize, Serialize)] /// Event that is emitted when the daemon has finished generating a key. pub enum KeygenEvent { - NewKey(wireguard::PublicKey), + NewKey(PublicKey), TooManyKeys, GenerationFailure, } @@ -29,7 +49,7 @@ pub enum KeygenEvent { impl fmt::Display for KeygenEvent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { match self { - KeygenEvent::NewKey(public_key) => write!(f, "New wireguard key {}", public_key), + KeygenEvent::NewKey(new_key) => write!(f, "New wireguard key {}", new_key.key), KeygenEvent::TooManyKeys => write!(f, "Account has too many keys already"), KeygenEvent::GenerationFailure => write!(f, "Failed to generate new wireguard key"), } |
