Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cpp/various-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanCoding committed Oct 22, 2024
2 parents 6f5ccf1 + 31fd122 commit 42480fc
Show file tree
Hide file tree
Showing 46 changed files with 2,926 additions and 1,092 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/ci-php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- phpdev-*
paths:
- "php/**"
- ".github/workflows/ci-php.yaml"
Expand Down Expand Up @@ -129,8 +130,14 @@ jobs:
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/php}" >> $GITHUB_ENV
echo $RELEASE_VERSION
- name: extract version
if: startsWith(github.ref, 'refs/heads/phpdev-')
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/phpdev-}" >> $GITHUB_ENV
echo $RELEASE_VERSION
- name: checkout
if: startsWith(github.ref, 'refs/tags/php')
if: startsWith(github.ref, 'refs/tags/php') || startsWith(github.ref, 'refs/heads/phpdev-')
uses: actions/checkout@v4

- name: publish on site repo
Expand All @@ -151,8 +158,25 @@ jobs:
git remote add origin https://ata-no-one:[email protected]/GDATASoftwareAG/vaas-php
git push origin main --tags --force
- name: publish on site repo
if: startsWith(github.ref, 'refs/heads/phpdev-')
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
working-directory: php/src/vaas
run: |
git config --global user.email "[email protected]"
git config --global user.name "Version Bot"
sed -i "s/\"version\": \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\": \"$RELEASE_VERSION\"/g" ./composer.json
cp ../../../Readme.md .
git init
git add .
git commit -m"publish php $RELEASE_VERSION"
git branch -M $RELEASE_VERSION
git remote add origin https://ata-no-one:[email protected]/GDATASoftwareAG/vaas-php
git push origin $RELEASE_VERSION --force
- name: sync packagist
if: startsWith(github.ref, 'refs/tags/php')
if: startsWith(github.ref, 'refs/tags/php') || startsWith(github.ref, 'refs/heads/phpdev-')
env:
PACKAGIST_API_TOKEN: ${{ secrets.PACKAGIST_API_TOKEN }}
run: curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=gdatacyberdefense&apiToken=$PACKAGIST_API_TOKEN" -d'{"repository":{"url":"https://packagist.org/packages/gdata/vaas"}}'
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ _trial_temp*/
ruby/.idea
ruby/Gemfile.lock
ruby/test/test.txt
ruby/**/*.gem

*.env*

