Skip to content

Commit

Permalink
Support Detections and file/mime type #390
Browse files Browse the repository at this point in the history
Java implementation
  • Loading branch information
ata-no-one authored and pstadermann committed Mar 11, 2024
1 parent fcb632f commit 5b1b336
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions java/src/main/java/de/gdata/vaas/messages/Detection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.gdata.vaas.messages;

import lombok.Getter;
import lombok.NonNull;

@Getter
public class Detection {
int engine;

@NonNull
String fileName;

@NonNull
String virus;
}
13 changes: 13 additions & 0 deletions java/src/main/java/de/gdata/vaas/messages/LibMagic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.gdata.vaas.messages;

import lombok.Getter;
import lombok.NonNull;

@Getter
public class LibMagic {
@NonNull
String fileType;

@NonNull
String mimeType;
}
8 changes: 8 additions & 0 deletions java/src/main/java/de/gdata/vaas/messages/VaasVerdict.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
import lombok.Getter;
import lombok.NonNull;

import java.util.ArrayList;

public class VaasVerdict {
@Getter
@NonNull
String sha256;
@Getter
@NonNull
Verdict verdict;
@Getter
ArrayList<Detection> detections;
@Getter
LibMagic libMagic;

public VaasVerdict(VerdictResponse verdictResponse) {
this.sha256 = verdictResponse.sha256;
this.verdict = verdictResponse.verdict;
this.detections = verdictResponse.detections;
this.libMagic = verdictResponse.libMagic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.NonNull;
import java.util.ArrayList;

public class VerdictResponse extends MessageType {
@Getter
Expand All @@ -25,6 +26,12 @@ public class VerdictResponse extends MessageType {
@Getter
@SerializedName("upload_token")
String uploadToken;
@Getter
@SerializedName("detections")
ArrayList<Detection> detections;
@Getter
@SerializedName("libMagic")
LibMagic libMagic;

private VerdictResponse() {
super(Kind.VerdictResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,20 @@ private Vaas getVaasWithCredentials()
client.connect();
return client;
}

@Test
public void forStream_WithEicarFile_ReturnsMaliciousVerdictWithDetections() throws Exception {
var url = new URL("https://secure.eicar.org/eicar.com.txt");
var conn = url.openConnection();
var inputStream = conn.getInputStream();
var contentLength = conn.getContentLengthLong();

var vaas = this.getVaasWithCredentials();
var verdict = vaas.forStream(inputStream, contentLength);

assertNotNull(verdict.getDetections());
assertEquals(Verdict.MALICIOUS, verdict.getVerdict());
assertEquals("EICAR virus test files", verdict.getLibMagic().getFileType());
assertEquals("text/plain", verdict.getLibMagic().getMimeType());
}
}

0 comments on commit 5b1b336

Please sign in to comment.