yao/commercial/machine_windows.go
Max 6e003875b4 feat(licenses): implement machine ID binding for license validation
- Added support for machine ID binding in license certificates, ensuring that if a machine ID is specified, it must match the current runtime machine ID for the license to be valid.
- Introduced new tests to verify behavior for empty, matching, and mismatching machine IDs in certificates, enhancing the robustness of license validation.
- Updated LicenseInfo struct to include MachineID field, reflecting the new binding requirement.
2026-03-27 17:18:17 +08:00

28 lines
547 B
Go

//go:build windows
package commercial
import (
"os/exec"
"strings"
)
func platformMachineID() string {
out, err := exec.Command("reg", "query",
`HKLM\SOFTWARE\Microsoft\Cryptography`,
"/v", "MachineGuid",
).Output()
if err != nil {
return ""
}
for _, line := range strings.Split(string(out), "\n") {
line = strings.TrimSpace(line)
if strings.Contains(line, "MachineGuid") {
fields := strings.Fields(line)
if len(fields) >= 3 {
return strings.TrimSpace(strings.ToLower(fields[len(fields)-1]))
}
}
}
return ""
}