mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-04-24 10:10:50 +00:00
check response status before parse the response bytes
This commit is contained in:
@@ -70,6 +70,11 @@ func (c *RemoteServer) doAction(action string, req []byte) ([]byte, error) {
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
// Return response body as error if status code != 200
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, errors.New(string(body))
|
||||
}
|
||||
|
||||
return body, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -133,6 +133,10 @@ func runEncrypt() {
|
||||
|
||||
resp, err := roServer.Encrypt(req)
|
||||
processError(err)
|
||||
if resp.Status != "ok" {
|
||||
log.Fatal("response status error:", resp.Status)
|
||||
return
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
outBytes := []byte(base64.StdEncoding.EncodeToString(resp.Response))
|
||||
ioutil.WriteFile(outPath, outBytes, 0644)
|
||||
@@ -161,6 +165,10 @@ func runReEncrypt() {
|
||||
|
||||
resp, err := roServer.ReEncrypt(req)
|
||||
processError(err)
|
||||
if resp.Status != "ok" {
|
||||
log.Fatal("response status error:", resp.Status)
|
||||
return
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
outBytes := []byte(base64.StdEncoding.EncodeToString(resp.Response))
|
||||
ioutil.WriteFile(outPath, outBytes, 0644)
|
||||
@@ -185,10 +193,14 @@ func runDecrypt() {
|
||||
|
||||
resp, err := roServer.Decrypt(req)
|
||||
processError(err)
|
||||
if resp.Status != "ok" {
|
||||
log.Fatal("response status error:", resp.Status)
|
||||
return
|
||||
}
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
var msg core.DecryptWithDelegates
|
||||
err = json.Unmarshal(resp.Response, &msg)
|
||||
processError(err)
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
fmt.Println("Secure:", msg.Secure)
|
||||
fmt.Println("Delegates:", msg.Delegates)
|
||||
ioutil.WriteFile(outPath, msg.Data, 0644)
|
||||
|
||||
Reference in New Issue
Block a user