5using System.Threading.Tasks;
24 : base(
"/Attachments")
29 new LegalSignature(this.legalComponent.MainDomain.Address.Value,
this.legalComponent)
33 public override bool HandlesSubPaths =>
true;
34 public override bool UserSessions =>
true;
40 string AttachmentId = Request.
SubPath[1..];
41 int i = AttachmentId.IndexOf(
'@');
45 string AttachmentDomain = AttachmentId[(i + 1)..];
46 AttachmentId = AttachmentId[..i];
48 if (AttachmentDomain != this.legalComponent.MainDomain.Address.Value)
51 throw new BadRequestException(
"Attachment URL required for accessing attachment hosted by other nodes.");
53 KeyValuePair<string, TemporaryFile> P = await
Gateway.
ContractsClient.GetAttachmentAsync(AttachmentUrl, Networking.XMPP.Contracts.SignWith.LatestApprovedId, 30000);
56 Response.ContentType = P.Key;
60 int BufferSize = (int)Math.Min(65536, c);
61 byte[] Buffer =
new byte[BufferSize];
65 i = await File.TryReadAllAsync(Buffer, 0, (
int)Math.Min(BufferSize, c));
67 throw new IOException(
"Unexpected end of file.");
69 await Response.
Write(
true, Buffer, 0, i);
92 if (this.legalComponent.IsComponentDomain(Addr.
Domain,
true))
97 if (User.From.Account == Identity.Account &&
this.legalComponent.Server.IsServerDomain(User.From.Domain,
true))
107 Authorized = this.legalComponent.IsAccessToContractAuthorized(User.From.BareJid,
Attachment.
ContractId);
113 if (this.legalComponent.IsComponentDomain(Addr.
Domain,
true))
128 Authorized = await
Contract.
CanRead(User.From,
this.legalComponent.Server,
this.legalComponent);
133 this.legalComponent.ContractAuthorization(User.From.BareJid, User.From.BareJid,
Attachment.
ContractId,
true);
173 Aes Aes = Aes.Create();
177 Aes.Mode = CipherMode.CBC;
178 Aes.Padding = PaddingMode.Zeros;
180 byte[] Key =
new byte[32];
181 byte[] IV =
new byte[16];
186 using ICryptoTransform Decryptor = Aes.CreateDecryptor(Key, IV);
187 using (CryptoStream DecryptedAttachmentFile =
new CryptoStream(AttachmentFile, Decryptor, CryptoStreamMode.Read))
189 byte[] Buffer =
new byte[65536];
195 i = await DecryptedAttachmentFile.TryReadAllAsync(Buffer, 0, 65536);
197 i = await DecryptedAttachmentFile.TryReadAllAsync(Buffer, 0, (
int)c);
200 throw new IOException(
"Unexpected end of file.");
202 await Response.
Write(
false, Buffer, 0, i);
211 return this.authentication;
Static class managing the runtime environment of the IoT Gateway.
static ContractsClient ContractsClient
XMPP Contracts Client, if such a compoent is available on the XMPP broker.
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...
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
Represents an HTTP request.
HttpRequestHeader Header
Request header.
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
IUser User
Authenticated user, if available, or null if not available.
Represets a response of an HTTP client request.
Task Write(byte[] Data)
Returns binary data in the response.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Contains information about one XMPP address.
CaseInsensitiveString Domain
Domain
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< object > TryLoadObject(string CollectionName, object ObjectId)
Tries to load an object given its Object ID ObjectId and its collection name CollectionName .
This filter selects objects that have a named field equal to a given value.
Class managing the contents of a temporary file. When the class is disposed, the temporary file is de...
Represents an attachment to a document.
CaseInsensitiveString ContractId
Contract ID, if attachment is associated with a contract, or null otherwise.
CaseInsensitiveString UploaderLegalId
Legal ID of uploader
long Size
Size of attachment, in bytes.
string LocalFileName
Local Filename of attachment.
byte[] Salt
Salt used for deriving keys for decrypting attachment file.
string ContentType
Internet Content Type of binary attachment.
async Task GET(HttpRequest Request, HttpResponse Response)
Executes the GET method on the resource.
bool AllowsGET
If the GET method is allowed.
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
Contains the definition of a contract
Task< bool > CanRead(XmppAddress Jid, XmppServer Server, LegalComponent LegalComponent)
Checks if a client with a given Jid is allowed to read the contract.
User object representing a legal identity.
Legal (digital identities, smart contracts) service component.
GET Interface for HTTP resources.
ContractVisibility
Visibility types for contracts.