Skip to content

Commit

Permalink
💾 Feat(Dashboard): Accept remote KWC invoking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynesshely committed Mar 14, 2024
1 parent c7f2835 commit 4608129
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
12 changes: 12 additions & 0 deletions KitX Shared/KitX.Shared.CSharp/Security/EncryptedContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using KitX.Shared.CSharp.Device;

namespace KitX.Shared.CSharp.Security;

public class EncryptedContent
{
public DeviceLocator? Device { get; set; }

public string? RsaEncryptedAesKeyBase64 { get; set; }

public string? AesEncryptedContentBase64 { get; set; }
}
2 changes: 2 additions & 0 deletions KitX Shared/KitX.Shared.CSharp/WebCommand/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct Command

public int BodyLength { get; set; }

public string PluginConnectionId { get; set; }

public string FunctionName { get; set; }

public List<Parameter> FunctionArgs { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace KitX.Shared.CSharp.WebCommand.Infos;

public struct CompressionInfo
public class CompressionInfo
{

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
namespace KitX.Shared.CSharp.WebCommand.Infos;

public struct EncryptionInfo
public class EncryptionInfo
{
public bool IsEncrypted { get; set; }
public bool IsEncrypted { get; set; } = false;

public string EncryptionMethod { get; set; }
public EncryptionMethods EncryptionMethod { get; set; } = EncryptionMethods.RSA;
}

public string EncryptionKeyId { get; set; }
public enum EncryptionMethods
{
Custom = 0,
RSA = 1,
AES = 2,
}
50 changes: 41 additions & 9 deletions KitX Shared/KitX.Shared.CSharp/WebCommand/Request.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
using KitX.Shared.CSharp.Device;
using System;
using KitX.Shared.CSharp.Device;
using KitX.Shared.CSharp.WebCommand.Infos;

namespace KitX.Shared.CSharp.WebCommand;

public struct Request
public class Request
{
public string Type { get; set; }
public RequestTypes Type { get; set; } = RequestTypes.Command;

public string Version { get; set; }
public RequestVersions Version { get; set; } = RequestVersions.V1;

public DeviceLocator Sender { get; set; }
public DeviceLocator? Sender { get; set; }

public DeviceLocator Target { get; set; }
public DeviceLocator? Target { get; set; }

public EncryptionInfo EncryptionInfo { get; set; }
public EncryptionInfo EncryptionInfo { get; set; } = new();

public CompressionInfo CompressionInfo { get; set; }
public CompressionInfo CompressionInfo { get; set; } = new();

public string Content { get; set; }
public string Content { get; set; } = string.Empty;
}

public enum RequestTypes
{
Unknown = 0,
Command = 1,
}

public enum RequestVersions
{
Unknown = 0,
V1 = 1,
}

public static class RequestExtensions
{
public static string GetContent(this Request request, Func<string, string> decryptFunc) => decryptFunc.Invoke(request.Content);

public static void Match(this Request request, string decryptedContent, Action<string>? matchCommand = null)
{
switch (request.Type)
{
case RequestTypes.Unknown:
break;
case RequestTypes.Command:
matchCommand?.Invoke(decryptedContent);
break;
}
}

public static Request Rebuild(this Request request, Func<Request, Request> rebuilder) => rebuilder(request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public RequestBuilder UpdateCommand(Func<Command, Command> updater)
return this;
}

private Request Build()
public Request Build()
{
_request.Content = _serializer?.Invoke(_command) ?? throw new ArgumentNullException(nameof(Serializer));

Expand Down

0 comments on commit 4608129

Please sign in to comment.