Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2005-07-26 02:15:52 +0400
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2005-07-26 02:15:52 +0400
commitcbe4d07f35f58a5f26c982bf25a4144dfb4c7b27 (patch)
tree340d451dcdf93e1a1541db2e829e5fed869f427c /mcs
parent442bd78945d6c44aa348dd1dae253942142bfe3b (diff)
From HEAD
svn path=/branches/mono-1-1-8/mcs/; revision=47671
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System.Web/System.Web.Configuration/ChangeLog15
-rw-r--r--mcs/class/System.Web/System.Web.Configuration/MachineKeyConfig.cs117
-rw-r--r--mcs/class/System.Web/System.Web.Configuration/MachineKeyConfigHandler.cs65
-rw-r--r--mcs/class/System.Web/System.Web.Configuration/MachineKeyValidation.cs21
4 files changed, 134 insertions, 84 deletions
diff --git a/mcs/class/System.Web/System.Web.Configuration/ChangeLog b/mcs/class/System.Web/System.Web.Configuration/ChangeLog
index a04cc2ec820..d84673463ed 100644
--- a/mcs/class/System.Web/System.Web.Configuration/ChangeLog
+++ b/mcs/class/System.Web/System.Web.Configuration/ChangeLog
@@ -1,3 +1,18 @@
+2005-07-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * MachineKeyConfigHandler.cs: removed unused code. Use
+ MachineKeyValidation.
+ * MachineKeyValidation.cs: made internal for 1.1 and added AES.
+ * MachineKeyConfig.cs: new property to return 24 bits needed for 3DES.
+ fix typo from last patch ('AutoGenerate'). Made the keys different when
+ both are autogenerated.
+
+2005-07-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * MachineKeyConfigHandler.cs:
+ * MachineKeyConfig.cs: patch from Miguel that moves code from
+ MachineKeyConfigHandler to MachineKeyConfig.
+
2005-06-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HandlerItem.cs: the path matches 'path\z', as the previous '\Apath\z'
diff --git a/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfig.cs b/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfig.cs
index 50e066515a1..791453bbf7e 100644
--- a/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfig.cs
+++ b/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfig.cs
@@ -5,6 +5,7 @@
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
+// Copyright (c) 2005 Novell, Inc (http://www.novell.com)
//
//
@@ -32,54 +33,126 @@ using System;
using System.Collections;
using System.Configuration;
using System.Xml;
+using System.Security.Cryptography;
namespace System.Web.Configuration
{
class MachineKeyConfig
{
- static MachineKeyConfig machineKey;
- byte [] validationKey;
- byte [] decryptionKey;
- string validationType;
+ static MachineKeyConfig machine_key;
+ byte [] validation_key;
+ bool isolate_validation;
+ byte [] decryption_key;
+ byte [] decryption_key_192bits;
+ bool isolate_decryption; // For us, this is always true by now.
+ MachineKeyValidation validation_type;
+ static byte [] autogenerated;
+ static byte [] autogenerated_decrypt;
+
+ static MachineKeyConfig ()
+ {
+ autogenerated = new byte [64];
+ RNGCryptoServiceProvider cp = new RNGCryptoServiceProvider ();
+ cp.GetBytes (autogenerated);
+ autogenerated_decrypt = new byte [64];
+ cp.GetBytes (autogenerated_decrypt);
+ }
+
internal MachineKeyConfig (object parent)
{
if (parent is MachineKeyConfig) {
MachineKeyConfig p = (MachineKeyConfig) parent;
- validationKey = p.validationKey;
- decryptionKey = p.decryptionKey;
- validationType = p.validationType;
+ validation_key = p.validation_key;
+ decryption_key = p.decryption_key;
+ validation_type = p.validation_type;
}
}
+ static byte ToHexValue (char c, bool high)
+ {
+ byte v;
+ if (c >= '0' && c <= '9')
+ v = (byte) (c - '0');
+ else if (c >= 'a' && c <= 'f')
+ v = (byte) (c - 'a' + 10);
+ else if (c >= 'A' && c <= 'F')
+ v = (byte) (c - 'A' + 10);
+ else
+ throw new ArgumentException ("Invalid hex character");
+
+ if (high)
+ v <<= 4;
+
+ return v;
+ }
+
+ internal static byte [] GetBytes (string key, int len)
+ {
+ byte [] result = new byte [len / 2];
+ for (int i = 0; i < len; i += 2)
+ result [i / 2] = (byte) (ToHexValue (key [i], true) + ToHexValue (key [i + 1], false));
+
+ return result;
+ }
+
+ static byte [] MakeKey (string key, bool decryption, out bool isolate)
+ {
+ if (key == null || key.StartsWith ("AutoGenerate")){
+ isolate = key.IndexOf ("IsolateApps") != 1;
+
+ // Same key for validation and decryption when both are autogenerated.
+ return (decryption) ? autogenerated_decrypt : autogenerated;
+ }
+
+ isolate = false;
+
+ int len = key.Length;
+ if (len < 40 || len > 128 || (len % 2) == 1)
+ throw new ArgumentException ("Invalid key length");
+
+ return GetBytes (key, len);
+ }
+
+ internal void SetValidationKey (string n)
+ {
+ validation_key = MakeKey (n, false, out isolate_validation);
+ }
+
internal byte [] ValidationKey {
- get { return validationKey; }
- set { validationKey = value; }
+ get { return validation_key; }
}
+ internal void SetDecryptionKey (string n)
+ {
+ decryption_key = MakeKey (n, true, out isolate_decryption);
+ decryption_key_192bits = new byte [24];
+ int count = 24;
+ if (decryption_key.Length < 24)
+ count = decryption_key.Length;
+ Buffer.BlockCopy (decryption_key, 0, decryption_key_192bits, 0, count);
+ }
+
internal byte [] DecryptionKey {
- get { return decryptionKey; }
- set { decryptionKey = value; }
+ get { return decryption_key; }
}
- internal string ValidationType {
- get {
- if (validationType == null)
- validationType = "SHA1";
+ internal byte [] DecryptionKey192Bits {
+ get { return decryption_key_192bits; }
+ }
- return validationType;
+ internal MachineKeyValidation ValidationType {
+ get {
+ return validation_type;
}
set {
- if (value == null)
- return;
-
- validationType = value;
+ validation_type = value;
}
}
internal static MachineKeyConfig MachineKey {
- get { return machineKey; }
- set { machineKey = value; }
+ get { return machine_key; }
+ set { machine_key = value; }
}
}
}
diff --git a/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfigHandler.cs b/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfigHandler.cs
index cb64198a620..e3237bf3ceb 100644
--- a/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfigHandler.cs
+++ b/mcs/class/System.Web/System.Web.Configuration/MachineKeyConfigHandler.cs
@@ -31,60 +31,12 @@
using System;
using System.Collections;
using System.Configuration;
-using System.Security.Cryptography;
using System.Xml;
namespace System.Web.Configuration
{
class MachineKeyConfigHandler : IConfigurationSectionHandler
{
- static byte [] autogenerated;
- static MachineKeyConfigHandler ()
- {
- autogenerated = new byte [64];
- RNGCryptoServiceProvider cp = new RNGCryptoServiceProvider ();
- cp.GetBytes (autogenerated);
- }
-
- static byte ToHexValue (char c, bool high)
- {
- byte v;
- if (c >= '0' && c <= '9')
- v = (byte) (c - '0');
- else if (c >= 'a' && c <= 'f')
- v = (byte) (c - 'a' + 10);
- else if (c >= 'A' && c <= 'F')
- v = (byte) (c - 'A' + 10);
- else
- throw new ArgumentException ("Invalid hex character");
-
- if (high)
- v <<= 4;
-
- return v;
- }
-
- internal static byte [] GetBytes (string key, int len)
- {
- byte [] result = new byte [len / 2];
- for (int i = 0; i < len; i += 2)
- result [i / 2] = (byte) (ToHexValue (key [i], true) + ToHexValue (key [i + 1], false));
-
- return result;
- }
-
- static byte [] MakeKey (string key)
- {
- if (key == null || key == "AutoGenerated")
- return autogenerated;
-
- int len = key.Length;
- if (len < 40 || len > 128 || (len % 2) == 1)
- throw new ArgumentException ("Invalid key length");
-
- return GetBytes (key, len);
- }
-
public object Create (object parent, object context, XmlNode section)
{
if (section.HasChildNodes)
@@ -92,25 +44,30 @@ namespace System.Web.Configuration
MachineKeyConfig config = new MachineKeyConfig (parent);
- string validationKey = AttValue ("validationKey", section);
try {
- config.ValidationKey = MakeKey (validationKey);
+ config.SetValidationKey (AttValue ("validationKey", section));
} catch (ArgumentException e) {
ThrowException (e.Message, section);
}
- string decryptionKey = AttValue ("decryptionKey", section);
try {
- config.DecryptionKey = MakeKey (decryptionKey);
+ config.SetDecryptionKey (AttValue ("decryptionKey", section));
} catch (ArgumentException e) {
ThrowException (e.Message, section);
}
string validation = AttValue ("validation", section);
- if (validation != "SHA1" && validation != "MD5" && validation != "3DES")
+ MachineKeyValidation valid = 0;
+ if (validation == "SHA1")
+ valid = MachineKeyValidation.SHA1;
+ else if (validation == "MD5")
+ valid = MachineKeyValidation.MD5;
+ else if (validation == "TripleDES")
+ valid = MachineKeyValidation.TripleDES;
+ else
ThrowException ("Invalid 'validation' value", section);
- config.ValidationType = validation;
+ config.ValidationType = valid;
if (section.Attributes != null && section.Attributes.Count != 0)
ThrowException ("Unrecognized attribute", section);
diff --git a/mcs/class/System.Web/System.Web.Configuration/MachineKeyValidation.cs b/mcs/class/System.Web/System.Web.Configuration/MachineKeyValidation.cs
index 101c2fd1d5e..a7b75150edb 100644
--- a/mcs/class/System.Web/System.Web.Configuration/MachineKeyValidation.cs
+++ b/mcs/class/System.Web/System.Web.Configuration/MachineKeyValidation.cs
@@ -28,14 +28,19 @@
using System.Resources;
-#if NET_2_0
namespace System.Web.Configuration
{
- public enum MachineKeyValidation
- {
- MD5 = 0,
- SHA1 = 1,
- TripleDES = 2,
- }
-}
+#if NET_2_0
+ public
+#else
+ internal
#endif
+ enum MachineKeyValidation
+ {
+ MD5 = 0,
+ SHA1 = 1,
+ TripleDES = 2,
+ AES = 3
+ }
+}
+