-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
161 lines (138 loc) · 3.65 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
package main
import (
"bufio"
"fmt"
"io/ioutil"
"math/rand"
"os"
"regexp"
"strconv"
"time"
"github.com/crowdware/shift-go/lib"
)
func readPythonConfig(filePath string) (string, string, error) {
fileContent, err := ioutil.ReadFile(filePath)
if err != nil {
return "", "", fmt.Errorf("failed to read file: %v", err)
}
re := regexp.MustCompile(`SHIFT_CLIENT_KEY\s*=\s*"(.*?)"`)
match := re.FindStringSubmatch(string(fileContent))
if len(match) != 2 {
return "", "", fmt.Errorf("unable to find SHIFT_CLIENT_KEY in the file")
}
clientKey := match[1]
re = regexp.MustCompile(`SHIFT_SECRET_KEY\s*=\s*"(.*?)"`)
match = re.FindStringSubmatch(string(fileContent))
if len(match) != 2 {
return "", "", fmt.Errorf("unable to find SHIFT_SECRET_KEY in the file")
}
secretkey := match[1]
return secretkey, clientKey, nil
}
func generateRandomNumber(min, max int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(max-min+1) + min
}
func writeVars() {
file, err := os.Create("./lib/crypto_vars.go.temp")
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()
writer := bufio.NewWriter(file)
text := "package lib\n\n"
text += "const debug = false\n"
text += "const initial_amount = 1\n\n"
text += "const var1 = " + strconv.Itoa(generateRandomNumber(1000, 9999)) + "\n"
text += "const var2 = " + strconv.Itoa(generateRandomNumber(1000, 9999)) + "\n"
text += "const var3 = " + strconv.Itoa(generateRandomNumber(10, 99)) + "\n"
text += "const var4 = " + strconv.Itoa(generateRandomNumber(100000, 999999)) + "\n"
text += "const var5 = " + strconv.Itoa(generateRandomNumber(100000, 999999)) + "\n"
text += "\n"
text += "const secret_key_enc = \"\"\n"
text += "const client_key_enc = \"\"\n"
_, err = writer.WriteString(text)
if err != nil {
fmt.Println("Error writing to file:", err)
return
}
err = writer.Flush()
if err != nil {
fmt.Println("Error flushing writer:", err)
return
}
}
func secret() {
infile, err := os.Open("./lib/crypto_vars.go")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer infile.Close()
scanner := bufio.NewScanner(infile)
text := ""
numLines := 12
lineCount := 0
for scanner.Scan() {
line := scanner.Text()
text += line + "\n"
lineCount++
if lineCount == numLines {
break
}
}
if err := scanner.Err(); err != nil {
fmt.Println("Error reading file:", err)
}
file, err := os.Create("./lib/crypto_vars.go.temp")
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()
writer := bufio.NewWriter(file)
text += "\n"
secret_key, client_key, err := readPythonConfig("shift_keys.py")
if err != nil {
fmt.Println("Error reading Python config:", err)
return
}
secret_key_enc := lib.Encrypt(secret_key)
text += "const secret_key_enc = \"" + secret_key_enc + "\"\n"
client_key_enc := lib.Encrypt(client_key)
text += "const client_key_enc = \"" + client_key_enc + "\"\n"
_, err = writer.WriteString(text)
if err != nil {
fmt.Println("Error writing to file:", err)
return
}
err = writer.Flush()
if err != nil {
fmt.Println("Error flushing writer:", err)
return
}
}
/*
** Initialize secret keys.
** First exchange variable1...variable5 in crypto_vars.go
** And then encrypt the API keys based on these vars and also put them into crypto_vars.go
*/
func main() {
if len(os.Args) > 1 {
if os.Args[1] == "vars" {
writeVars()
} else if os.Args[1] == "secret" {
secret()
} else if os.Args[1] == "test" {
test()
} else {
fmt.Println("Unknown argument:" + os.Args[1])
}
} else {
fmt.Println("Shift")
fmt.Println("Usage: go run . <arg> | where args are: vars | secret")
}
}
func test() {
}