From 6aa4aedc4c598b4f4ae9bb06f6f876cb9488c1b4 Mon Sep 17 00:00:00 2001 From: Philip Stadermann Date: Mon, 24 Jun 2024 12:53:25 +0200 Subject: [PATCH 01/13] Rust example: Use description and version from Cargo.toml --- rust/examples/gscan/Cargo.toml | 4 ++-- rust/examples/gscan/src/main.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/examples/gscan/Cargo.toml b/rust/examples/gscan/Cargo.toml index 438e0187..6009059c 100644 --- a/rust/examples/gscan/Cargo.toml +++ b/rust/examples/gscan/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gscan" -version = "0.1.0" +version = "1.0.0" edition = "2021" authors = ["GDATA CyberDefense AG "] license = "MIT" @@ -10,7 +10,7 @@ publish = false [dependencies] vaas = { version = "5.0.0" } tokio = { version = "1.37", features = [ "rt-multi-thread", "macros"] } -clap = { version = "4.5.4", features = ["env"]} +clap = { version = "4.5.4", features = ["env", "cargo"]} reqwest = "0.12.4" futures = "0.3.30" dotenv = "0.15" \ No newline at end of file diff --git a/rust/examples/gscan/src/main.rs b/rust/examples/gscan/src/main.rs index b7678b0a..3076e843 100644 --- a/rust/examples/gscan/src/main.rs +++ b/rust/examples/gscan/src/main.rs @@ -1,14 +1,14 @@ -use clap::{Arg, ArgAction, Command}; +use clap::{crate_authors, crate_description, crate_name, crate_version, Arg, ArgAction, Command}; use reqwest::Url; use std::{collections::HashMap, path::PathBuf, str::FromStr}; use vaas::{error::VResult, CancellationToken, Vaas, VaasVerdict}; #[tokio::main] async fn main() -> VResult<()> { - let matches = Command::new("GDATA command line scanner") - .version("0.1.0") - .author("GDATA CyberDefense AG") - .about("Scan files for malicious content") + let matches = Command::new(crate_name!()) + .version(crate_version!()) + .author(crate_authors!()) + .about(crate_description!()) .arg( Arg::new("files") .short('f') From 36b125b9b8a15d4b2ad2e5bc1bb2838e41d52a1c Mon Sep 17 00:00:00 2001 From: Philip Stadermann Date: Mon, 24 Jun 2024 13:31:55 +0200 Subject: [PATCH 02/13] Rust: Upgrade example to Vaas 5.0.0 --- rust/examples/gscan/src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rust/examples/gscan/src/main.rs b/rust/examples/gscan/src/main.rs index 3076e843..43821e20 100644 --- a/rust/examples/gscan/src/main.rs +++ b/rust/examples/gscan/src/main.rs @@ -1,7 +1,10 @@ use clap::{crate_authors, crate_description, crate_name, crate_version, Arg, ArgAction, Command}; use reqwest::Url; use std::{collections::HashMap, path::PathBuf, str::FromStr}; -use vaas::{error::VResult, CancellationToken, Vaas, VaasVerdict}; +use vaas::{ + auth::authenticators::ClientCredentials, error::VResult, CancellationToken, Connection, Vaas, + VaasVerdict, +}; #[tokio::main] async fn main() -> VResult<()> { @@ -58,10 +61,11 @@ async fn main() -> VResult<()> { let client_id = matches.get_one::("client_id").unwrap(); let client_secret = matches.get_one::("client_secret").unwrap(); - let token = Vaas::get_token(client_id, client_secret).await?; + let authenticator = ClientCredentials::new(client_id.to_owned(), client_secret.to_owned()); + let vaas_connection = Vaas::builder(authenticator).build()?.connect().await?; - let file_verdicts = scan_files(&files, &token).await?; - let url_verdicts = scan_urls(&urls, &token).await?; + let file_verdicts = scan_files(&files, &vaas_connection).await?; + let url_verdicts = scan_urls(&urls, &vaas_connection).await?; file_verdicts.iter().for_each(|(f, v)| { println!( @@ -90,12 +94,10 @@ async fn main() -> VResult<()> { async fn scan_files<'a>( files: &'a [PathBuf], - token: &str, + vaas_connection: &Connection, ) -> VResult)>> { - let vaas = Vaas::builder(token.into()).build()?.connect().await?; - let ct = CancellationToken::from_minutes(1); - let verdicts = vaas.for_file_list(files, &ct).await; + let verdicts = vaas_connection.for_file_list(files, &ct).await; let results = files.iter().zip(verdicts).collect(); Ok(results) @@ -103,14 +105,12 @@ async fn scan_files<'a>( async fn scan_urls( urls: &[Url], - token: &str, + vaas_connection: &Connection, ) -> VResult>> { - let vaas = Vaas::builder(token.into()).build()?.connect().await?; - let ct = CancellationToken::from_minutes(1); let mut verdicts = HashMap::new(); for url in urls { - let verdict = vaas.for_url(url, &ct).await; + let verdict = vaas_connection.for_url(url, &ct).await; verdicts.insert(url.to_owned(), verdict); } From 173d5cf6f01472fe4b68d07b99a648355f1db305 Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 13:52:01 +0200 Subject: [PATCH 03/13] test rust binary releaser --- .github/workflows/ci-rust-gscan-cli.yaml | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/ci-rust-gscan-cli.yaml diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml new file mode 100644 index 00000000..d90340a7 --- /dev/null +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -0,0 +1,72 @@ +name: vaas-rust-ci +on: + push: + branches: + - main + - rust_example_1_0_0 + paths: + - "rust/example/gdscan/**" + - ".github/workflows/ci-rust-gscan-cli.yaml" + tags: + - "rs*" + pull_request: + branches: + - main + - rust_example_1_0_0 + paths: + - "rust/example/gdscan/**" + - ".github/workflows/ci-rust-gscan-cli.yaml" + release: + types: [created] + +# env: +# CLIENT_ID: ${{ secrets.CLIENT_ID }} +# CLIENT_SECRET: ${{secrets.CLIENT_SECRET}} +# VAAS_URL: "wss://gateway.production.vaas.gdatasecurity.de" +# TOKEN_URL: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token" +# VAAS_CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }} +# VAAS_USER_NAME: ${{ secrets.VAAS_USER_NAME }} +# VAAS_PASSWORD: ${{secrets.VAAS_PASSWORD}} + +jobs: + release: + name: release ${{ matrix.target }} + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + target: [x86_64-pc-windows-gnu, x86_64-unknown-linux-musl] + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: Scan for Viruses + uses: ./.github/actions/vaas-scan-action + with: + VAAS_CLIENT_ID: ${{ secrets.VAAS_SCAN_CLIENT_ID }} + VAAS_CLIENT_SECRET: ${{ secrets.VAAS_SCAN_CLIENT_SECRET }} + + - uses: actions/checkout@master + - name: Compile and release + uses: rust-build/rust-build.action@v1.4.5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + RUSTTARGET: ${{ matrix.target }} + EXTRA_FILES: "Readme.md" + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: Binary + path: | + ${{ steps.compile.outputs.BUILT_ARCHIVE }} + ${{ steps.compile.outputs.BUILT_CHECKSUM }} + + - name: Microsoft Teams Notification + uses: skitionek/notify-microsoft-teams@master + if: failure() + with: + webhook_url: ${{ secrets.MSTEAMS_WEBHOOK }} + overwrite: "{title: `Failed workflow on for VaaS-SDK ${workflow}`, sections: [{activityTitle: 'build failed', activitySubtitle: `Failed workflow on for VaaS-SDK ${workflow}`, activityImage: 'https://adaptivecards.io/content/cats/3.png'}], themeColor: '#ff0000'}" From 2c5c67444676b188d6a01d4da540e40e5aa51e37 Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 13:55:08 +0200 Subject: [PATCH 04/13] add correct dir --- .github/workflows/ci-rust-gscan-cli.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index d90340a7..1f62d20a 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -53,6 +53,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: + SRC_DIR: rust/examples/gscan RUSTTARGET: ${{ matrix.target }} EXTRA_FILES: "Readme.md" From 95afc28998687da8c807a219a841682feb356247 Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 14:04:02 +0200 Subject: [PATCH 05/13] set upload mode to none --- .github/workflows/ci-rust-gscan-cli.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index 1f62d20a..c526b635 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -56,6 +56,7 @@ jobs: SRC_DIR: rust/examples/gscan RUSTTARGET: ${{ matrix.target }} EXTRA_FILES: "Readme.md" + UPLOAD_MODE: none - name: Upload artifact uses: actions/upload-artifact@v3 From 83a99a34ce28161e1090aa943ae5e431ddf6b14b Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 14:10:19 +0200 Subject: [PATCH 06/13] add id --- .github/workflows/ci-rust-gscan-cli.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index c526b635..1f147cc9 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -48,7 +48,8 @@ jobs: VAAS_CLIENT_SECRET: ${{ secrets.VAAS_SCAN_CLIENT_SECRET }} - uses: actions/checkout@master - - name: Compile and release + - name: build + id: build uses: rust-build/rust-build.action@v1.4.5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -63,8 +64,8 @@ jobs: with: name: Binary path: | - ${{ steps.compile.outputs.BUILT_ARCHIVE }} - ${{ steps.compile.outputs.BUILT_CHECKSUM }} + ${{ steps.build.outputs.BUILT_ARCHIVE }} + ${{ steps.build.outputs.BUILT_CHECKSUM }} - name: Microsoft Teams Notification uses: skitionek/notify-microsoft-teams@master From 7399121e1ac19047ec35448d9bdec9346a14a337 Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 15:33:43 +0200 Subject: [PATCH 07/13] only build for windows --- .github/workflows/ci-rust-gscan-cli.yaml | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index 1f147cc9..35496344 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -7,8 +7,6 @@ on: paths: - "rust/example/gdscan/**" - ".github/workflows/ci-rust-gscan-cli.yaml" - tags: - - "rs*" pull_request: branches: - main @@ -19,24 +17,11 @@ on: release: types: [created] -# env: -# CLIENT_ID: ${{ secrets.CLIENT_ID }} -# CLIENT_SECRET: ${{secrets.CLIENT_SECRET}} -# VAAS_URL: "wss://gateway.production.vaas.gdatasecurity.de" -# TOKEN_URL: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token" -# VAAS_CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }} -# VAAS_USER_NAME: ${{ secrets.VAAS_USER_NAME }} -# VAAS_PASSWORD: ${{secrets.VAAS_PASSWORD}} jobs: release: name: release ${{ matrix.target }} - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: - target: [x86_64-pc-windows-gnu, x86_64-unknown-linux-musl] - + runs-on: ubuntu-22.04 steps: - name: checkout uses: actions/checkout@v4 @@ -55,14 +40,14 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: SRC_DIR: rust/examples/gscan - RUSTTARGET: ${{ matrix.target }} + RUSTTARGET: x86_64-pc-windows-gnu EXTRA_FILES: "Readme.md" UPLOAD_MODE: none - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: Binary + name: gscan-cli path: | ${{ steps.build.outputs.BUILT_ARCHIVE }} ${{ steps.build.outputs.BUILT_CHECKSUM }} From 8b7d31a9a8e56feeee76543ff39308ee42fd5c23 Mon Sep 17 00:00:00 2001 From: Philip Stadermann Date: Mon, 24 Jun 2024 15:20:22 +0200 Subject: [PATCH 08/13] Rust example: Output detection --- rust/examples/gscan/src/main.rs | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/rust/examples/gscan/src/main.rs b/rust/examples/gscan/src/main.rs index 43821e20..19f1e9e3 100644 --- a/rust/examples/gscan/src/main.rs +++ b/rust/examples/gscan/src/main.rs @@ -67,31 +67,31 @@ async fn main() -> VResult<()> { let file_verdicts = scan_files(&files, &vaas_connection).await?; let url_verdicts = scan_urls(&urls, &vaas_connection).await?; - file_verdicts.iter().for_each(|(f, v)| { - println!( - "File: {:?} -> {}", - f, - match v { - Ok(v) => v.verdict.to_string(), - Err(e) => e.to_string(), - } - ) - }); + file_verdicts + .iter() + .for_each(|(f, v)| print_verdicts(f.display().to_string(), v)); - url_verdicts.iter().for_each(|(u, v)| { - println!( - "Url: {:?} -> {}", - u.to_string(), - match v { - Ok(v) => v.verdict.to_string(), - Err(e) => e.to_string(), - } - ) - }); + url_verdicts.iter().for_each(|(u, v)| print_verdicts(u, v)); Ok(()) } +fn print_verdicts>(i: I, v: &VResult) { + print!("{} -> ", i.as_ref()); + match v { + Ok(v) => { + print!("{}", v.verdict); + if let Some(detection) = &v.detection { + print!(" {}", detection); + } + println!(); + } + Err(e) => { + println!("{}", e.to_string()); + } + }; +} + async fn scan_files<'a>( files: &'a [PathBuf], vaas_connection: &Connection, From 6bce0f09a7850c67c1f29b0ad2cf130ea9d65a68 Mon Sep 17 00:00:00 2001 From: Philip Stadermann Date: Mon, 24 Jun 2024 15:36:08 +0200 Subject: [PATCH 09/13] Rust example: Spelling --- rust/examples/gscan/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/examples/gscan/src/main.rs b/rust/examples/gscan/src/main.rs index 19f1e9e3..7db4b516 100644 --- a/rust/examples/gscan/src/main.rs +++ b/rust/examples/gscan/src/main.rs @@ -18,7 +18,7 @@ async fn main() -> VResult<()> { .long("files") .required_unless_present("urls") .action(ArgAction::Append) - .help("List of files to scan spearated by whitepace"), + .help("List of files to scan separated by whitepace"), ) .arg( Arg::new("urls") @@ -26,7 +26,7 @@ async fn main() -> VResult<()> { .long("urls") .action(ArgAction::Append) .required_unless_present("files") - .help("List of urls to scan spearated by whitepace"), + .help("List of urls to scan separated by whitepace"), ) .arg( Arg::new("client_id") From 0a0e3ecd1c62e3c9d547ad3794debc28e3e7b40f Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 15:59:08 +0200 Subject: [PATCH 10/13] add release --- .github/workflows/ci-rust-gscan-cli.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index 35496344..89374eca 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -44,13 +44,15 @@ jobs: EXTRA_FILES: "Readme.md" UPLOAD_MODE: none - - name: Upload artifact - uses: actions/upload-artifact@v3 + - name: release + uses: svenstaro/upload-release-action@v2 + id: attach_to_release with: - name: gscan-cli - path: | - ${{ steps.build.outputs.BUILT_ARCHIVE }} - ${{ steps.build.outputs.BUILT_CHECKSUM }} + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ steps.build.outputs.BUILT_ARCHIVE }} + asset_name: gscan + tag: ${{ github.ref }} + overwrite: true - name: Microsoft Teams Notification uses: skitionek/notify-microsoft-teams@master From 7ef0fc7be7bf03eb51e6dd1dd1e2cb0c283f6e3f Mon Sep 17 00:00:00 2001 From: Kevin Heise Date: Mon, 24 Jun 2024 16:00:20 +0200 Subject: [PATCH 11/13] add files --- .github/workflows/ci-rust-gscan-cli.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index 89374eca..ce5007d4 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -44,7 +44,12 @@ jobs: EXTRA_FILES: "Readme.md" UPLOAD_MODE: none - - name: release + - name: Github Release + uses: softprops/action-gh-release@v2 + with: + files: ${{ steps.build.outputs.BUILT_ARCHIVE }} + + - name: Attach file to release uses: svenstaro/upload-release-action@v2 id: attach_to_release with: From 11832eca4e21c84886b1d69a2b5fd3852c1f6111 Mon Sep 17 00:00:00 2001 From: Philip Stadermann Date: Mon, 26 Aug 2024 12:10:56 +0200 Subject: [PATCH 12/13] Port to vaas 6.0.0 --- rust/examples/gscan/Cargo.toml | 8 ++++---- rust/examples/gscan/src/main.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/examples/gscan/Cargo.toml b/rust/examples/gscan/Cargo.toml index 6009059c..0d5323ff 100644 --- a/rust/examples/gscan/Cargo.toml +++ b/rust/examples/gscan/Cargo.toml @@ -8,9 +8,9 @@ description = "GDATA Verdict-as-a-Service CLI Scanner" publish = false [dependencies] -vaas = { version = "5.0.0" } -tokio = { version = "1.37", features = [ "rt-multi-thread", "macros"] } -clap = { version = "4.5.4", features = ["env", "cargo"]} +vaas = { version = "6.0.0" } +tokio = { version = "1.37", features = ["rt-multi-thread", "macros"] } +clap = { version = "4.5.4", features = ["env", "cargo"] } reqwest = "0.12.4" futures = "0.3.30" -dotenv = "0.15" \ No newline at end of file +dotenv = "0.15" diff --git a/rust/examples/gscan/src/main.rs b/rust/examples/gscan/src/main.rs index 7db4b516..a2c85afc 100644 --- a/rust/examples/gscan/src/main.rs +++ b/rust/examples/gscan/src/main.rs @@ -58,8 +58,12 @@ async fn main() -> VResult<()> { .map(|f| Url::parse(f).unwrap_or_else(|_| panic!("Not a valid url: {}", f))) .collect::>(); - let client_id = matches.get_one::("client_id").unwrap(); - let client_secret = matches.get_one::("client_secret").unwrap(); + let client_id = matches + .get_one::("client_id") + .expect("--client_id or the enviroment variable CLIENT_ID must be set"); + let client_secret = matches + .get_one::("client_secret") + .expect("--client_secret or the enviroment variable CLIENT_SECRET must be set"); let authenticator = ClientCredentials::new(client_id.to_owned(), client_secret.to_owned()); let vaas_connection = Vaas::builder(authenticator).build()?.connect().await?; @@ -80,11 +84,7 @@ fn print_verdicts>(i: I, v: &VResult) { print!("{} -> ", i.as_ref()); match v { Ok(v) => { - print!("{}", v.verdict); - if let Some(detection) = &v.detection { - print!(" {}", detection); - } - println!(); + println!("{}", v.verdict); } Err(e) => { println!("{}", e.to_string()); From 5c521eb12c065a102f556931e0f2ccfc0670adfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=B6hling=2C=20Maximilian?= Date: Tue, 27 Aug 2024 10:23:06 +0200 Subject: [PATCH 13/13] Fix gscan CI release --- .github/workflows/ci-rust-gscan-cli.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-rust-gscan-cli.yaml b/.github/workflows/ci-rust-gscan-cli.yaml index ce5007d4..be410d7a 100644 --- a/.github/workflows/ci-rust-gscan-cli.yaml +++ b/.github/workflows/ci-rust-gscan-cli.yaml @@ -43,19 +43,22 @@ jobs: RUSTTARGET: x86_64-pc-windows-gnu EXTRA_FILES: "Readme.md" UPLOAD_MODE: none + ARCHIVE_NAME: "gscan.zip" - name: Github Release + if: startsWith(github.ref, 'refs/tags/gscan') uses: softprops/action-gh-release@v2 with: files: ${{ steps.build.outputs.BUILT_ARCHIVE }} - name: Attach file to release + if: startsWith(github.ref, 'refs/tags/gscan') uses: svenstaro/upload-release-action@v2 id: attach_to_release with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.build.outputs.BUILT_ARCHIVE }} - asset_name: gscan + asset_name: gscan.zip tag: ${{ github.ref }} overwrite: true