-
Notifications
You must be signed in to change notification settings - Fork 58
/
main.go
198 lines (175 loc) · 5.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
import (
"bytes"
crand "crypto/rand"
"crypto/tls"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"strconv"
"strings"
"time"
"golang.org/x/crypto/curve25519"
)
type Response struct {
ID string `json:"id"`
Type string `json:"type"`
Model string `json:"model"`
Name string `json:"name"`
Key string `json:"key"`
Account Account
Config Config
Token string `json:"token"`
Warp bool `json:"warp_enabled"`
Waitlist bool `json:"waitlist_enabled"`
Created string `json:"created"`
Updated string `json:"updated"`
TOS string `json:"tos"`
Place int `json:"place"`
Locale string `json:"locale"`
Enabled bool `json:"enabled"`
InstallID string `json:"install_id"`
FCMToken string `json:"fcm_token"`
SerialNum string `json:"serial_number"`
}
type Account struct {
ID string `json:"id"`
AccountType string `json:"account_type"`
Created string `json:"created"`
Updated string `json:"updated"`
PremiumData int `json:"premium_data"`
Quota int `json:"quota"`
Usage int `json:"usage"`
WarpPlus bool `json:"warp_plus"`
ReferralCount int `json:"referral_count"`
ReferralRenewalCount int `json:"referral_renewal_countdown"`
Role string `json:"role"`
License string `json:"license"`
}
type Config struct {
ClientID string `json:"client_id"`
Peers []Peer `json:"peers"`
Interface struct {
Addresses Addresses `json:"addresses"`
} `json:"interface"`
Services struct {
HTTPProxy string `json:"http_proxy"`
} `json:"services"`
}
type Peer struct {
PublicKey string `json:"public_key"`
Endpoint struct {
V4 string `json:"v4"`
V6 string `json:"v6"`
Host string `json:"host"`
} `json:"endpoint"`
}
type Addresses struct {
V4 string `json:"v4"`
V6 string `json:"v6"`
}
func main() {
err, privateKey, publicKey := GenerateKey()
if err != nil {
panic(err)
}
url := "https://api.cloudflareclient.com/v0a2158/reg"
method := "POST"
rand.Seed(time.Now().UnixNano())
//installID为22位随机字符串
installID := RandStringRunes(22)
//fcm_token = install_id:APA91b+134位随机字符串
fcmtoken := RandStringRunes(134)
payload := []byte(`{"key":"` + publicKey + `","install_id":"` + installID + `","fcm_token":"` + installID + `:APA91b` + fcmtoken + `","tos":"` + time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + `","model":"Android","serial_number":"` + installID + `","locale":"zh_CN"}`)
client := &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
MaxVersion: tls.VersionTLS12},
}}
req, err := http.NewRequest(method, url, bytes.NewBuffer(payload))
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("CF-Client-Version", "a-6.10-2158")
req.Header.Add("User-Agent", "okhttp/3.12.1")
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
var response Response
err = json.Unmarshal(body, &response)
if err != nil {
fmt.Println(err)
return
}
// 从JSON响应体中提取"client_id"的值
clientID := response.Config.ClientID
// 解码base64编码的字符串并将其转换为十六进制
decoded, err := base64.StdEncoding.DecodeString(clientID)
if err != nil {
fmt.Println(err)
return
}
hexString := hex.EncodeToString(decoded)
// 将十六进制字符串转换为十进制值并打印它们
var decValues []string
for i := 0; i < len(hexString); i += 2 {
hexByte := hexString[i : i+2]
decValue, _ := strconv.ParseInt(hexByte, 16, 64)
decValues = append(decValues, fmt.Sprintf("%d%d%d", decValue/100, (decValue/10)%10, decValue%10))
}
reserved := []int{}
for i := 0; i < len(hexString); i += 2 {
hexByte := hexString[i : i+2]
decValue, _ := strconv.ParseInt(hexByte, 16, 64)
reserved = append(reserved, int(decValue))
}
v4 := response.Config.Interface.Addresses.V4
v6 := response.Config.Interface.Addresses.V6
fmt.Println("device_id:", response.ID)
fmt.Println("token:", response.Token)
fmt.Println("account_id:", response.Account.ID)
fmt.Println("account_type:", response.Account.AccountType)
fmt.Println("license:", response.Account.License)
fmt.Println("private_key:", privateKey)
fmt.Println("public_key:", response.Config.Peers[0].PublicKey)
fmt.Println("client_id:", response.Config.ClientID)
fmt.Println("reserved: [", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(reserved)), ", "), "[]"), "]")
fmt.Println("v4:", v4)
fmt.Println("v6:", v6)
fmt.Println("endpoint:", response.Config.Peers[0].Endpoint.Host)
}
func RandStringRunes(n int) string {
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_")
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
func GenerateKey() (error, string, string) {
b := make([]byte, 32)
if _, err := crand.Read(b); err != nil {
return fmt.Errorf("无法读取随机字节: %v", err), "", ""
}
b[0] &= 248
b[31] &= 127
b[31] |= 64
var pub, priv [32]byte
copy(priv[:], b)
curve25519.ScalarBaseMult(&pub, &priv)
return nil, base64.StdEncoding.EncodeToString(priv[:]), base64.StdEncoding.EncodeToString(pub[:])
}