refactor: AsymmetricPublicKey durch ClientPublicKey ersetzt und RSA-Schlüsselverwaltung verbessert
- `AsymmetricPublicKey` in `ClientPublicKey` umbenannt - `ClientPublicKey` von `RSAKeyBase` abgeleitet für RSA-Funktionalität - Dynamischen PEM-Import in `UpdateContent` hinzugefügt
This commit is contained in:
parent
106d31b068
commit
85a047467e
@ -1,14 +0,0 @@
|
|||||||
using DigitalData.Core.Abstractions.Security;
|
|
||||||
|
|
||||||
namespace DigitalData.Auth.Client;
|
|
||||||
|
|
||||||
public class AsymmetricPublicKey : IUniqueSecurityContext, IAsymmetricPublicKey
|
|
||||||
{
|
|
||||||
public required string Issuer { get; init; }
|
|
||||||
|
|
||||||
public required string Audience { get; init; }
|
|
||||||
|
|
||||||
public string? Id { get; init; }
|
|
||||||
|
|
||||||
public string Content { get; internal set; } = string.Empty;
|
|
||||||
}
|
|
||||||
@ -34,7 +34,7 @@ public class AuthClient : IAuthClient, IAsyncDisposable
|
|||||||
|
|
||||||
public bool IsConnected { get; private set; } = false;
|
public bool IsConnected { get; private set; } = false;
|
||||||
|
|
||||||
public IEnumerable<AsymmetricPublicKey> PublicKeys => _params.PublicKeys;
|
public IEnumerable<ClientPublicKey> PublicKeys => _params.PublicKeys;
|
||||||
|
|
||||||
public async Task StartAsync()
|
public async Task StartAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,7 +10,7 @@ public static class ClientEvents
|
|||||||
public static readonly ClientEvent UpdatePublicKeys = (client, issuer, audience, content, logger) =>
|
public static readonly ClientEvent UpdatePublicKeys = (client, issuer, audience, content, logger) =>
|
||||||
{
|
{
|
||||||
if(client.PublicKeys.TryGet(issuer, audience, out var publicKey))
|
if(client.PublicKeys.TryGet(issuer, audience, out var publicKey))
|
||||||
publicKey.Content = content;
|
publicKey.UpdateContent(content);
|
||||||
else
|
else
|
||||||
logger?.LogWarning(
|
logger?.LogWarning(
|
||||||
"Failed to update public key: No matching key found. Issuer: {Issuer}, Audience: {Audience}. Ensure the key exists before attempting an update.", issuer, audience);
|
"Failed to update public key: No matching key found. Issuer: {Issuer}, Audience: {Audience}. Ensure the key exists before attempting an update.", issuer, audience);
|
||||||
|
|||||||
@ -41,5 +41,5 @@ public class ClientParams
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AsymmetricPublicKey> PublicKeys { get; set; } = new();
|
public List<ClientPublicKey> PublicKeys { get; set; } = new();
|
||||||
}
|
}
|
||||||
34
DigitalData.Auth.Client/ClientPublicKey.cs
Normal file
34
DigitalData.Auth.Client/ClientPublicKey.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using DigitalData.Core.Abstractions.Security;
|
||||||
|
using DigitalData.Core.Security.RSAKey;
|
||||||
|
|
||||||
|
namespace DigitalData.Auth.Client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a public RSA key, allowing dynamic updates and PEM import functionality.
|
||||||
|
/// </summary>
|
||||||
|
public class ClientPublicKey : RSAKeyBase, IAsymmetricPublicKey, IAsymmetricKey, IUniqueSecurityContext
|
||||||
|
{
|
||||||
|
public required string Issuer { get; init; }
|
||||||
|
|
||||||
|
public required string Audience { get; init; }
|
||||||
|
|
||||||
|
private string _content = string.Empty;
|
||||||
|
|
||||||
|
public override string Content
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _content;
|
||||||
|
}
|
||||||
|
init
|
||||||
|
{
|
||||||
|
UpdateContent(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateContent(string content)
|
||||||
|
{
|
||||||
|
_content = content;
|
||||||
|
RSA.ImportFromPem(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.3.0" />
|
<PackageReference Include="DigitalData.Core.Abstractions" Version="3.3.0" />
|
||||||
|
<PackageReference Include="DigitalData.Core.Security" Version="1.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -206,7 +206,7 @@ public class AuthClientTests
|
|||||||
public async Task StartAsync_ShouldUpdateAllPublicKey()
|
public async Task StartAsync_ShouldUpdateAllPublicKey()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var publicKey = new AsymmetricPublicKey() { Issuer = "Foo", Audience = "Bar" };
|
var publicKey = new ClientPublicKey() { Issuer = "Foo", Audience = "Bar" };
|
||||||
var provider = Build(opt =>
|
var provider = Build(opt =>
|
||||||
{
|
{
|
||||||
opt.Url = _hubUrl;
|
opt.Url = _hubUrl;
|
||||||
@ -229,7 +229,7 @@ public class AuthClientTests
|
|||||||
public async Task Reconnected_ShouldUpdateAllPublicKey()
|
public async Task Reconnected_ShouldUpdateAllPublicKey()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var publicKey = new AsymmetricPublicKey() { Issuer = "Foo", Audience = "Bar" };
|
var publicKey = new ClientPublicKey() { Issuer = "Foo", Audience = "Bar" };
|
||||||
var provider = Build(opt =>
|
var provider = Build(opt =>
|
||||||
{
|
{
|
||||||
opt.Url = _hubUrl;
|
opt.Url = _hubUrl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user