-
Notifications
You must be signed in to change notification settings - Fork 87
Conversation
@ajaybhargavb Will these changes fix #154? TL;DR ... The prob described in that issue was that DI wasn't working for public class CustomXmlDecryptor : IXmlDecryptor
{
private byte[] _key;
public CustomXmlDecryptor()
{
}
public CustomXmlDecryptor(IOptions<CustomDataProtectionOptions> dataProtectionOptions)
{
_key = dataProtectionOptions.Value.Key;
}
public XElement Decrypt(XElement encryptedElement)
{
// Code here uses _key to decrypt
}
}
public CustomXmlDecryptor(IServiceProvider services)
{
var dataProtectionOptions =
services.GetRequiredService<IOptions<CustomDataProtectionOptions>>();
_key = dataProtectionOptions.Value.Key;
} ... to make it work. |
@guardrex, this change won't fix the issue that you referenced. It was never supported. |
4df6218
to
8ee57f7
Compare
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddLogging(); | ||
serviceCollection.AddDataProtection() | ||
.PersistKeysToFileSystem(new DirectoryInfo(@"c:\temp-keys")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use some other path for the sake of the sample? Does this work on non-Windows?
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddDataProtection() | ||
// point at a specific folder and use DPAPI to encrypt keys | ||
.PersistKeysToFileSystem(new DirectoryInfo(@"c:\temp-keys")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
// one key in the key ring | ||
services.GetDataProtector("Sample.KeyManager.v1").Protect("payload"); | ||
Console.WriteLine("Performed a protect operation."); | ||
Thread.Sleep(2000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
samples/NonDISample/Program.cs
Outdated
{ | ||
// get the path to %LOCALAPPDATA%\myapp-keys | ||
var destFolder = Path.Combine( | ||
Environment.GetEnvironmentVariable("LOCALAPPDATA"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens on non-Windows?
{ | ||
throw Error.Common_PropertyCannotBeNullOrEmpty(nameof(configuration.EncryptionAlgorithmType)); | ||
} | ||
typeof(SymmetricAlgorithm).AssertIsAssignableFrom(configuration.EncryptionAlgorithmType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked offline
@@ -118,7 +107,7 @@ internal static string GetDefaultProtectionDescriptorString() | |||
using (var currentIdentity = WindowsIdentity.GetCurrent()) | |||
{ | |||
// use the SID to create an SDDL string | |||
return Invariant($"SID={currentIdentity.User.Value}"); | |||
return String.Format(CultureInfo.InvariantCulture, "SID={0}", currentIdentity.User.Value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
!
@@ -107,7 +87,11 @@ private static RegistryKey GetDefaultHklmStorageKey() | |||
// Even though this is in HKLM, WAS ensures that applications hosted in IIS are properly isolated. | |||
// See APP_POOL::EnsureSharedMachineKeyStorage in WAS source for more info. | |||
// The version number will need to change if IIS hosts Core CLR directly. | |||
var aspnetAutoGenKeysBaseKeyName = Invariant($@"SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\AutoGenKeys\{WindowsIdentity.GetCurrent().User.Value}"); | |||
var aspnetAutoGenKeysBaseKeyName = String.Format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
! And elsewhere, too.
@@ -21,4 +21,8 @@ | |||
<PackageReference Include="xunit" Version="2.2.0-*" /> | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does VS just put this here? If we remove it, will VS put it back? (If so, leave it.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, VS will just put this back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok that's fine then.
|
||
private static IAuthenticatedEncryptor CreateEncryptorInstanceFromDescriptor(CngGcmAuthenticatedEncryptorDescriptor descriptor) | ||
{ | ||
var key = new Key( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ick, can this use named params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
IServiceCollection serviceCollection = new ServiceCollection(); | ||
RunTestWithRegValues(serviceCollection, new Dictionary<string, object>() | ||
// Arrange | ||
var registryEntries = new Dictionary<string, object>() | ||
{ | ||
["unused"] = 42 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's unused, do we need to set any values in the registry at all?
🆙 📅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
/// Settings for configuring authenticated encryption algorithms. | ||
/// </summary> | ||
public sealed class AuthenticatedEncryptionSettings : IInternalAuthenticatedEncryptionSettings | ||
public class AuthenticatedEncryptorFactory : IAuthenticatedEncryptorFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be sealed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should. Looks like I missed this one. Good catch 👍
- Refactored builder extensions and service collection extensions - Refactored Settings/Configuration/Descriptor - Removed ConfigurationCommon/AuthenticatedEncryptorConfigurationExtensions - Added IAuthenticatedEncryptorFactory and implementations - Refactored IKey to have Descriptor instead of CreateEncryptorInstance() - Handled Repository/Encryptor special logic - Added samples - Updated tests
6db8037
to
cde3b96
Compare
Thanks @Eilon @rynowak @GrabYourPitchforks |
🎉 |
Issue - #134
@rynowak @davidfowl @blowdart