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

Cs/http api #671

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3e64fa0
WIP: Improve authenticator
GermanCoding Nov 26, 2024
80a5196
check expiration in seconds
doxthree Nov 26, 2024
9219d1e
1 test
Nov 26, 2024
abc2a7c
Parse IDP error messages, add test
GermanCoding Nov 26, 2024
078a836
El testo
Nov 26, 2024
c8a870b
Add authenticator throttling; Add even more tests
GermanCoding Nov 26, 2024
e9a29c5
New api
Nov 26, 2024
c0668bf
WIP: ForSha256
GermanCoding Nov 26, 2024
b988631
Remove websocket
Nov 27, 2024
909c804
Option defaults
Nov 27, 2024
f74169f
Reorder methods like interface
Nov 27, 2024
721266b
WIP
Nov 28, 2024
34cd535
Remaining tests for For*
Nov 28, 2024
8c2167d
add forurl method
doxthree Nov 28, 2024
93ad48a
add mssing urlreport
doxthree Nov 28, 2024
f0144b6
ForStream
Nov 28, 2024
8b7ac91
add forfile test
doxthree Nov 28, 2024
10a9a27
check options
doxthree Nov 28, 2024
686355d
ForFile: Check if ForSha256 returns Detection, FileType, MimeType
Nov 28, 2024
9d0e666
add options in url
doxthree Nov 28, 2024
10cd163
CSharpier this!
Nov 28, 2024
ba3c2c3
Rider CSharpier
Nov 28, 2024
c9d4aa9
ForSha256Async_SendsOptions
Nov 29, 2024
fb49257
fun with mocked httpclient
doxthree Dec 2, 2024
b140bdc
http mocking
ata-no-one Dec 2, 2024
eb13c54
WIP add more tests and error parsing for non success status codes
lennartdohmann Dec 2, 2024
724ffaa
Fix parsing of Vaas errors with problem details
lennartdohmann Dec 2, 2024
de3cd4b
some broken test
ata-no-one Dec 3, 2024
fcd7ab0
WIP tests
lennartdohmann Dec 3, 2024
d22ffbc
add new test cases for user agent and request id
doxthree Dec 3, 2024
525caca
fix client exception test
ata-no-one Dec 3, 2024
c6b1c38
Completed forfile tests
doxthree Dec 3, 2024
8c2c44b
Finished test for forstream & forurl + bugfixes
doxthree Dec 4, 2024
34bc4ca
exclude dotnet dirs
doxthree Dec 4, 2024
c8b75d1
fix test error
ata-no-one Dec 5, 2024
1157d0e
remove handler mock
ata-no-one Dec 5, 2024
7207fac
cleanup and remove unsused websocket stuff
doxthree Dec 13, 2024
014267c
use https aas vaas endpoint
doxthree Dec 13, 2024
1a3e1e3
Refactor:
lennartdohmann Dec 25, 2024
d81712d
diable examples because it expects the websocket uri
doxthree Jan 7, 2025
d09ff6f
dotnet: Update all non-major dependencies
Jan 12, 2025
2bcdefc
Making TokenReceiver.cs class abstract, and just implement TokenReque…
lennartdohmann Jan 14, 2025
8b44766
Merge pull request #684 from GDATASoftwareAG/cs/http_api_refactor
lennartdohmann Jan 14, 2025
0a2b555
Merge branch 'main' into cs/http_api
doxthree Jan 14, 2025
d8da010
Merge pull request #689 from GDATASoftwareAG/renovate/dotnet/all-non-…
doxthree Jan 14, 2025
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
28 changes: 14 additions & 14 deletions .github/workflows/ci-dotnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{secrets.CLIENT_SECRET}}
VAAS_URL: "wss://gateway.production.vaas.gdatasecurity.de"
VAAS_URL: "https://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 }}
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
run: |
echo "CLIENT_ID=${{ secrets.STAGING_CLIENT_ID }}" >> $GITHUB_ENV
echo "CLIENT_SECRET=${{ secrets.STAGING_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "VAAS_URL=wss://gateway.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV
echo "VAAS_URL=https://gateway.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token" >> $GITHUB_ENV
echo "VAAS_CLIENT_ID=${{ secrets.STAGING_VAAS_CLIENT_ID }}" >> $GITHUB_ENV
echo "VAAS_USER_NAME=${{ secrets.STAGING_VAAS_USER_NAME }}" >> $GITHUB_ENV
Expand All @@ -67,7 +67,7 @@ jobs:
run: |
echo "CLIENT_ID=${{ secrets.DEVELOP_CLIENT_ID }}" >> $GITHUB_ENV
echo "CLIENT_SECRET=${{ secrets.DEVELOP_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "VAAS_URL=wss://gateway.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV
echo "VAAS_URL=https://gateway.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-develop/protocol/openid-connect/token" >> $GITHUB_ENV
echo "VAAS_CLIENT_ID=${{ secrets.DEVELOP_VAAS_CLIENT_ID }}" >> $GITHUB_ENV
echo "VAAS_USER_NAME=${{ secrets.DEVELOP_VAAS_USER_NAME }}" >> $GITHUB_ENV
Expand Down Expand Up @@ -101,19 +101,19 @@ jobs:
run: dotnet test --no-restore --verbosity normal
working-directory: dotnet/Vaas

- name: Run example FileScan
env:
SCAN_PATH: "Program.cs"
run: dotnet run FileScan
working-directory: dotnet/examples/VaasExample
# - name: Run example FileScan
# env:
# SCAN_PATH: "Program.cs"
# run: dotnet run FileScan
# working-directory: dotnet/examples/VaasExample

- name: Run example UrlScan
run: dotnet run UrlScan
working-directory: dotnet/examples/VaasExample
# - name: Run example UrlScan
# run: dotnet run UrlScan
# working-directory: dotnet/examples/VaasExample

