A lightweight Rust crate for generating machine ID hashes on Linux, macOS, and Windows.
This project is a simplified fork of doroved/mid. Mobile platform code, build scripts, examples, and documentation have been removed so the crate only focuses on desktop platforms.
- Linux
- macOS
- Windows
iOS, Android, and other mobile targets are not supported.
mid::get(key): returns the HMAC-SHA256 hash of the machine ID data.mid::data(key): returns the raw platform fields and the final hash.mid::print(key): prints debug information only in debug builds.mid::additional_data(): macOS only, returns extra device information that is not used in the hash.
The key must not be empty. Machine ID values can change after hardware replacement, OS reinstall, virtualization changes, or changes to the underlying system fields.
[dependencies]
mid = { git = "https://github.com/brookqin/mid" }Enable serialization support when needed:
[dependencies]
mid = { git = "https://github.com/brookqin/mid", features = ["serde", "serde_json"] }Get the machine ID hash:
let machine_id = mid::get("mySecretKey")?;
println!("{machine_id}");Get the raw fields and hash:
let data = mid::data("mySecretKey")?;
println!("{:?}", data.result);
println!("{}", data.hash);Get additional macOS device data:
#[cfg(target_os = "macos")]
{
let info = mid::additional_data()?;
println!("{info:?}");
}Run the example:
cargo run --example example --features serde,serde_jsonThe crate reads and merges these sources:
Machine IDfromhostnamectl status/var/lib/dbus/machine-id/etc/machine-id/sys/class/dmi/id/product_uuid
Linux machine-id values can be changed by users or system processes, so they should not be treated as a strong security boundary.
The crate reads stable hardware fields from system_profiler SPHardwareDataType SPSecureElementDataType:
- Model Number
- Serial Number
- Hardware UUID
- SEID
additional_data() also reads username, hostname, OS version, chip, memory size, CPU core count, and language settings. These fields are not used in the hash.
The crate reads the raw SMBIOS firmware table through the Windows
GetSystemFirmwareTable API and uses these fields:
- Type 1 System Information UUID
- Type 1 System Information serial number
- Type 2 Baseboard serial number
- Type 4 Processor ID
Compared with the source project doroved/mid, this repository has been simplified as follows:
- Removed iOS and Android source entry points.
- Removed iOS build scripts, Xcode example project, xcframework artifacts, and mobile documentation.
- Removed mobile-only dependencies and
staticliboutput configuration. - Kept the Linux, macOS, and Windows Rust APIs.
- Rewrote the README so it matches the current desktop-only scope.
The source project doroved/mid is licensed under MIT OR Apache-2.0. This project keeps the same dual-license model. See: