Skip to content

Commit

Permalink
Merge pull request #441 from GDATASoftwareAG/golang/440-implement-api…
Browse files Browse the repository at this point in the history
…-changes-for-fields-detection-mime-and-filetype-in-all-sdks

implements the api changes
  • Loading branch information
lennartdohmann authored Apr 29, 2024
2 parents 477de7f + 7349096 commit 374f0eb
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 159 deletions.
16 changes: 5 additions & 11 deletions golang/vaas/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/GDATASoftwareAG/vaas/golang/vaas

go 1.22.2
go 1.22

require (
github.com/Noooste/websocket v1.0.3
Expand All @@ -10,21 +10,15 @@ require (
)

require (
github.com/Noooste/fhttp v1.0.11 // indirect
github.com/Noooste/utls v1.2.7 // indirect
github.com/Noooste/fhttp v1.0.12 // indirect
github.com/Noooste/utls v1.2.9 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cloudflare/circl v1.3.8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/onsi/ginkgo/v2 v2.15.0 // indirect
github.com/onsi/gomega v1.30.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/quic-go/quic-go v0.42.0 // indirect
github.com/refraction-networking/utls v1.6.3 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
36 changes: 8 additions & 28 deletions golang/vaas/go.sum
Original file line number Diff line number Diff line change
@@ -1,61 +1,41 @@
github.com/Noooste/fhttp v1.0.11 h1:tpVXalX6gCkNaUA694RJ/bIUh2Ypzg8vXKJMnS9mpDM=
github.com/Noooste/fhttp v1.0.11/go.mod h1:CMVxKOhNheqJN5HYE4Rlvz2SRdV8Uv7YWmi6OwmB/Bk=
github.com/Noooste/utls v1.2.7 h1:NLlRybZDzW+dXk/Uavb2E+pWeK+GAH2XkWq3g+C/WA0=
github.com/Noooste/utls v1.2.7/go.mod h1:MRUEmRiDO6ORKziZ2ObNwMjxy0vRviJ91JF1qVa0loM=
github.com/Noooste/fhttp v1.0.12 h1:2N15bIATKaC6q+LVyRGyxPyuqEPvwAS3Uk1peC3YVHU=
github.com/Noooste/fhttp v1.0.12/go.mod h1:CMVxKOhNheqJN5HYE4Rlvz2SRdV8Uv7YWmi6OwmB/Bk=
github.com/Noooste/utls v1.2.9 h1:VLNs0WmPFjswU4PxXTHl0AY4sarHi+638c3cSI9Hsng=
github.com/Noooste/utls v1.2.9/go.mod h1:dHM5MlRyB/ieog9axOxkEh4qZRgw5xA406y7sEdVmoQ=
github.com/Noooste/websocket v1.0.3 h1:drW7tvZ3YqzqI9wApnaH1Q0syFMXO7gbLlsBWjZvMNA=
github.com/Noooste/websocket v1.0.3/go.mod h1:Qhw0Rtuju/fPPbcb3R5XGq7poa51qPDL462jTltl9nQ=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cloudflare/circl v1.3.8 h1:j+V8jJt09PoeMFIu2uh5JUyEaIHTXVOHslFoLNAKqwI=
github.com/cloudflare/circl v1.3.8/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo=
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/quic-go v0.42.0 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM=
github.com/quic-go/quic-go v0.42.0/go.mod h1:132kz4kL3F9vxhW3CtQJLDVwcFe5wdWeJXXijhsO57M=
github.com/refraction-networking/utls v1.6.3 h1:MFOfRN35sSx6K5AZNIoESsBuBxS2LCgRilRIdHb6fDc=
github.com/refraction-networking/utls v1.6.3/go.mod h1:yil9+7qSl+gBwJqztoQseO6Pr3h62pQoY1lXiNR/FPs=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8=
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
9 changes: 0 additions & 9 deletions golang/vaas/pkg/messages/detection.go

This file was deleted.

8 changes: 0 additions & 8 deletions golang/vaas/pkg/messages/lib_magic.go

This file was deleted.

11 changes: 6 additions & 5 deletions golang/vaas/pkg/messages/vaas_verdict.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package messages

// VaasVerdict represents the verdict information returned by the VaaS server.
type VaasVerdict struct {
Verdict Verdict
Sha256 string
ErrMsg string
Detections []Detection
LibMagic LibMagic
Verdict Verdict
Sha256 string
ErrMsg string
Detection string
MimeType string
FileType string
}
17 changes: 9 additions & 8 deletions golang/vaas/pkg/messages/verdict_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package messages

// VerdictResponse represents the response containing the verdict information.
type VerdictResponse struct {
Kind string `json:"kind"`
Sha256 string `json:"sha256"`
GUID string `json:"guid"`
Verdict Verdict `json:"verdict"`
URL string `json:"url"`
UploadToken string `json:"upload_token"`
Detections []Detection `json:"detections"`
LibMagic LibMagic `json:"lib_magic"`
Kind string `json:"kind"`
Sha256 string `json:"sha256"`
GUID string `json:"guid"`
Verdict Verdict `json:"verdict"`
URL string `json:"url"`
UploadToken string `json:"upload_token"`
Detection string `json:"detection"`
FileType string `json:"file_type"`
MimeType string `json:"mime_type"`
}

// IsValid checks if the VerdictResponse is valid.
Expand Down
30 changes: 17 additions & 13 deletions golang/vaas/pkg/vaas/vaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ func (v *vaas) ForSha256List(ctx context.Context, sha256List []string) ([]msg.Va
defer waitGroup.Done()
verdict, err := v.ForSha256(ctx, sha256)
if err != nil {
verdict = msg.VaasVerdict{Sha256: sha256, Verdict: msg.Error, ErrMsg: err.Error(), Detections: verdict.Detections, LibMagic: verdict.LibMagic}
verdict = msg.VaasVerdict{Sha256: sha256, Verdict: msg.Error, ErrMsg: err.Error(),
Detection: verdict.Detection, FileType: verdict.FileType, MimeType: verdict.MimeType}
}
verdicts[i] = verdict
}(i, sha256)
Expand Down Expand Up @@ -352,10 +353,11 @@ func (v *vaas) ForUrl(ctx context.Context, url string) (msg.VaasVerdict, error)
}

return msg.VaasVerdict{
Verdict: response.Verdict,
Sha256: response.Sha256,
Detections: response.Detections,
LibMagic: response.LibMagic,
Verdict: response.Verdict,
Sha256: response.Sha256,
Detection: response.Detection,
MimeType: response.MimeType,
FileType: response.FileType,
}, nil
}

Expand Down Expand Up @@ -410,10 +412,11 @@ func (v *vaas) ForStream(ctx context.Context, stream io.Reader, contentLength in
response = <-responseChan

return msg.VaasVerdict{
Verdict: response.Verdict,
Sha256: response.Sha256,
Detections: response.Detections,
LibMagic: response.LibMagic,
Verdict: response.Verdict,
Sha256: response.Sha256,
Detection: response.Detection,
MimeType: response.MimeType,
FileType: response.FileType,
}, nil
}

Expand Down Expand Up @@ -492,10 +495,11 @@ func (v *vaas) forFileWithSha(ctx context.Context, data io.Reader, sha256 string
}

return msg.VaasVerdict{
Verdict: response.Verdict,
Sha256: response.Sha256,
Detections: response.Detections,
LibMagic: response.LibMagic,
Verdict: response.Verdict,
Sha256: response.Sha256,
Detection: response.Detection,
FileType: response.FileType,
MimeType: response.MimeType,
}, nil
}

Expand Down
14 changes: 6 additions & 8 deletions golang/vaas/pkg/vaas/vaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,16 @@ func TestVaas_ForStream_WithStreamFromUrl_RetunsMaliciousWithDetectionsAndMimeTy
t.Errorf("verdict should be %v, got %v", msg.Malicious, verdict.Verdict)
}

