MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / GetClientId

Function GetClientId

cmd/detail/client.go:59–95  ·  view source on GitHub ↗

GetClientId 获取客户端id

()

Source from the content-addressed store, hash-verified

57
58// GetClientId 获取客户端id
59func GetClientId() string {
60 // 默认id
61 id := "XXXXXXXXXXXXXXXX"
62 // 尝试读取.key文件
63 excFilepath, err := os.Executable()
64 if err != nil {
65 logs.Error(err)
66 }
67 idFile := filepath.Join(filepath.Dir(excFilepath), ".key")
68 if _, err := os.Stat(idFile); err != nil {
69 // 文件不存在则生成随机ID并保存
70 if f, err := os.Create(idFile); err != nil {
71 logs.Error(err)
72 } else {
73 defer f.Close()
74 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
75 idbyte := []byte(id)
76 for i := range idbyte {
77 idbyte[i] = chars[mrand.Intn(26)]
78 }
79 f.Write(idbyte)
80 id = string(idbyte)
81 }
82 } else {
83 // 文件存在则读取ID
84 idbyte, err := os.ReadFile(idFile)
85 if err != nil {
86 logs.Error(err)
87 }
88 if len(idbyte) == 16 {
89 if ok, err := regexp.Match(`[A-Z]{16}`, idbyte); ok && err == nil {
90 id = string(idbyte)
91 }
92 }
93 }
94 return id
95}
96
97// Detect 发送任务解析请求
98func Detect(dtype string, reqbody []byte) (repbody []byte, err error) {

Callers 2

DetectFunction · 0.85
getAesKeyFunction · 0.85

Calls 3

ErrorFunction · 0.92
WriteMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected