2using System.Collections.Generic;
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;
37 DateTime Expires = DateTime.Now.AddMinutes(1);
43 if (!this.nonceByExpiration.ContainsKey(Expires))
45 this.expirationByNonce[Nonce] = Expires;
46 this.nonceByExpiration[Expires] = Nonce;
53 Expires = Expires.AddTicks(b[0] & 15);
56 return "NeuroFoundation.Sign realm=\"" + this.realm +
"\", n=\"" + Nonce +
"\"";
61 if (!(Request.
Session is
null) &&
63 v.ValueObject is
IUser User &&
70 if (!(Authorization is
null) && Authorization.
Value.StartsWith(
"NeuroFoundation.Sign ", StringComparison.CurrentCultureIgnoreCase))
72 string FullJid =
null;
74 string NonceStr =
null;
75 string SignatureStr =
null;
79 switch (P.Key.ToLower())
94 SignatureStr = P.Value;
99 if (this.realm != Realm || NonceStr is
null || SignatureStr is
null || FullJid is
null)
102 DateTime TP = DateTime.Now;
106 LinkedList<DateTime> ToRemove =
null;
108 foreach (KeyValuePair<DateTime, string> Pair
in this.nonceByExpiration)
112 if (ToRemove is
null)
113 ToRemove =
new LinkedList<DateTime>();
115 ToRemove.AddLast(Pair.Key);
116 this.expirationByNonce.Remove(Pair.Value);
122 if (!(ToRemove is
null))
124 foreach (DateTime ExpiryDate
in ToRemove)
125 this.nonceByExpiration.Remove(ExpiryDate);
128 if (!this.expirationByNonce.TryGetValue(NonceStr, out TP))
133 this.expirationByNonce.Remove(NonceStr);
134 this.nonceByExpiration.Remove(TP);
139 byte[] Nonce = Convert.FromBase64String(NonceStr);
140 byte[] Signature = Convert.FromBase64String(SignatureStr);
141 (
LegalIdentity Identity, _) = await this.legalComponent.ValidateSenderSignature(From,
null, TP, Nonce, Signature,
null);
143 if (Identity is
null)
147 string AttachmentId = Request.
SubPath.Substring(1);
153 if (ID.Attachments is
null)
165 if (!(Identity is
null))
173 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.
Variables 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.
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.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
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 async void Fail(string Message, string UserName, string RemoteEndpoint, string Protocol, params KeyValuePair< string, object >[] Tags)
Handles a failed login attempt.
Represents an attachment to a document.
CaseInsensitiveString Id
Attachment ID
Represents an attachment to a document.
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 GetChallenge()
Gets a challenge for the authenticating client to respond to.
Provisioning and registry service component.
Basic interface for a user.
IdentityState
Lists recognized legal identity states.