refactor(CryptographParams): Aktualisierung, um TokenDeskriptoren mit Decryptoren zu initialisieren
This commit is contained in:
parent
87ad45f42a
commit
60ae8de550
@ -54,13 +54,19 @@ namespace DigitalData.Core.Security.Config
|
|||||||
if (!Directory.Exists(PemDirectory))
|
if (!Directory.Exists(PemDirectory))
|
||||||
Directory.CreateDirectory(PemDirectory);
|
Directory.CreateDirectory(PemDirectory);
|
||||||
|
|
||||||
foreach (var decryptor in Decryptors)
|
var privateKeys = new List<RSAPrivateKey>();
|
||||||
|
privateKeys.AddRange(Decryptors);
|
||||||
|
privateKeys.AddRange(TokenDescriptors);
|
||||||
|
if (VaultDecryptor is not null)
|
||||||
|
privateKeys.Add(VaultDecryptor);
|
||||||
|
|
||||||
|
foreach (var privateKey in privateKeys)
|
||||||
{
|
{
|
||||||
// set default path
|
// set default path
|
||||||
if (decryptor.IsPemNull)
|
if (privateKey.IsPemNull)
|
||||||
{
|
{
|
||||||
var file_name_params = new List<object> { decryptor.Issuer, decryptor.Audience, KeySizeInBits, DateTime.Now.ToTag(DateTagFormat) };
|
var file_name_params = new List<object> { privateKey.Issuer, privateKey.Audience, KeySizeInBits, DateTime.Now.ToTag(DateTagFormat) };
|
||||||
if (decryptor.IsEncrypted)
|
if (privateKey.IsEncrypted)
|
||||||
file_name_params.Add(Secrets.Version);
|
file_name_params.Add(Secrets.Version);
|
||||||
|
|
||||||
var file_name = $"{string.Join(FileNameSeparator, file_name_params)}.{FileExtension}";
|
var file_name = $"{string.Join(FileNameSeparator, file_name_params)}.{FileExtension}";
|
||||||
@ -68,14 +74,14 @@ namespace DigitalData.Core.Security.Config
|
|||||||
var path = Path.Combine(PemDirectory, file_name);
|
var path = Path.Combine(PemDirectory, file_name);
|
||||||
|
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
decryptor.SetPem(File.ReadAllText(path));
|
privateKey.SetPem(File.ReadAllText(path));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var pem = decryptor.IsEncrypted
|
var pem = privateKey.IsEncrypted
|
||||||
? Instance.RSAFactory.CreateEncryptedPrivateKeyPem(pbeParameters: PbeParameters, keySizeInBits: KeySizeInBits, password: Secrets.PBE_PASSWORD)
|
? Instance.RSAFactory.CreateEncryptedPrivateKeyPem(pbeParameters: PbeParameters, keySizeInBits: KeySizeInBits, password: Secrets.PBE_PASSWORD)
|
||||||
: Instance.RSAFactory.CreatePrivateKeyPem(keySizeInBits: KeySizeInBits);
|
: Instance.RSAFactory.CreatePrivateKeyPem(keySizeInBits: KeySizeInBits);
|
||||||
|
|
||||||
decryptor.SetPem(pem);
|
privateKey.SetPem(pem);
|
||||||
|
|
||||||
// Save file in background
|
// Save file in background
|
||||||
Task.Run(async () => await File.WriteAllTextAsync(path: path, pem));
|
Task.Run(async () => await File.WriteAllTextAsync(path: path, pem));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user