5-improve-encrypted-storage (#6)
Added the use of DEK's for encryption of secrets. Both the KEK's and DEK's are stored in a way that you can have multiple key of which one is active. But the others are still available for decrypting. This allows for implementing key rotation. Co-authored-by: eelke <eelke@eelkeklein.nl> Co-authored-by: Eelke76 <31384324+Eelke76@users.noreply.github.com> Reviewed-on: #6
This commit is contained in:
parent
138f335af0
commit
07393f57fc
87 changed files with 1903 additions and 533 deletions
41
IdentityShroud.Core/Security/KekId.cs
Normal file
41
IdentityShroud.Core/Security/KekId.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace IdentityShroud.Core.Security;
|
||||
|
||||
[JsonConverter(typeof(KekIdJsonConverter))]
|
||||
[TypeConverter(typeof(KekIdTypeConverter))]
|
||||
public readonly record struct KekId
|
||||
{
|
||||
public Guid Id { get; }
|
||||
|
||||
public KekId(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public static KekId NewId()
|
||||
{
|
||||
return new KekId(Guid.NewGuid());
|
||||
}
|
||||
}
|
||||
|
||||
public class KekIdJsonConverter : JsonConverter<KekId>
|
||||
{
|
||||
public override KekId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
=> new KekId(reader.GetGuid());
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, KekId value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.Id);
|
||||
}
|
||||
|
||||
public class KekIdTypeConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||
=> sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||
|
||||
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
|
||||
=> value is string s ? new KekId(Guid.Parse(s)) : base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue