0
@@ -5,19 +5,28 @@ using System.Text;
0
using System.Security.Cryptography;
0
using DotNetOpenId.Store;
0
using System.Collections.Generic;
0
+using IProviderAssociationStore = DotNetOpenId.Store.IAssociationStore<DotNetOpenId.Store.AssociationConsumerType>;
0
namespace DotNetOpenId.Provider {
0
internal class Signatory {
0
- static readonly TimeSpan associationLifetime = TimeSpan.FromDays(14);
0
- static readonly Uri _normal_key = new Uri("http://localhost/|normal");
0
- static readonly Uri _dumb_key = new Uri("http://localhost/|dumb");
0
- IAssociationStore store;
0
- public Signatory(IAssociationStore store) {
0
+ /// The duration any association and secret key the Provider generates will be good for.
0
+ static readonly TimeSpan smartAssociationLifetime = TimeSpan.FromDays(14);
0
+ /// The duration a secret key used for signing dumb client requests will be good for.
0
+ static readonly TimeSpan dumbSecretLifetime = TimeSpan.FromMinutes(5);
0
+ /// The store for shared secrets.
0
+ IProviderAssociationStore store;
0
+ public Signatory(IProviderAssociationStore store) {
0
throw new ArgumentNullException("store");
0
@@ -35,7 +44,7 @@ namespace DotNetOpenId.Provider {
0
string assoc_handle = ((AssociatedRequest)response.Request).AssociationHandle;
0
if (!string.IsNullOrEmpty(assoc_handle)) {
0
- assoc = this.GetAssociation(assoc_handle,
false);
0
+ assoc = this.GetAssociation(assoc_handle,
AssociationConsumerType.Smart);
0
@@ -45,7 +54,7 @@ namespace DotNetOpenId.Provider {
0
response.Fields[QueryStringArgs.openidnp.invalidate_handle] = assoc_handle;
0
- assoc = this.CreateAssociation(
true);
0
+ assoc = this.CreateAssociation(
AssociationConsumerType.Dumb);
0
if (TraceUtil.Switch.TraceInfo) {
0
@@ -54,7 +63,7 @@ namespace DotNetOpenId.Provider {
0
- assoc = this.CreateAssociation(
true);
0
+ assoc = this.CreateAssociation(
AssociationConsumerType.Dumb);
0
TraceUtil.ServerTrace(String.Format("No assoc_handle supplied. Creating new association."));
0
@@ -79,7 +88,7 @@ namespace DotNetOpenId.Provider {
0
- Association assoc = this.GetAssociation(assoc_handle,
true);
0
+ Association assoc = this.GetAssociation(assoc_handle,
AssociationConsumerType.Dumb);
0
@@ -126,9 +135,10 @@ namespace DotNetOpenId.Provider {
0
return expected_sig.Equals(signature, StringComparison.OrdinalIgnoreCase);
0
- public virtual Association CreateAssociation(
bool dumb) {
0
+ public virtual Association CreateAssociation(
AssociationConsumerType associationType) {
0
if (TraceUtil.Switch.TraceInfo) {
0
- TraceUtil.ServerTrace(String.Format("Start Create Association. InDumbMode = {0}", dumb));
0
+ TraceUtil.ServerTrace(String.Format("Start Create Association. Association type = {0}",
0
RNGCryptoServiceProvider generator = new RNGCryptoServiceProvider();
0
@@ -147,19 +157,19 @@ namespace DotNetOpenId.Provider {
0
handle = "{{HMAC-SHA1}{" + seconds + "}{" + uniq + "}";
0
- assoc = new HmacSha1Association(handle, secret, associationLifetime);
0
+ assoc = new HmacSha1Association(handle, secret,
0
+ associationType == AssociationConsumerType.Dumb ? dumbSecretLifetime : smartAssociationLifetime);
0
- Uri key = dumb ? _dumb_key : _normal_key;
0
- store.StoreAssociation(key, assoc);
0
+ store.StoreAssociation(associationType, assoc);
0
if (TraceUtil.Switch.TraceInfo) {
0
- TraceUtil.ServerTrace(String.Format("End Create Association. Association successfully created. key = '{0}', handle = '{1}' ",
key, handle));
0
+ TraceUtil.ServerTrace(String.Format("End Create Association. Association successfully created. key = '{0}', handle = '{1}' ",
associationType, handle));
0
- public virtual Association GetAssociation(string assoc_handle,
bool dumb) {
0
+ public virtual Association GetAssociation(string assoc_handle,
AssociationConsumerType associationType) {
0
if (TraceUtil.Switch.TraceInfo) {
0
TraceUtil.ServerTrace(String.Format("Start get association from store '{0}'.", assoc_handle));
0
@@ -168,11 +178,10 @@ namespace DotNetOpenId.Provider {
0
if (assoc_handle == null)
0
throw new ArgumentNullException(QueryStringArgs.openidnp.assoc_handle);
0
- Uri key = dumb ? _dumb_key : _normal_key;
0
- Association assoc = store.GetAssociation(key, assoc_handle);
0
+ Association assoc = store.GetAssociation(associationType, assoc_handle);
0
if (assoc == null || assoc.IsExpired) {
0
TraceUtil.ServerTrace("Association expired or not in store. Trying to remove association if it still exists.");
0
- store.RemoveAssociation(
key, assoc_handle);
0
+ store.RemoveAssociation(
associationType, assoc_handle);
0
@@ -183,13 +192,12 @@ namespace DotNetOpenId.Provider {
0
- public virtual void Invalidate(string assoc_handle,
bool dumb) {
0
+ public virtual void Invalidate(string assoc_handle,
AssociationConsumerType associationType) {
0
if (TraceUtil.Switch.TraceInfo) {
0
TraceUtil.ServerTrace(String.Format("Start invalidate association '{0}'.", assoc_handle));
0
- Uri key = dumb ? _dumb_key : _normal_key;
0
- store.RemoveAssociation(key, assoc_handle);
0
+ store.RemoveAssociation(associationType, assoc_handle);
0
if (TraceUtil.Switch.TraceInfo) {
0
TraceUtil.ServerTrace(String.Format("End invalidate association '{0}'.", assoc_handle));