예제 #1
0
        /// <summary>
        /// <para>Edits the specified object's value using the editor style indicated by <see cref="GetEditStyle"/>. This should be a <see cref="DpapiSettings"/> object.</para>
        /// </summary>
        /// <param name="context"><para>An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information.</para></param>
        /// <param name="provider"><para>An <see cref="IServiceProvider"/> that this editor can use to obtain services.</para></param>
        /// <param name="value"><para>The object to edit. This should be a <see cref="DpapiSettings"/> object.</para></param>
        /// <returns><para>The new value of the <see cref="DpapiSettings"/> object.</para></returns>
        /// <seealso cref="UITypeEditor.EditValue(ITypeDescriptorContext, IServiceProvider, object)"/>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Debug.Assert(provider != null, "No service provider; we cannot edit the value");
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
                if (edSvc != null)
                {
                    IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                    using (DpapiSettingsEditorUI dialog = new DpapiSettingsEditorUI(required))
                    {
                        if (ConfirmMessage.Length > 0)
                        {
                            dialog.ConfirmMessage = this.ConfirmMessage;
                        }

                        DpapiSettings dpapiSettings = value as DpapiSettings;
                        InitializeDialog(dialog, dpapiSettings);
                        DpapiSettingsData newSettingsData = dialog.DpapiSettingsData;
                        return(HandleResult(service.ShowDialog(dialog), dpapiSettings, newSettingsData));
                    }
                }
            }
            return(value);
        }
        /// <summary>
        /// <para>If DPAPI settings change, this saves the key algorithm out with the new settings.</para>
        /// </summary>
        /// <param name="dialogResult">
        /// <para>One of the <see cref="DialogResult"/> values.</para>
        /// </param>
        /// <param name="originalSettings">
        /// <para>The original <see cref="DpapiSettings"/> before editing.</para>
        /// </param>
        /// <param name="newSettingsData">
        /// <para>The new <see cref="DpapiSettingsData"/> from the editor.</para>
        /// </param>
        /// <returns>
        /// <para>If accepted, the new <see cref="DpapiSettings"/>; otherwise the <paramref name="originalSettings"/>.</para>
        /// </returns>
        protected override object HandleResult(DialogResult dialogResult, DpapiSettings originalSettings, DpapiSettingsData newSettingsData)
        {
            bool returnBaseResult = true;

            if (dialogResult == DialogResult.OK)
            {
                DpapiSettings newDpapiSettings = null;
                if (newSettingsData != null)
                {
                    newDpapiSettings = new DpapiSettings(newSettingsData);
                }

                if (newDpapiSettings != originalSettings)
                {
                    returnBaseResult = SaveKeyAlgorithmPairWithNewDapiSettings(newDpapiSettings, originalSettings);
                }
            }

            if (returnBaseResult)
            {
                return base.HandleResult(dialogResult, originalSettings, newSettingsData);
            }
            else
            {
                return originalSettings;
            }
        }
예제 #3
0
        public void SerializeTest()
        {
            XmlSerializer         xmlSerializer         = new XmlSerializer(typeof(ConfigurationSettings), new Type[] { typeof(XmlFileStorageProviderData) });
            ConfigurationSettings configurationSettings = new ConfigurationSettings();

            configurationSettings.XmlIncludeTypes.Add(new XmlIncludeTypeData("My Custom Storage Provider", "Microsoft.Practices.EnterpriseLibrary.Configuration.MyCustomStorageProvider, Microsoft.Practices.EnterpriseLibrary.Configuration"));
            configurationSettings.XmlIncludeTypes.Add(new XmlIncludeTypeData("My Custom Transformer", "Microsoft.Practices.EnterpriseLibrary.Configuration.MyCustomTransformer, Microsoft.Practices.EnterpriseLibrary.Configuration"));
            configurationSettings.XmlIncludeTypes.Add(new XmlIncludeTypeData("My Custom Key Algorithm Pair Storage Provider Data", "Microsoft.Practices.EnterpriseLibrary.Configuration.MyCustomKeyAlgorithmPairStorageProviderData, Microsoft.Practices.EnterpriseLibrary.Configuration"));
            configurationSettings.ApplicationName = "MyApplication";
            ConfigurationSectionData configurationSection = new ConfigurationSectionData("ApplConfig1", false, GetStorageProvider(), GetTransformer());

            configurationSettings.ConfigurationSections.Add(configurationSection);
            configurationSection = new ConfigurationSectionData("ApplConfig2", false, GetStorageProvider(), GetTransformer());
            configurationSettings.ConfigurationSections.Add(configurationSection);
            FileKeyAlgorithmPairStorageProviderData fileKeyAlgorithmPairStorageProviderData = new FileKeyAlgorithmPairStorageProviderData("FileStore", "foo.data");
            DpapiSettingsData dpapiData = new DpapiSettingsData(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 5, 6 }, DpapiStorageMode.Machine);

            fileKeyAlgorithmPairStorageProviderData.DpapiSettings     = dpapiData;
            configurationSettings.KeyAlgorithmPairStorageProviderData = fileKeyAlgorithmPairStorageProviderData;
            StringBuilder configXml = new StringBuilder();
            XmlTextWriter writer    = new XmlTextWriter(new StringWriter(configXml, CultureInfo.CurrentCulture));

            writer.Formatting = Formatting.None;
            xmlSerializer.Serialize(writer, configurationSettings);
            writer.Close();
            Assert.AreEqual(xmlString, configXml.ToString());
        }