- name: Run example HashsumScan
run: dotnet run HashsumScan
working-directory: dotnet/examples/VaasExample
# - name: Run example HashsumScan
# run: dotnet run HashsumScan
# working-directory: dotnet/examples/VaasExample

- name: Pack
if: startsWith(github.ref, 'refs/tags/cs')
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ lib/

bin/
obj/
.idea/
.mono/

# Python
__pycache__/
Expand Down
5 changes: 3 additions & 2 deletions dotnet/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
{
"name": "C# (.NET)",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/dotnet:1-6.0-bullseye",
"image": "mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm",
"customizations": {
"vscode": {
"extensions": [
"jcamp.dotnet-test-provider-explorer"
"jcamp.dotnet-test-provider-explorer",
"ms-dotnettools.csdevkit"
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions dotnet/Vaas/.idea/.idea.Vaas/.idea/CSharpierPlugin.xml

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

6 changes: 6 additions & 0 deletions dotnet/Vaas/.idea/.idea.Vaas/.idea/externalDependencies.xml

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

3 changes: 3 additions & 0 deletions dotnet/Vaas/Vaas.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vaas", "src\Vaas\Vaas.csproj", "{F83EA992-9DB1-43FF-89F2-836F4B325345}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{59EEE214-8910-4FBC-AA18-F7070B700D49}"
ProjectSection(SolutionItems) = preProject
test\.env = test\.env
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vaas.Test", "test\Vaas.Test\Vaas.Test.csproj", "{5C11F0F4-1483-4850-BB24-4A04E7EED14A}"
EndProject
Expand Down
93 changes: 0 additions & 93 deletions dotnet/Vaas/src/Vaas/Authentication/Authenticator.cs

This file was deleted.

21 changes: 0 additions & 21 deletions dotnet/Vaas/src/Vaas/Authentication/BearerTokenHandler.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Vaas.Authentication;

public class ClientCredentialsGrantAuthenticator : IAuthenticator
{
private readonly TokenReceiver _tokenReceiver;

private string ClientId { get; }
private string ClientSecret { get; }

public ClientCredentialsGrantAuthenticator(
string clientId,
string clientSecret,
Uri? tokenUrl = null,
HttpClient? httpClient = null,
ISystemClock? systemClock = null
)
{
_tokenReceiver = new ClientCredentialsTokenReceiver(
this,
tokenUrl,
httpClient,
systemClock
);
ClientId = clientId;
ClientSecret = clientSecret;
}

public async Task<string> GetTokenAsync(CancellationToken cancellationToken)
{
return await _tokenReceiver.GetTokenAsync(cancellationToken);
}

private class ClientCredentialsTokenReceiver(
IAuthenticator authenticator,
Uri? tokenUrl = null,
HttpClient? httpClient = null,
ISystemClock? systemClock = null
) : TokenReceiver(authenticator, tokenUrl, httpClient, systemClock)
{
protected override FormUrlEncodedContent TokenRequestToForm()
{
var authenticator = (ClientCredentialsGrantAuthenticator)Authenticator;
return new FormUrlEncodedContent(
new List<KeyValuePair<string, string>>
{
new("client_id", authenticator.ClientId),
new(
"client_secret",
authenticator.ClientSecret ?? throw new InvalidOperationException()
),
new("grant_type", "client_credentials"),
}
);
}
}
}
12 changes: 12 additions & 0 deletions dotnet/Vaas/src/Vaas/Authentication/ErrorResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Vaas.Authentication;

public class ErrorResponse
{
[JsonPropertyName("error")]
public required string Error { get; init; }

[JsonPropertyName("error_description")]
public string? ErrorDescription { get; init; }
}
7 changes: 7 additions & 0 deletions dotnet/Vaas/src/Vaas/Authentication/GrantType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Vaas.Authentication;

public enum GrantType
{
ClientCredentials,
Password,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Vaas.Authentication;

public class ResourceOwnerPasswordGrantAuthenticator : IAuthenticator
{
private readonly TokenReceiver _tokenReceiver;

private string ClientId { get; }
private string UserName { get; }
private string Password { get; }

public ResourceOwnerPasswordGrantAuthenticator(
string clientId,
string userName,
string password,
Uri? tokenUrl = null,
HttpClient? httpClient = null,
ISystemClock? systemClock = null
)
{
_tokenReceiver = new ResourceOwnerPasswordTokenReceiver(
this,
tokenUrl,
httpClient,
systemClock
);
ClientId = clientId;
UserName = userName;
Password = password;
}

public async Task<string> GetTokenAsync(CancellationToken cancellationToken)
{
return await _tokenReceiver.GetTokenAsync(cancellationToken);
}

private class ResourceOwnerPasswordTokenReceiver(
IAuthenticator authenticator,
Uri? tokenUrl = null,
HttpClient? httpClient = null,
ISystemClock? systemClock = null
) : TokenReceiver(authenticator, tokenUrl, httpClient, systemClock)
{
protected override FormUrlEncodedContent TokenRequestToForm()
{
var authenticator = (ResourceOwnerPasswordGrantAuthenticator)Authenticator;
return new FormUrlEncodedContent(
new List<KeyValuePair<string, string>>
{
new("client_id", authenticator.ClientId),
new(
"username",
authenticator.UserName ?? throw new InvalidOperationException()
),
new(
"password",
authenticator.Password ?? throw new InvalidOperationException()
),
new("grant_type", "password"),
}
);
}
}
}
2 changes: 1 addition & 1 deletion dotnet/Vaas/src/Vaas/Authentication/SystemClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public interface ISystemClock
public class SystemClock : ISystemClock
{
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
}
}
Loading