3using System.Threading.Tasks;
20 private readonly Dictionary<string, DateTime> expirationByNonce =
new Dictionary<string, DateTime>();
21 private readonly SortedDictionary<DateTime, string> nonceByExpiration =
new SortedDictionary<DateTime, string>();
23 private readonly
string realm;
32 public override bool UserSessions =>
true;
42 DateTime Expires = DateTime.Now.AddMinutes(1);
48 if (!this.nonceByExpiration.ContainsKey(Expires))
50 this.expirationByNonce[Nonce] = Expires;
51 this.nonceByExpiration[Expires] = Nonce;
58 Expires = Expires.AddTicks(b[0] & 15);
61 return new string[] {
"NeuroFoundation.Sign realm=\"" + this.realm +
"\", n=\"" + Nonce +
"\"" };
66 if (!(Request.
Session is
null) &&
68 v.ValueObject is
IUser User &&
75 if (!(Authorization is
null) && Authorization.
Value.StartsWith(
"NeuroFoundation.Sign ", StringComparison.CurrentCultureIgnoreCase))
77 string FullJid =
null;
79 string NonceStr =
null;
80 string SignatureStr =
null;
84 switch (P.Key.ToLower())
99 SignatureStr = P.Value;
104 if (this.realm != Realm || NonceStr is
null || SignatureStr is
null || FullJid is
null)
107 DateTime TP = DateTime.Now;
111 LinkedList<DateTime> ToRemove =
null;
113 foreach (KeyValuePair<DateTime, string> Pair
in this.nonceByExpiration)
117 ToRemove ??=
new LinkedList<DateTime>();
118 ToRemove.AddLast(Pair.Key);
119 this.expirationByNonce.Remove(Pair.Value);
125 if (!(ToRemove is
null))
127 foreach (DateTime ExpiryDate
in ToRemove)
128 this.nonceByExpiration.Remove(ExpiryDate);
131 if (!this.expirationByNonce.TryGetValue(NonceStr, out TP))
136 this.expirationByNonce.Remove(NonceStr);
137 this.nonceByExpiration.Remove(TP);
142 byte[] Nonce = Convert.FromBase64String(NonceStr);
143 byte[] Signature = Convert.FromBase64String(SignatureStr);
144 (
LegalIdentity Identity,
_) = await this.legalComponent.ValidateSenderSignature(From,
null, TP, Nonce, Signature,
null);
146 if (Identity is
null)
150 string AttachmentId = Request.
SubPath[1..];
168 if (!(Identity is
null))
176 if (Identity is
null)
Helps with parsing of commong data types.
static KeyValuePair< string, string >[] ParseFieldValues(string Value)
Parses a set of comma or semicolon-separated field values, optionaly delimited by ' or " characters.
Static class managing the runtime environment of the IoT Gateway.
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
string Value
HTTP Field Value
Represents an HTTP request.
HttpRequestHeader Header
Request header.
string RemoteEndPoint
Remote end-point.
SessionVariables Session
Contains session states, if the resource requires sessions, or null otherwise.
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
HttpResource Resource
Resource being accessed.
override bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Contains information about one XMPP address.
CaseInsensitiveString BareJid
Bare JID
CaseInsensitiveString Account
Account
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
This filter selects objects that conform to all child-filters provided.
This filter selects objects that have a named field equal to a given value.
Contains information about a variable.
Class that monitors login events, and help applications determine malicious intent....
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.
Represents an attachment to a document.
CaseInsensitiveString Id
Attachment ID
Represents an attachment to a document.
AttachmentReference[] Attachments
Attachments assigned to the legal identity.
IdentityState State
Current state of identity
User object representing a legal identity.
bool HasPrivilege(string Privilege)
If user has a given privilege.
static async Task< LegalIdentityUser > Create(LegalIdentity Identity, XmppAddress From, LegalComponent LegalComponent)
Creates a user object representing a legal identity.
override async Task< IUser > IsAuthenticated(HttpRequest Request)
Checks if the request is authorized.
override string[] GetChallenges(HttpRequest Request)
Gets available challenges for the authenticating client to respond to.
override string DisplayName
Display name for authentication scheme.
Legal (digital identities, smart contracts) service component.
Basic interface for a user.
IdentityState
Lists recognized legal identity states.