예제 #4
0
            public override SymmetricCryptoProviderData GetSymmetricCryptoProviderData(string instanceName)
            {
                DpapiSymmetricCryptoProviderData data = new DpapiSymmetricCryptoProviderData();

                data.Name = "name";
                DpapiSettingsData settingsData = new DpapiSettingsData();

                settingsData.Mode       = DpapiStorageMode.User;
                data.DataProtectionMode = settingsData;
                return(data);
            }
예제 #5
0
 /// <summary>
 /// <para>Initialzie a new instance of the <see cref="DpapiSettings"/> class with a <see cref="DpapiSettingsData"/> object.</para>
 /// </summary>
 /// <param name="settingsData">A <see cref="DpapiSettingsData"/> object containing the configuration data from storage.</param>
 public DpapiSettings(DpapiSettingsData settingsData)
 {
     if (settingsData != null)
     {
         this.Mode    = settingsData.Mode;
         this.Entropy = settingsData.Entropy;
     }
     else
     {
         this.Mode    = DpapiStorageMode.Machine;
         this.Entropy = null;
     }
 }
예제 #6
0
 /// <summary>
 /// <para>Initialzie a new instance of the <see cref="DpapiSettings"/> class with a <see cref="DpapiSettingsData"/> object.</para>
 /// </summary>
 /// <param name="settingsData">A <see cref="DpapiSettingsData"/> object containing the configuration data from storage.</param>
 public DpapiSettings(DpapiSettingsData settingsData)
 {
     if (settingsData != null)
     {
         this.Mode = settingsData.Mode;
         this.Entropy = settingsData.Entropy;
     }
     else
     {
         this.Mode = DpapiStorageMode.Machine;
         this.Entropy = null;
     }
 }
예제 #7
0
        public void Properties()
        {
            DpapiStorageMode mode = DpapiStorageMode.Machine;

            byte[] entropy = new byte[] { 0, 1, 2, 3, 4 };

            DpapiSettingsData data = new DpapiSettingsData();

            data.Mode    = mode;
            data.Entropy = entropy;

            Assert.AreEqual(mode, data.Mode);
            Assert.AreEqual(entropy, data.Entropy);
        }
예제 #8
0
        private bool Save()
        {
            bool result = true;

            if (firstRun)
            {
                this.data = new DpapiSettingsData();
            }
            else
            {
                if (!ConfirmSave())
                {
                    return(false);
                }
            }

            switch (dpapiSettingsControl.DpapiStorageMode)
            {
            case DpapiStorageMode.User:
                this.data.Mode    = DpapiStorageMode.User;
                this.data.Entropy = null;
                break;

            case DpapiStorageMode.Machine:
                result = SaveMachineMode();
                break;

            default:
                if (required)
                {
                    MessageBox.Show(SR.DpapiMissingModeErrorMessage, SR.DpapiMissingModeCaption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    result = false;
                }
                else
                {
                    this.data = null;
                }
                break;
            }

            return(result);
        }
예제 #9
0
        public void Properties()
        {
            string           name = "name";
            DpapiStorageMode mode = DpapiStorageMode.User;

            byte[] machineEntropy = new byte[16];
            CryptographyUtility.GetRandomBytes(machineEntropy);

            DpapiSymmetricCryptoProviderData data = new DpapiSymmetricCryptoProviderData();

            data.Name = name;

            Assert.AreEqual(name, data.Name, "name");
            Assert.AreEqual(typeof(DpapiSymmetricCryptoProvider).AssemblyQualifiedName, data.TypeName, "type");

            DpapiSettingsData dpapiData = new DpapiSettingsData();

            dpapiData.Mode          = mode;
            dpapiData.Entropy       = machineEntropy;
            data.DataProtectionMode = dpapiData;
            Assert.AreEqual(mode, data.DataProtectionMode.Mode, "Mode");
            Assert.IsTrue(CryptographyUtility.CompareBytes(machineEntropy, dpapiData.Entropy), "Entropy");
        }
예제 #10
0
        protected virtual object HandleResult(DialogResult dialogResult, DpapiSettings originalSettings, DpapiSettingsData newSettingsData)
        {
            if (dialogResult == DialogResult.OK)
            {
                if (newSettingsData == null)
                {
                    return(null);
                }

                return(new DpapiSettings(newSettingsData));
            }
            else
            {
                return(originalSettings);
            }
        }
예제 #11
0
        protected virtual object HandleResult(DialogResult dialogResult, DpapiSettings originalSettings, DpapiSettingsData newSettingsData)
        {
            if (dialogResult == DialogResult.OK)
            {
                if (newSettingsData == null)
                {
                    return null;
                }

                return new DpapiSettings(newSettingsData);
            }
            else
            {
                return originalSettings;
            }
        }
 public void SerializeTest()
 {
     XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigurationSettings), new Type[] {typeof(XmlFileStorageProviderData)});
     ConfigurationSettings configurationSettings = new ConfigurationSettings();
     configurationSettings.XmlIncludeTypes.Add(new XmlIncludeTypeData("My Custom Storage Provider", "Microsoft.Practices.EnterpriseLibrary.Configuration.MyCustomStorageProvider, Microsoft.Practices.EnterpriseLibrary.Configuration"));
     configurationSettings.XmlIncludeTypes.Add(new XmlIncludeTypeData("My Custom Transformer", "Microsoft.Practices.EnterpriseLibrary.Configuration.MyCustomTransformer, Microsoft.Practices.EnterpriseLibrary.Configuration"));
     configurationSettings.XmlIncludeTypes.Add(new XmlIncludeTypeData("My Custom Key Algorithm Pair Storage Provider Data", "Microsoft.Practices.EnterpriseLibrary.Configuration.MyCustomKeyAlgorithmPairStorageProviderData, Microsoft.Practices.EnterpriseLibrary.Configuration"));
     configurationSettings.ApplicationName = "MyApplication";
     ConfigurationSectionData configurationSection = new ConfigurationSectionData("ApplConfig1", false, GetStorageProvider(), GetTransformer());
     configurationSettings.ConfigurationSections.Add(configurationSection);
     configurationSection = new ConfigurationSectionData("ApplConfig2", false, GetStorageProvider(), GetTransformer());
     configurationSettings.ConfigurationSections.Add(configurationSection);
     FileKeyAlgorithmPairStorageProviderData fileKeyAlgorithmPairStorageProviderData = new FileKeyAlgorithmPairStorageProviderData("FileStore", "foo.data");
     DpapiSettingsData dpapiData = new DpapiSettingsData(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 5, 6}, DpapiStorageMode.Machine);
     fileKeyAlgorithmPairStorageProviderData.DpapiSettings = dpapiData;
     configurationSettings.KeyAlgorithmPairStorageProviderData = fileKeyAlgorithmPairStorageProviderData;
     StringBuilder configXml = new StringBuilder();
     XmlTextWriter writer = new XmlTextWriter(new StringWriter(configXml, CultureInfo.CurrentCulture));
     writer.Formatting = Formatting.None;
     xmlSerializer.Serialize(writer, configurationSettings);
     writer.Close();
     Assert.AreEqual(xmlString, configXml.ToString());
 }
