diff --git a/core/Cargo.lock b/core/Cargo.lock index 0cb7bb35..f502fd84 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -1196,6 +1196,23 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "default-net" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c5a6569a908354d49b10db3c516d69aca1eccd97562fd31c98b13f00b73ca66" +dependencies = [ + "dlopen2", + "libc", + "memalloc", + "netlink-packet-core", + "netlink-packet-route", + "netlink-sys", + "once_cell", + "system-configuration 0.5.1", + "windows 0.48.0", +] + [[package]] name = "der" version = "0.7.10" @@ -1288,6 +1305,17 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "dlopen2" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b4f5f101177ff01b8ec4ecc81eead416a8aa42819a2869311b3420fa114ffa" +dependencies = [ + "libc", + "once_cell", + "winapi", +] + [[package]] name = "dotenvy" version = "0.15.7" @@ -2269,9 +2297,9 @@ dependencies = [ "netlink-proto", "netlink-sys", "rtnetlink", - "system-configuration", + "system-configuration 0.6.1", "tokio", - "windows", + "windows 0.53.0", ] [[package]] @@ -3241,6 +3269,12 @@ dependencies = [ "digest", ] +[[package]] +name = "memalloc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df39d232f5c40b0891c10216992c2f250c054105cb1e56f0fc9032db6203ecc1" + [[package]] name = "memchr" version = "2.7.5" @@ -3927,11 +3961,12 @@ dependencies = [ [[package]] name = "posemesh-domain-http" -version = "1.5.2" +version = "1.5.3" dependencies = [ "base64 0.22.1", "bytes", "console_error_panic_hook", + "default-net", "dotenvy", "futures", "posemesh-utils", @@ -5237,6 +5272,17 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys 0.5.0", +] + [[package]] name = "system-configuration" version = "0.6.1" @@ -5245,7 +5291,17 @@ checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.9.4", "core-foundation", - "system-configuration-sys", + "system-configuration-sys 0.6.0", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] @@ -6527,6 +6583,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows" version = "0.53.0" diff --git a/core/domain-http/CHANGELOG.md b/core/domain-http/CHANGELOG.md index 388167bd..65bbf24e 100644 --- a/core/domain-http/CHANGELOG.md +++ b/core/domain-http/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.5.3 + +### Features +- Set gateway mac addres to request header + ## v1.5.2 ### Features diff --git a/core/domain-http/Cargo.toml b/core/domain-http/Cargo.toml index 0265ad8b..951775a0 100644 --- a/core/domain-http/Cargo.toml +++ b/core/domain-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "posemesh-domain-http" -version = "1.5.2" +version = "1.5.3" edition = "2024" repository = "https://github.com/aukilabs/posemesh/tree/main/core" description = "HTTP client library for interacting with AukiLabs domain data services, supporting both native and WebAssembly targets." @@ -19,6 +19,7 @@ bytes = "1.10.1" thiserror.workspace = true [target.'cfg(not(target_family="wasm"))'.dependencies] +default-net = "0.22.0" tokio = { workspace = true, features = ["full"] } uniffi = { workspace = true, optional = true } diff --git a/core/domain-http/src/discovery.rs b/core/domain-http/src/discovery.rs index a083694b..06c30ed6 100644 --- a/core/domain-http/src/discovery.rs +++ b/core/domain-http/src/discovery.rs @@ -81,6 +81,25 @@ pub struct CreateDomainRequest { domain_server_url: String, } +/// Returns the gateway MAC address on native targets. On WASM/browser this always returns +/// empty string — browsers cannot access network interfaces, gateway, or MAC addresses. +fn get_mac_address() -> Result { + #[cfg(not(target_family = "wasm"))] + { + match default_net::get_default_gateway() { + Ok(gateway) => Ok(gateway.mac_addr.to_string()), + Err(_) => Err(DomainError::InvalidRequest("No gateway found")), + } + } + + #[cfg(target_family = "wasm")] + { + // Browsers cannot access network interfaces, gateway IP, or MAC addresses. + // Return empty string so auth still works; server may use other identifiers. + Ok(String::new()) + } +} + impl DiscoveryService { pub fn new(api_url: &str, dds_url: &str, client_id: &str) -> Self { let api_client = AuthClient::new(api_url, client_id); @@ -134,6 +153,10 @@ impl DiscoveryService { .header("Content-Type", "application/json") .header("posemesh-client-id", self.api_client.client_id.clone()) .header("posemesh-sdk-version", crate::VERSION) + .header( + "posemesh-gateway-mac", + get_mac_address().unwrap_or_default(), + ) .send() .await?; @@ -260,12 +283,14 @@ impl DiscoveryService { let dds_url = self.dds_url.clone(); let client_id = self.api_client.client_id.clone(); async move { + let mac_address = get_mac_address().unwrap_or_default(); let response = client .post(format!("{}/api/v1/domains/{}/auth", dds_url, domain_id)) .bearer_auth(access_token) .header("Content-Type", "application/json") .header("posemesh-client-id", client_id) .header("posemesh-sdk-version", crate::VERSION) + .header("posemesh-gateway-mac", mac_address) .send() .await?; @@ -321,6 +346,10 @@ impl DiscoveryService { .header("Content-Type", "application/json") .header("posemesh-client-id", self.api_client.client_id.clone()) .header("posemesh-sdk-version", crate::VERSION) + .header( + "posemesh-gateway-mac", + get_mac_address().unwrap_or_default(), + ) .json(&CreateDomainRequest { name: name.to_string(), domain_server_id: domain_server_id.to_string(), @@ -384,6 +413,10 @@ impl DiscoveryService { .header("Content-Type", "application/json") .header("posemesh-client-id", self.api_client.client_id.clone()) .header("posemesh-sdk-version", crate::VERSION) + .header( + "posemesh-gateway-mac", + get_mac_address().unwrap_or_default(), + ) .send() .await?; if response.status().is_success() { @@ -415,6 +448,10 @@ impl DiscoveryService { .header("Content-Type", "application/json") .header("posemesh-client-id", self.api_client.client_id.clone()) .header("posemesh-sdk-version", crate::VERSION) + .header( + "posemesh-gateway-mac", + get_mac_address().unwrap_or_default(), + ) .send() .await?; if response.status().is_success() {