2 // System.Web.Configuration.MachineKeySection
5 // Chris Toshok (toshok@ximian.com)
7 // (c) Copyright 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.ComponentModel;
33 using System.Configuration;
34 using System.Security.Cryptography;
38 namespace System.Web.Configuration {
40 public sealed class MachineKeySection : ConfigurationSection
42 static ConfigurationProperty decryptionProp;
43 static ConfigurationProperty decryptionKeyProp;
44 static ConfigurationProperty validationProp;
45 static ConfigurationProperty validationKeyProp;
46 static ConfigurationPropertyCollection properties;
48 static MachineKeySection ()
50 decryptionProp = new ConfigurationProperty ("decryption", typeof (string), "Auto",
51 PropertyHelper.WhiteSpaceTrimStringConverter,
52 PropertyHelper.NonEmptyStringValidator,
53 ConfigurationPropertyOptions.None);
54 decryptionKeyProp = new ConfigurationProperty ("decryptionKey", typeof (string), "AutoGenerate,IsolateApps",
55 PropertyHelper.WhiteSpaceTrimStringConverter,
56 PropertyHelper.NonEmptyStringValidator,
57 ConfigurationPropertyOptions.None);
58 validationProp = new ConfigurationProperty ("validation", typeof (MachineKeyValidation), MachineKeyValidation.SHA1,
59 new MachineKeyValidationConverter (),
60 PropertyHelper.DefaultValidator,
61 ConfigurationPropertyOptions.None);
62 validationKeyProp = new ConfigurationProperty ("validationKey", typeof (string), "AutoGenerate,IsolateApps",
63 PropertyHelper.WhiteSpaceTrimStringConverter,
64 PropertyHelper.NonEmptyStringValidator,
65 ConfigurationPropertyOptions.None);
67 properties = new ConfigurationPropertyCollection ();
69 properties.Add (decryptionProp);
70 properties.Add (decryptionKeyProp);
71 properties.Add (validationProp);
72 properties.Add (validationKeyProp);
74 MachineKeySectionUtils.AutoGenKeys ();
77 protected override void Reset (ConfigurationElement parentElement)
79 base.Reset (parentElement);
82 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
83 [StringValidator (MinLength = 1)]
84 [ConfigurationProperty ("decryption", DefaultValue = "Auto")]
85 public string Decryption {
86 get { return (string) base [decryptionProp];}
87 set { base[decryptionProp] = value; }
90 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
91 [StringValidator (MinLength = 1)]
92 [ConfigurationProperty ("decryptionKey", DefaultValue = "AutoGenerate,IsolateApps")]
93 public string DecryptionKey {
94 get { return (string) base [decryptionKeyProp];}
96 base[decryptionKeyProp] = value;
97 MachineKeySectionUtils.SetDecryptionKey (value);
101 [TypeConverter (typeof (MachineKeyValidationConverter))]
102 [ConfigurationProperty ("validation", DefaultValue = "SHA1")]
103 public MachineKeyValidation Validation {
104 get { return (MachineKeyValidation) base [validationProp];}
105 set { base[validationProp] = value; }
108 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
109 [StringValidator (MinLength = 1)]
110 [ConfigurationProperty ("validationKey", DefaultValue = "AutoGenerate,IsolateApps")]
111 public string ValidationKey {
112 get { return (string) base [validationKeyProp];}
114 base[validationKeyProp] = value;
115 MachineKeySectionUtils.SetValidationKey (value);
119 protected override ConfigurationPropertyCollection Properties {
120 get { return properties; }