Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ValidateSenderContractSignature.cs
2using System.Threading.Tasks;
8
10{
15 {
16 private readonly LegalComponent legal;
17 private readonly IEDalerContractualPaymentUri contractualPaymentUri;
18 private Contract contract = null;
19 private readonly TaskCompletionSource<Contract> contractWaiter = new TaskCompletionSource<Contract>();
20 private bool prepareCompleted = false;
21
29 : base((EDalerUri)Uri)
30 {
31 this.legal = Legal;
32 this.contractualPaymentUri = Uri;
33 }
34
35 internal async Task<Contract> GetContractAsync()
36 {
37 if (this.prepareCompleted)
38 return this.contract;
39 else
40 return await this.contractWaiter.Task;
41 }
42
47 protected override async Task<bool> DoPrepare()
48 {
49 try
50 {
51 CaseInsensitiveString ContractId = this.contractualPaymentUri.ContractWithSignatures;
53 return false;
54
55 KeyValuePair<Contract, IqResultEventArgs> P = await this.legal.GetContract(ContractId);
56 this.contract = P.Key;
57 if (!await ValidateContractSigned.CheckContractValid(this.contract, this.Uri, ContractId, XmppServerModule.Legal))
58 return false;
59
60 bool SenderFound = false;
61
62 foreach (ClientSignature Signature in this.contract.ClientSignatures)
63 {
64 switch (this.Uri.FromType)
65 {
66 case EntityType.LegalId:
67 if (Signature.LegalId == this.Uri.From.Address)
68 SenderFound = true;
69 break;
70
71 case EntityType.NetworkJid:
72 if (Signature.BareJid == this.Uri.From.Address)
73 SenderFound = true;
74 break;
75 }
76
77 if (SenderFound)
78 break;
79 }
80
81 if (!SenderFound)
82 {
83 this.Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Sender not part in the contract.", false);
84 return false;
85 }
86
87 XmppAddress Addr = new XmppAddress(this.contract.ContractId);
88 if (!await this.legal.ValidateServerSignature(Addr.Domain,
89 this.Uri.PreSign, this.Uri.Signature, this.Uri.Created))
90 {
91 this.Uri.State.Error(Uris.States.EDalerUriErrorType.Forbidden, "Invalid server signature.", false);
92 return false;
93 }
94
95 return true;
96 }
97 finally
98 {
99 this.prepareCompleted = true;
100 this.contractWaiter.TrySetResult(this.contract);
101 }
102 }
103
108 protected override Task<bool> DoExecute()
109 {
110 return Task.FromResult(true); // No need to do nothing.
111 }
112
117 protected override Task<bool> DoCommit()
118 {
119 return Task.FromResult(true); // No need to do nothing.
120 }
121
126 protected override Task<bool> DoRollback()
127 {
128 return Task.FromResult(true); // No need to do nothing.
129 }
130 }
131}
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
CaseInsensitiveString Domain
Domain
Definition: XmppAddress.cs:97
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Abstract base class for eDaler transactions.
Validates a contract has been signed before a transaction can be realized.
Validates that the sender has signed the contract and that the contract is valid.
ValidateSenderContractSignature(IEDalerContractualPaymentUri Uri, LegalComponent Legal)
Validates that the sender has signed the contract and that the contract is valid.
Abstract base class for eDaler URIs
Definition: EDalerUri.cs:20
EDalerUriState State
URI State object.
Definition: EDalerUri.cs:173
Service Module hosting the XMPP broker and its components.
EntityType
Type of entity referred to in transaction.
Definition: Transaction.cs:15