Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Forced both validation and encryption at all times, rather than making

it configurable.
  • Loading branch information...
commit f500d538eadb0dfcbef99e8eaf354aaa29bdfb37 1 parent 8de1ef4
@mehrdada mehrdada authored
View
8 AppHarbor.Web.Security/ConfigFileAuthenticationConfiguration.cs
@@ -22,14 +22,6 @@ public bool SlidingExpiration
}
}
- public CookieProtection CookieProtection
- {
- get
- {
- return CookieProtection.All;
- }
- }
-
public string LoginUrl
{
get
View
57 AppHarbor.Web.Security/CookieProtector.cs
@@ -11,21 +11,8 @@ public class CookieProtector : IDisposable
public CookieProtector(ICookieAuthenticationConfiguration configuration)
{
- switch (configuration.CookieProtection)
- {
- case CookieProtection.None:
- break;
- case CookieProtection.Encryption:
- _encryption = Encryption.Create(configuration.EncryptionAlgorithm, configuration.EncryptionKey, configuration.EncryptionIV);
- break;
- case CookieProtection.Validation:
- _validation = Validation.Create(configuration.ValidationAlgorithm, configuration.ValidationKey);
- break;
- default:
- _encryption = Encryption.Create(configuration.EncryptionAlgorithm, configuration.EncryptionKey, configuration.EncryptionIV);
- _validation = Validation.Create(configuration.ValidationAlgorithm, configuration.ValidationKey);
- break;
- }
+ _encryption = Encryption.Create(configuration.EncryptionAlgorithm, configuration.EncryptionKey, configuration.EncryptionIV);
+ _validation = Validation.Create(configuration.ValidationAlgorithm, configuration.ValidationKey);
}
public bool Validate(string cookie, out string data)
@@ -56,23 +43,17 @@ public bool Validate(string cookie, out byte[] data)
var cookieData = new byte[versionedCookieData.Length - 1];
Buffer.BlockCopy(versionedCookieData, 1, cookieData, 0, cookieData.Length);
- if (_validation != null)
+ if (_validation.Validate(cookieData))
{
- if (_validation.Validate(cookieData))
- {
- cookieData = _validation.StripSignature(cookieData);
- }
- else
- {
- return false;
- }
+ cookieData = _validation.StripSignature(cookieData);
}
-
- if (_encryption != null)
+ else
{
- cookieData = _encryption.Decrypt(cookieData);
+ return false;
}
+ cookieData = _encryption.Decrypt(cookieData);
+
data = cookieData;
return true;
}
@@ -89,15 +70,8 @@ public string Protect(string data)
public string Protect(byte[] data)
{
- if (_encryption != null)
- {
- data = _encryption.Encrypt(data);
- }
-
- if (_validation != null)
- {
- data = _validation.Sign(data);
- }
+ data = _encryption.Encrypt(data);
+ data = _validation.Sign(data);
var versionedData = new byte[data.Length + 1];
Buffer.BlockCopy(data, 0, versionedData, 1, data.Length);
@@ -106,15 +80,8 @@ public string Protect(byte[] data)
public void Dispose()
{
- if (_encryption != null)
- {
- _encryption.Dispose();
- }
-
- if (_validation != null)
- {
- _validation.Dispose();
- }
+ _encryption.Dispose();
+ _validation.Dispose();
}
}
}
View
1  AppHarbor.Web.Security/ICookieAuthenticationConfiguration.cs
@@ -8,7 +8,6 @@ public interface ICookieAuthenticationConfiguration
string CookieName { get; }
bool SlidingExpiration { get; }
TimeSpan Timeout { get; }
- CookieProtection CookieProtection { get; }
string LoginUrl { get; }
string EncryptionAlgorithm { get; }
byte[] EncryptionKey { get; }
Please sign in to comment.
Something went wrong with that request. Please try again.