//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging.Bindings {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
///
/// A persistent store for rotating symmetric cryptographic keys.
///
///
/// Implementations should persist it in such a way that the keys are shared across all servers
/// on a web farm, where applicable.
/// The store should consider protecting the persistent store against theft resulting in the loss
/// of the confidentiality of the keys. One possible mitigation is to asymmetrically encrypt
/// each key using a certificate installed in the server's certificate store.
///
[ContractClass(typeof(ICryptoKeyStoreContract))]
public interface ICryptoKeyStore {
///
/// 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.
CryptoKey GetKey(string bucket, string 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 .
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "Important for scalability")]
IEnumerable> GetKeys(string 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.
void StoreKey(string bucket, string handle, CryptoKey key);
///
/// Removes the key.
///
/// The bucket name. Case sensitive.
/// The key handle. Case sensitive.
void RemoveKey(string bucket, string handle);
}
///
/// Code contract for the interface.
///
[ContractClassFor(typeof(ICryptoKeyStore))]
internal abstract class ICryptoKeyStoreContract : ICryptoKeyStore {
///
/// 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.
///
CryptoKey ICryptoKeyStore.GetKey(string bucket, string handle) {
Requires.NotNullOrEmpty(bucket, "bucket");
Requires.NotNullOrEmpty(handle, "handle");
throw new NotImplementedException();
}
///
/// Gets a sequence of existing keys within a given bucket.
///
/// The bucket name. Case sensitive.
///
/// A sequence of handles and keys, ordered by descending .
///
IEnumerable> ICryptoKeyStore.GetKeys(string bucket) {
Requires.NotNullOrEmpty(bucket, "bucket");
Contract.Ensures(Contract.Result>>() != null);
throw new NotImplementedException();
}
///
/// 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.
void ICryptoKeyStore.StoreKey(string bucket, string handle, CryptoKey key) {
Requires.NotNullOrEmpty(bucket, "bucket");
Requires.NotNullOrEmpty(handle, "handle");
Requires.NotNull(key, "key");
throw new NotImplementedException();
}
///
/// Removes the key.
///
/// The bucket name. Case sensitive.
/// The key handle. Case sensitive.
void ICryptoKeyStore.RemoveKey(string bucket, string handle) {
Requires.NotNullOrEmpty(bucket, "bucket");
Requires.NotNullOrEmpty(handle, "handle");
throw new NotImplementedException();
}
}
}