summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj1
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Bindings/HardCodedKeyCryptoKeyStore.cs98
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs16
3 files changed, 113 insertions, 2 deletions
diff --git a/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj b/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj
index 88513af..253528b 100644
--- a/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj
+++ b/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj
@@ -27,6 +27,7 @@
<Compile Include="Messaging\Bindings\AsymmetricCryptoKeyStoreWrapper.cs" />
<Compile Include="Messaging\Bindings\CryptoKey.cs" />
<Compile Include="Messaging\Bindings\CryptoKeyCollisionException.cs" />
+ <Compile Include="Messaging\Bindings\HardCodedKeyCryptoKeyStore.cs" />
<Compile Include="Messaging\Bindings\ICryptoKeyStore.cs" />
<Compile Include="Messaging\Bindings\MemoryCryptoKeyStore.cs" />
<Compile Include="Messaging\BinaryDataBagFormatter.cs" />
diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/HardCodedKeyCryptoKeyStore.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/HardCodedKeyCryptoKeyStore.cs
new file mode 100644
index 0000000..c828616
--- /dev/null
+++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/HardCodedKeyCryptoKeyStore.cs
@@ -0,0 +1,98 @@
+//-----------------------------------------------------------------------
+// <copyright file="HardCodedKeyCryptoKeyStore.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Messaging.Bindings {
+ using System;
+ using System.Collections.Generic;
+ using Validation;
+
+ /// <summary>
+ /// A trivial implementation of <see cref="ICryptoKeyStore"/> that has only one fixed key.
+ /// This is meant for simple, low-security applications. Greater security requires an
+ /// implementation of <see cref="ICryptoKeyStore"/> that actually stores and retrieves
+ /// keys from a persistent store.
+ /// </summary>
+ public class HardCodedKeyCryptoKeyStore : ICryptoKeyStore {
+ /// <summary>
+ /// The handle to report for the hard-coded key.
+ /// </summary>
+ private const string HardCodedKeyHandle = "fxd";
+
+ /// <summary>
+ /// The one crypto key singleton instance.
+ /// </summary>
+ private readonly CryptoKey OneCryptoKey;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HardCodedKeyCryptoKeyStore"/> class.
+ /// </summary>
+ /// <param name="secretAsBase64">The 256-bit secret as a base64 encoded string.</param>
+ public HardCodedKeyCryptoKeyStore(string secretAsBase64)
+ : this(Convert.FromBase64String(Requires.NotNull(secretAsBase64, "secretAsBase64"))) {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HardCodedKeyCryptoKeyStore"/> class.
+ /// </summary>
+ /// <param name="secret">The 256-bit secret.</param>
+ public HardCodedKeyCryptoKeyStore(byte[] secret) {
+ Requires.NotNull(secret, "secret");
+ this.OneCryptoKey = new CryptoKey(secret, DateTime.MaxValue.AddDays(-2).ToUniversalTime());
+ }
+
+ #region ICryptoKeyStore Members
+
+ /// <summary>
+ /// Gets the key in a given bucket and handle.
+ /// </summary>
+ /// <param name="bucket">The bucket name. Case sensitive.</param>
+ /// <param name="handle">The key handle. Case sensitive.</param>
+ /// <returns>
+ /// The cryptographic key, or <c>null</c> if no matching key was found.
+ /// </returns>
+ public CryptoKey GetKey(string bucket, string handle) {
+ if (handle == HardCodedKeyHandle) {
+ return OneCryptoKey;
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Gets a sequence of existing keys within a given bucket.
+ /// </summary>
+ /// <param name="bucket">The bucket name. Case sensitive.</param>
+ /// <returns>
+ /// A sequence of handles and keys, ordered by descending <see cref="CryptoKey.ExpiresUtc" />.
+ /// </returns>
+ public IEnumerable<KeyValuePair<string, CryptoKey>> GetKeys(string bucket) {
+ return new[] { new KeyValuePair<string, CryptoKey>(HardCodedKeyHandle, OneCryptoKey) };
+ }
+
+ /// <summary>
+ /// Stores a cryptographic key.
+ /// </summary>
+ /// <param name="bucket">The name of the bucket to store the key in. Case sensitive.</param>
+ /// <param name="handle">The handle to the key, unique within the bucket. Case sensitive.</param>
+ /// <param name="key">The key to store.</param>
+ /// <exception cref="System.NotSupportedException"></exception>
+ public void StoreKey(string bucket, string handle, CryptoKey key) {
+ throw new NotSupportedException();
+ }
+
+ /// <summary>
+ /// Removes the key.
+ /// </summary>
+ /// <param name="bucket">The bucket name. Case sensitive.</param>
+ /// <param name="handle">The key handle. Case sensitive.</param>
+ /// <exception cref="System.NotSupportedException"></exception>
+ public void RemoveKey(string bucket, string handle) {
+ throw new NotSupportedException();
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
index a10e1aa..753148e 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
@@ -22,17 +22,29 @@ namespace DotNetOpenAuth.OAuth2 {
private readonly string secret;
/// <summary>
- /// Initializes a new instance of the <see cref="ClientDescription"/> class.
+ /// Initializes a new instance of the <see cref="ClientDescription"/> class
+ /// to represent a confidential client (one that has an authenticating secret.)
/// </summary>
/// <param name="secret">The secret.</param>
/// <param name="defaultCallback">The default callback.</param>
/// <param name="clientType">Type of the client.</param>
- public ClientDescription(string secret, Uri defaultCallback, ClientType clientType) {
+ public ClientDescription(string secret, Uri defaultCallback = null, ClientType clientType = ClientType.Confidential) {
this.secret = secret;
this.DefaultCallback = defaultCallback;
this.ClientType = clientType;
}
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ClientDescription"/> class
+ /// to represent a public client (one that does not have an authenticating secret.)
+ /// </summary>
+ /// <param name="defaultCallback">The default callback.</param>
+ /// <param name="clientType">Type of the client.</param>
+ public ClientDescription(Uri defaultCallback = null, ClientType clientType = ClientType.Public) {
+ this.DefaultCallback = defaultCallback;
+ this.ClientType = clientType;
+ }
+
#region IClientDescription Members
/// <summary>