Files
yml2213 ef36453694 feat(dcauth): 移除机器码,改用纯设备码认证
- DCAuth 协议升级到 v2,签名原文只含设备码;客户端 2.0.0,旧版本返回 426
- 删除客户端机器码采集、后端 machine_code_* 字段与日志、后台机器码展示
- 102 迁移在生产执行前直接改为无机器码结构;SQL 守卫仅放行该文件
- Mock 短信不启用每日限额;修复慢电脑首次启动的协议转发竞态
- 新增 macOS DCAuth.app 打包脚本,注册 dcauth:// 协议,浏览器可直接唤起
2026-10-21 20:46:25 +08:00

50 lines
1.0 KiB
Go

package main
import (
"crypto/sha256"
"strings"
)
const crockfordAlphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
func buildDeviceID(publicKey []byte) string {
material := append([]byte("dcauth.device.v1"), publicKey...)
sum := sha256.Sum256(material)
return formatCode("D1", sum[:])
}
func formatCode(prefix string, data []byte) string {
encoded := base32Crockford(data)
if len(encoded) > 20 {
encoded = encoded[:20]
}
groups := make([]string, 0, 5)
for len(encoded) > 0 {
size := 4
if len(encoded) < size {
size = len(encoded)
}
groups = append(groups, encoded[:size])
encoded = encoded[size:]
}
return prefix + "-" + strings.Join(groups, "-")
}
func base32Crockford(data []byte) string {
var builder strings.Builder
var buffer uint32
var bits uint
for _, value := range data {
buffer = (buffer << 8) | uint32(value)
bits += 8
for bits >= 5 {
bits -= 5
builder.WriteByte(crockfordAlphabet[(buffer>>bits)&31])
}
}
if bits > 0 {
builder.WriteByte(crockfordAlphabet[(buffer<<(5-bits))&31])
}
return builder.String()
}