public void SetUp() { provider = new HashAlgorithmProviderDataManageabilityProvider(); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); configurationObject = new HashAlgorithmProviderData(); }
public void HashProviderWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(HashAlgorithmProviderData), registeredProvider); provider = new ConfigurationSectionManageabilityProviderWrapper( new CryptographySettingsManageabilityProvider(subProviders)); HashAlgorithmProviderData hashProvider1Data = new HashAlgorithmProviderData("hashProvider1", typeof(Object), false); section.HashProviders.Add(hashProvider1Data); HashAlgorithmProviderData hashProvider2Data = new HashAlgorithmProviderData("hashProvider2", typeof(Object), false); section.HashProviders.Add(hashProvider2Data); MockRegistryKey machineHashProvidersKey = new MockRegistryKey(false); machineKey.AddSubKey(CryptographySettingsManageabilityProvider.HashProvidersKeyName, machineHashProvidersKey); MockRegistryKey machineHashProvider2Key = new MockRegistryKey(false); machineHashProvidersKey.AddSubKey("hashProvider2", machineHashProvider2Key); machineHashProvider2Key.AddBooleanValue(CryptographySettingsManageabilityProvider.PolicyValueName, false); provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, false, machineKey, userKey, true, wmiSettings); Assert.AreEqual(2, section.HashProviders.Count); Assert.IsNotNull(section.HashProviders.Get("hashProvider1")); Assert.IsNotNull(section.HashProviders.Get("hashProvider2")); Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineHashProvidersKey, machineHashProvider2Key)); }
public void SetUp() { provider = new HashAlgorithmProviderDataManageabilityProvider(); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); configurationObject = new HashAlgorithmProviderData(); }
public void SetUp() { provider = new ConfigurationElementManageabilityProviderWrapper(new HashAlgorithmProviderDataManageabilityProvider()); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); wmiSettings = new List <ConfigurationSetting>(); configurationObject = new HashAlgorithmProviderData(); }
private void AddSaltToHash(byte[] salt, ref byte[] hash) { HashAlgorithmProviderData data = GetHashAlgorithmProviderDataFromCursor(); if (!data.SaltEnabled) { return; } hash = CryptographyUtility.CombineBytes(salt, hash); }
public void AddTo(CryptographySettings settings) { var providerSetting = new HashAlgorithmProviderData(providerSettings.Name, providerSettings.Type, true); settings.HashProviders.Add(providerSetting); if (isDefault) { settings.DefaultHashProviderName = providerSetting.Name; } }
public EncryptUsingHashAlgorithmProviderNamedBuilder(IConfigureCryptography context, string algorithmProviderName) : base(context) { providerData = new HashAlgorithmProviderData { Name = algorithmProviderName }; CryptographySettings.HashProviders.Add(providerData); }
public void HashWithBadType() { HashAlgorithmProviderData data = new HashAlgorithmProviderData(); data.AlgorithmType = "bad type"; data.Name = "bad"; IHashProvider hashProvider = new HashAlgorithmProvider(); hashProvider.Initialize(new TestCryptographyConfigurationView(data)); hashProvider.CreateHash(plainText); }
public void Properties() { string algorithmType = "oeorihgr"; HashAlgorithmProviderData data = new HashAlgorithmProviderData(); data.AlgorithmType = algorithmType; data.SaltEnabled = true; Assert.AreEqual(algorithmType, data.AlgorithmType, "alg"); Assert.AreEqual(true, data.SaltEnabled, "salt"); }
public void HashHMACSHA1FailsUsingHashAlgorithmProvider() { HashAlgorithmProviderData keyData = new HashAlgorithmProviderData(); keyData.AlgorithmType = typeof(HMACSHA1).AssemblyQualifiedName; keyData.SaltEnabled = false; keyData.Name = "BadHMACSHA1"; IHashProvider hashProvider = new HashAlgorithmProvider(); hashProvider.Initialize(new TestCryptographyConfigurationView(keyData)); hashProvider.CreateHash(plainText); }
public void Properties() { string algorithmType = "oeorihgr"; HashAlgorithmProviderData data = new HashAlgorithmProviderData(); data.AlgorithmType = algorithmType; data.SaltEnabled = true; Assert.AreEqual(algorithmType, data.AlgorithmType, "alg"); Assert.AreEqual(true, data.SaltEnabled, "salt"); }
private void CheckAlgorithmType() { HashAlgorithmProviderData data = GetHashAlgorithmProviderDataFromCursor(); Type type = Type.GetType(data.AlgorithmType); if (type == null) { throw new ConfigurationException(SR.ExceptionCreatingHashAlgorithmInstance); } else if (type.IsSubclassOf(typeof(KeyedHashAlgorithm))) { throw new ConfigurationException(SR.MustUseKeyedHashAlgorithmProvider); } }
/// <summary> /// Gets the cryptographer used for hashing. /// </summary> /// <returns> /// A <see cref="HashCryptographer"/> object. /// </returns> protected virtual HashCryptographer GetHashCryptographer() { try { CheckAlgorithmType(); } catch (ConfigurationException ex) { CryptographyUtility.LogCryptographyException(ex); throw; } HashAlgorithmProviderData data = GetHashAlgorithmProviderDataFromCursor(); return(new HashCryptographer(data.AlgorithmType)); }
private void AddSaltToPlainText(ref byte[] salt, ref byte[] plaintext) { HashAlgorithmProviderData data = GetHashAlgorithmProviderDataFromCursor(); if (!data.SaltEnabled) { return; } if (salt == null) { salt = CryptographyUtility.GetRandomBytes(SaltLength); } plaintext = CryptographyUtility.CombineBytes(salt, plaintext); }
public void RegisteredHashProviderDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(HashAlgorithmProviderData), registeredProvider); provider = new ConfigurationSectionManageabilityProviderWrapper( new CryptographySettingsManageabilityProvider(subProviders)); HashAlgorithmProviderData hashProviderData = new HashAlgorithmProviderData("hashProvider1", typeof(Object), false); section.HashProviders.Add(hashProviderData); MockRegistryKey machineHashProvidersKey = new MockRegistryKey(false); machineKey.AddSubKey(CryptographySettingsManageabilityProvider.HashProvidersKeyName, machineHashProvidersKey); MockRegistryKey machineHashProviderKey = new MockRegistryKey(false); machineHashProvidersKey.AddSubKey("hashProvider1", machineHashProviderKey); MockRegistryKey machineOtherhashProviderKey = new MockRegistryKey(false); machineHashProvidersKey.AddSubKey("hashProvider2", machineOtherhashProviderKey); MockRegistryKey userhashProvidersKey = new MockRegistryKey(false); userKey.AddSubKey(CryptographySettingsManageabilityProvider.HashProvidersKeyName, userhashProvidersKey); MockRegistryKey userhashProviderKey = new MockRegistryKey(false); userhashProvidersKey.AddSubKey("hashProvider1", userhashProviderKey); MockRegistryKey userOtherhashProviderKey = new MockRegistryKey(false); userhashProvidersKey.AddSubKey("hashProvider2", userOtherhashProviderKey); provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings); Assert.IsTrue(registeredProvider.called); Assert.AreSame(hashProviderData, registeredProvider.LastConfigurationObject); Assert.AreSame(machineHashProviderKey, registeredProvider.machineKey); Assert.AreSame(userhashProviderKey, registeredProvider.userKey); Assert.IsTrue( MockRegistryKey.CheckAllClosed(machineHashProvidersKey, machineHashProviderKey, machineOtherhashProviderKey, userhashProvidersKey, userhashProviderKey, userOtherhashProviderKey)); }
/// <summary> /// Extracts the salt from the hashedText. /// </summary> /// <param name="hashedtext">The hash in which to extract the salt.</param> /// <returns>The extracted salt.</returns> protected byte[] ExtractSalt(byte[] hashedtext) { HashAlgorithmProviderData data = GetHashAlgorithmProviderDataFromCursor(); if (!data.SaltEnabled) { return(null); } byte[] salt = null; if (hashedtext.Length > SaltLength) { salt = new byte[SaltLength]; Buffer.BlockCopy(hashedtext, 0, salt, 0, SaltLength); } return(salt); }
protected override void Arrange() { updatableConfigurationSource = new ConfigurationSourceUpdatable(); cryptoSettings = new CryptographySettings(); hashProvider = new HashAlgorithmProviderData("hash provider", typeof(MD5), true); cryptoSettings.HashProviders.Add(hashProvider); cryptoSettings.DefaultHashProviderName = hashProvider.Name; symmetricAlgorithmProvider = new CustomSymmetricCryptoProviderData("symm provider", typeof(MockCustomSymmetricProvider)); cryptoSettings.SymmetricCryptoProviders.Add(symmetricAlgorithmProvider); cryptoSettings.DefaultSymmetricCryptoProviderName = symmetricAlgorithmProvider.Name; updatableConfigurationSource.Add(CryptographySettings.SectionName, cryptoSettings); container = new UnityContainer(); containerConfigurator = new UnityContainerConfigurator(container); EnterpriseLibraryContainer.ConfigureContainer(containerConfigurator, updatableConfigurationSource); }
public void HashAlgorithmProviderDataTest() { bool saltEnabled = false; Type algorithmType = typeof(MD5CryptoServiceProvider); string name = "some name"; HashAlgorithmProviderData data = new HashAlgorithmProviderData(); data.Name = name; data.AlgorithmType = algorithmType; data.SaltEnabled = saltEnabled; Assert.AreEqual(name, data.Name); Assert.AreEqual(algorithmType, data.AlgorithmType); Assert.AreEqual(saltEnabled, data.SaltEnabled); HashAlgorithmProviderNode node = new HashAlgorithmProviderNode(data); Assert.AreEqual(name, node.Name); Assert.AreEqual(algorithmType, node.AlgorithmType); Assert.AreEqual(saltEnabled, node.SaltEnabled); }
public void RegisteredHashProviderDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary <Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(HashAlgorithmProviderData), registeredProvider); provider = new CryptographySettingsManageabilityProvider(subProviders); HashAlgorithmProviderData hashProviderData = new HashAlgorithmProviderData("hashProvider1", typeof(Object), false); section.HashProviders.Add(hashProviderData); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(hashProviderData, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }
public void HashAlgorithmProviderDataTest() { bool saltEnabled = false; Type algorithmType = typeof(MD5CryptoServiceProvider); string name = "some name"; HashAlgorithmProviderData data = new HashAlgorithmProviderData(); data.Name = name; data.AlgorithmType = algorithmType; data.SaltEnabled = saltEnabled; Assert.AreEqual(name, data.Name); Assert.AreEqual(algorithmType, data.AlgorithmType); Assert.AreEqual(saltEnabled, data.SaltEnabled); HashAlgorithmProviderNode node = new HashAlgorithmProviderNode(data); Assert.AreEqual(name, node.Name); Assert.AreEqual(algorithmType, node.AlgorithmType); Assert.AreEqual(saltEnabled, node.SaltEnabled); }
/// <summary> /// Constructs a new instance /// with the corresponding runtime configuration data. /// </summary> /// <param name="hashAlgorithmProviderData">The corresponding runtime configuration data.</param> public HashAlgorithmProviderNode(HashAlgorithmProviderData hashAlgorithmProviderData) : base(hashAlgorithmProviderData) { algorithmType = hashAlgorithmProviderData.AlgorithmType; saltEnabled = hashAlgorithmProviderData.SaltEnabled; }
/// <summary> /// Constructs a new instance /// with the corresponding runtime configuration data. /// </summary> /// <param name="hashAlgorithmProviderData">The corresponding runtime configuration data.</param> public HashAlgorithmProviderNode(HashAlgorithmProviderData hashAlgorithmProviderData) : base(hashAlgorithmProviderData) { this.hashAlgorithmProviderData = hashAlgorithmProviderData; }
public void RegisteredHashProviderDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(HashAlgorithmProviderData), registeredProvider); provider = new CryptographySettingsManageabilityProvider(subProviders); HashAlgorithmProviderData hashProviderData = new HashAlgorithmProviderData("hashProvider1", typeof(Object), false); section.HashProviders.Add(hashProviderData); MockRegistryKey machineHashProvidersKey = new MockRegistryKey(false); machineKey.AddSubKey(CryptographySettingsManageabilityProvider.HashProvidersKeyName, machineHashProvidersKey); MockRegistryKey machineHashProviderKey = new MockRegistryKey(false); machineHashProvidersKey.AddSubKey("hashProvider1", machineHashProviderKey); MockRegistryKey machineOtherhashProviderKey = new MockRegistryKey(false); machineHashProvidersKey.AddSubKey("hashProvider2", machineOtherhashProviderKey); MockRegistryKey userhashProvidersKey = new MockRegistryKey(false); userKey.AddSubKey(CryptographySettingsManageabilityProvider.HashProvidersKeyName, userhashProvidersKey); MockRegistryKey userhashProviderKey = new MockRegistryKey(false); userhashProvidersKey.AddSubKey("hashProvider1", userhashProviderKey); MockRegistryKey userOtherhashProviderKey = new MockRegistryKey(false); userhashProvidersKey.AddSubKey("hashProvider2", userOtherhashProviderKey); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(hashProviderData, registeredProvider.LastConfigurationObject); Assert.AreSame(machineHashProviderKey, registeredProvider.machineKey); Assert.AreSame(userhashProviderKey, registeredProvider.userKey); Assert.IsTrue( MockRegistryKey.CheckAllClosed(machineHashProvidersKey, machineHashProviderKey, machineOtherhashProviderKey, userhashProvidersKey, userhashProviderKey, userOtherhashProviderKey)); }
public void RegisteredHashProviderDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(HashAlgorithmProviderData), registeredProvider); provider = new CryptographySettingsManageabilityProvider(subProviders); HashAlgorithmProviderData hashProviderData = new HashAlgorithmProviderData("hashProvider1", typeof(Object), false); section.HashProviders.Add(hashProviderData); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(hashProviderData, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }
/// <summary> /// Constructs a new instance /// with the corresponding runtime configuration data. /// </summary> /// <param name="hashAlgorithmProviderData">The corresponding runtime configuration data.</param> public HashAlgorithmProviderNode(HashAlgorithmProviderData hashAlgorithmProviderData) : base(hashAlgorithmProviderData) { this.hashAlgorithmProviderData = hashAlgorithmProviderData; }
/// <summary> /// Constructs a new instance /// with the corresponding runtime configuration data. /// </summary> /// <param name="hashAlgorithmProviderData">The corresponding runtime configuration data.</param> public HashAlgorithmProviderNode(HashAlgorithmProviderData hashAlgorithmProviderData) : base(hashAlgorithmProviderData) { algorithmType = hashAlgorithmProviderData.AlgorithmType; saltEnabled = hashAlgorithmProviderData.SaltEnabled; }
public void HashProviderWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(HashAlgorithmProviderData), registeredProvider); provider = new CryptographySettingsManageabilityProvider(subProviders); HashAlgorithmProviderData hashProvider1Data = new HashAlgorithmProviderData("hashProvider1", typeof(Object), false); section.HashProviders.Add(hashProvider1Data); HashAlgorithmProviderData hashProvider2Data = new HashAlgorithmProviderData("hashProvider2", typeof(Object), false); section.HashProviders.Add(hashProvider2Data); MockRegistryKey machineHashProvidersKey = new MockRegistryKey(false); machineKey.AddSubKey(CryptographySettingsManageabilityProvider.HashProvidersKeyName, machineHashProvidersKey); MockRegistryKey machineHashProvider2Key = new MockRegistryKey(false); machineHashProvidersKey.AddSubKey("hashProvider2", machineHashProvider2Key); machineHashProvider2Key.AddBooleanValue(CryptographySettingsManageabilityProvider.PolicyValueName, false); provider.OverrideWithGroupPolicies(section, false, machineKey, userKey); Assert.AreEqual(2, section.HashProviders.Count); Assert.IsNotNull(section.HashProviders.Get("hashProvider1")); Assert.IsNotNull(section.HashProviders.Get("hashProvider2")); Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineHashProvidersKey, machineHashProvider2Key)); }