diff --git a/.unreleased/LLT-5866_teliod_remove_app_user_uid_config b/.unreleased/LLT-5866_teliod_remove_app_user_uid_config new file mode 100644 index 000000000..e69de29bb diff --git a/clis/teliod/example_teliod_config.json b/clis/teliod/example_teliod_config.json index 2c191d0ba..1a1ee0ff6 100644 --- a/clis/teliod/example_teliod_config.json +++ b/clis/teliod/example_teliod_config.json @@ -2,7 +2,6 @@ "log_level": "trace", "log_file_path": "example_log_file.log", "authentication_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "app_user_uid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "interface": { "name": "utun10", "config_provider": "manual" diff --git a/clis/teliod/src/config.rs b/clis/teliod/src/config.rs index 315a1c4e0..8be7f8dbf 100644 --- a/clis/teliod/src/config.rs +++ b/clis/teliod/src/config.rs @@ -3,7 +3,7 @@ use std::{num::NonZeroU64, path::PathBuf, str::FromStr}; use serde::{de, Deserialize, Deserializer, Serialize}; use smart_default::SmartDefault; use std::fs; -use tracing::{debug, info, level_filters::LevelFilter}; +use tracing::{debug, info, level_filters::LevelFilter, warn}; use uuid::Uuid; use telio::crypto::SecretKey; @@ -57,26 +57,30 @@ fn reconnect_after_expiry_default() -> Percentage { #[derive(Serialize, Deserialize, Debug, Default)] pub struct DeviceIdentity { - pub hw_identifier: String, + pub hw_identifier: Uuid, pub private_key: SecretKey, pub machine_identifier: String, } -pub fn generate_hw_identifier(private_key: SecretKey) -> String { +pub fn generate_hw_identifier() -> Uuid { // Generate hw_identifier - let public_key = private_key.public(); - debug!("Generating hw identifier"); - format!("{}.{}", public_key, "teliod") + debug!("Generating a new hw identifier"); + Uuid::new_v4() } impl DeviceIdentity { pub fn from_file(identity_path: &PathBuf) -> Option { - info!("Fetching config"); + info!("Fetching identity config"); if let Ok(file) = fs::File::open(identity_path) { - debug!("found existing config."); + debug!( + "Found existing identity config {}", + identity_path.to_string_lossy() + ); if let Ok(c) = serde_json::from_reader(file) { return Some(c); + } else { + warn!("Reading identity config failed"); } } None @@ -90,8 +94,6 @@ pub struct TeliodDaemonConfig { pub log_file_path: String, pub interface: InterfaceConfig, - pub app_user_uid: Uuid, - #[serde(deserialize_with = "deserialize_authentication_token")] pub authentication_token: String, @@ -163,7 +165,6 @@ mod tests { let expected = TeliodDaemonConfig { log_level: LevelFilter::INFO, log_file_path: "test.log".to_owned(), - app_user_uid: Uuid::from_str("2ba97921-38d7-4736-9d47-261cf3e5c223").unwrap(), interface: InterfaceConfig { name: "utun10".to_owned(), config_provider: InterfaceConfigurationProvider::Manual, @@ -183,7 +184,6 @@ mod tests { let json = r#"{ "log_level": "Info", "log_file_path": "test.log", - "app_user_uid": "2ba97921-38d7-4736-9d47-261cf3e5c223", "interface": { "name": "utun10", "config_provider": "manual" @@ -198,7 +198,6 @@ mod tests { let json = r#"{ "log_level": "Info", "log_file_path": "test.log", - "app_user_uid": "2ba97921-38d7-4736-9d47-261cf3e5c223", "interface": { "name": "utun10", "config_provider": "manual" diff --git a/clis/teliod/src/core_api.rs b/clis/teliod/src/core_api.rs index d4fac5745..aa39b8cfd 100644 --- a/clis/teliod/src/core_api.rs +++ b/clis/teliod/src/core_api.rs @@ -71,22 +71,19 @@ fn build_backoff() -> Result { Ok(ExponentialBackoff::new(backoff_bounds)?) } -pub async fn init_with_api( - auth_token: &str, - interface_name: &str, -) -> Result { +pub async fn init_with_api(auth_token: &str) -> Result { let mut identity_path = dirs::data_local_dir().ok_or(Error::NoDataLocalDir)?; identity_path.push("teliod"); if !identity_path.exists() { let _ = create_dir_all(&identity_path); } - identity_path.push(&format!("{interface_name}.json")); + identity_path.push(&format!("data.json")); let mut device_identity = match DeviceIdentity::from_file(&identity_path) { Some(identity) => identity, None => { let private_key = SecretKey::gen(); - let hw_identifier = generate_hw_identifier(private_key.clone()); + let hw_identifier = generate_hw_identifier(); let machine_identifier = match fetch_identifier_with_exp_backoff(auth_token, private_key.public()).await { @@ -95,7 +92,7 @@ pub async fn init_with_api( Error::DeviceNotFound => { info!("Unable to load identifier due to {e}. Registering ..."); register_machine_with_exp_backoff( - &hw_identifier, + &hw_identifier.to_string(), private_key.public(), auth_token, ) @@ -118,7 +115,7 @@ pub async fn init_with_api( if status == StatusCode::NOT_FOUND { debug!("Unable to update. Registering machine ..."); device_identity.machine_identifier = register_machine_with_exp_backoff( - &device_identity.hw_identifier, + &device_identity.hw_identifier.to_string(), device_identity.private_key.public(), auth_token, ) @@ -285,7 +282,7 @@ async fn update_machine(device_identity: &DeviceIdentity, auth_token: &str) -> R .header(header::ACCEPT, "application/json") .json(&MeshConfig { public_key: device_identity.private_key.public(), - hardware_identifier: device_identity.hw_identifier.clone(), + hardware_identifier: device_identity.hw_identifier.to_string(), os: OS_NAME.to_owned(), os_version: "teliod".to_owned(), device_type: "other".to_owned(), diff --git a/clis/teliod/src/daemon.rs b/clis/teliod/src/daemon.rs index 23dbb7200..60f7f7888 100644 --- a/clis/teliod/src/daemon.rs +++ b/clis/teliod/src/daemon.rs @@ -193,8 +193,6 @@ pub async fn daemon_event_loop(config: TeliodDaemonConfig) -> Result<(), TeliodE let socket = DaemonSocket::new(&DaemonSocket::get_ipc_socket_path()?)?; - let nc = NotificationCenter::new(&config).await?; - // Tx is unused here, but this channel can be used to communicate with the // telio task let (tx, rx) = mpsc::channel(10); @@ -206,8 +204,11 @@ pub async fn daemon_event_loop(config: TeliodDaemonConfig) -> Result<(), TeliodE // are dummy and program will not run as it expects real tokens. let mut identity = DeviceIdentity::default(); if !config.authentication_token.eq(EMPTY_TOKEN) { - identity = init_with_api(&config.authentication_token, &config.interface.name).await?; + identity = init_with_api(&config.authentication_token).await?; } + + let nc = NotificationCenter::new(&config, &identity.hw_identifier).await?; + let tx_clone = tx.clone(); let token_ptr = Arc::new(config.authentication_token); diff --git a/clis/teliod/src/nc.rs b/clis/teliod/src/nc.rs index 000a68bea..85d89205c 100644 --- a/clis/teliod/src/nc.rs +++ b/clis/teliod/src/nc.rs @@ -86,12 +86,15 @@ struct NCConfig { } impl NotificationCenter { - pub async fn new(config: &super::TeliodDaemonConfig) -> Result { + pub async fn new( + config: &super::TeliodDaemonConfig, + app_user_uid: &Uuid, + ) -> Result { let callbacks = Arc::new(Mutex::new(vec![])); let nc_config = NCConfig { authentication_token: config.authentication_token.clone(), - app_user_uid: config.app_user_uid, + app_user_uid: *app_user_uid, callbacks: callbacks.clone(), http_certificate_file_path: config.http_certificate_file_path.clone(), diff --git a/nat-lab/data/teliod/config.json b/nat-lab/data/teliod/config.json index cd3d3caf0..337c83f84 100644 --- a/nat-lab/data/teliod/config.json +++ b/nat-lab/data/teliod/config.json @@ -2,7 +2,6 @@ "log_level": "trace", "log_file_path": "teliod_natlab.log", "authentication_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "app_user_uid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "interface": { "name": "teliod", "config_provider": "manual"