2using System.Collections.Generic;
4using System.Threading.Tasks;
34 : base(
"Legal/SignContract",
35 new KeyValuePair<Type,
Expression>(typeof(Dictionary<string, object>), new
Expression(jsonPattern)),
61 string KeyId = (string)Parameters[
"PKeyId"].AssociatedObjectValue;
64 string Role = (string)Parameters[
"PRole"].AssociatedObjectValue;
65 string Nonce = (string)Parameters[
"PNonce"].AssociatedObjectValue;
66 string KeySignature = (string)Parameters[
"PKeySignature"].AssociatedObjectValue;
67 string RequestSignature = (string)Parameters[
"PRequestSignature"].AssociatedObjectValue;
69 if (
string.IsNullOrEmpty(KeyId))
72 if (
string.IsNullOrEmpty(Nonce) || Nonce.Length < 32)
78 if (Identity.Account != User.
UserName)
79 throw new ForbiddenException(
"Only allowed to add attachments to your own legal identities.");
89 StringBuilder sb =
new StringBuilder();
104 sb.Append(KeySignature);
106 string s2 = sb.ToString();
113 sb.Append(ContractId);
117 string s3 = sb.ToString();
119 string s = Convert.ToBase64String(
122 Encoding.UTF8.GetBytes(s3)));
124 if (s != RequestSignature)
126 string Msg =
"Request Signature invalid.";
132 string Msg =
"Nonce value has already been used.";
139 int i = ContractId.
IndexOf(
'@');
143 string LegalDomain = ContractId.
Substring(i + 1);
158 await Client.
SendIqGet(LegalDomain,
"<getContract id=\"" +
XML.
Encode(ContractId) +
"\" xmlns=\"" +
165 if (e.Ok && !((E = e.FirstElement) is
null) && E.LocalName ==
"contract")
167 Networking.XMPP.Contracts.ParsedContract Contract;
171 Contract = await Networking.XMPP.Contracts.Contract.Parse(E, Gateway.ContractsClient, true);
172 if (Contract?.Contract is null)
174 await Response.Return(new InternalServerErrorException(
"Unable to parse contract."));
184 StringBuilder Xml =
new StringBuilder();
185 Contract.Contract.Serialize(Xml,
false,
false,
false,
false,
false,
false,
false);
186 byte[] Data = Encoding.UTF8.GetBytes(Xml.ToString());
188 byte[] Signature = KeyEndpoint.
Sign(Data);
191 "\" role=\"" +
XML.
Encode(Role) +
"\" s=\"" +
192 Convert.ToBase64String(Signature) +
"\" xmlns=\"" +
197 if (e2.Ok && !((E = e2.FirstElement) is
null) && E.LocalName ==
"contract")
199 await Response.Return(new NamedDictionary<string, object>(
"ContractResponse", AgentNamespace)
207 catch (Exception ex2)
227 LegalDomain,
string.Empty,
"<getContract id=\"" +
XML.
Encode(ContractId) +
"\" xmlns=\"" +
234 if (e.Ok && !((E = e.FirstElement) is
null) && E.LocalName ==
"contract")
238 if (Contract?.Contract is
null)
244 StringBuilder Xml =
new StringBuilder();
246 byte[] Data = Encoding.UTF8.GetBytes(Xml.ToString());
248 byte[] Signature = KeyEndpoint.Sign(Data);
252 LegalDomain,
string.Empty,
"<signContract id=\"" +
XML.
Encode(ContractId) +
253 "\" role=\"" +
XML.
Encode(Role) +
"\" s=\"" +
254 Convert.ToBase64String(Signature) +
"\" xmlns=\"" +
259 if (e2.Ok && !((E = e2.FirstElement) is
null) && E.LocalName ==
"contract")
261 await Response.Return(new NamedDictionary<string, object>(
"ContractResponse", AgentNamespace)
269 catch (Exception ex2)
271 await Response.SendResponse(ex2);
282 await Response.SendResponse(ex);
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.
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
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.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
The server encountered an unexpected condition which prevented it from fulfilling the 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...
Abstract base class for Elliptic Curve endpoints.
override byte[] Sign(byte[] Data)
Signs binary data using the local private key.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
static XmppException GetExceptionObject(XmlElement StanzaElement)
Gets an XMPP Exception object corresponding to its XML definition.
Task< uint > SendIqSet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Set request.
Task< uint > SendIqGet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Get request.
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
int IndexOf(CaseInsensitiveString value, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current System....
CaseInsensitiveString Substring(int startIndex, int length)
Retrieves a substring from this instance. The substring starts at a specified character position and ...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
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.
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.
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.
string Password
Password of account
Account Account
Account object.
string UserName
User Name.
static async Task< ParsedContract > Parse(XmlElement Xml, LegalComponent Legal)
Parses a contract from is XML representation.
void Serialize(StringBuilder Xml, bool IncludeNamespace, bool IncludeIdAttribute, bool IncludeClientSignatures, bool IncludeAttachments, bool IncludeStatus, bool IncludeServerSignature, bool IncludeAttachmentReferences, Dictionary< string, string > AttachmentsUrls, LegalComponent LegalComponent)
Serializes the Contract, in normalized form.
Contains information about a parsed contract.
Contract Contract
Contract object
Provisioning and registry service component.
static string NamespaceSmartContracts(NamespaceSet Version)
Returns the namespace for smart contracts.
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.
static Exception ToHttpException(XmppException ex)
Tries to convert an XMPP Exception to an HTTP Exception.
Contains an encrypted key for an agent.
string Namespace
Namespace of algorithm
string LocalName
Local Name of algorithm
Applies for a new Legal ID
Signs a contract using a legal ID.
override bool Synchronous
If the resource is synchronous (i.e. returns a response in the method handler), or if it is asynchron...
SignContract()
Signs a contract using a 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.
NamespaceSet
Namespace versions