Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php/105/useshed usecache flags #368

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions php/examples/VaasExample/GetVerdictByFile.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

namespace VaasExamples;

use Monolog\Logger;
use VaasSdk\ClientCredentialsGrantAuthenticator;
use VaasSdk\Vaas;

@@ -22,4 +21,4 @@
$scanPath = getenv("SCAN_PATH");
$vaasVerdict = $vaas->ForFile($scanPath);

fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is $vaasVerdict->Verdict \n");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is " . $vaasVerdict->Verdict->value . " \n");
7 changes: 4 additions & 3 deletions php/examples/VaasExample/GetVerdictByHash.php
Original file line number Diff line number Diff line change
@@ -10,15 +10,16 @@
$authenticator = new ClientCredentialsGrantAuthenticator(
getenv("CLIENT_ID"),
getenv("CLIENT_SECRET"),
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token");
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
);
$vaas = new Vaas(
getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de"
);
$vaas->Connect($authenticator->getToken());

// EICAR
$vaasVerdict = $vaas->ForSha256("000005c43196142f01d615a67b7da8a53cb0172f8e9317a2ec9a0a39a1da6fe8");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is $vaasVerdict->Verdict \n");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is " . $vaasVerdict->Verdict->value . " \n");
// SOMEFILE
$vaasVerdict = $vaas->ForSha256("70caea443deb0d0a890468f9ac0a9b1187676ba3e66eb60a722b187107eb1ea8");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is $vaasVerdict->Verdict \n");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is " . $vaasVerdict->Verdict->value . " \n");
7 changes: 4 additions & 3 deletions php/examples/VaasExample/GetVerdictByUrl.php
Original file line number Diff line number Diff line change
@@ -10,15 +10,16 @@
$authenticator = new ClientCredentialsGrantAuthenticator(
getenv("CLIENT_ID"),
getenv("CLIENT_SECRET"),
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token");
getenv("TOKEN_URL") ?? "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
);
$vaas = new Vaas(
getenv("VAAS_URL") ?? "wss://gateway.production.vaas.gdatasecurity.de"
);
$vaas->Connect($authenticator->getToken());

// EICAR
$vaasVerdict = $vaas->ForUrl("https://secure.eicar.org/eicar.com");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is $vaasVerdict->Verdict \n");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is " . $vaasVerdict->Verdict->value . " \n");
// SOMEFILE
$vaasVerdict = $vaas->ForUrl("https://www.gdatasoftware.com/oem/verdict-as-a-service");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is $vaasVerdict->Verdict \n");
fwrite(STDOUT, "Verdict for $vaasVerdict->Sha256 is " . $vaasVerdict->Verdict->value . " \n");
7 changes: 2 additions & 5 deletions php/src/vaas/Message/AuthRequest.php
Original file line number Diff line number Diff line change
@@ -2,17 +2,14 @@

namespace VaasSdk\Message;

use Ramsey\Uuid\Rfc4122\UuidV4;