예제 #13
0
        /// <summary>
        /// <para>If DPAPI settings change, this saves the key algorithm out with the new settings.</para>
        /// </summary>
        /// <param name="dialogResult">
        /// <para>One of the <see cref="DialogResult"/> values.</para>
        /// </param>
        /// <param name="originalSettings">
        /// <para>The original <see cref="DpapiSettings"/> before editing.</para>
        /// </param>
        /// <param name="newSettingsData">
        /// <para>The new <see cref="DpapiSettingsData"/> from the editor.</para>
        /// </param>
        /// <returns>
        /// <para>If accepted, the new <see cref="DpapiSettings"/>; otherwise the <paramref name="originalSettings"/>.</para>
        /// </returns>
        protected override object HandleResult(DialogResult dialogResult, DpapiSettings originalSettings, DpapiSettingsData newSettingsData)
        {
            bool returnBaseResult = true;

            if (dialogResult == DialogResult.OK)
            {
                DpapiSettings newDpapiSettings = null;
                if (newSettingsData != null)
                {
                    newDpapiSettings = new DpapiSettings(newSettingsData);
                }

                if (newDpapiSettings != originalSettings)
                {
                    returnBaseResult = SaveKeyAlgorithmPairWithNewDapiSettings(newDpapiSettings, originalSettings);
                }
            }

            if (returnBaseResult)
            {
                return(base.HandleResult(dialogResult, originalSettings, newSettingsData));
            }
            else
            {
                return(originalSettings);
            }
        }
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="DpapiSymmetricCryptoProviderData"/> class with a name.</para>
 /// </summary>
 /// <param name="name">The name for the <see cref="DpapiSymmetricCryptoProviderData"/>.</param>
 /// <param name="data">The <see cref="DpapiSettingsData"/> for the provider.</param>
 public DpapiSymmetricCryptoProviderData(string name, DpapiSettingsData data) : base(name)
 {
     this.data = data;
 }
예제 #15
0
        private bool Save()
        {
            bool result = true;

            if (firstRun)
            {
                this.data = new DpapiSettingsData();
            }
            else
            {
                if (!ConfirmSave())
                {
                    return false;
                }
            }

            switch (dpapiSettingsControl.DpapiStorageMode)
            {
                case DpapiStorageMode.User:
                    this.data.Mode = DpapiStorageMode.User;
                    this.data.Entropy = null;
                    break;
                case DpapiStorageMode.Machine:
                    result = SaveMachineMode();
                    break;
                default:
                    if (required)
                    {
                        MessageBox.Show(SR.DpapiMissingModeErrorMessage, SR.DpapiMissingModeCaption,
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        result = false;
                    }
                    else
                    {
                        this.data = null;
                    }
                    break;
            }

            return result;
        }