//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.RelyingParty { using System; using System.Collections.Generic; using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.OpenId.ChannelElements; /// /// An in-memory store for Relying Parties, suitable for single server, single process /// ASP.NET web sites. /// public class StandardRelyingPartyApplicationStore : IOpenIdApplicationStore { /// /// The nonce store to use. /// private readonly INonceStore nonceStore; /// /// The association store to use. /// private readonly ICryptoKeyStore keyStore; /// /// Initializes a new instance of the class. /// public StandardRelyingPartyApplicationStore() { this.nonceStore = new NonceMemoryStore(OpenIdElement.Configuration.MaxAuthenticationTime); this.keyStore = new MemoryCryptoKeyStore(); } #region ICryptoKeyStore Members /// /// Gets the key in a given bucket and handle. /// /// The bucket name. Case sensitive. /// The key handle. Case sensitive. /// /// The cryptographic key, or null if no matching key was found. /// public CryptoKey GetKey(string bucket, string handle) { return this.keyStore.GetKey(bucket, handle); } /// /// Gets a sequence of existing keys within a given bucket. /// /// The bucket name. Case sensitive. /// /// A sequence of handles and keys, ordered by descending . /// public IEnumerable> GetKeys(string bucket) { return this.keyStore.GetKeys(bucket); } /// /// Stores a cryptographic key. /// /// The name of the bucket to store the key in. Case sensitive. /// The handle to the key, unique within the bucket. Case sensitive. /// The key to store. /// Thrown in the event of a conflict with an existing key in the same bucket and with the same handle. public void StoreKey(string bucket, string handle, CryptoKey key) { this.keyStore.StoreKey(bucket, handle, key); } /// /// Removes the key. /// /// The bucket name. Case sensitive. /// The key handle. Case sensitive. public void RemoveKey(string bucket, string handle) { this.keyStore.RemoveKey(bucket, handle); } #endregion #region INonceStore Members /// /// Stores a given nonce and timestamp. /// /// The context, or namespace, within which the must be unique. /// A series of random characters. /// The timestamp that together with the nonce string make it unique. /// The timestamp may also be used by the data store to clear out old nonces. /// /// True if the nonce+timestamp (combination) was not previously in the database. /// False if the nonce was stored previously with the same timestamp. /// /// /// The nonce must be stored for no less than the maximum time window a message may /// be processed within before being discarded as an expired message. /// If the binding element is applicable to your channel, this expiration window /// is retrieved or set using the /// property. /// public bool StoreNonce(string context, string nonce, DateTime timestampUtc) { return this.nonceStore.StoreNonce(context, nonce, timestampUtc); } #endregion } }