NetDevPack / NetDevPack/Security.Jwt
Add data protection to DatabaseJsonWebKeyStore and FileSystemStore
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 297
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
Recently switch from DataProtectionStore to DatabaseJsonWebKeyStore and noticed that no DataProtection is present.
It looks to me that mentioned stores are generally less secure than default one.
Note that for example MsalDistributedTokenCacheAdapterOptions has an option to Encrypt (default false):
services.Configure<MsalDistributedTokenCacheAdapterOptions>(options =>
{
// Just for extra security here
options.Encrypt = true;
});
I added protection to DatabaseJsonWebKeyStore like this:
keyModel.Property(key => key.Parameters).HasColumnName("parameters").HasConversion(
val => Protect(val), dbVal => Unprotect(dbVal)
);
With:
string Protect(string val)
{
return dataProtector.Protect(val);
}
string Unprotect(string dbVal)
{
try
{
return dataProtector.Unprotect(dbVal);
}
catch
{
// Something bad but also maybe unprotected payload
return dbVal;
}
}
But I think would be nice to have it in the stores out of the box.
The other option will be to add protection at a higher level for KeyMaterial but that won't work good for some scenarios. For example I'd like to store a public key separately so I can access it from other services but keep private key only to the specific service.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the DatabaseJsonWebKeyStore and FileSystemStore implementations, then compare their persistence paths with DataProtectionStore. Determine how data protection should be configured in both stores and how existing unprotected values should be handled. Done means both stores protect private key material while preserving the intended ability to share public keys.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cryptography, databases, security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100