2using System.Collections.Generic;
3using System.Security.Cryptography;
5using System.Threading.Tasks;
36 : base(
"Legal/ApplyId",
37 new KeyValuePair<Type,
Expression>(typeof(Dictionary<string, object>), new
Expression(jsonPattern)),
57 string KeyId = (string)Parameters[
"PKeyId"].AssociatedObjectValue;
58 string Nonce = (string)Parameters[
"PNonce"].AssociatedObjectValue;
59 string KeySignature = (string)Parameters[
"PKeySignature"].AssociatedObjectValue;
60 string RequestSignature = (string)Parameters[
"PRequestSignature"].AssociatedObjectValue;
61 object[] PropertyNames = (
object[])Parameters[
"PPropertyName"].AssociatedObjectValue;
62 object[] PropertyValues = (
object[])Parameters[
"PPropertyValue"].AssociatedObjectValue;
63 Dictionary<CaseInsensitiveString, Property> PropertiesByName =
new Dictionary<CaseInsensitiveString, Property>();
64 List<Property> Properties =
new List<Property>();
65 StringBuilder sb =
new StringBuilder();
68 if (
string.IsNullOrEmpty(Agent))
71 if (
string.IsNullOrEmpty(KeyId))
74 if (
string.IsNullOrEmpty(Nonce) || Nonce.Length < 32)
95 sb.Append(KeySignature);
97 string s2 = sb.ToString();
102 int i, c = PropertyNames?.Length ?? 0;
103 if ((PropertyValues?.Length ?? 0) != c)
106 bool JidAdded =
false;
107 bool EMailAdded =
false;
108 bool PhoneNrAdded =
false;
110 for (i = 0; i < c; i++)
112 if (!(PropertyNames[i] is
string PropertyName) ||
string.IsNullOrEmpty(PropertyName))
115 if (!(PropertyValues[i] is
string PropertyValue) ||
string.IsNullOrEmpty(PropertyValue))
118 switch (PropertyName.ToUpper())
124 int j = PropertyValue.IndexOf(
'@');
128 if (PropertyValue.Substring(0, j) != User.
UserName)
168 string s = Convert.ToBase64String(
171 Encoding.UTF8.GetBytes(s3)));
173 if (s != RequestSignature)
175 string Msg =
"Request Signature invalid.";
181 string Msg =
"Nonce value has already been used.";
191 Properties.Add(
new Property(
"JID", BareJid));
193 if (!EMailAdded && !
string.IsNullOrEmpty(User.
Account.
EMail))
199 Properties.Add(
new Property(
"AGENT", Agent));
202 DateTime From = TP.Date;
211 Updated = DateTime.MinValue,
215 Provider = LegalDomain,
216 Properties = Properties.ToArray(),
217 Version = NamespaceSet.Current
220 StringBuilder Xml =
new StringBuilder();
221 Identity.Serialize(Xml,
false,
false,
false,
false,
false,
false,
false,
null,
XmppServerModule.Legal);
222 Identity.ClientSignature = KeyEndpoint.
Sign(Encoding.UTF8.GetBytes(Xml.ToString()));
229 ToRemove.Id.
Value, BareJid,
"LegalIdDeleted", ToRemove.GetTags());
234 Identity.Id = Identity.ObjectId +
"@" + LegalDomain;
239 KeyValuePair<string, object>[] Tags = Identity.GetTags();
241 Log.
Informational(
"Legal Identity application registered.", Identity.Id.Value, BareJid,
242 "LegalIdRegistered", Tags);
244 XmppServerModule.Legal?.IdentityAuthorization(BareJid, BareJid, Identity.Id,
true);
247 Identity.Serialize(Xml,
true,
true,
true,
true,
true,
true,
true,
null,
XmppServerModule.Legal);
248 string IdentityXml = Xml.ToString();
250 XmlDocument IdentityDoc =
new XmlDocument()
252 PreserveWhitespace =
true
254 IdentityDoc.LoadXml(IdentityXml);
258 {
"Identity", IdentityDoc }
261 StringBuilder Markdown =
new StringBuilder();
263 Markdown.Append(
"Legal identity application received: [`");
264 Markdown.Append(Identity.Id);
265 Markdown.Append(
"`](");
267 Markdown.Append(Identity.Id);
268 Markdown.AppendLine(
")");
269 Markdown.AppendLine();
288 Markdown.AppendLine(
"Other identities registered for the same account:");
295 Markdown.Append(
"[`");
296 Markdown.Append(ID.Id);
297 Markdown.Append(
"`](");
299 Markdown.Append(ID.Id);
300 Markdown.AppendLine(
")");
301 Markdown.AppendLine();
313 string.Empty, IdentityXml);
325 string s4 = s2 +
":" + Convert.ToBase64String(
AgentKey.
Salt);
327 byte[] IV =
new byte[16];
331 Aes Aes = Aes.Create();
335 Aes.Mode = CipherMode.CBC;
336 Aes.Padding = PaddingMode.PKCS7;
338 using (ICryptoTransform Decryptor = Aes.CreateDecryptor(Key, IV))
345 Doc =
new XmlDocument();
346 Doc.LoadXml(Encoding.UTF8.GetString(Decrypted));
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Static class managing the application event log. Applications and services log events on this static ...
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static bool IsDomain(string DomainOrHost, bool IncludeAlternativeDomains)
If a domain or host name represents the gateway.
static Task SendNotification(Graph Graph)
Sends a graph as a notification message to configured notification recipients.
static string GetUrl(string LocalResource)
Gets a URL for a resource.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
Represets a response of an HTTP client request.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
IE2eEndpoint Parse(XmlElement Xml)
Parses endpoint information from an XML element.
abstract string LocalName
Local name of the E2E encryption scheme
Abstract base class for Elliptic Curve endpoints.
override byte[] PublicKey
Remote public key.
override byte[] Sign(byte[] Data)
Signs binary data using the local private key.
XmppAddress MainDomain
Main/principal domain address
Contains information about one XMPP address.
CaseInsensitiveString Address
XMPP Address
Task< bool > SendMessage(string Type, string Id, string From, string To, string Language, string ContentXml)
Sends a Message stanza to a recipient.
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< IEnumerable< object > > FindDelete(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
static async Task Update(object Object)
Updates an object in the database.
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
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.
This filter selects objects that have a named field not equal to a given value.
Static class managing persistent settings.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
Class managing a script expression.
Contains methods for simple hash calculations.
static byte[] ComputeHMACSHA256Hash(byte[] Key, byte[] Data)
Computes the HMAC-SHA-256 hash of a block of binary data.
static byte[] ComputeSHA256Hash(byte[] Data)
Computes the SHA-256 hash of a block of binary data.
Contains information about a broker account.
CaseInsensitiveString EMail
E-mail address associated with account.
string Password
Password of account
CaseInsensitiveString PhoneNr
Phone number associated with account.
Account Account
Account object.
string UserName
User Name.
override string ToString()
Object.ToString()
CaseInsensitiveString Name
Property name
CaseInsensitiveString Value
Property value
Provisioning and registry service component.
static DateTime NowSecond
Current Date & Time, to a precision of one second.
Task< bool > HasNonceBeenUsed(string Nonce)
Checks if a Nonce value has been used.
Task RegisterNonceValue(string Nonce)
Registers a nonce value.
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
AgentApi Api
Reference to Agent API.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Contains an encrypted key for an agent.
byte[] Salt
Cryptographic salt.
string Namespace
Namespace of algorithm
string LocalName
Local Name of algorithm
byte[] EncryptedKey
Encypted key.
Gets available cryptographic algorithms.
static bool TryGetAlgorithm(string LocalName, string Namespace, out EllipticCurveEndpoint Algorithm)
Tries to get an algorithm given its fully qualified name.
Applies for a new Legal ID
ApplyId()
Applies for a new Legal ID
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
Service Module hosting the XMPP broker and its components.
IdentityState
Lists recognized legal identity states.