refactor(IAsymmetricKey): Die Implementierung von IUniqueSecurityContext wurde entfernt und stattdessen die Eigenschaft Id hinzugefügt.
- Aktualisierte verwandte Implementierungen.
This commit is contained in:
parent
97c4f7bf8f
commit
66e3c771dd
@ -1,10 +1,9 @@
|
|||||||
using Microsoft.IdentityModel.Tokens;
|
namespace DigitalData.Core.Abstractions.Security
|
||||||
using System.Security.Cryptography;
|
{
|
||||||
|
public interface IAsymmetricKey
|
||||||
|
{
|
||||||
|
string Id { get; }
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstractions.Security
|
|
||||||
{
|
|
||||||
public interface IAsymmetricKey : IUniqueSecurityContext
|
|
||||||
{
|
|
||||||
string Content { get; }
|
string Content { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,6 +1,4 @@
|
|||||||
using Microsoft.IdentityModel.Tokens;
|
namespace DigitalData.Core.Abstractions.Security
|
||||||
|
|
||||||
namespace DigitalData.Core.Abstractions.Security
|
|
||||||
{
|
{
|
||||||
public interface IAsymmetricPrivateKey : IAsymmetricKey
|
public interface IAsymmetricPrivateKey : IAsymmetricKey
|
||||||
{
|
{
|
||||||
|
|||||||
@ -65,7 +65,7 @@ namespace DigitalData.Core.Security.Config
|
|||||||
// set default path
|
// set default path
|
||||||
if (privateKey.IsPemNull)
|
if (privateKey.IsPemNull)
|
||||||
{
|
{
|
||||||
var file_name_params = new List<object> { privateKey.Issuer, privateKey.Audience, KeySizeInBits, DateTime.Now.ToTag(DateTagFormat) };
|
var file_name_params = new List<object> { privateKey.Id, KeySizeInBits, DateTime.Now.ToTag(DateTagFormat) };
|
||||||
if (privateKey.IsEncrypted)
|
if (privateKey.IsEncrypted)
|
||||||
file_name_params.Add(Secrets.Version);
|
file_name_params.Add(Secrets.Version);
|
||||||
|
|
||||||
|
|||||||
@ -59,8 +59,6 @@ namespace DigitalData.Core.Security.RSAKey
|
|||||||
public IAsymmetricDecryptor CreateDecryptor(string pem, string? issuer = null, string? audience = null, bool encrypt = false, RSAEncryptionPadding? padding = null) => new RSADecryptor()
|
public IAsymmetricDecryptor CreateDecryptor(string pem, string? issuer = null, string? audience = null, bool encrypt = false, RSAEncryptionPadding? padding = null) => new RSADecryptor()
|
||||||
{
|
{
|
||||||
Content = pem,
|
Content = pem,
|
||||||
Issuer = issuer ?? string.Empty,
|
|
||||||
Audience = audience ?? string.Empty,
|
|
||||||
IsEncrypted = encrypt,
|
IsEncrypted = encrypt,
|
||||||
Padding = padding ?? RSAEncryptionPadding.OaepSHA256
|
Padding = padding ?? RSAEncryptionPadding.OaepSHA256
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,9 +10,7 @@ namespace DigitalData.Core.Security.RSAKey
|
|||||||
|
|
||||||
protected virtual RSA RSA { get; } = RSA.Create();
|
protected virtual RSA RSA { get; } = RSA.Create();
|
||||||
|
|
||||||
public string Issuer { get; init; } = string.Empty;
|
public string Id { get; init; }
|
||||||
|
|
||||||
public string Audience { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
internal RSAKeyBase()
|
internal RSAKeyBase()
|
||||||
|
|||||||
@ -45,14 +45,12 @@ namespace DigitalData.Core.Security.RSAKey
|
|||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_pem))
|
if (string.IsNullOrEmpty(_pem))
|
||||||
throw PemIsNullException;
|
throw new InvalidOperationException ($"The content of RSA private key is null or empty. Id: {Id}.");
|
||||||
|
|
||||||
if (IsEncrypted)
|
if (IsEncrypted)
|
||||||
RSA.ImportFromEncryptedPem(Content, Secrets.PBE_PASSWORD.AsSpan());
|
RSA.ImportFromEncryptedPem(Content, Secrets.PBE_PASSWORD.AsSpan());
|
||||||
else
|
else
|
||||||
RSA.ImportFromPem(Content);
|
RSA.ImportFromPem(Content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InvalidOperationException PemIsNullException => new($"Content is null or empty. Issuer: {Issuer}, Audience: {Audience}.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11,6 +11,11 @@ namespace DigitalData.Core.Security.RSAKey
|
|||||||
public string? ApiRoute { get; init; }
|
public string? ApiRoute { get; init; }
|
||||||
|
|
||||||
#region SecurityTokenDescriptor Map
|
#region SecurityTokenDescriptor Map
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value of the 'audience' claim.
|
||||||
|
/// </summary>
|
||||||
|
public string Audience { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the compression algorithm that will be used to compress the JWT token payload.
|
/// Defines the compression algorithm that will be used to compress the JWT token payload.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -26,6 +31,11 @@ namespace DigitalData.Core.Security.RSAKey
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? Expires { get; set; }
|
public DateTime? Expires { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the issuer of this <see cref="SecurityTokenDescriptor"/>.
|
||||||
|
/// </summary>
|
||||||
|
public string Issuer { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the time the security token was issued. This value should be in UTC.
|
/// Gets or sets the time the security token was issued. This value should be in UTC.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user