6using System.Threading.Tasks;
41 : base(
"Account/Transfer",
42 new KeyValuePair<Type,
Expression>(typeof(Dictionary<string, object>), new
Expression(jsonPattern)),
63 string KeyId = (string)Parameters[
"PKeyId"]?.AssociatedObjectValue;
64 string Nonce = (string)Parameters[
"PNonce"].AssociatedObjectValue;
65 string KeySignature = (string)Parameters[
"PKeySignature"]?.AssociatedObjectValue;
66 string RequestSignature = (string)Parameters[
"PRequestSignature"].AssociatedObjectValue;
67 string Pin = (string)Parameters[
"PPin"]?.AssociatedObjectValue;
69 StringBuilder sb =
new StringBuilder();
72 if (
string.IsNullOrEmpty(Nonce) || Nonce.Length < 32)
75 if (
string.IsNullOrEmpty(KeyId))
77 if (!
string.IsNullOrEmpty(KeySignature))
94 sb.Append(
AgentKey?.LocalName ??
string.Empty);
96 sb.Append(
AgentKey?.Namespace ??
string.Empty);
103 sb.Append(KeySignature);
105 string s2 = sb.ToString();
112 string s3 = sb.ToString();
114 string s = Convert.ToBase64String(
117 Encoding.UTF8.GetBytes(s3)));
119 if (s != RequestSignature)
121 string Msg =
"Request Signature invalid.";
127 string Msg =
"Nonce value has already been used.";
144 DateTime Today = DateTime.Today;
146 if (Next.Value == DateTime.MaxValue)
148 sb.Append(
"This endpoint (");
150 sb.Append(
") has been blocked from the system.");
154 sb.Append(
"Too many failed identity applications in a row registered. Try again after ");
155 sb.Append(TP.ToLongTimeString());
157 if (TP.Date != Today)
159 if (TP.Date == Today.AddDays(1))
160 sb.Append(
" tomorrow");
164 sb.Append(TP.ToShortDateString());
168 sb.Append(
". Remote Endpoint: ");
177 sb.Append(
"<Transfer xmlns=\"");
178 sb.Append(Networking.XMPP.Contracts.ContractsClient.NamespaceOnboarding);
189 s = KeyEndpoint.
Curve.Export();
192 sb.Append(
"<LegalId>");
194 sb.Append(
"<S n=\"");
196 sb.Append(
"\" v=\"");
197 sb.Append(
XML.
Encode(Doc.DocumentElement.GetAttribute(
"d")));
200 sb.Append(
"<DT n=\"Timestamp\" v=\"");
210 Convert.ToBase64String(Identity.
ClientPubKey) == KeyEndpoint.PublicKeyBase64)
212 sb.Append(
"<State legalId=\"");
214 sb.Append(
"\" publicKey=\"");
215 sb.Append(KeyEndpoint.PublicKeyBase64);
216 sb.Append(
"\" timestamp=\"");
222 sb.Append(
"</LegalId>");
225 if (!
string.IsNullOrEmpty(Pin))
227 sb.Append(
"<Pin pin=\"");
232 User.
Account.AppendAccountXml(sb,
false);
234 sb.Append(
"</Transfer>");
236 string TransferXml = sb.ToString();
237 byte[] Bin = Encoding.UTF8.GetBytes(TransferXml);
244 sb.Append(
"<Info xmlns='");
245 sb.Append(Networking.XMPP.Contracts.ContractsClient.NamespaceOnboarding);
246 sb.Append(
"' base64='");
247 sb.Append(Convert.ToBase64String(Encrypted));
248 sb.Append(
"' once='true' expires='");
249 sb.Append(
XML.
Encode(DateTime.UtcNow.AddHours(1)));
255 if (Client.
Domain ==
"example.com" &&
260 XmlElement E = await Client.
IqSetAsync(
"onboarding." + OnboardingNeuron, sb.ToString());
262 foreach (XmlNode N
in E.ChildNodes)
264 if (N is XmlElement E2 && E2.LocalName ==
"Code" && E2.HasAttribute(
"code"))
266 string Code = E2.GetAttribute(
"code");
270 sb.Append(
"obinfo:");
271 sb.Append(OnboardingNeuron);
275 sb.Append(Convert.ToBase64String(Key));
277 sb.Append(Convert.ToBase64String(IV));
279 string OnboardingUri = sb.ToString();
284 sb.Append(WebUtility.UrlEncode(OnboardingUri));
285 sb.Append(
"?w=400&h=400&q=2");
293 Created = DateTime.UtcNow,
300 {
"onboardingUri", OnboardingUri },
302 {
"qrCodeWidth", 400 },
303 {
"qrCodeHeight", 400 }
323 if (!
string.IsNullOrEmpty(CodeObj.
Token))
342 new KeyValuePair<string, object>(
"Account", CodeObj.
Account),
343 new KeyValuePair<string, object>(
"Keys Deleted", KeyCount));
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
static XmlDocument ParseXml(string Xml)
Parses an XML Document from its string representation.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
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 Task< bool > HasNonceBeenUsed(string Nonce)
Checks if a Nonce value has been used.
static LoginAuditor LoginAuditor
Current Login Auditor. Should be used by modules accepting user logins, to protect the system from un...
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
static string GetUrl(string LocalResource)
Gets a URL for a resource.
static Task RegisterNonceValue(string Nonce)
Registers a nonce value.
static XmppClient XmppClient
XMPP Client connection of gateway.
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...
The user has sent too many requests in a given amount of time. Intended for use with rate limiting sc...
abstract string LocalName
Local name of the E2E encryption scheme
Abstract base class for Elliptic Curve endpoints.
EllipticCurve Curve
Elliptic Curve
bool HasPrivateKey
If the key contains a private key.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
async Task< XmlElement > IqSetAsync(string To, string Xml)
Performs an asynchronous IQ Set request/response operation.
string Domain
Current Domain.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Delete(object Object)
Deletes 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 lesser or equal to a given value.
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 that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
static byte[] Encrypt(byte[] Data, byte[] Key, byte[] IV, CipherMode CipherMode=CipherMode.CBC, PaddingMode PaddingMode=PaddingMode.PKCS7)
Performs AES encryption of data.
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.
Use JWT tokens for authentication. The Bearer scheme defined in RFC 6750 is used: https://tools....
static string GetAccessToken(HttpRequest Request)
Gets the access token from an HTTP request.
A factory that can create and validate JWT tokens.
static void Deprecate(JwtToken Token)
Deprecates a token.
Contains information about a Java Web Token (JWT). JWT is defined in RFC 7519: https://tools....
static bool TryParse(string Token, out JwtToken ParsedToken)
Tries to parse a JWT token.
Contains information about a broker account.
CaseInsensitiveString UserName
User Name of account
string Password
Password of account
Account Account
Account object.
string UserName
User Name.
CaseInsensitiveString Id
ID of the legal identity
byte[] ClientPubKey
Client Public key
bool HasClientPublicKey
If the identity has a client public key
Legal (digital identities, smart contracts) service component.
static Task< string > GetOnboardingNeuronDomainName()
Gets the domain name of the Nnboarding Neuron.
Contains information about an Agent Transfer code.
string Account
Account the code is associated with.
string Token
JWT token used.
Applies for a new Legal ID
Transfer()
Applies for a new Legal ID
static async Task TransferCodeDelivered(string Code)
Called when a transfer code has been delivered to a recipient.
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
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.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Contains an encrypted key for an agent.
DateTime Created
When key was first created.
DateTime Updated
When key was last updated.
Applies for a new Legal ID
Reason
Reason a token is not valid.