Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PackageUrlValidator.cs
1using System;
2using System.Threading.Tasks;
6
8{
10 {
11 public PackageUrlValidator()
12 {
13 }
14
15 public override string GetChallenge()
16 {
17 throw new BadRequestException();
18 }
19
20 public override async Task<IUser> IsAuthenticated(HttpRequest Request)
21 {
22 if (!Request.Header.TryGetQueryParameter("s", out string SignatureStr) ||
23 !Request.Header.TryGetQueryParameter("p", out string PublishedStr) ||
24 XML.TryParse(PublishedStr, out DateTime Published))
25 {
26 return null;
27 }
28
29 Package Package = await ProvisioningComponent.GetPackage(Request.SubPath);
30 if (Package is null ||
31 Package.Published != Published ||
32 string.Compare(Convert.ToBase64String(Package.Signature), SignatureStr, true) != 0)
33 {
34 return null;
35 }
36
37 return new PackageUser(Package);
38 }
39
40 private class PackageUser : IUser
41 {
42 private readonly Package package;
43
44 public PackageUser(Package Package)
45 {
46 this.package = Package;
47 }
48
49 public string UserName => this.package.FileName;
50 public string PasswordHash => throw new InvalidOperationException();
51 public string PasswordHashType => throw new InvalidOperationException();
52
53 public bool HasPrivilege(string Privilege)
54 {
55 return false;
56 }
57 }
58 }
59}
Helps with common XML-related tasks.
Definition: XML.cs:19
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
Definition: XML.cs:744
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
bool TryGetQueryParameter(string QueryParameter, out string Value)
Tries to get the value of an individual query parameter, if available.
Represents an HTTP request.
Definition: HttpRequest.cs:18
HttpRequestHeader Header
Request header.
Definition: HttpRequest.cs:134
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
Definition: HttpRequest.cs:146
Contains information about a software package.
Definition: Package.cs:18
byte[] Signature
Cryptographic signature of package, as calculated by the issuer of the package.
Definition: Package.cs:46
CaseInsensitiveString FileName
Filename of package.
Definition: Package.cs:40
DateTime Published
When package was published.
Definition: Package.cs:76
override async Task< IUser > IsAuthenticated(HttpRequest Request)
Checks if the request is authorized.
override string GetChallenge()
Gets a challenge for the authenticating client to respond to.
Basic interface for a user.
Definition: IUser.cs:7