2using System.Threading.Tasks;
20 private readonly
int nrDigits;
21 private readonly
byte[] secret;
24 private readonly
string endpoint;
25 private readonly
int timeStepSeconds;
26 private readonly
long t0;
150 DateTime Timestamp,
int PassCode)
153 RemoteEndPoint, Timestamp, this.timeStepSeconds, PassCode, this.auditor);
168 string RemoteEndPoint, DateTime Timestamp,
int TimeStepSeconds,
int PassCode,
242 if (Counter <= LastCounter)
252 if (EarliestOpportunity.HasValue)
256 bool Ok = Expected == PassCode;
262 Ok = Expected == PassCode;
270 Ok = Expected == PassCode;
Static class managing persistent counters.
static Task< long > IncrementCounter(CaseInsensitiveString Key)
Increments a counter.
static Task< long > DecrementCounter(CaseInsensitiveString Key)
Decrements a counter.
static async Task< long > GetCount(CaseInsensitiveString Key)
Gets the current count of a counter.
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Static class of application-wide semaphores that can be used to order access to editable objects.
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...
Class that monitors login events, and help applications determine malicious intent....
async Task< DateTime?> GetEarliestLoginOpportunity(string RemoteEndPoint, string Protocol)
Checks when a remote endpoint can login.
static async void Success(string Message, string UserName, string RemoteEndPoint, string Protocol, params KeyValuePair< string, object >[] Tags)
Handles a successful login attempt.
static void Fail(string Message, string UserName, string RemoteEndPoint, string Protocol)
Handles a failed login attempt.
Contains OTP secret information for an OTP endpoint.
int TimeStepSeconds
Time step in seconds.
byte[] Secret
Endpoint secret.
HashFunction? HashFunction
Hash function used for the endpoint.
int NrDigits
Number of digits.
Implements the HOTP calculator algorithm, as defined in RFC 4226: https://datatracker....
int Compute(long Counter)
Calculates the expected one-time-password for the given counter value.
const int DefaultNrDigits
Default number of digits (6).
const HashFunction DefaultHashFunction
Default Hash Function (SHA-1)
Implements the TOTP calculator algorithm, as defined in RFC 6238: https://datatracker....
const long DefaultT0
Default time when starting counting steps (0).
static long CalcCounter(DateTime Timestamp, int TimeStepSeconds, long T0)
Calculates the counter number for use with the HOTP algorithm.
Implements the TOTP validator algorithm, as defined in RFC 6238: https://datatracker....
int TimeStepSeconds
Time step in seconds.
static async Task< TotpValidator > TryCreate(string OtpEndpoint, LoginAuditor Auditor)
Tries to create an TOTP calculator for the given endpoint.
TotpValidator(int NrDigits, byte[] Secret, HashFunction HashFunction, int TimeStepSeconds, string OtpEndpoint, LoginAuditor Auditor)
Implements the TOTP validator algorithm, as defined in RFC 6238: https://datatracker....
static async Task< ValidationResult > Validate(int NrDigits, byte[] Secret, HashFunction HashFunction, string OtpEndpoint, string RemoteEndPoint, DateTime Timestamp, int TimeStepSeconds, long T0, int PassCode, LoginAuditor Auditor)
Calculates the expected one-time-password for the given counter value.
static async Task< ValidationResult > Validate(int NrDigits, byte[] Secret, HashFunction HashFunction, string OtpEndpoint, string RemoteEndPoint, DateTime Timestamp, int TimeStepSeconds, int PassCode, LoginAuditor Auditor)
Calculates the expected one-time-password for the given counter value.
static Task< ValidationResult > Validate(byte[] Secret, string OtpEndpoint, string RemoteEndPoint, DateTime Timestamp, int TimeStepSeconds, int PassCode, LoginAuditor Auditor)
Calculates the expected one-time-password for the given counter value.
TotpValidator(int NrDigits, byte[] Secret, HashFunction HashFunction, int TimeStepSeconds, long T0, string OtpEndpoint, LoginAuditor Auditor)
Implements the TOTP validator algorithm, as defined in RFC 6238: https://datatracker....
TotpValidator(int NrDigits, byte[] Secret, string OtpEndpoint, LoginAuditor Auditor)
Implements the TOTP validator algorithm, as defined in RFC 6238: https://datatracker....
int NrDigits
Number of digits to present.
static Task< ValidationResult > Validate(int NrDigits, byte[] Secret, string OtpEndpoint, string RemoteEndPoint, DateTime Timestamp, int TimeStepSeconds, int PassCode, LoginAuditor Auditor)
Calculates the expected one-time-password for the given counter value.
HashFunction HashFunction
Hash function to use in computation.
string OtpEndpoint
OTP Endpoint
TotpValidator(byte[] Secret, string OtpEndpoint, LoginAuditor Auditor)
Implements the TOTP validator algorithm, as defined in RFC 6238: https://datatracker....
const string ProtocolName
Protocol name (TOTP).
Task< ValidationResult > Validate(string OtpEndpoint, string RemoteEndPoint, DateTime Timestamp, int PassCode)
Calculates the expected one-time-password for the given counter value.
LoginAuditor Auditor
Login auditor.
Contains information of a HOTP or TOTP validation attempt.
CredentialAlgorithm
Specifies the type of external credential algorithm to use.
HashFunction
Hash method enumeration.