()
| 557 | } |
| 558 | |
| 559 | func deriveMachineID() (uuid.UUID, error) { |
| 560 | // use /etc/machine-id |
| 561 | machineID, err := os.ReadFile("/etc/machine-id") |
| 562 | if err != nil { |
| 563 | return uuid.Nil, err |
| 564 | } |
| 565 | |
| 566 | // 16 bytes, not secret |
| 567 | key := []byte("man moon machine") |
| 568 | mac, err := blake2b.New(16, key) |
| 569 | if err != nil { |
| 570 | return uuid.Nil, err |
| 571 | } |
| 572 | mac.Write(machineID) |
| 573 | machineHash := mac.Sum(nil) |
| 574 | var u uuid.UUID |
| 575 | copy(u[:], machineHash) |
| 576 | // Make it a v4 uuid (taken from uuid.NewRandom): |
| 577 | u[6] = (u[6] & 0x0f) | 0x40 // Version 4 |
| 578 | u[8] = (u[8] & 0x3f) | 0x80 // Variant is 10 |
| 579 | |
| 580 | return u, nil |
| 581 | } |
| 582 | |
| 583 | func readExistingUUID() (uuid.UUID, error) { |
| 584 | id, err := identity.LoadDefaultIdentity() |
no outgoing calls
no test coverage detected
searching dependent graphs…