Coder Social home page Coder Social logo

doroved / mid Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 0.0 102 KB

Creating a Machine ID hash for MacOS/Windows/Linux

Home Page: https://crates.io/crates/mid

Rust 100.00%
auth authentication deviceid hardwareid hostid hwid library machine-id machine-identity machineid

mid's Introduction

Crates.io Version Crates.io Total Downloads docs.rs

README RU

mid

Creating a Machine ID hash for MacOS/Windows/Linux.

Utilizes the most static system parameters possible to generate reliable device hashes for licensing your software.

Change Log

v2.1.0 - June 30, 2024

  • Added mid::additional_data function that returns additional device data that is not involved in forming the device hash. Currently available for MacOS only.

v2.0.0 - March 24, 2024

  • Returned to_lowercase() for Windows MID result, which was mistakenly removed in v1.1.3. This will change the current Windows device hashes! If necessary, use version 2.0.0 for new projects only, or ask users to re-bind the license for new hashes in the current project.
  • Added mid::data function that returns data structure: key, result, hash.
  • mid::print outputs data to the console only in debug mode, it will not be included in the release build of the project.
  • Linux uses 3 sources to get machine-id.
  • The secret key for hashing cannot be empty.
  • Complete code refactoring has been performed.

List of parameters that are used on each platform.

MacOS

system_profiler SPHardwareDataType

The command returns information about the computer's hardware characteristics. Parameters used:

  • Model Number: This parameter represents the computer or device model number. It is used for uniquely identifying a specific model within the manufacturer's range.

  • Serial Number: This parameter is the unique serial number of the computer or device. It is used to identify a specific unit within a particular model.

  • Hardware UUID: This parameter represents the hardware UUID of the computer or device. It serves to provide unique identification of a specific unit across different systems and environments.

  • Provisioning UDID: This parameter represents the device's unique device identifier (UDID), which can be used in the provisioning process or device setup, usually in a corporate or managed environment.

system_profiler SPSecureElementDataType

The command returns information about the Secure Element. This element is used to store encrypted data, such as information about payment cards and other confidential data. Parameters used:

  • Platform ID: The unique identifier of the platform to which the Secure Element belongs.
  • SEID: The unique identifier of the Secure Element. Created during the NFC chip firmware at the manufacturer's factory.

Windows

PowerShell - expandable automation tool. Parameters used:

  • powershell -command "Get-WmiObject Win32_ComputerSystemProduct": Returns the unique product identifier (UUID) of the computer. Usually associated with the computer's motherboard. In rare cases, it may change after replacing or reinstalling the motherboard or after changing the device's BIOS/UEFI.

  • powershell -command "Get-WmiObject Win32_BIOS": Returns the computer's BIOS serial number. It usually remains constant and does not change.

  • powershell -command "Get-WmiObject Win32_BaseBoard": Returns the serial number of the computer's baseboard. It usually remains constant and does not change.

  • powershell -command "Get-WmiObject Win32_Processor": Returns the computer's processor identifier. It should remain unchanged, except in cases of processor replacement.

Linux

  • machine-id: A machine identifier (ID) that is used to uniquely identify a computer on Linux systems.

Unfortunately this parameter is subject to user modification and no reliable solution for Linux has been found yet.

Installation

Add the dependency to Cargo.toml

[dependencies]
mid = "2.1.0"

Or install using Cargo CLI

cargo add mid

How to Use

Get machine ID hash

let machine_id = mid::get("mySecretKey").unwrap();
Example: 3f9af06fd78d3390ef35e059623f58af03b7f6ca91690f5af031b774fd541977

Get MID key/result/hash data

let mid_data = mid::data("mySecretKey").unwrap();
MacOS example: MidData { key: "mySecretKey", result: ["ModelNumber", "SerialNumber", "HardwareUUID", "ProvisioningUDID", "PlatformID", "SEID"], hash: "3f9af06fd78d3390ef35e059623f58af03b7f6ca91690f5af031b774fd541977" }

Output the MID key/result/hash to the console in debug_assertions mode

mid::print("mySecretKey");
MacOS example:
MID.print[key]: mySecretKey
MID.print[result]: ["ModelNumber", "SerialNumber", "HardwareUUID", "ProvisioningUDID", "PlatformID", "SEID"]
MID.print[hash]: 3f9af06fd78d3390ef35e059623f58af03b7f6ca91690f5af031b774fd541977
  • MID key - The secret key for hashing
  • MID result - Array of OS parameters
  • MID hash - SHA-256 hash from result

Get additional device data

This data does not contribute to the device hash. Currently available for MacOS only.

let additional_data = mid::additional_data().unwrap();
println!("{:?}", additional_data);
AdditionalData { username: "doroved", hostname: "MacBook-Pro--doroved.local", os_name: "Sonoma", os_version: "14.5", os_full: "Sonoma 14.5", chip: "Apple M1 Pro", memsize: 16, cpu_core_count: 8, languages: ["ru-RU", "bg-RU", "en-RU"] }

Subscribe to my X

Here I will share my developments and projects https://x.com/doroved

References

mid's People

Contributors

doroved avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mid's Issues

Парочка изменений

Здравствуйте! Мне очень понравился Ваш проект. Во время внедрения в своё приложение, я пересмотрел некоторые реализованные Вами способы для большей оптимизации и уменьшения размера итогового приложения.

Вот несколько моих изменений:

  1. Для windows можно использовать библиотеку wmi, которая позволяет быстро и без спавна окон powershell получить необходимые параметры (код указан в качестве примера):
    #[cfg(target_os = "windows")]
    pub fn get_mid_result() -> Result<String, MIDError> {
    use wmi::{COMLibrary, WMIConnection};

    let com_connection = unsafe { COMLibrary::assume_initialized() };
    let wmi_connection =
        WMIConnection::new(com_connection.into()).expect("Failed to connect to WMI");

    let mac_address_base: Vec<MACGeneric> = wmi_connection
        .raw_query("SELECT MACAddress from Win32_NetworkAdapter WHERE MACAddress IS NOT NULL")
        .unwrap();

    let bios_serial_base: Vec<SerialNumberGeneric> = wmi_connection
        .raw_query("SELECT SerialNumber from Win32_BIOS WHERE SerialNumber IS NOT NULL")
        .unwrap();

    let processor_id_base: Vec<ProcessorIdGeneric> = wmi_connection
        .raw_query("SELECT ProcessorId from Win32_Processor WHERE ProcessorId IS NOT NULL")
        .unwrap();

    let mut result = Vec::new();

    parse_and_push(&mac_address_base[0].MACAddress, &mut result);
    parse_and_push(&bios_serial_base[0].SerialNumber, &mut result);
    parse_and_push(&processor_id_base[0].ProcessorId, &mut result);

    if result.is_empty() {
        return Err(MIDError::ResultMidError);
    }

    let combined_string = result.join("|");

    Ok(combined_string)
    }
  1. Так как ring очень много весит, я использовал sha2 для генерации уникального идентификатора ПК. Это позволило сильно уменьшить размер приложения.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.