if verdict.LibMagic.MimeType != "text/plain" {
t.Errorf("expected mime type to be text/plain, got %v", verdict.LibMagic.MimeType)
if verdict.MimeType != "text/plain" {
t.Errorf("expected mime type to be text/plain, got %v", verdict.MimeType)
}

if len(verdict.Detections) == 0 {
t.Errorf("expected detections, got none")
if verdict.Detection == "" {
t.Errorf("expected a detection, got empty string")
}

for _, detection := range verdict.Detections {
if detection.Virus == "EICAR_TEST_FILE" {
return
}
if verdict.Detection != "EICAR-Test-File" {
t.Errorf("detection has to be EICAR-Test-File, got %v", verdict.Detection)
}
}

Expand Down
2 changes: 0 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,5 @@ pub use crate::vaas::Vaas;
pub use builder::Builder;
pub use cancellation::CancellationToken;
pub use connection::Connection;
pub use message::Detection;
pub use message::LibMagic;
pub use sha256::Sha256;
pub use vaas_verdict::VaasVerdict;
12 changes: 0 additions & 12 deletions rust/src/message/detection.rs

This file was deleted.

10 changes: 0 additions & 10 deletions rust/src/message/lib_magic.rs

This file was deleted.

5 changes: 4 additions & 1 deletion rust/src/message/message_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ mod tests {
"guid": "9dae843d-e947-41db-ad39-ec73704529ed",
"verdict": "Clean",
"url": null,
"upload_token": null
"upload_token": null,
"detection": "",
"file_type": "",
"mime_type": ""
}
"#
.to_string();
Expand Down
4 changes: 0 additions & 4 deletions rust/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
mod auth_request;
mod auth_response;
mod detection;
mod error;
mod kind;
mod lib_magic;
mod message_type;
mod open_id_connect_token_response;
mod upload_url;
Expand All @@ -17,9 +15,7 @@ mod verdict_response;

pub(super) use auth_request::AuthRequest;
pub(super) use auth_response::AuthResponse;
pub use detection::Detection;
pub(super) use error::ErrorResponse;
pub use lib_magic::LibMagic;
pub(super) use message_type::MessageType;
pub(super) use open_id_connect_token_response::OpenIdConnectTokenResponse;
pub(super) use upload_url::UploadUrl;
Expand Down
29 changes: 8 additions & 21 deletions rust/src/message/verdict_response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::{Detection, LibMagic};
use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
Expand All @@ -10,8 +9,9 @@ pub struct VerdictResponse {
pub verdict: String,
pub url: Option<String>,
pub upload_token: Option<String>,
pub detections: Option<Vec<Detection>>,
pub lib_magic: Option<LibMagic>,
pub detection: Option<String>,
pub file_type: Option<String>,
pub mime_type: Option<String>,
}

impl TryFrom<&String> for VerdictResponse {
Expand All @@ -23,11 +23,11 @@ impl TryFrom<&String> for VerdictResponse {

#[cfg(test)]
mod tests {
use crate::message::{detection::Detection, lib_magic::LibMagic, VerdictResponse};
use crate::message::VerdictResponse;

#[test]
fn deserialize() {
let json = r#"{"sha256":"275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f","file_name":null,"verdict":"Malicious","upload_token":null,"url":null,"detections":[{"engine":2,"file_name":"/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118","virus":"EICAR-Test-File"},{"engine":3,"file_name":"/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118","virus":"EICAR_TEST_FILE"}],"lib_magic":{"file_type":"EICAR virus test files","mime_type":"text/plain"},"kind":"VerdictResponse","request_id":"ed7207a5-d65a-4400-b91c-673ff39cfd8b","guid":"ed7207a5-d65a-4400-b91c-673ff39cfd8b"}"#;
let json = r#"{"sha256":"275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f","file_name":null,"verdict":"Malicious","upload_token":null,"url":null,"detection":"EICAR-Test-File","file_type":"EICAR virus test files","mime_type":"text/plain","kind":"VerdictResponse","request_id":"ed7207a5-d65a-4400-b91c-673ff39cfd8b","guid":"ed7207a5-d65a-4400-b91c-673ff39cfd8b"}"#;
let verdict_response: VerdictResponse = serde_json::from_str(json).unwrap();

assert_eq!(
Expand All @@ -38,22 +38,9 @@ mod tests {
verdict: "Malicious".to_string(),
url: None,
upload_token: None,
detections: Some(vec![
Detection {
engine: 2,
file_name: "/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118".to_string(),
virus: "EICAR-Test-File".to_string()
},
Detection {
engine: 3,
file_name: "/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118".to_string(),
virus: "EICAR_TEST_FILE".to_string()
}
]),
lib_magic: Some(LibMagic {
file_type: "EICAR virus test files".to_string(),
mime_type: "text/plain".to_string()
})
detection: Some("EICAR-Test-File".to_string()),
file_type: Some("EICAR virus test files".to_string()),
mime_type: Some("text/plain".to_string()),
},
verdict_response
);
Expand Down
Loading

0 comments on commit 374f0eb

Please sign in to comment.