class AuthRequest
class AuthRequest extends BaseMessage
{
public Kind $kind;
public string $token;
public string $session_id;

public function __construct(string $token, string $sessionId = "")
{
$this->kind = new Kind(Kind::AUTH_REQUEST);
$this->kind = Kind::AuthRequest;
$this->token = $token;
$this->session_id = $sessionId;
}
8 changes: 6 additions & 2 deletions php/src/vaas/Message/AuthResponse.php
Original file line number Diff line number Diff line change
@@ -2,10 +2,14 @@

namespace VaasSdk\Message;

class AuthResponse
class AuthResponse extends BaseMessage
{
public Kind $kind;
public bool $success;
public ?string $session_id;
public string $text;

public function __construct()
{
$this->kind = Kind::AuthResponse;
}
}
8 changes: 8 additions & 0 deletions php/src/vaas/Message/BaseMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace VaasSdk\Message;

class BaseMessage
{
public Kind $kind;
}
20 changes: 20 additions & 0 deletions php/src/vaas/Message/BaseVerdictRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace VaasSdk\Message;

use Ramsey\Uuid\Rfc4122\UuidV4;

class BaseVerdictRequest extends BaseMessage
{
public string $guid;
public string $session_id;
public bool $UseShed; # no simple way to rename the field in the json output
public bool $UseCache;

public function __construct(kind $kind, string $uuid = null, string $SessionId)
{
$this->kind = $kind;
$this->guid = $uuid != null ? $uuid : UuidV4::getFactory()->uuid4()->toString();
$this->session_id = $SessionId;
}
}
7 changes: 5 additions & 2 deletions php/src/vaas/Message/Error.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

namespace VaasSdk\Message;

class Error
class Error extends BaseMessage
{
public string $type;

@@ -12,7 +12,10 @@ class Error

public ?ProblemDetails $problem_details;

public Kind $kind;
public function __construct()
{
$this->kind = Kind::Error;
}

/**
* @return string
60 changes: 8 additions & 52 deletions php/src/vaas/Message/Kind.php
Original file line number Diff line number Diff line change
@@ -2,57 +2,13 @@

namespace VaasSdk\Message;

use JsonSerializable;
use VaasSdk\Exceptions\UnknownKindException;

class Kind implements JsonSerializable
enum Kind: string
{
public const AUTH_REQUEST = "AuthRequest";
public const AUTH_RESPONSE = "AuthResponse";
public const VERDICT_REQUEST = "VerdictRequest";
public const VERDICT_RESPONSE = "VerdictResponse";
public const VERDICT_REQUEST_FOR_URL = "VerdictRequestForUrl";
public const VERDICT_REQUEST_FOR_STREAM = "VerdictRequestForStream";
public const ERROR = "Error";

private string $_kindString = "";

public function __construct(string $type)
{
switch ($type) {
case self::AUTH_REQUEST:
$this->_kindString = self::AUTH_REQUEST;
break;
case self::AUTH_RESPONSE:
$this->_kindString = self::AUTH_RESPONSE;
break;
case self::VERDICT_REQUEST:
$this->_kindString = self::VERDICT_REQUEST;
break;
case self::VERDICT_RESPONSE:
$this->_kindString = self::VERDICT_RESPONSE;
break;
case self::VERDICT_REQUEST_FOR_URL:
$this->_kindString = self::VERDICT_REQUEST_FOR_URL;
break;
case self::VERDICT_REQUEST_FOR_STREAM:
$this->_kindString = self::VERDICT_REQUEST_FOR_STREAM;
break;
case self::ERROR:
$this->_kindString = self::ERROR;
break;
default:
throw new UnknownKindException();
}
}

public function __toString()
{
return $this->_kindString;
}

public function jsonSerialize(): string
{
return $this->_kindString;
}
case AuthRequest = "AuthRequest";
case AuthResponse = "AuthResponse";
case VerdictRequest = "VerdictRequest";
case VerdictResponse = "VerdictResponse";
case VerdictRequestForUrl = "VerdictRequestForUrl";
case VerdictRequestForStream = "VerdictRequestForStream";
case Error = "Error";
}
46 changes: 5 additions & 41 deletions php/src/vaas/Message/Verdict.php
Original file line number Diff line number Diff line change
@@ -2,46 +2,10 @@

namespace VaasSdk\Message;

use VaasSdk\Exceptions\UnkownVerdictException;
use JsonSerializable;

class Verdict implements JsonSerializable
enum Verdict: string
{
public const MALICIOUS = "Malicious";
public const CLEAN = "Clean";
public const UNKNOWN = "Unknown";
public const PUP = "Pup";

private string $_verdictString = "";

public function __construct(string $type)
{
switch ($type) {
case self::MALICIOUS:
$this->_verdictString = Verdict::MALICIOUS;
break;
case self::CLEAN:
$this->_verdictString = Verdict::CLEAN;
break;
case self::UNKNOWN:
$this->_verdictString = Verdict::UNKNOWN;
break;
case self::PUP:
$this->_verdictString = Verdict::PUP;
break;

default:
throw new UnkownVerdictException();
}
}

public function __toString()
{
return $this->_verdictString;
}

public function jsonSerialize(): string
{
return $this->_verdictString;
}
case MALICIOUS = "Malicious";
case CLEAN = "Clean";
case UNKNOWN = "Unknown";
case PUP = "Pup";
}
11 changes: 2 additions & 9 deletions php/src/vaas/Message/VerdictRequest.php
Original file line number Diff line number Diff line change
@@ -2,20 +2,13 @@

namespace VaasSdk\Message;

use Ramsey\Uuid\Rfc4122\UuidV4;

class VerdictRequest
class VerdictRequest extends BaseVerdictRequest
{
public string $sha256;
public string $guid;
public Kind $kind;
public string $session_id;

public function __construct(string $sha256, string $uuid = null, string $SessionId)
{
$this->kind = new Kind(Kind::VERDICT_REQUEST);
$this->guid = $uuid != null ? $uuid : UuidV4::getFactory()->uuid4()->toString();
parent::__construct(Kind::VerdictRequest, $uuid, $SessionId);
$this->sha256 = $sha256;
$this->session_id = $SessionId;
}
}
10 changes: 2 additions & 8 deletions php/src/vaas/Message/VerdictRequestForStream.php
Original file line number Diff line number Diff line change
@@ -4,16 +4,10 @@

use Ramsey\Uuid\Rfc4122\UuidV4;

class VerdictRequestForStream
class VerdictRequestForStream extends BaseVerdictRequest
{
public string $guid;
public Kind $kind;
public string $session_id;

public function __construct(string $SessionId, string $uuid = null)
{
$this->kind = new Kind(Kind::VERDICT_REQUEST_FOR_STREAM);
$this->guid = $uuid != null ? $uuid : UuidV4::getFactory()->uuid4()->toString();
$this->session_id = $SessionId;
parent::__construct(Kind::VerdictRequestForStream, $uuid, $SessionId);
}
}
9 changes: 2 additions & 7 deletions php/src/vaas/Message/VerdictRequestForUrl.php
Original file line number Diff line number Diff line change
@@ -4,18 +4,13 @@

use Ramsey\Uuid\Rfc4122\UuidV4;

class VerdictRequestForUrl
class VerdictRequestForUrl extends BaseVerdictRequest
{
public string $url;
public string $guid;
public Kind $kind;
public string $session_id;

public function __construct(string $url, string $uuid = null, string $SessionId)
{
$this->kind = new Kind(Kind::VERDICT_REQUEST_FOR_URL);
$this->guid = $uuid != null ? $uuid : UuidV4::getFactory()->uuid4()->toString();
parent::__construct(Kind::VerdictRequestForUrl, $uuid, $SessionId);
$this->url = $url;
$this->session_id = $SessionId;
}
}
2 changes: 1 addition & 1 deletion php/src/vaas/Message/VerdictResponse.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

namespace VaasSdk\Message;

class VerdictResponse
class VerdictResponse extends BaseMessage
{
public Verdict $verdict;
public ?string $url;
Loading