From 86f9b42fcce8790e2385b02b8195a29bf90dbf46 Mon Sep 17 00:00:00 2001 From: Lennart Dohmann Date: Tue, 12 Mar 2024 10:17:46 +0100 Subject: [PATCH 1/5] PHP implementation of #390 --- php/src/vaas/Message/Detection.php | 40 ++++++++++++++++++++++++ php/src/vaas/Message/LibMagic.php | 29 +++++++++++++++++ php/src/vaas/Message/VaasVerdict.php | 4 +++ php/src/vaas/Message/VerdictResponse.php | 3 ++ php/tests/vaas/VaasTest.php | 15 +++++++++ 5 files changed, 91 insertions(+) create mode 100644 php/src/vaas/Message/Detection.php create mode 100644 php/src/vaas/Message/LibMagic.php diff --git a/php/src/vaas/Message/Detection.php b/php/src/vaas/Message/Detection.php new file mode 100644 index 00000000..4e5e1135 --- /dev/null +++ b/php/src/vaas/Message/Detection.php @@ -0,0 +1,40 @@ +engine; + } + + public function setEngine(int $engine): void + { + $this->engine = $engine; + } + + public function getFileName(): string + { + return $this->fileName; + } + + public function setFileName(string $fileName): void + { + $this->fileName = $fileName; + } + + public function getVirus(): string + { + return $this->virus; + } + + public function setVirus(string $virus): void + { + $this->virus = $virus; + } +} \ No newline at end of file diff --git a/php/src/vaas/Message/LibMagic.php b/php/src/vaas/Message/LibMagic.php new file mode 100644 index 00000000..0bb3399f --- /dev/null +++ b/php/src/vaas/Message/LibMagic.php @@ -0,0 +1,29 @@ +mimeType; + } + + public function setMimeType(string $mimeType): void + { + $this->mimeType = $mimeType; + } + + public function getFileType(): string + { + return $this->fileType; + } + + public function setFileType(string $fileType): void + { + $this->fileType = $fileType; + } +} \ No newline at end of file diff --git a/php/src/vaas/Message/VaasVerdict.php b/php/src/vaas/Message/VaasVerdict.php index 03508658..68bdb945 100644 --- a/php/src/vaas/Message/VaasVerdict.php +++ b/php/src/vaas/Message/VaasVerdict.php @@ -9,9 +9,13 @@ public function __construct(VerdictResponse $verdictResponse) $this->Sha256 = $verdictResponse->sha256 ?? ""; $this->Verdict = $verdictResponse->verdict ?? Verdict::UNKNOWN; $this->Guid = $verdictResponse->guid ?? ""; + $this->LibMagic = $verdictResponse->libMagic ?? null; + $this->Detections = $verdictResponse->detections ?? null; } public string $Sha256; public Verdict $Verdict; public string $Guid; + public ?LibMagic $LibMagic; + public ?array $Detections; } diff --git a/php/src/vaas/Message/VerdictResponse.php b/php/src/vaas/Message/VerdictResponse.php index 75b5cea7..93e4953e 100644 --- a/php/src/vaas/Message/VerdictResponse.php +++ b/php/src/vaas/Message/VerdictResponse.php @@ -9,4 +9,7 @@ class VerdictResponse extends BaseMessage public string $guid; public string $sha256; public ?string $upload_token; + public ?LibMagic $libMagic; + + public ?array $detections; } diff --git a/php/tests/vaas/VaasTest.php b/php/tests/vaas/VaasTest.php index 85139188..92988571 100644 --- a/php/tests/vaas/VaasTest.php +++ b/php/tests/vaas/VaasTest.php @@ -596,4 +596,19 @@ public function testForStream_WithEicarUrlContentAsStream_ReturnsMalicious() $this->assertEquals(Verdict::MALICIOUS, $verdict->Verdict); } + + public function testForStream_WithEicarUrlContentAsStream_ReturnsMaliciousWithDetectionAndMimeType() + { + $vaas = $this->_getVaas(); + $vaas->Connect($this->getClientCredentialsGrantAuthenticator()->getToken()); + $httpClient = new Client(); + $response = $httpClient->get(self::MALICIOUS_URL); + $stream = new Stream($response->getBody()->detach()); + + $verdict = $vaas->ForStream($stream); + + $this->assertEquals(Verdict::MALICIOUS, $verdict->Verdict); + $this->assertEquals("text/plain", $verdict->LibMagic->getMimeType()); + $this->assertContains("EICAR-Test-File", array_column($verdict->Detections, "virus")); + } } From 90fe85f42e5ca48d2e28306f8f6dbbcb7ba4a673 Mon Sep 17 00:00:00 2001 From: unglaublicherdude Date: Wed, 13 Mar 2024 09:00:22 +0100 Subject: [PATCH 2/5] removes the empty line --- php/src/vaas/Message/VerdictResponse.php | 1 - 1 file changed, 1 deletion(-) diff --git a/php/src/vaas/Message/VerdictResponse.php b/php/src/vaas/Message/VerdictResponse.php index 93e4953e..fec27bff 100644 --- a/php/src/vaas/Message/VerdictResponse.php +++ b/php/src/vaas/Message/VerdictResponse.php @@ -10,6 +10,5 @@ class VerdictResponse extends BaseMessage public string $sha256; public ?string $upload_token; public ?LibMagic $libMagic; - public ?array $detections; } From 8034be8ca23304d9fb7158d3c257678eb6f4466c Mon Sep 17 00:00:00 2001 From: unglaublicherdude Date: Wed, 13 Mar 2024 09:07:19 +0100 Subject: [PATCH 3/5] consistency --- php/src/vaas/Message/Detection.php | 32 +----------------- php/src/vaas/Message/Error.php | 43 ------------------------- php/src/vaas/Message/LibMagic.php | 22 +------------ php/src/vaas/Message/ProblemDetails.php | 19 +---------- 4 files changed, 3 insertions(+), 113 deletions(-) diff --git a/php/src/vaas/Message/Detection.php b/php/src/vaas/Message/Detection.php index 4e5e1135..c275574f 100644 --- a/php/src/vaas/Message/Detection.php +++ b/php/src/vaas/Message/Detection.php @@ -7,34 +7,4 @@ class Detection public ?int $engine; public string $fileName; public string $virus; - - public function getEngine(): int - { - return $this->engine; - } - - public function setEngine(int $engine): void - { - $this->engine = $engine; - } - - public function getFileName(): string - { - return $this->fileName; - } - - public function setFileName(string $fileName): void - { - $this->fileName = $fileName; - } - - public function getVirus(): string - { - return $this->virus; - } - - public function setVirus(string $virus): void - { - $this->virus = $virus; - } -} \ No newline at end of file +} diff --git a/php/src/vaas/Message/Error.php b/php/src/vaas/Message/Error.php index 8d244e71..0d567eab 100644 --- a/php/src/vaas/Message/Error.php +++ b/php/src/vaas/Message/Error.php @@ -5,55 +5,12 @@ class Error extends BaseMessage { public string $type; - public string $requestId; - public string $text; - public ?ProblemDetails $problem_details; public function __construct() { $this->kind = Kind::Error; } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * @return Kind - */ - public function getKind(): Kind - { - return $this->kind; - } - - /** - * @return ProblemDetails - */ - public function getProblemDetails(): ProblemDetails - { - return $this->problem_details; - } - - /** - * @return string - */ - public function getRequestId(): string - { - return $this->requestId; - } - - /** - * @return string - */ - public function getText(): string - { - return $this->text; - } } diff --git a/php/src/vaas/Message/LibMagic.php b/php/src/vaas/Message/LibMagic.php index 0bb3399f..e09509f0 100644 --- a/php/src/vaas/Message/LibMagic.php +++ b/php/src/vaas/Message/LibMagic.php @@ -6,24 +6,4 @@ class LibMagic { public string $fileType; public string $mimeType; - - public function getMimeType(): string - { - return $this->mimeType; - } - - public function setMimeType(string $mimeType): void - { - $this->mimeType = $mimeType; - } - - public function getFileType(): string - { - return $this->fileType; - } - - public function setFileType(string $fileType): void - { - $this->fileType = $fileType; - } -} \ No newline at end of file +} diff --git a/php/src/vaas/Message/ProblemDetails.php b/php/src/vaas/Message/ProblemDetails.php index aee6a513..58638384 100644 --- a/php/src/vaas/Message/ProblemDetails.php +++ b/php/src/vaas/Message/ProblemDetails.php @@ -5,22 +5,5 @@ class ProblemDetails { public string $type; - public string $detail; - - /** - * @return string - */ - public function getDetail(): string - { - return $this->detail; - } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } -} \ No newline at end of file +} From 737dfae9f3d8d9a121e7daae488c02d3a3b37ea5 Mon Sep 17 00:00:00 2001 From: Lennart Dohmann Date: Wed, 13 Mar 2024 11:36:09 +0100 Subject: [PATCH 4/5] Fix field usage due to consistency --- php/src/vaas/Vaas.php | 2 +- php/tests/vaas/VaasTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/src/vaas/Vaas.php b/php/src/vaas/Vaas.php index a6616b6c..6fcf4227 100644 --- a/php/src/vaas/Vaas.php +++ b/php/src/vaas/Vaas.php @@ -374,7 +374,7 @@ private function _waitForVerdict(string $guid): VerdictResponse private function _handleWebSocketErrorResponse(Error $errorResponse): void { if (isset($errorResponse->problem_details->detail)) { - $details = $errorResponse->problem_details->getDetail(); + $details = $errorResponse->problem_details->detail; } else { $details = null; } diff --git a/php/tests/vaas/VaasTest.php b/php/tests/vaas/VaasTest.php index 92988571..a4e16b92 100644 --- a/php/tests/vaas/VaasTest.php +++ b/php/tests/vaas/VaasTest.php @@ -608,7 +608,7 @@ public function testForStream_WithEicarUrlContentAsStream_ReturnsMaliciousWithDe $verdict = $vaas->ForStream($stream); $this->assertEquals(Verdict::MALICIOUS, $verdict->Verdict); - $this->assertEquals("text/plain", $verdict->LibMagic->getMimeType()); + $this->assertEquals("text/plain", $verdict->LibMagic->mimeType); $this->assertContains("EICAR-Test-File", array_column($verdict->Detections, "virus")); } } From c6e628b0554b17bebf0a3bee8a44306e73264476 Mon Sep 17 00:00:00 2001 From: Lennart Dohmann Date: Wed, 13 Mar 2024 11:46:12 +0100 Subject: [PATCH 5/5] Fix field usage due to consistency part 2 --- php/src/vaas/Vaas.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/src/vaas/Vaas.php b/php/src/vaas/Vaas.php index 6fcf4227..0a904be4 100644 --- a/php/src/vaas/Vaas.php +++ b/php/src/vaas/Vaas.php @@ -378,7 +378,7 @@ private function _handleWebSocketErrorResponse(Error $errorResponse): void } else { $details = null; } - $errorType = $errorResponse->getType(); + $errorType = $errorResponse->type; if ($errorType == "ClientError") { throw new VaasClientException($details); }