diff --git a/api/fileupload.go b/api/fileupload.go index 106e9e0fe963b7967641eb1fdd9a157d96938a25..5400ff18de91acbe3b371b50e9a475454d0cf8db 100644 --- a/api/fileupload.go +++ b/api/fileupload.go @@ -64,23 +64,13 @@ func UploadFileRetrieve(c *gin.Context) { logging.Logerror(err, "ERROR in RedisResponse, Fileupload API") http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError) return - // Maybe do another call to delete the key from the database? } - /** - //var checkData utils.ResultFrontendResponse - err = json.Unmarshal(responseBytes, &checkdata) - if err!=nil { - fmt.Println(string(checkData)) - } - fmt.Println(string(checkData)) - */ err = json.Unmarshal(responseBytes, &fileData) if err != nil { fmt.Println("Error handling redis response:" + err.Error()) logging.Logerror(err, "ERROR handling redis response, fileupload API") http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError) return - // Maybe do another call to delete the key from the database? } } @@ -145,10 +135,11 @@ func UploadFile(c *gin.Context) { logging.Logerror(err, "") } + // fetch API key APIKey := utils.APIKeyVirusTotal + // add API key to relevant header req.Header.Add("X-Apikey", APIKey) - // error handle here, user should not be able to send requests without api key // dynamically set content type, based on the formdata writer req.Header.Set("Content-Type", writer.FormDataContentType()) @@ -156,6 +147,7 @@ func UploadFile(c *gin.Context) { // perform the prepared API request res, err := http.DefaultClient.Do(req) + // as long as the request returns 200 if err != nil { log.Println(err) logging.Logerror(err, "") @@ -163,13 +155,12 @@ func UploadFile(c *gin.Context) { defer res.Body.Close() - // så lenge status 200 - // read the response contents, _ := ioutil.ReadAll(res.Body) var jsonResponse utils.VirusTotalUploadID + // unmarshal contents unmarshalledID := json.Unmarshal(contents, &jsonResponse) if unmarshalledID != nil { @@ -177,6 +168,7 @@ func UploadFile(c *gin.Context) { logging.Logerror(err, "") } + // fetch ID which is base64 encoded encodedID := jsonResponse.Data.ID // decode provided values for virustotal report diff --git a/api/virustotal.go b/api/virustotal.go index 7259a4426b651079adcd272d0d90375aba862e91..46dab32b50d7b47ab910eb9d215ef145514e2362 100644 --- a/api/virustotal.go +++ b/api/virustotal.go @@ -12,12 +12,9 @@ import ( // CallVirusTotal returns data on a file id from virustotal func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error) { - // VT key has been added. REMEMBER TO DEACTIVATE AND CHANGE BEFORE FINAL RELEASE. // prepare request towards API // Convert []byte to string and print to screen APIKey := utils.APIKeyVirusTotal - // remember to change api key, and reference it to a file instead - // as well as deactivate the key from the account, as it's leaked. if id == "" { log.Println("error, ID is empty") logging.Logerrorinfo("Error, ID is empty - Upload") @@ -61,12 +58,10 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error log.Println("here is the test output we maybe want") i := 0 - // TODO for later, remove teststruct, as it's only used to put into response, later var testStruct = make([]utils.FrontendResponse2, len(vtResponse.Data.Attributes.LastAnalysisResults)) // iterate through results for _, val := range vtResponse.Data.Attributes.LastAnalysisResults { - //log.Printf("testing, %s, %s", key, val) // initialize struct // print log.Println(val) @@ -85,11 +80,7 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error testStruct[i].EN.Description = vtResponse.Data.Attributes.Magic testStruct[i].EN.Tags = vtResponse.Data.Attributes.TypeTag - //testStruct.EN.Description = - // can also display the total status (last analysis stats) - // this is an int ^^ so cant fill it in frontendresponse2 - // question is, do we do it here or later i++ } @@ -118,8 +109,6 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error response.NO.Result = "Filen er mistenkelig. Det anbefales å ikke videre håndtere filen. " } - //var engines int = len(vtResponse.Data.Attributes.LastAnalysisResults) - utils.SetResultFile(&response, i-1) log.Println(response)