Debian Codegraph @

id.go

raw symbols SCIP
1 // Package machineid provides support for reading the unique machine id of most OSs (without admin privileges).
2 //
3 // https://github.com/denisbrodbeck/machineid
4 //
5 // https://godoc.org/github.com/denisbrodbeck/machineid/cmd/machineid
6 //
7 // This package is Cross-Platform (tested on Win7+, Debian 8+, Ubuntu 14.04+, OS X 10.6+, FreeBSD 11+)
8 // and does not use any internal hardware IDs (no MAC, BIOS, or CPU).
9 //
10 // Returned machine IDs are generally stable for the OS installation
11 // and usually stay the same after updates or hardware changes.
12 //
13 // This package allows sharing of machine IDs in a secure way by
14 // calculating HMAC-SHA256 over a user provided app ID, which is keyed by the machine id.
15 //
16 // Caveat: Image-based environments have usually the same machine-id (perfect clone).
17 // Linux users can generate a new id with `dbus-uuidgen` and put the id into
18 // `/var/lib/dbus/machine-id` and `/etc/machine-id`.
19 // Windows users can use the `sysprep` toolchain to create images, which produce valid images ready for distribution.
20 package machineid // import "github.com/denisbrodbeck/machineid"
21
22 import (
23 "fmt"
24 )
25
26 // ID returns the platform specific machine id of the current host OS.
27 // Regard the returned id as "confidential" and consider using ProtectedID() instead.
28 func ID() (string, error) {
29 id, err := machineID()
30 if err != nil {
31 return "", fmt.Errorf("machineid: %v", err)
32 }
33 return id, nil
34 }
35
36 // ProtectedID returns a hashed version of the machine ID in a cryptographically secure way,
37 // using a fixed, application-specific key.
38 // Internally, this function calculates HMAC-SHA256 of the application ID, keyed by the machine ID.
39 func ProtectedID(appID string) (string, error) {
40 id, err := ID()
41 if err != nil {
42 return "", fmt.Errorf("machineid: %v", err)
43 }
44 return protect(appID, id), nil
45 }