diff --git a/api.go b/api.go index ec80501..6f2999a 100644 --- a/api.go +++ b/api.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math/rand" "net/url" "os" @@ -57,7 +56,7 @@ type HARData struct { } func readHAR() { - file, err := ioutil.ReadFile("chatgpt.har") + file, err := os.ReadFile("chatgpt.har") if err != nil { fmt.Println(err) return @@ -88,7 +87,7 @@ func readHAR() { arkHeader = make(http.Header) for _, h := range arkReq.Request.Headers { // arkHeader except cookie & content-length - if strings.EqualFold(h.Name, "content-length") == false && strings.EqualFold(h.Name, "cookie") == false && strings.HasPrefix(h.Name, ":") == false { + if !strings.EqualFold(h.Name, "content-length") && !strings.EqualFold(h.Name, "cookie") && !strings.HasPrefix(h.Name, ":") { arkHeader.Set(h.Name, h.Value) if strings.EqualFold(h.Name, "user-agent") { bv = h.Value diff --git a/crypt.go b/crypt.go index 405c4b0..dc85d5f 100644 --- a/crypt.go +++ b/crypt.go @@ -135,6 +135,9 @@ func Decrypt(data string, key string) string { func AesDecrypt(baseText string, password string) (string, error) { encBytes, err := base64.StdEncoding.DecodeString(baseText) + if err != nil { + return "", err + } var encData encryptionData err = json.Unmarshal(encBytes, &encData) if err != nil { @@ -145,6 +148,9 @@ func AesDecrypt(baseText string, password string) (string, error) { return "", err } salt, err := hex.DecodeString(encData.S) + if err != nil { + return "", err + } key, iv, err := DefaultEvpKDF([]byte(password), salt) if err != nil { return "", err diff --git a/util.go b/util.go index db70c67..45b3ed0 100644 --- a/util.go +++ b/util.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "math/rand" "net/url" "os" "strings" @@ -74,12 +73,3 @@ func getRequestId(sessionId string) string { pwd := fmt.Sprintf("REQUESTED%sID", sessionId) return Encrypt(`{"sc":[147,307]}`, pwd) } - -func randomHex(length int) string { - chars := []rune("0123456789abcdef") - var b strings.Builder - for i := 0; i < length; i++ { - b.WriteRune(chars[rand.Intn(len(chars))]) - } - return b.String() -}