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
diff options
context:
space:
mode:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2005-07-26 18:50:10 +0400
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2005-07-26 18:50:10 +0400
commitb0b51607e6b747f7d94f8dc4e0dffc815c837400 (patch)
treeafd4cc922d71cb7cc40d02cd6dacc23477f2632c
parentdb8b68eb75dd8a1773ea380c5ab299ecb96a02e8 (diff)
forms cookie from HEAD
svn path=/branches/mono-1-1-7/mcs/; revision=47703
-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
-rw-r--r--mcs/class/System.Web/System.Web.Security/ChangeLog23
-rw-r--r--mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs158
-rw-r--r--mcs/class/System.Web/System.Web.Security/FormsAuthenticationTicket.cs172
7 files changed, 381 insertions, 190 deletions
diff --git a/mcs/class/System.Web/System.Web.Configuration/ChangeLog b/mcs/class/System.Web/System.Web.Configuration/ChangeLog
index 3e12533e5a7..54430bfd29b 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-04-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* CompilerCollection.cs: added CompareLanguages method.
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
+ }
+}
+
diff --git a/mcs/class/System.Web/System.Web.Security/ChangeLog b/mcs/class/System.Web/System.Web.Security/ChangeLog
index 64924f5cf60..2b9b7b28567 100644
--- a/mcs/class/System.Web/System.Web.Security/ChangeLog
+++ b/mcs/class/System.Web/System.Web.Security/ChangeLog
@@ -1,3 +1,26 @@
+2005-07-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * FormsAuthentication.cs: the init_vector must be the same accross
+ restarts, otherwise the cookie does not work even when a decryption
+ key is provided. Initialize it to the bytes of the cookie name. Fixes
+ bug #75635.
+
+2005-07-25 Eyal Alaluf <eyala@mainsoft.com>
+
+ * FormsAuthenticationModule.cs: Check for null config
+
+2005-07-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * FormsAuthentication.cs: my previous patch missed a "small" detail: it
+ didn't include the verification key when computing/checking the
+ validation hash. Now this is really a MAC or HMAC or...
+
+2005-07-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * FormsAuthentication.cs:
+ * FormsAuthenticationTicket.cs: added support for validation and
+ encryption of the auth. cookie and improved serialization of the ticket.
+
2005-04-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* FormsAuthentication.cs:
diff --git a/mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs b/mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs
index 2bd716f0ef7..0bb04b34e17 100644
--- a/mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs
+++ b/mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs
@@ -5,6 +5,7 @@
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
+// Copyright (c) 2005 Novell, Inc (http://www.novell.com)
//
//
@@ -41,13 +42,17 @@ namespace System.Web.Security
{
public sealed class FormsAuthentication
{
+ const int MD5_hash_size = 16;
+ const int SHA1_hash_size = 20;
+
static string authConfigPath = "system.web/authentication";
static bool initialized;
static string cookieName;
static string cookiePath;
static int timeout;
- //static FormsProtectionEnum protection;
+ static FormsProtectionEnum protection;
static object locker = new object ();
+ static byte [] init_vector; // initialization vector used for 3DES
#if NET_1_1
static bool requireSSL;
static bool slidingExpiration;
@@ -91,28 +96,71 @@ namespace System.Web.Security
return (password == stored);
}
+ static FormsAuthenticationTicket Decrypt2 (byte [] bytes)
+ {
+ if (protection == FormsProtectionEnum.None)
+ return FormsAuthenticationTicket.FromByteArray (bytes);
+
+ MachineKeyConfig config = HttpContext.GetAppConfig ("system.web/machineKey") as MachineKeyConfig;
+ bool all = (protection == FormsProtectionEnum.All);
+
+ byte [] result = bytes;
+ if (all || protection == FormsProtectionEnum.Encryption) {
+ ICryptoTransform decryptor;
+ decryptor = new TripleDESCryptoServiceProvider().CreateDecryptor (config.DecryptionKey192Bits, init_vector);
+ result = decryptor.TransformFinalBlock (bytes, 0, bytes.Length);
+ bytes = null;
+ }
+
+ if (all || protection == FormsProtectionEnum.Validation) {
+ int count;
+
+ if (config.ValidationType == MachineKeyValidation.MD5)
+ count = MD5_hash_size;
+ else
+ count = SHA1_hash_size; // 3DES and SHA1
+
+ byte [] vk = config.ValidationKey;
+ byte [] mix = new byte [result.Length - count + vk.Length];
+ Buffer.BlockCopy (result, 0, mix, 0, result.Length - count);
+ Buffer.BlockCopy (vk, 0, mix, result.Length - count, vk.Length);
+
+ byte [] hash = null;
+ switch (config.ValidationType) {
+ case MachineKeyValidation.MD5:
+ hash = MD5.Create ().ComputeHash (mix);
+ break;
+ // From MS docs: "When 3DES is specified, forms authentication defaults to SHA1"
+ case MachineKeyValidation.TripleDES:
+ case MachineKeyValidation.SHA1:
+ hash = SHA1.Create ().ComputeHash (mix);
+ break;
+ }
+
+ if (result.Length < count)
+ throw new ArgumentException ("Error validating ticket (length).", "encryptedTicket");
+
+ int i, k;
+ for (i = result.Length - count, k = 0; k < count; i++, k++) {
+ if (result [i] != hash [k])
+ throw new ArgumentException ("Error validating ticket.", "encryptedTicket");
+ }
+ }
+
+ return FormsAuthenticationTicket.FromByteArray (result);
+ }
+
public static FormsAuthenticationTicket Decrypt (string encryptedTicket)
{
if (encryptedTicket == null || encryptedTicket == String.Empty)
throw new ArgumentException ("Invalid encrypted ticket", "encryptedTicket");
Initialize ();
- byte [] bytes = MachineKeyConfigHandler.GetBytes (encryptedTicket, encryptedTicket.Length);
- string decrypted = Encoding.ASCII.GetString (bytes);
- FormsAuthenticationTicket ticket = null;
+
+ FormsAuthenticationTicket ticket;
+ byte [] bytes = MachineKeyConfig.GetBytes (encryptedTicket, encryptedTicket.Length);
try {
- string [] values = decrypted.Split ((char) 1, (char) 2, (char) 3, (char) 4, (char) 5, (char) 6, (char) 7);
- if (values.Length != 8)
- throw new Exception (values.Length + " " + encryptedTicket);
-
-
- ticket = new FormsAuthenticationTicket (Int32.Parse (values [0]),
- values [1],
- new DateTime (Int64.Parse (values [2])),
- new DateTime (Int64.Parse (values [3])),
- (values [4] == "1"),
- values [5],
- values [6]);
+ ticket = Decrypt2 (bytes);
} catch (Exception) {
ticket = null;
}
@@ -126,24 +174,45 @@ namespace System.Web.Security
throw new ArgumentNullException ("ticket");
Initialize ();
- StringBuilder allTicket = new StringBuilder ();
- allTicket.Append (ticket.Version);
- allTicket.Append ('\u0001');
- allTicket.Append (ticket.Name);
- allTicket.Append ('\u0002');
- allTicket.Append (ticket.IssueDate.Ticks);
- allTicket.Append ('\u0003');
- allTicket.Append (ticket.Expiration.Ticks);
- allTicket.Append ('\u0004');
- allTicket.Append (ticket.IsPersistent ? '1' : '0');
- allTicket.Append ('\u0005');
- allTicket.Append (ticket.UserData);
- allTicket.Append ('\u0006');
- allTicket.Append (ticket.CookiePath);
- allTicket.Append ('\u0007');
- //if (protection == FormsProtectionEnum.None)
- return GetHexString (allTicket.ToString ());
- //TODO: encrypt and validate
+ byte [] ticket_bytes = ticket.ToByteArray ();
+ if (protection == FormsProtectionEnum.None)
+ return GetHexString (ticket_bytes);
+
+ byte [] result = ticket_bytes;
+ MachineKeyConfig config = HttpContext.GetAppConfig ("system.web/machineKey") as MachineKeyConfig;
+ bool all = (protection == FormsProtectionEnum.All);
+ if (all || protection == FormsProtectionEnum.Validation) {
+ byte [] valid_bytes = null;
+ byte [] vk = config.ValidationKey;
+ byte [] mix = new byte [ticket_bytes.Length + vk.Length];
+ Buffer.BlockCopy (ticket_bytes, 0, mix, 0, ticket_bytes.Length);
+ Buffer.BlockCopy (vk, 0, mix, result.Length, vk.Length);
+
+ switch (config.ValidationType) {
+ case MachineKeyValidation.MD5:
+ valid_bytes = MD5.Create ().ComputeHash (mix);
+ break;
+ // From MS docs: "When 3DES is specified, forms authentication defaults to SHA1"
+ case MachineKeyValidation.TripleDES:
+ case MachineKeyValidation.SHA1:
+ valid_bytes = SHA1.Create ().ComputeHash (mix);
+ break;
+ }
+
+ int tlen = ticket_bytes.Length;
+ int vlen = valid_bytes.Length;
+ result = new byte [tlen + vlen];
+ Buffer.BlockCopy (ticket_bytes, 0, result, 0, tlen);
+ Buffer.BlockCopy (valid_bytes, 0, result, tlen, vlen);
+ }
+
+ if (all || protection == FormsProtectionEnum.Encryption) {
+ ICryptoTransform encryptor;
+ encryptor = new TripleDESCryptoServiceProvider().CreateEncryptor (config.DecryptionKey192Bits, init_vector);
+ result = encryptor.TransformFinalBlock (result, 0, result.Length);
+ }
+
+ return GetHexString (result);
}
public static HttpCookie GetAuthCookie (string userName, bool createPersistentCookie)
@@ -187,7 +256,6 @@ namespace System.Web.Security
if (userName == null)
return null;
- //TODO: what's createPersistentCookie used for?
Initialize ();
HttpRequest request = HttpContext.Current.Request;
string returnUrl = request ["RETURNURL"];
@@ -215,7 +283,7 @@ namespace System.Web.Security
static string GetHexString (string str)
{
- return GetHexString (Encoding.ASCII.GetBytes (str));
+ return GetHexString (Encoding.UTF8.GetBytes (str));
}
static string GetHexString (byte [] bytes)
@@ -237,9 +305,9 @@ namespace System.Web.Security
byte [] bytes;
if (String.Compare (passwordFormat, "MD5", true) == 0) {
- bytes = MD5.Create ().ComputeHash (Encoding.ASCII.GetBytes (password));
+ bytes = MD5.Create ().ComputeHash (Encoding.UTF8.GetBytes (password));
} else if (String.Compare (passwordFormat, "SHA1", true) == 0) {
- bytes = SHA1.Create ().ComputeHash (Encoding.ASCII.GetBytes (password));
+ bytes = SHA1.Create ().ComputeHash (Encoding.UTF8.GetBytes (password));
} else {
throw new ArgumentException ("The format must be either MD5 or SHA1", "passwordFormat");
}
@@ -265,7 +333,7 @@ namespace System.Web.Security
cookieName = authConfig.CookieName;
timeout = authConfig.Timeout;
cookiePath = authConfig.CookiePath;
- //protection = authConfig.Protection;
+ protection = authConfig.Protection;
#if NET_1_1
requireSSL = authConfig.RequireSSL;
slidingExpiration = authConfig.SlidingExpiration;
@@ -274,12 +342,22 @@ namespace System.Web.Security
cookieName = ".MONOAUTH";
timeout = 30;
cookiePath = "/";
- //protection = FormsProtectionEnum.All;
+ protection = FormsProtectionEnum.All;
#if NET_1_1
slidingExpiration = true;
#endif
}
+ // IV is 8 bytes long for 3DES
+ init_vector = new byte [8];
+ int len = cookieName.Length;
+ for (int i = 0; i < 8; i++) {
+ if (i >= len)
+ break;
+
+ init_vector [i] = (byte) cookieName [i];
+ }
+
initialized = true;
}
}
diff --git a/mcs/class/System.Web/System.Web.Security/FormsAuthenticationTicket.cs b/mcs/class/System.Web/System.Web.Security/FormsAuthenticationTicket.cs
index a2036f737df..cb108d98c40 100644
--- a/mcs/class/System.Web/System.Web.Security/FormsAuthenticationTicket.cs
+++ b/mcs/class/System.Web/System.Web.Security/FormsAuthenticationTicket.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)
//
//
@@ -29,6 +30,7 @@
//
using System;
+using System.IO;
namespace System.Web.Security
{
@@ -36,12 +38,74 @@ namespace System.Web.Security
public sealed class FormsAuthenticationTicket
{
int version;
- string name;
- DateTime issueDate;
+ bool persistent;
+ DateTime issue_date;
DateTime expiration;
- bool isPersistent;
- string userData;
- string cookiePath;
+ string name;
+ string cookie_path;
+ string user_data;
+
+ /*
+ internal void ToStr ()
+ {
+ Console.WriteLine ("version: {0}", version);
+ Console.WriteLine ("persistent: {0}", persistent);
+ Console.WriteLine ("issue_date: {0}", issue_date);
+ Console.WriteLine ("expiration: {0}", expiration);
+ Console.WriteLine ("name: {0}", name);
+ Console.WriteLine ("cookie_path: {0}", cookie_path);
+ Console.WriteLine ("user_data: {0}", user_data);
+ }
+ */
+
+ internal byte [] ToByteArray ()
+ {
+ MemoryStream ms = new MemoryStream ();
+ BinaryWriter writer = new BinaryWriter (ms);
+ writer.Write (version);
+ writer.Write (persistent);
+ writer.Write (issue_date.Ticks);
+ writer.Write (expiration.Ticks);
+ writer.Write (name != null);
+ if (name != null)
+ writer.Write (name);
+
+ writer.Write (cookie_path != null);
+ if (cookie_path != null)
+ writer.Write (cookie_path);
+
+ writer.Write (user_data != null);
+ if (user_data != null)
+ writer.Write (user_data);
+
+ writer.Flush ();
+ return ms.ToArray ();
+ }
+
+ internal static FormsAuthenticationTicket FromByteArray (byte [] bytes)
+ {
+ MemoryStream ms = new MemoryStream (bytes);
+ BinaryReader reader = new BinaryReader (ms);
+ FormsAuthenticationTicket ticket = new FormsAuthenticationTicket ();
+ ticket.version = reader.ReadInt32 ();
+ ticket.persistent = reader.ReadBoolean ();
+ ticket.issue_date = new DateTime (reader.ReadInt64 ());
+ ticket.expiration = new DateTime (reader.ReadInt64 ());
+ if (reader.ReadBoolean ())
+ ticket.name = reader.ReadString ();
+
+ if (reader.ReadBoolean ())
+ ticket.cookie_path = reader.ReadString ();
+
+ if (reader.ReadBoolean ())
+ ticket.user_data = reader.ReadString ();
+
+ return ticket;
+ }
+
+ private FormsAuthenticationTicket ()
+ {
+ }
public FormsAuthenticationTicket (int version,
string name,
@@ -52,11 +116,11 @@ namespace System.Web.Security
{
this.version = version;
this.name = name;
- this.issueDate = issueDate;
+ this.issue_date = issueDate;
this.expiration = expiration;
- this.isPersistent = isPersistent;
- this.userData = userData;
- this.cookiePath = "/";
+ this.persistent = isPersistent;
+ this.user_data = userData;
+ this.cookie_path = "/";
}
public FormsAuthenticationTicket (int version,
@@ -69,31 +133,31 @@ namespace System.Web.Security
{
this.version = version;
this.name = name;
- this.issueDate = issueDate;
+ this.issue_date = issueDate;
this.expiration = expiration;
- this.isPersistent = isPersistent;
- this.userData = userData;
- this.cookiePath = cookiePath;
+ this.persistent = isPersistent;
+ this.user_data = userData;
+ this.cookie_path = cookiePath;
}
public FormsAuthenticationTicket (string name, bool isPersistent, int timeout)
{
this.version = 1;
this.name = name;
- this.issueDate = DateTime.Now;
- this.isPersistent = isPersistent;
- if (isPersistent)
- expiration = issueDate.AddYears (50);
+ this.issue_date = DateTime.Now;
+ this.persistent = isPersistent;
+ if (persistent)
+ expiration = issue_date.AddYears (50);
else
- expiration = issueDate.AddMinutes ((double) timeout);
+ expiration = issue_date.AddMinutes ((double) timeout);
- this.userData = String.Empty;
- this.cookiePath = "/";
+ this.user_data = "";
+ this.cookie_path = "/";
}
- internal void SetDates (DateTime issueDate, DateTime expiration)
+ internal void SetDates (DateTime issue_date, DateTime expiration)
{
- this.issueDate = issueDate;
+ this.issue_date = issue_date;
this.expiration = expiration;
}
@@ -101,67 +165,43 @@ namespace System.Web.Security
{
return new FormsAuthenticationTicket (version,
name,
- issueDate,
+ issue_date,
expiration,
- isPersistent,
- userData,
- cookiePath);
+ persistent,
+ user_data,
+ cookie_path);
}
- public string CookiePath
- {
- get {
- return cookiePath;
- }
+ public string CookiePath {
+ get { return cookie_path; }
}
- public DateTime Expiration
- {
- get {
- return expiration;
- }
+ public DateTime Expiration {
+ get { return expiration; }
}
- public bool Expired
- {
- get {
- return DateTime.Now > expiration;
- }
+ public bool Expired {
+ get { return DateTime.Now > expiration; }
}
- public bool IsPersistent
- {
- get {
- return isPersistent;
- }
+ public bool IsPersistent {
+ get { return persistent; }
}
- public DateTime IssueDate
- {
- get {
- return issueDate;
- }
+ public DateTime IssueDate {
+ get { return issue_date; }
}
- public string Name
- {
- get {
- return name;
- }
+ public string Name {
+ get { return name; }
}
- public string UserData
- {
- get {
- return userData;
- }
+ public string UserData {
+ get { return user_data; }
}
- public int Version
- {
- get {
- return version;
- }
+ public int Version {
+ get { return version; }
}
}
}