summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-07-24 12:21:21 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-07-24 12:21:21 -0700
commit8b6684df4bd03851bd45a343d0018a08fa7188de (patch)
tree4bff13a307d33ef2b3188a5909d2a0a2c2222897 /src
parentbd790bad7767d113de4dcb2a8c64fbdfd1a30f00 (diff)
downloadDotNetOpenAuth-8b6684df4bd03851bd45a343d0018a08fa7188de.zip
DotNetOpenAuth-8b6684df4bd03851bd45a343d0018a08fa7188de.tar.gz
DotNetOpenAuth-8b6684df4bd03851bd45a343d0018a08fa7188de.tar.bz2
Fixed the way we convert DateTimes to the zone we expect.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs4
-rw-r--r--src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs2
-rw-r--r--src/DotNetOpenAuth/Messaging/MessagingUtilities.cs24
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/TokenHandlingBindingElement.cs4
-rw-r--r--src/DotNetOpenAuth/OpenId/Association.cs2
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/DateTimeEncoder.cs3
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs2
-rw-r--r--src/DotNetOpenAuth/OpenId/Messages/IndirectSignedResponse.cs2
8 files changed, 34 insertions, 9 deletions
diff --git a/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs b/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs
index 1d4d28e..3d624a6 100644
--- a/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs
+++ b/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs
@@ -73,7 +73,7 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// <see cref="StandardExpirationBindingElement.MaximumMessageAge"/> property.
/// </remarks>
public bool StoreNonce(string context, string nonce, DateTime timestamp) {
- if (timestamp.ToUniversalTime() + this.maximumMessageAge < DateTime.UtcNow) {
+ if (timestamp.ToUniversalTimeSafe() + this.maximumMessageAge < DateTime.UtcNow) {
// The expiration binding element should have taken care of this, but perhaps
// it's at the boundary case. We should fail just to be safe.
return false;
@@ -115,7 +115,7 @@ namespace DotNetOpenAuth.Messaging.Bindings {
/// </summary>
public void ClearExpiredNonces() {
lock (this.nonceLock) {
- var oldNonceLists = this.usedNonces.Keys.Where(time => time.ToUniversalTime() + this.maximumMessageAge < DateTime.UtcNow).ToList();
+ var oldNonceLists = this.usedNonces.Keys.Where(time => time.ToUniversalTimeSafe() + this.maximumMessageAge < DateTime.UtcNow).ToList();
foreach (DateTime time in oldNonceLists) {
this.usedNonces.Remove(time);
}
diff --git a/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs
index 5fcf4bd..7b00e34 100644
--- a/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs
+++ b/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs
@@ -87,7 +87,7 @@ namespace DotNetOpenAuth.Messaging.Bindings {
if (expiringMessage != null) {
// Yes the UtcCreationDate is supposed to always be in UTC already,
// but just in case a given message failed to guarantee that, we do it here.
- DateTime expirationDate = expiringMessage.UtcCreationDate.ToUniversalTime() + MaximumMessageAge;
+ DateTime expirationDate = expiringMessage.UtcCreationDate.ToUniversalTimeSafe() + MaximumMessageAge;
if (expirationDate < DateTime.UtcNow) {
throw new ExpiredMessageException(expirationDate, expiringMessage);
}
diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
index b5d535c..d696711 100644
--- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
@@ -776,6 +776,30 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
+ /// Ensures that UTC times are converted to local times. Unspecified kinds are unchanged.
+ /// </summary>
+ /// <returns>Local time.</returns>
+ internal static DateTime ToLocalTimeSafe(this DateTime value) {
+ if (value.Kind == DateTimeKind.Unspecified) {
+ return value;
+ }
+
+ return value.ToLocalTime();
+ }
+
+ /// <summary>
+ /// Ensures that local times are converted to UTC times. Unspecified kinds are unchanged.
+ /// </summary>
+ /// <returns>UTC time.</returns>
+ internal static DateTime ToUniversalTimeSafe(this DateTime value) {
+ if (value.Kind == DateTimeKind.Unspecified) {
+ return value;
+ }
+
+ return value.ToUniversalTime();
+ }
+
+ /// <summary>
/// A class to convert a <see cref="Comparison&lt;T&gt;"/> into an <see cref="IComparer&lt;T&gt;"/>.
/// </summary>
/// <typeparam name="T">The type of objects being compared.</typeparam>
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/TokenHandlingBindingElement.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/TokenHandlingBindingElement.cs
index ce7bb98..0f755a6 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/TokenHandlingBindingElement.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/TokenHandlingBindingElement.cs
@@ -146,7 +146,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
try {
IServiceProviderAccessToken token = this.tokenManager.GetAccessToken(message.AccessToken);
- if (token.ExpirationDate.HasValue && DateTime.Now >= token.ExpirationDate.Value.ToLocalTime()) {
+ if (token.ExpirationDate.HasValue && DateTime.Now >= token.ExpirationDate.Value.ToLocalTimeSafe()) {
Logger.OAuth.ErrorFormat(
"OAuth access token {0} rejected because it expired at {1}, and it is now {2}.",
token.Token,
@@ -173,7 +173,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
try {
IServiceProviderRequestToken token = this.tokenManager.GetRequestToken(message.Token);
TimeSpan ttl = DotNetOpenAuthSection.Configuration.OAuth.ServiceProvider.SecuritySettings.MaximumRequestTokenTimeToLive;
- if (DateTime.Now >= token.CreatedOn.ToLocalTime() + ttl) {
+ if (DateTime.Now >= token.CreatedOn.ToLocalTimeSafe() + ttl) {
Logger.OAuth.ErrorFormat(
"OAuth request token {0} rejected because it was originally issued at {1}, expired at {2}, and it is now {3}.",
token.Token,
diff --git a/src/DotNetOpenAuth/OpenId/Association.cs b/src/DotNetOpenAuth/OpenId/Association.cs
index eb7c880..ce129bb 100644
--- a/src/DotNetOpenAuth/OpenId/Association.cs
+++ b/src/DotNetOpenAuth/OpenId/Association.cs
@@ -149,7 +149,7 @@ namespace DotNetOpenAuth.OpenId {
if (privateData == null) {
throw new ArgumentNullException("privateData");
}
- expires = expires.ToUniversalTime();
+ expires = expires.ToUniversalTimeSafe();
TimeSpan remainingLifeLength = expires - DateTime.UtcNow;
byte[] secret = privateData; // the whole of privateData is the secret key for now.
// We figure out what derived type to instantiate based on the length of the secret.
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/DateTimeEncoder.cs b/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/DateTimeEncoder.cs
index 82297d0..9dc0574 100644
--- a/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/DateTimeEncoder.cs
+++ b/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/DateTimeEncoder.cs
@@ -7,6 +7,7 @@
namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy {
using System;
using System.Globalization;
+ using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Reflection;
/// <summary>
@@ -39,7 +40,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy {
public string Encode(object value) {
DateTime? dateTime = value as DateTime?;
if (dateTime.HasValue) {
- return dateTime.Value.ToUniversalTime().ToString(PermissibleDateTimeFormats[0], CultureInfo.InvariantCulture);
+ return dateTime.Value.ToUniversalTimeSafe().ToString(PermissibleDateTimeFormats[0], CultureInfo.InvariantCulture);
} else {
return null;
}
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs b/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs
index 4b2bcc9..b476cf7 100644
--- a/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs
+++ b/src/DotNetOpenAuth/OpenId/Extensions/ProviderAuthenticationPolicy/PolicyResponse.cs
@@ -90,7 +90,7 @@ namespace DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy {
// Convert to UTC and cut to the second, since the protocol only allows for
// that level of precision.
- this.authenticationTimeUtc = OpenIdUtilities.CutToSecond(value.Value.ToUniversalTime());
+ this.authenticationTimeUtc = OpenIdUtilities.CutToSecond(value.Value.ToUniversalTimeSafe());
} else {
this.authenticationTimeUtc = null;
}
diff --git a/src/DotNetOpenAuth/OpenId/Messages/IndirectSignedResponse.cs b/src/DotNetOpenAuth/OpenId/Messages/IndirectSignedResponse.cs
index 0d105ad..9462d21 100644
--- a/src/DotNetOpenAuth/OpenId/Messages/IndirectSignedResponse.cs
+++ b/src/DotNetOpenAuth/OpenId/Messages/IndirectSignedResponse.cs
@@ -201,7 +201,7 @@ namespace DotNetOpenAuth.OpenId.Messages {
/// </exception>
DateTime IExpiringProtocolMessage.UtcCreationDate {
get { return this.creationDateUtc; }
- set { this.creationDateUtc = value.ToUniversalTime(); }
+ set { this.creationDateUtc = value.ToUniversalTimeSafe(); }
}
/// <summary>