Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ValidateSenderContractSignature.cs
1using System.Threading.Tasks;
7
9{
14 {
15 private readonly LegalComponent legal;
16 private readonly IEDalerContractualPaymentUri contractualPaymentUri;
17 private Contract contract = null;
18 private readonly TaskCompletionSource<Contract> contractWaiter = new TaskCompletionSource<Contract>();
19 private bool prepareCompleted = false;
20
28 : base((EDalerUri)Uri)
29 {
30 this.legal = Legal;
31 this.contractualPaymentUri = Uri;
32 }
33
34 internal async Task<Contract> GetContractAsync()
35 {
36 if (this.prepareCompleted)
37 return this.contract;
38 else
39 return await this.contractWaiter.Task;
40 }
41
46 protected override async Task<bool> DoPrepare()
47 {
48 try
49 {
50 CaseInsensitiveString ContractId = this.contractualPaymentUri.ContractWithSignatures;
52 return false;
53
54 this.contract = await this.legal.GetContract(ContractId);
55 if (!await ValidateContractSigned.CheckContractValid(this.contract, this.Uri, ContractId, XmppServerModule.Legal))
56 return false;
57
58 bool SenderFound = false;
59
60 foreach (ClientSignature Signature in this.contract.ClientSignatures)
61 {
62 switch (this.Uri.FromType)
63 {
64 case EntityType.LegalId:
65 if (Signature.LegalId == this.Uri.From.Address)
66 SenderFound = true;
67 break;
68
69 case EntityType.NetworkJid:
70 if (Signature.BareJid == this.Uri.From.Address)
71 SenderFound = true;
72 break;
73 }
74
75 if (SenderFound)
76 break;
77 }
78
79 if (!SenderFound)
80 {
81 this.Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Sender not part in the contract.", false);
82 return false;
83 }
84
85 XmppAddress Addr = new XmppAddress(this.contract.ContractId);
86 if (!await this.legal.ValidateServerSignature(Addr.Domain, this.Uri.PreSign, this.Uri.Signature))
87 {
88 this.Uri.State.Error(Uris.States.EDalerUriErrorType.Forbidden, "Invalid server signature.", false);
89 return false;
90 }
91
92 return true;
93 }
94 finally
95 {
96 this.prepareCompleted = true;
97 this.contractWaiter.TrySetResult(this.contract);
98 }
99 }
100
105 protected override Task<bool> DoExecute()
106 {
107 return Task.FromResult(true); // No need to do nothing.
108 }
109
114 protected override Task<bool> DoCommit()
115 {
116 return Task.FromResult(true); // No need to do nothing.
117 }
118
123 protected override Task<bool> DoRollback()
124 {
125 return Task.FromResult(true); // No need to do nothing.
126 }
127 }
128}
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