Compare commits
7 Commits
3658bdcba0
...
c11911c4a7
| Author | SHA1 | Date | |
|---|---|---|---|
| c11911c4a7 | |||
| eb5849c16d | |||
| 08a954f836 | |||
| c37e8d3fb4 | |||
| 1d6c8de71b | |||
| adbee34498 | |||
| 0f88e82e28 |
15
Akari.Prototype.Client/Akari.Prototype.Client.csproj
Normal file
15
Akari.Prototype.Client/Akari.Prototype.Client.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="0.10.3" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.3" />
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Akari.Prototype.Shared\Akari.Prototype.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
7
Akari.Prototype.Client/App.axaml
Normal file
7
Akari.Prototype.Client/App.axaml
Normal file
@@ -0,0 +1,7 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Akari.Prototype.Client.App">
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Light"/>
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
24
Akari.Prototype.Client/App.axaml.cs
Normal file
24
Akari.Prototype.Client/App.axaml.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Akari.Prototype.Client
|
||||
{
|
||||
public class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow = new MainWindow();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Akari.Prototype.Client/MainWindow.axaml
Normal file
9
Akari.Prototype.Client/MainWindow.axaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Akari.Prototype.Client.MainWindow"
|
||||
Title="Akari.Prototype.Client">
|
||||
Welcome to Avalonia!
|
||||
</Window>
|
||||
22
Akari.Prototype.Client/MainWindow.axaml.cs
Normal file
22
Akari.Prototype.Client/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Akari.Prototype.Client
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Akari.Prototype.Client/Program.cs
Normal file
22
Akari.Prototype.Client/Program.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace Akari.Prototype.Client
|
||||
{
|
||||
class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.LogToTrace();
|
||||
}
|
||||
}
|
||||
11
Akari.Prototype.Client/nuget.config
Normal file
11
Akari.Prototype.Client/nuget.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
To use the Avalonia CI feed to get unstable packages, move this file to the root of your solution.
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="AvaloniaCI" value="https://www.myget.org/F/avalonia-ci/api/v2" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -1,13 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CliFx" Version="2.0.4" />
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.34.0" />
|
||||
@@ -15,4 +11,8 @@
|
||||
<PackageReference Include="Spectre.Console" Version="0.39.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Akari.Prototype.Shared\Akari.Prototype.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Akari.Prototype.Server";
|
||||
|
||||
package greet;
|
||||
|
||||
// The greeting service definition.
|
||||
service Greeter {
|
||||
// Sends a greeting
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
// The request message containing the user's name.
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// The response message containing the greetings.
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
109
Akari.Prototype.Server/Services/AkariService.cs
Normal file
109
Akari.Prototype.Server/Services/AkariService.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using Akari.Prototype.Server.Services;
|
||||
using Akari.Prototype.Server.Utils;
|
||||
using Akari.Prototype.Shared.Protos;
|
||||
using Google.Protobuf;
|
||||
using Grpc.Core;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Akari.Prototype.Server
|
||||
{
|
||||
public class AkariService : AkariApi.AkariApiBase
|
||||
{
|
||||
private readonly ILogger<AkariService> _logger;
|
||||
private readonly IApplicationsManager _applications;
|
||||
|
||||
public AkariService(ILogger<AkariService> logger, IApplicationsManager applications)
|
||||
{
|
||||
_logger = logger;
|
||||
_applications = applications;
|
||||
}
|
||||
|
||||
public override Task<DecryptResponse> Decrypt(DecryptRequest request, ServerCallContext context)
|
||||
{
|
||||
_logger.LogDebug($"Received decrypt request: {request}");
|
||||
|
||||
if (!_applications.Contains(request.Application))
|
||||
{
|
||||
_logger.LogDebug($"Application not found: {request.Application}");
|
||||
|
||||
return Task.FromResult(new DecryptResponse()
|
||||
{
|
||||
ErrorMessage = "Application not found"
|
||||
});
|
||||
}
|
||||
|
||||
if (!_applications.VerifyToken(request.Application, request.Token))
|
||||
{
|
||||
_logger.LogDebug($"Invalid token: {request.Token}");
|
||||
|
||||
return Task.FromResult(new DecryptResponse()
|
||||
{
|
||||
ErrorMessage = "Invalid token"
|
||||
});
|
||||
}
|
||||
|
||||
if (_applications.TryRetrieveKey(request.Application, request.Token, out var key))
|
||||
{
|
||||
_logger.LogDebug($"Key retrieved, sending decrypted data...");
|
||||
|
||||
return Task.FromResult(new DecryptResponse()
|
||||
{
|
||||
Plain = ByteString.CopyFrom(Security.AesGcmDecrypt(key, request.Encrypted.ToByteArray()))
|
||||
});
|
||||
}
|
||||
|
||||
_logger.LogDebug($"No fingerprint auth found for {request.Application}");
|
||||
|
||||
return Task.FromResult(new DecryptResponse()
|
||||
{
|
||||
ErrorMessage = "No fingerprint auth found for this application"
|
||||
});
|
||||
}
|
||||
|
||||
public override Task<EncryptResponse> Encrypt(EncryptRequest request, ServerCallContext context)
|
||||
{
|
||||
_logger.LogDebug($"Received encrypt request: {request}");
|
||||
|
||||
if (!_applications.Contains(request.Application))
|
||||
{
|
||||
_logger.LogDebug($"Application not found: {request.Application}");
|
||||
|
||||
return Task.FromResult(new EncryptResponse()
|
||||
{
|
||||
ErrorMessage = "Application not found"
|
||||
});
|
||||
}
|
||||
|
||||
if (!_applications.VerifyToken(request.Application, request.Token))
|
||||
{
|
||||
_logger.LogDebug($"Invalid token: {request.Token}");
|
||||
|
||||
return Task.FromResult(new EncryptResponse()
|
||||
{
|
||||
ErrorMessage = "Wrong token"
|
||||
});
|
||||
}
|
||||
|
||||
if (_applications.TryRetrieveKey(request.Application, request.Token, out var key))
|
||||
{
|
||||
_logger.LogDebug($"Key retrieved, sending decrypted data...");
|
||||
|
||||
return Task.FromResult(new EncryptResponse()
|
||||
{
|
||||
Encrypted = ByteString.CopyFrom(Security.AesGcmEncrypt(key, request.Plain.ToByteArray()))
|
||||
});
|
||||
}
|
||||
|
||||
_logger.LogDebug($"No fingerprint auth found for {request.Application}");
|
||||
|
||||
return Task.FromResult(new EncryptResponse()
|
||||
{
|
||||
ErrorMessage = "No fingerprint auth found for this application"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ namespace Akari.Prototype.Server.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool VerifyToken(string applicationName, string applicationToken)
|
||||
public bool VerifyToken(string applicationName, string applicationToken)
|
||||
{
|
||||
if (!_applications.TryGetValue(applicationName, out var application))
|
||||
{
|
||||
@@ -194,6 +194,8 @@ namespace Akari.Prototype.Server.Services
|
||||
if (!_authManager.TryGetKey(application.Fingerprints, out var fingerprintName, out var fingerprintKey))
|
||||
{
|
||||
_logger.LogDebug($"Can't retrieve '{applicationName}' key, no fingerprint auth found");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
applicationKey = _keyManager.RetrieveKey(applicationName, fingerprintName, fingerprintKey);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using Grpc.Core;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Akari.Prototype.Server
|
||||
{
|
||||
public class GreeterService : Greeter.GreeterBase
|
||||
{
|
||||
private readonly ILogger<GreeterService> _logger;
|
||||
public GreeterService(ILogger<GreeterService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
|
||||
{
|
||||
return Task.FromResult(new HelloReply
|
||||
{
|
||||
Message = "Hello " + request.Name
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ namespace Akari.Prototype.Server.Services
|
||||
|
||||
bool AddFingerprint(string applicationName, string fingerprintName);
|
||||
|
||||
bool VerifyToken(string applicationName, string applicationToken);
|
||||
|
||||
bool TryRetrieveKey(string applicationName, string applicationToken, out AesGcm key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Akari.Prototype.Server
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapGrpcService<GreeterService>();
|
||||
endpoints.MapGrpcService<AkariService>();
|
||||
|
||||
endpoints.MapGet("/", async context =>
|
||||
{
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Akari.Prototype.Server.Utils
|
||||
|
||||
// We write everything into one big array for easier encoding
|
||||
int encryptedDataLength = 4 + nonceSize + 4 + tagSize + cipherSize;
|
||||
Span<byte> encryptedData = encryptedDataLength < 1024
|
||||
Span<byte> encryptedData = encryptedDataLength <= 1024
|
||||
? stackalloc byte[encryptedDataLength]
|
||||
: new byte[encryptedDataLength];
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Akari.Prototype.Server.Utils
|
||||
var cipherBytes = encryptedData.Slice(4 + nonceSize + 4 + tagSize, cipherSize);
|
||||
|
||||
// Decrypt
|
||||
Span<byte> plainBytes = cipherSize < 1024
|
||||
Span<byte> plainBytes = cipherSize <= 1024
|
||||
? stackalloc byte[cipherSize]
|
||||
: new byte[cipherSize];
|
||||
|
||||
|
||||
24
Akari.Prototype.Shared/Akari.Prototype.Shared.csproj
Normal file
24
Akari.Prototype.Shared/Akari.Prototype.Shared.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.17.2" />
|
||||
<PackageReference Include="Grpc.Core.Api" Version="2.38.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.38.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Protos\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="**/*.proto" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
37
Akari.Prototype.Shared/Protos/akari.proto
Normal file
37
Akari.Prototype.Shared/Protos/akari.proto
Normal file
@@ -0,0 +1,37 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Akari.Prototype.Shared.Protos";
|
||||
|
||||
package akari;
|
||||
|
||||
service AkariApi {
|
||||
rpc Encrypt (EncryptRequest) returns (EncryptResponse);
|
||||
|
||||
rpc Decrypt (DecryptRequest) returns (DecryptResponse);
|
||||
}
|
||||
|
||||
message EncryptRequest {
|
||||
string application = 1;
|
||||
string token = 2;
|
||||
bytes plain = 3;
|
||||
}
|
||||
|
||||
message EncryptResponse {
|
||||
oneof response {
|
||||
string error_message = 1;
|
||||
bytes encrypted = 2;
|
||||
}
|
||||
}
|
||||
|
||||
message DecryptRequest {
|
||||
string application = 1;
|
||||
string token = 2;
|
||||
bytes encrypted = 3;
|
||||
}
|
||||
|
||||
message DecryptResponse {
|
||||
oneof response {
|
||||
string error_message = 1;
|
||||
bytes plain = 2;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31321.278
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akari.Prototype.Server", "Akari.Prototype.Server\Akari.Prototype.Server.csproj", "{AFF5FC9F-41B5-4B05-953E-02DBC28833CD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akari.Prototype.Server", "Akari.Prototype.Server\Akari.Prototype.Server.csproj", "{AFF5FC9F-41B5-4B05-953E-02DBC28833CD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akari.Prototype.Client", "Akari.Prototype.Client\Akari.Prototype.Client.csproj", "{3CEA1E09-B799-42B5-A258-A5E549FEC0ED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akari.Prototype.Shared", "Akari.Prototype.Shared\Akari.Prototype.Shared.csproj", "{F0555B06-E172-490C-BF5D-AFA8D837358B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,6 +19,14 @@ Global
|
||||
{AFF5FC9F-41B5-4B05-953E-02DBC28833CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AFF5FC9F-41B5-4B05-953E-02DBC28833CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AFF5FC9F-41B5-4B05-953E-02DBC28833CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3CEA1E09-B799-42B5-A258-A5E549FEC0ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3CEA1E09-B799-42B5-A258-A5E549FEC0ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3CEA1E09-B799-42B5-A258-A5E549FEC0ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3CEA1E09-B799-42B5-A258-A5E549FEC0ED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F0555B06-E172-490C-BF5D-AFA8D837358B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F0555B06-E172-490C-BF5D-AFA8D837358B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F0555B06-E172-490C-BF5D-AFA8D837358B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F0555B06-E172-490C-BF5D-AFA8D837358B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user