2using System.Collections.Generic;
3using System.Net.Security;
4using System.Security.Cryptography;
6using System.Threading.Tasks;
16 private static readonly RandomNumberGenerator rnd = RandomNumberGenerator.Create();
28 public abstract string Name
46 public abstract bool Allowed(SslStream SslStream);
55 List<KeyValuePair<string, string>> Result =
new List<KeyValuePair<string, string>>();
56 StringBuilder sb =
new StringBuilder();
57 string Key =
string.Empty;
60 foreach (
char ch
in s)
73 Result.Add(
new KeyValuePair<string, string>(sb.ToString(),
string.Empty));
85 Result.Add(
new KeyValuePair<string, string>(Key,
string.Empty));
100 Result.Add(
new KeyValuePair<string, string>(Key, sb.ToString()));
125 if (State == 2 && !
string.IsNullOrEmpty(Key))
126 Result.Add(
new KeyValuePair<string, string>(Key, sb.ToString()));
128 return Result.ToArray();
136 protected static byte[]
CONCAT(params
byte[][] Data)
140 foreach (
byte[] Part
in Data)
145 byte[] Result =
new byte[c];
147 foreach (
byte[] Part
in Data)
150 Array.Copy(Part, 0, Result, i, j);
162 protected static string CONCAT(params
string[] Parameters)
164 StringBuilder sb =
new StringBuilder();
166 foreach (
string s
in Parameters)
169 return sb.ToString();
178 protected static byte[]
CONCAT(
byte[] Data, params
string[] Parameters)
180 return CONCAT(Data, Encoding.UTF8.GetBytes(
CONCAT(Parameters)));
188 protected static string HEX(
byte[] Data)
200 protected static byte[]
XOR(
byte[] U1,
byte[] U2)
202 int i, c = U1.Length;
204 throw new Exception(
"Arrays must be of the same size.");
206 byte[] Response =
new byte[c];
208 for (i = 0; i < c; i++)
209 Response[i] = (
byte)(U1[i] ^ U2[i]);
256 throw new ArgumentException(
"Count must be positive.", nameof(Count));
258 byte[] Result =
new byte[Count];
262 rnd.GetBytes(Result);
Base class for all authentication mechanisms.
static string HEX(byte[] Data)
Converts a byte array to a hexadecimal string.
abstract Task< bool?> AuthenticationRequest(string Data, ISaslServerSide Connection, ISaslPersistenceLayer PersistenceLayer)
Authentication request has been made.
static byte[] CONCAT(byte[] Data, params string[] Parameters)
Concatenates a byte array with a sequence of strings.
static byte[] CONCAT(params byte[][] Data)
Concatenates a sequence of byte arrays.
abstract int Weight
Weight of mechanisms. The higher the value, the more preferred.
abstract bool Allowed(SslStream SslStream)
Checks if a mechanism is allowed during the current conditions.
abstract Task< bool?> ResponseRequest(string Data, ISaslServerSide Connection, ISaslPersistenceLayer PersistenceLayer)
Response request has been made.
abstract Task Initialize()
Performs intitialization of the mechanism. Can be used to set static properties that will be used thr...
static byte[] XOR(byte[] U1, byte[] U2)
XORs two byte arrays.
static string CONCAT(params string[] Parameters)
Concatenates a sequence of strings.
AuthenticationMechanism()
Base class for all authentication mechanisms.
KeyValuePair< string, string >[] ParseCommaSeparatedParameterList(string s)
Parses a parameter list in a challenge string.
abstract Task< bool?> Authenticate(string UserName, string Password, ISaslClientSide Connection)
Authenticates the user using the provided credentials.
static byte[] GetRandomBytes(int Count)
Gets an array of random bytes.
abstract string Name
Name of the mechanism.
Contains methods for simple hash calculations.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
Interface for authentication mechanisms.
Interface for client-side client connections.
Interface for XMPP Server persistence layers. The persistence layer should implement caching.
Interface for server-side client connections.