2using System.Collections.Generic;
4using System.Security.Cryptography;
5using System.Threading.Tasks;
23 : base(
"/Attachments")
28 new LegalSignature(this.legalComponent.MainDomain.Address.Value,
this.legalComponent)
32 public override bool HandlesSubPaths =>
true;
33 public override bool UserSessions =>
true;
39 string AttachmentId = Request.
SubPath.Substring(1);
40 int i = AttachmentId.IndexOf(
'@');
44 string AttachmentDomain = AttachmentId.Substring(i + 1);
45 AttachmentId = AttachmentId.Substring(0, i);
47 if (AttachmentDomain != this.legalComponent.MainDomain.Address.Value)
50 throw new BadRequestException(
"Attachment URL required for accessing attachment hosted by other nodes.");
52 KeyValuePair<string, TemporaryFile> P = await
Gateway.
ContractsClient.GetAttachmentAsync(AttachmentUrl, Networking.XMPP.Contracts.SignWith.LatestApprovedId, 30000);
55 Response.ContentType = P.Key;
59 int BufferSize = (int)Math.Min(65536, c);
60 byte[] Buffer =
new byte[BufferSize];
64 i = await File.TryReadAllAsync(Buffer, 0, (
int)Math.Min(BufferSize, c));
66 throw new IOException(
"Unexpected end of file.");
68 await Response.
Write(Buffer, 0, i);
93 if (User.From.Account == Identity.Account &&
this.legalComponent.Server.IsServerDomain(User.From.Domain,
true))
102 Authorized = this.legalComponent.IsAccessToContractAuthorized(User.From.BareJid,
Attachment.
ContractId);
111 Authorized = await
Contract.
CanRead(User.From,
this.legalComponent.Server,
this.legalComponent);
113 this.legalComponent.ContractAuthorization(User.From.BareJid, User.From.BareJid,
Attachment.
ContractId,
true);
133 Aes Aes = Aes.Create();
137 Aes.Mode = CipherMode.CBC;
138 Aes.Padding = PaddingMode.Zeros;
140 byte[] Key =
new byte[32];
141 byte[] IV =
new byte[16];
146 using (ICryptoTransform Decryptor = Aes.CreateDecryptor(Key, IV))
148 using (CryptoStream DecryptedAttachmentFile =
new CryptoStream(AttachmentFile, Decryptor, CryptoStreamMode.Read))
150 byte[] Buffer =
new byte[65536];
156 i = await DecryptedAttachmentFile.TryReadAllAsync(Buffer, 0, 65536);
158 i = await DecryptedAttachmentFile.TryReadAllAsync(Buffer, 0, (
int)c);
161 throw new IOException(
"Unexpected end of file.");
163 await Response.
Write(Buffer, 0, i);
174 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.
async 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...
bool EndsWith(CaseInsensitiveString value, StringComparison comparisonType)
Determines whether the end of this string instance matches the specified string when compared using t...
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.
Provisioning and registry service component.
GET Interface for HTTP resources.