4using System.Threading.Tasks;
36 : base(
"Legal/SignContract",
37 new KeyValuePair<Type,
Expression>(typeof(Dictionary<string, object>), new
Expression(jsonPattern)),
63 string KeyId = (string)Parameters[
"PKeyId"].AssociatedObjectValue;
66 string Role = (string)Parameters[
"PRole"].AssociatedObjectValue;
67 string Nonce = (string)Parameters[
"PNonce"].AssociatedObjectValue;
68 string KeySignature = (string)Parameters[
"PKeySignature"].AssociatedObjectValue;
69 string RequestSignature = (string)Parameters[
"PRequestSignature"].AssociatedObjectValue;
71 if (
string.IsNullOrEmpty(KeyId))
74 if (
string.IsNullOrEmpty(Nonce) || Nonce.Length < 32)
80 if (Identity.Account != User.
UserName)
81 throw new ForbiddenException(Request,
"Only allowed to add attachments to your own legal identities.");
83 if (Identity.
State != IoTBroker.Legal.Identity.IdentityState.Approved)
91 StringBuilder sb =
new StringBuilder();
106 sb.Append(KeySignature);
108 string s2 = sb.ToString();
115 sb.Append(ContractId);
119 string s3 = sb.ToString();
121 string s = Convert.ToBase64String(
124 Encoding.UTF8.GetBytes(s3)));
126 if (s != RequestSignature)
128 string Msg =
"Request Signature invalid.";
134 string Msg =
"Nonce value has already been used.";
141 int i = ContractId.
IndexOf(
'@');
145 string LegalDomain = ContractId.
Substring(i + 1);
160 await Client.
SendIqGet(LegalDomain,
"<getContract id=\"" +
XML.
Encode(ContractId) +
"\" xmlns=\"" +
167 if (e.Ok && !((E = e.FirstElement) is
null) && E.LocalName ==
"contract")
169 Networking.XMPP.Contracts.ParsedContract Contract;
173 Contract = await Networking.XMPP.Contracts.Contract.Parse(E, Gateway.ContractsClient, true);
174 if (Contract?.Contract is null)
176 await Response.SendResponse(new InternalServerErrorException(
"Unable to parse contract."));
186 StringBuilder Xml =
new StringBuilder();
187 Contract.Contract.Serialize(Xml,
false,
false,
false,
false,
false,
false,
false);
188 byte[] Data = Encoding.UTF8.GetBytes(Xml.ToString());
190 byte[] Signature = KeyEndpoint.
Sign(Data);
193 "\" role=\"" +
XML.
Encode(Role) +
"\" s=\"" +
194 Convert.ToBase64String(Signature) +
"\" xmlns=\"" +
199 if (e2.Ok && !((E = e2.FirstElement) is
null) && E.LocalName ==
"contract")
201 await Response.Return(new NamedDictionary<string, object>(
"ContractResponse", AgentNamespace)
209 catch (Exception ex2)
229 LegalDomain,
string.Empty,
"<getContract id=\"" +
XML.
Encode(ContractId) +
"\" xmlns=\"" +
236 if (e.Ok && !((E = e.FirstElement) is
null) && E.LocalName ==
"contract")
240 if (Contract?.Contract is
null)
246 StringBuilder Xml =
new StringBuilder();
248 byte[] Data = Encoding.UTF8.GetBytes(Xml.ToString());
250 byte[] Signature = KeyEndpoint.Sign(Data);
254 LegalDomain,
string.Empty,
"<signContract id=\"" +
XML.
Encode(ContractId) +
255 "\" role=\"" +
XML.
Encode(Role) +
"\" s=\"" +
256 Convert.ToBase64String(Signature) +
"\" xmlns=\"" +
261 if (e2.Ok && !((E = e2.FirstElement) is
null) && E.LocalName ==
"contract")
263 await Response.Return(new NamedDictionary<string, object>(
"ContractResponse", AgentNamespace)
271 catch (Exception ex2)
273 await Response.SendResponse(ex2);
284 await Response.SendResponse(ex);
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
Static class managing the application event log. Applications and services log events on this static ...
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
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 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.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
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 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.
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.
async Task 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.
static async Task< ParsedContract > Parse(XmlElement Xml, LegalComponent Legal)
Parses a contract from is XML representation.
Contains information about a parsed contract.
Contract Contract
Contract object
IdentityState State
Current state of identity
Legal (digital identities, smart contracts) service component.
static string NamespaceSmartContracts(NamespaceSet Version)
Returns the namespace for smart contracts.
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.
static Exception ToHttpException(HttpRequest Request, 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.
NamespaceSet
Namespace versions