feat (CryptFactory.RSADecryptorKeyFormatter): aktualisiert, um die erforderlichen Parameter als Eingabe zu nehmen, anstatt IRSADecryptor direkt als Eingabe zu nehmen
This commit is contained in:
@@ -10,13 +10,13 @@ namespace DigitalData.Core.Security
|
||||
|
||||
public IRSADecryptor this[string key] { get => _decryptors[key]; set => _decryptors[key] = value; }
|
||||
|
||||
public Func<IRSADecryptor, string, string, string, string> RSADecryptorKeyFormatter { get; }
|
||||
public Func<string, string, bool, Version?, string, string> RSAKeyNameFormatter { get; }
|
||||
|
||||
public CryptFactory(ILogger<CryptFactory> logger, IDictionary<string, IRSADecryptor> decryptors, Func<IRSADecryptor, string, string, string, string> rsaDecryptorKeyFormatter) : base()
|
||||
public CryptFactory(ILogger<CryptFactory> logger, IDictionary<string, IRSADecryptor> decryptors, Func<string, string, bool, Version?, string, string> rsaKeyNameFormatter) : base()
|
||||
{
|
||||
_decryptors = decryptors ?? new Dictionary<string, IRSADecryptor>();
|
||||
|
||||
RSADecryptorKeyFormatter = rsaDecryptorKeyFormatter;
|
||||
RSAKeyNameFormatter = rsaKeyNameFormatter;
|
||||
|
||||
logger?.LogInformation("Core.Secrets version: {Version}, Created on: {CreationDate}.", Secrets.Version, Secrets.CreationDate.ToString("dd.MM.yyyy"));
|
||||
}
|
||||
@@ -31,11 +31,13 @@ namespace DigitalData.Core.Security
|
||||
|
||||
public static readonly IEnumerable<string> KeyFileTags = new string[] { DefaultEncryptedPrivateKeyFileTag, DefaultPrivateKeyFileTag, DefaultPublicKeyFileTag };
|
||||
|
||||
public static readonly string PEMFileExtension = ".pem";
|
||||
|
||||
private static readonly Lazy<IEnumerable<string>> LazyLowerFileTags = new(() => KeyFileTags.Select(tag => tag.ToLower()));
|
||||
|
||||
//TODO: make the validation using regex
|
||||
public static string DefaultRSADecryptorKeyFormatter(IRSADecryptor decryptor, string issuer, string audience, string separator = "-_-")
|
||||
{
|
||||
public static string DefaultRSAKeyNameFormatter(string issuer, string audience, bool isPrivate = true, Version? passwordVersion = null, string separator = "-_-")
|
||||
{
|
||||
void ValidateForbidden(string value, string paramName)
|
||||
{
|
||||
if (Path.GetInvalidFileNameChars().Any(value.Contains) || LazyLowerFileTags.Value.Any(tag => value.ToLower().Contains(tag)))
|
||||
@@ -58,12 +60,16 @@ namespace DigitalData.Core.Security
|
||||
var sb = new StringBuilder(issuer.Length + audience.Length + separator.Length * 2 + 20);
|
||||
sb.Append(issuer).Append(separator).Append(audience).Append(separator);
|
||||
|
||||
if (decryptor.HasEncryptedPem)
|
||||
sb.Append("e-private").Append(separator).Append(decryptor.PasswordVersion);
|
||||
if (passwordVersion is null && isPrivate)
|
||||
sb.Append(DefaultPrivateKeyFileTag);
|
||||
else if(isPrivate)
|
||||
sb.Append(DefaultEncryptedPrivateKeyFileTag).Append(separator).Append(passwordVersion);
|
||||
else if(passwordVersion is null)
|
||||
sb.Append(DefaultPublicKeyFileTag);
|
||||
else
|
||||
sb.Append("private");
|
||||
sb.Append(DefaultPublicKeyFileTag).Append(separator).Append(passwordVersion);
|
||||
|
||||
var rsaKey = sb.Append(".pem").ToString();
|
||||
var rsaKey = sb.Append(PEMFileExtension).ToString();
|
||||
|
||||
return rsaKey;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user