mirror of
https://github.com/FabInfra/S22.Sasl.git
synced 2025-03-12 06:41:52 +01:00
provider model
This commit is contained in:
parent
235d86668c
commit
e8ec2d6b49
@ -32,5 +32,5 @@
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.0.1")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.1")]
|
||||||
|
@ -11,7 +11,7 @@ public class SaslConfigurationSection : ConfigurationSection {
|
|||||||
/// saslProvider elements.
|
/// saslProvider elements.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ConfigurationProperty("saslProviders", IsRequired = false,
|
[ConfigurationProperty("saslProviders", IsRequired = false,
|
||||||
IsKey = false, IsDefaultCollection = true)]
|
IsKey = false, IsDefaultCollection = false)]
|
||||||
public SaslProviderCollection SaslProviders {
|
public SaslProviderCollection SaslProviders {
|
||||||
get {
|
get {
|
||||||
return ((SaslProviderCollection) base["saslProviders"]);
|
return ((SaslProviderCollection) base["saslProviders"]);
|
||||||
|
@ -1,19 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
namespace S22.Sasl {
|
namespace S22.Sasl {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A factory class for producing instances of Sasl mechanisms.
|
/// A factory class for producing instances of Sasl mechanisms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class SaslFactory {
|
public static class SaslFactory {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A dictionary of Sasl mechanisms registered with the factory class.
|
/// A dictionary of Sasl mechanisms registered with the factory class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static Dictionary<string, Type> Mechanisms {
|
static Dictionary<string, Type> mechanisms {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of the names of all available mechanisms.
|
||||||
|
/// </summary>
|
||||||
|
public static IEnumerable<string> Mechanisms {
|
||||||
|
get {
|
||||||
|
return mechanisms.Keys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the Sasl mechanism with the specified
|
/// Creates an instance of the Sasl mechanism with the specified
|
||||||
/// name.
|
/// name.
|
||||||
@ -26,11 +36,11 @@ internal static class SaslFactory {
|
|||||||
/// specified name is not registered with Sasl.SaslFactory.</exception>
|
/// specified name is not registered with Sasl.SaslFactory.</exception>
|
||||||
public static SaslMechanism Create(string name) {
|
public static SaslMechanism Create(string name) {
|
||||||
name.ThrowIfNull("name");
|
name.ThrowIfNull("name");
|
||||||
if (!Mechanisms.ContainsKey(name)) {
|
if (!mechanisms.ContainsKey(name)) {
|
||||||
throw new SaslException("A Sasl mechanism with the specified name " +
|
throw new SaslException("A Sasl mechanism with the specified name " +
|
||||||
"is not registered with Sasl.SaslFactory.");
|
"is not registered with Sasl.SaslFactory.");
|
||||||
}
|
}
|
||||||
Type t = Mechanisms[name];
|
Type t = mechanisms[name];
|
||||||
object o = Activator.CreateInstance(t, true);
|
object o = Activator.CreateInstance(t, true);
|
||||||
return o as SaslMechanism;
|
return o as SaslMechanism;
|
||||||
}
|
}
|
||||||
@ -57,7 +67,7 @@ internal static class SaslFactory {
|
|||||||
"of Sasl.SaslMechanism");
|
"of Sasl.SaslMechanism");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Mechanisms.Add(name, t);
|
mechanisms.Add(name, t);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SaslException("Registration of Sasl mechanism failed.", e);
|
throw new SaslException("Registration of Sasl mechanism failed.", e);
|
||||||
}
|
}
|
||||||
@ -67,17 +77,26 @@ internal static class SaslFactory {
|
|||||||
/// Static class constructor. Initializes static properties.
|
/// Static class constructor. Initializes static properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static SaslFactory() {
|
static SaslFactory() {
|
||||||
Mechanisms = new Dictionary<string, Type>(
|
mechanisms = new Dictionary<string, Type>(
|
||||||
StringComparer.InvariantCultureIgnoreCase);
|
StringComparer.InvariantCultureIgnoreCase) {
|
||||||
|
{ "Plain", typeof(Mechanisms.SaslPlain) },
|
||||||
// Could be moved to App.config to support SASL "plug-in" mechanisms.
|
{ "Cram-Md5", typeof(Mechanisms.SaslCramMd5) },
|
||||||
var list = new Dictionary<string, Type>() {
|
{ "Digest-Md5", typeof(Mechanisms.SaslDigestMd5) },
|
||||||
{ "PLAIN", typeof(Sasl.Mechanisms.SaslPlain) },
|
{ "Scram-Sha-1", typeof(Mechanisms.SaslScramSha1) },
|
||||||
{ "DIGEST-MD5", typeof(Sasl.Mechanisms.SaslDigestMd5) },
|
{ "Ntlm", typeof(Mechanisms.SaslNtlm) },
|
||||||
{ "SCRAM-SHA-1", typeof(Sasl.Mechanisms.SaslScramSha1) },
|
{ "Ntlmv2", typeof(Mechanisms.SaslNtlmv2) },
|
||||||
|
{ "OAuth", typeof(Mechanisms.SaslOAuth) },
|
||||||
|
{ "OAuth2", typeof(Mechanisms.SaslOAuth2) },
|
||||||
|
{ "Srp", typeof(Mechanisms.SaslSrp) }
|
||||||
};
|
};
|
||||||
foreach (string key in list.Keys)
|
// Register any custom mechanisms configured in the app.config.
|
||||||
Mechanisms.Add(key, list[key]);
|
var configSection = ConfigurationManager.GetSection("saslConfigSection")
|
||||||
|
as SaslConfigurationSection;
|
||||||
|
if (configSection != null) {
|
||||||
|
foreach(SaslProvider provider in configSection.SaslProviders) {
|
||||||
|
mechanisms.Add(provider.Name, Type.GetType(provider.Type));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ namespace S22.Sasl {
|
|||||||
/// The abstract base class from which all classes implementing a Sasl
|
/// The abstract base class from which all classes implementing a Sasl
|
||||||
/// authentication mechanism must derive.
|
/// authentication mechanism must derive.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal abstract class SaslMechanism {
|
public abstract class SaslMechanism {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IANA name of the authentication mechanism.
|
/// IANA name of the authentication mechanism.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -48,7 +48,7 @@ internal abstract class SaslMechanism {
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal SaslMechanism() {
|
public SaslMechanism() {
|
||||||
Properties = new Dictionary<string, object>();
|
Properties = new Dictionary<string, object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +85,9 @@ public class SrpTest {
|
|||||||
[TestCategory("Srp")]
|
[TestCategory("Srp")]
|
||||||
public void DeserializeServerSecondMessage() {
|
public void DeserializeServerSecondMessage() {
|
||||||
ServerMessage2 m = ServerMessage2.Deserialize(serverMessage2);
|
ServerMessage2 m = ServerMessage2.Deserialize(serverMessage2);
|
||||||
|
|
||||||
Assert.IsTrue(m.Proof.SequenceEqual(expectedServerProof));
|
Assert.IsTrue(m.Proof.SequenceEqual(expectedServerProof));
|
||||||
Assert.IsTrue(m.InitialVector.SequenceEqual(expectedInitialVector));
|
Assert.IsTrue(m.InitialVector.SequenceEqual(expectedInitialVector));
|
||||||
Assert.AreEqual<string>(String.Empty, m.SessionId);
|
Assert.AreEqual(string.Empty, m.SessionId);
|
||||||
Assert.AreEqual<uint>(0, m.Ttl);
|
Assert.AreEqual<uint>(0, m.Ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,8 +95,10 @@ public class SrpTest {
|
|||||||
/// Verifies the various parts of a sample authentication exchange
|
/// Verifies the various parts of a sample authentication exchange
|
||||||
/// (Challenge generated by the Cyrus Sasl library).
|
/// (Challenge generated by the Cyrus Sasl library).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>The exchange was generated with the authorization id
|
/// <remarks>
|
||||||
/// (authId) set to the same value as the username.</remarks>
|
/// The exchange was generated with the authorization id (authId) set to the same value
|
||||||
|
/// as the username.
|
||||||
|
/// </remarks>
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[TestCategory("Srp")]
|
[TestCategory("Srp")]
|
||||||
public void VerifyAuthenticationExchange() {
|
public void VerifyAuthenticationExchange() {
|
||||||
@ -109,16 +110,14 @@ public class SrpTest {
|
|||||||
// Ensure the expected client initial-response is generated.
|
// Ensure the expected client initial-response is generated.
|
||||||
byte[] clientResponse = m.GetResponse(new byte[0]);
|
byte[] clientResponse = m.GetResponse(new byte[0]);
|
||||||
Assert.IsTrue(clientResponse.SequenceEqual(expectedClientFirst));
|
Assert.IsTrue(clientResponse.SequenceEqual(expectedClientFirst));
|
||||||
|
|
||||||
// Hand the server-challenge to the client and verify the expected
|
// Hand the server-challenge to the client and verify the expected
|
||||||
// client-response is generated.
|
// client-response is generated.
|
||||||
clientResponse = m.GetResponse(serverFirst);
|
clientResponse = m.GetResponse(serverFirst);
|
||||||
Assert.IsTrue(clientResponse.SequenceEqual(expectedClientSecond));
|
Assert.IsTrue(clientResponse.SequenceEqual(expectedClientSecond));
|
||||||
|
|
||||||
// Finally, hand the server-evidence to the client and verify the client
|
// Finally, hand the server-evidence to the client and verify the client
|
||||||
// responds with the empty string which concludes authentication.
|
// responds with the empty string which concludes authentication.
|
||||||
clientResponse = m.GetResponse(serverSecond);
|
clientResponse = m.GetResponse(serverSecond);
|
||||||
Assert.AreEqual<int>(0, clientResponse.Length);
|
Assert.AreEqual(0, clientResponse.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Server Message 1
|
#region Server Message 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user