I would like to get, in a portable way, the "machine ID" (Linux), the "system ID" (Windows), or whatever Apple uses. I need to provide this (or at least its MD5) to a remote site for authentication purposes. Anybody do a crate for this yet?
What is a machine ID as far as Linux is concerned? Windows probably has its own thing to identify your hardware. But Linux?
On Linux, applications like Maple will use the mac address of your network card as far as I understand.
What about multi user systems? Users shouldn't share the same id for identification. In addition what about organizations where a single user can login on multiple systems using windows AD, ldap or something similar?
Well, on linux you can just read the /etc/machine-id file.
Now maybe I will waste mine and yours time, but I googled...
On windows... if you know how to understand the ms docs , (My brain can not parse those pages.), this might be an easy task....? Machine.Id Property | Microsoft Docs
On mac, if you can translate this code? I think it is some form of "c" but it is called main.m? this is 8 years old and might work...?
But as @bjorn3 points out the machine id is probably not the best way to authenticate.
On linux, do not use the machine-id or an MD5 hash of it over the network. This is insecure.
From the man page:
This ID uniquely identifies the host. It should be considered "confidential", and must not be exposed in untrusted environments, in particular on the network. If a stable unique identifier that is tied to the machine is needed for some application, the machine ID or any part of it must not be used directly. Instead the machine ID should be hashed with a cryptographic, keyed hash function, using a fixed, application-specific key. That way the ID will be properly unique, and derived in a constant way from the machine ID but there will be no way to retrieve the original machine ID from the application-specific one. The sd_id128_get_machine_app_specific(3) API provides an implementation of such an algorithm.
I looked at the C++ code of the client program whose behavior I have to duplicate, and here's what they do:
Windows: Get serial number of "C" drive using
GetVolumeInformation. Take MD5 of serial number. (If there is no C drive, return contents of uninitialized memory. Yes, that's C++.)
- Apple: Uses technique described in Apple Technical Note TN1103: Uniquely Identifying a Macintosh Computer
Linux: Reads names in directory "
/dev/disk/by-uuid/. Takes longest name. Breaks ties by sorting alphabetically. Take MD5. (Takes MD5 of empty string if directory does not exist or is empty.)
So, any crates which do those things would be helpful. I can easily code the Linux version, but don't have dev environments for Windows, or a Mac at all, so existing code would help. Thanks.
I have to match this exactly, or the 2 factor identification system kicks in and the user has to re-auth.
Implemented the Linux version. Seems to be working.
For Windows, I need to call the WinAPI call "GetVolumeInformation". Is there a safe Rust binding for that? There's a raw binding in "winapi", and nothing in "winapi-util". Any other place I should look?
Also, regarding MD5: I truly hope this isn't being relied on for anything important. MD5 is terribly weak and unfit for any sort of authentication purposes. If it is for some form of DRM, then by all means, carry on.
That's useful, being an official Microsoft implementation,, but it's just the raw unsafe foreign function interface. Is there any package which wraps 'GetVolumeInformation' in safe Rust code?
Also, there's no published license on that, which is worrisome where Microsoft code is involved.
Cargo.toml file lists "MIT OR Apache-2.0": windows-rs/Cargo.toml at 95dcbedc956597ab948a166fbd354a6dad5ec061 · microsoft/windows-rs · GitHub
Ah, that helps. So I'm coding up the Windows interface.
I haven't done Win32 since the days when Petzold's book was useful.
Once I have this working, is there some crate to which I should submit it as a pull request? It belongs in some collection of Windows wrappers, not a very tiny standalone crate. What's used widely, maintained, and takes pull requests?
The windows-sys crate is automatically generated from the windows api definitions in GitHub - microsoft/win32metadata: Tooling to generate metadata for Win32 APIs in the Windows SDK. It looks like this already contains the GetVolumeInformationW api and so does the windows-sys crate.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.