.env*
59 changes: 45 additions & 14 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,58 @@ We provide SDKs for various programming languages to make it easy for you to int
|.NET|[.NET SDK](./dotnet/)|[Examples](./dotnet/examples)||[nuget.org](https://www.nuget.org/packages/GDataCyberDefense.Vaas)|
|Ruby|[Ruby SDK](./ruby/)|[Examples](./ruby/examples)|[Reamde](https://github.com/GDATASoftwareAG/vaas/blob/main/ruby/README.md)|[rubygems](https://rubygems.org/gems/vaas)|
|Go|[Go SDK](./golang/vaas/)|[Examples](./golang/examples)|[Readme](https://github.com/GDATASoftwareAG/vaas/blob/main/golang/vaas/README.md)|[Github](https://github.com/GDATASoftwareAG/vaas/tree/main/golang/vaas)|
|C++|[C++ SDK](./cpp/)||[Readme](https://github.com/GDATASoftwareAG/vaas/blob/main/cpp/README.md)|[Github](https://github.com/GDATASoftwareAG/vaas/tree/main/cpp)|

The following table shows the functionality supported by each SDK:

|Functionality|Rust|Java|PHP|TypeScript|.NET|Python|Ruby|Golang
|---|---|---|---|---|---|---|---|---|
|Check SHA256|✅|✅|✅|✅|✅|✅|✅|✅|
|Check SHA256 list|✅|✅|❌|✅|✅|❌|❌|✅|
|Check URL|✅|✅|✅|✅|✅|✅|✅|✅|
|Check file|✅|✅|✅|✅|✅|✅|✅|✅|
|Check file list|✅|✅|❌|✅|✅|❌|❌|✅|
|Custom Guids for tracability on user side|❌|❌|✅|❌|❌|✅|❌|❌|
|Functionality|Rust|Java|PHP|TypeScript|.NET|Python|Ruby|Golang|C++|
|---|---|---|---|---|---|---|---|---|---|
|Check SHA256|✅|✅|✅|✅|✅|✅|✅|✅|✅|
|Check SHA256 list|✅|✅|❌|✅|✅|❌|❌|✅|❌|
|Check URL|✅|✅|✅|✅|✅|✅|✅|✅|❌|
|Check file|✅|✅|✅|✅|✅|✅|✅|✅|✅|
|Check file list|✅|✅|❌|✅|✅|❌|❌|✅|❌|
|Custom Guids for tracability on user side|❌|❌|✅|❌|❌|✅|❌|❌|❌|


## Integration Ideas for Malware Detection trough VaaS
You can use VaaS to create various applications that scan for malicious content with a few lines of code. Here are some examples:

Create a command line scanner to find malware: [Example](rust/examples/gscan)
<img src="assets/gscan.gif" alt="GScan command line malware scanner" style="width:100%">
- [WordPress Plugin](https://wordpress.org/plugins/gdata-antivirus/) to scan for malware in uploaded files
- [Nextcloud App](https://apps.nextcloud.com/apps/gdatavaas) to scan files in your Nextcloud instance

Create a KDE Dolphin plugin to scan for malicious content: [Example](rust/examples/kde_dolphin)
<img src="assets/dolphin_plugin.gif" alt="KDE Dolphin malware scanner plugin" style="width:100%">
## Build & Test

The easiest way to build and test the SDKs is with the [Nix Package Manager](https://nixos.org/download/#download-nix) and the provided [Just](https://github.com/casey/just) file. Nix will take care of all dependencies and Just provides a simple interface to run the most common tasks.

To build and test the SDKs, run the following command:

```bash
# switch into a development shell with all dependencies installed.
# This will not alter your system, but provide a shell with all necessary tools.
nix develop

# Now use the Just tool to run the most common tasks
just -l # list all available tasks

# Just Examples
# Run the tests for the Rust SDK
just test-rust
```

There are `test-*`, `build-*`, `clean-*` and `release-*` tasks for each SDK, with the exception of Python and PHP, where no build task is available. You can also run the tests for all SDKs with `just test-all`. A `build-all` and `clean-all` task is available as well.

The `release-*` task triggers a Github Action to build and release a new version of the specified SDK. It needs a version number as an argument, which is used to tag the release. The version number should follow the [Semantic Versioning](https://semver.org/) scheme.

```bash
# Example: Release the Rust SDK with version 0.1.0
just release-rust 0.1.0
```

As the SDKs need credentials to authenticate to the VaaS API. You need to provide them in a `.env` file. Copy your `.env` file into the root directory of the project. The C++ SDK needs special credentials, which you can provide in a `.cpp.env` file.

```bash
# Copy the .env and .cpp.env file to all SDK folders
# to be able to run the integration tests
just populate-env

Create a WordPress plugin that scans all file uploads for malware: [Example](php/examples/wordpress)
<img src="assets/wordpress.gif" alt="Wordpress plugin malware scanner" style="width:100%">
Binary file removed assets/discord_bot.gif
Binary file not shown.
Binary file removed assets/dolphin_plugin.gif
Binary file not shown.
Binary file removed assets/gscan.gif
Binary file not shown.
Binary file removed assets/wordpress.gif
Binary file not shown.
5 changes: 3 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ set(CMAKE_CXX_STANDARD 17)
find_package(CURL REQUIRED)
find_package(jsoncpp CONFIG REQUIRED)
find_package(doctest CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)

# vaas_example
add_executable(vaas_example main.cpp)

target_link_libraries(vaas_example PRIVATE CURL::libcurl JsonCpp::JsonCpp)
target_link_libraries(vaas_example PRIVATE CURL::libcurl JsonCpp::JsonCpp OpenSSL::SSL OpenSSL::Crypto)

# test
add_executable(vaas_test vaas_test.cpp)

target_link_libraries(vaas_test PRIVATE CURL::libcurl JsonCpp::JsonCpp)
target_link_libraries(vaas_test PRIVATE CURL::libcurl JsonCpp::JsonCpp OpenSSL::SSL OpenSSL::Crypto)
82 changes: 82 additions & 0 deletions cpp/dotenv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Very simple dotenv implementation in C++,
* specifically for the use case of running tests in this repository.
*
* It tries to read `.env` file in the current directory or a custom file.
* If no file is found, no error is thrown, instead the environment variable
* is expected to be set in the environment.
*
* If both the file and the environment variable are set, the environment variable
* takes precedence.
*/

#ifndef DOTENV_H
#define DOTENV_H

#include <algorithm>
#include <exception>
#include <filesystem>
#include <fstream>
#include <map>
#include <stdexcept>
#include <string>

namespace dotenv {

class Dotenv {
private:
std::string envFile;
std::map<std::string, std::string> envFromFile;

std::map<std::string, std::string> readEnvFromFile() {
std::map<std::string, std::string> env;
std::ifstream file(envFile);
char charsToRemove[] = {'"', '\''};

if (!file) {
return env;
}

for (std::string line; std::getline(file, line);) {
const auto pos = line.find('=');
if (pos != std::string::npos) {
const auto key = line.substr(0, pos);
auto value = line.substr(pos + 1);

removeCharsFromString(value, charsToRemove);

env[key] = value;
}
}

return env;
}

static void removeCharsFromString(std::string& str, char* charsToRemove) {
for (unsigned int i = 0; i < sizeof(charsToRemove); ++i) {
str.erase(remove(str.begin(), str.end(), charsToRemove[i]), str.end());
}
}

public:
Dotenv() : Dotenv(".env") {}

Dotenv(const std::string& envFile) : envFile(envFile) {
this->envFromFile = readEnvFromFile();
}

std::string get(const std::string& key) {
if (std::getenv(key.c_str())) {
return std::string(std::getenv(key.c_str()));
}

if (envFromFile.find(key) != envFromFile.end()) {
return envFromFile[key];
}

throw std::runtime_error(key + " must be set");
}
};

} // namespace dotenv
#endif // !DOTENV_H
20 changes: 8 additions & 12 deletions cpp/vaas_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include "vaas.h"
#include "dotenv.h"
#include <doctest/doctest.h>

static char* program;
Expand All @@ -21,22 +22,17 @@ int main(int argc, char** argv) {
}

vaas::OIDCClient initAuthenticator() {
const auto tokenUrl = std::getenv("TOKEN_URL")
? std::getenv("TOKEN_URL")
: "https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token";
const auto clientId = std::getenv("CLIENT_ID")
? std::getenv("CLIENT_ID")
: throw std::runtime_error("CLIENT_ID must be set");
const auto clientSecret = std::getenv("CLIENT_SECRET")
? std::getenv("CLIENT_SECRET")
: throw std::runtime_error("CLIENT_SECRET must be set");
auto dotenv = dotenv::Dotenv();
const auto tokenUrl = dotenv.get("TOKEN_URL");
const auto clientId = dotenv.get("CLIENT_ID");
const auto clientSecret = dotenv.get("CLIENT_SECRET");
return vaas::OIDCClient(tokenUrl, clientId, clientSecret);
}

vaas::Vaas initVaas() {
const auto vaasUrl = std::getenv("VAAS_URL")
? std::getenv("VAAS_URL")
: "https://gateway.staging.vaas.gdatasecurity.de";
auto dotenv = dotenv::Dotenv();
auto vaasUrl = dotenv.get("VAAS_URL");

auto authenticator = initAuthenticator();
return vaas::Vaas(vaasUrl, std::move(authenticator));
}
Expand Down
8 changes: 4 additions & 4 deletions dotnet/Vaas/src/Vaas/Vaas.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.0.9</Version>
<Version>0.0.10</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
Expand All @@ -24,11 +24,11 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.3.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
<PackageReference Include="Websocket.Client" Version="5.1.2" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion dotnet/examples/VaasExample/VaasExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GDataCyberDefense.Vaas" Version="7.5.5" />
<PackageReference Include="GDataCyberDefense.Vaas" Version="7.5.7" />
</ItemGroup>

</Project>
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 42480fc

Please sign in to comment.