Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AcmeOrder.cs
1using System;
2using System.Collections.Generic;
3using System.Net.Http;
4using System.Security.Cryptography.X509Certificates;
5using System.Threading.Tasks;
8
10{
14 public enum AcmeOrderStatus
15 {
20 pending,
21
26 ready,
27
32 processing,
33
38 valid,
39
43 invalid
44 };
45
49 public class AcmeOrder : AcmeResource
50 {
51 private readonly AcmeOrderStatus status;
52 private readonly DateTime? expires = null;
53 private readonly DateTime? notBefore = null;
54 private readonly DateTime? notAfter = null;
55 private readonly AcmeIdentifier[] identifiers = null;
56 private AcmeAuthorization[] authorizations = null;
57 private readonly Uri[] authorizationUris = null;
58 private readonly AcmeException error = null; // TODO: Problem document
59 private readonly Uri finalize = null;
60 private readonly Uri certificate = null;
61
63 IEnumerable<KeyValuePair<string, object>> Obj, HttpResponseMessage Response)
65 {
66 foreach (KeyValuePair<string, object> P in Obj)
67 {
68 switch (P.Key)
69 {
70 case "status":
71 if (!Enum.TryParse(P.Value as string, out this.status))
72 throw new ArgumentException("Invalid ACME order status: " + P.Value.ToString(), "status");
73 break;
74
75 case "expires":
76 if (XML.TryParse(P.Value as string, out DateTime TP))
77 this.expires = TP;
78 else
79 throw new ArgumentException("Invalid date and time value.", "expires");
80 break;
81
82 case "notBefore":
83 if (XML.TryParse(P.Value as string, out TP))
84 this.notBefore = TP;
85 else
86 throw new ArgumentException("Invalid date and time value.", "notBefore");
87 break;
88
89 case "notAfter":
90 if (XML.TryParse(P.Value as string, out TP))
91 this.notAfter = TP;
92 else
93 throw new ArgumentException("Invalid date and time value.", "notAfter");
94 break;
95
96 case "identifiers":
97 if (P.Value is Array A)
98 {
99 List<AcmeIdentifier> Identifiers = new List<AcmeIdentifier>();
100
101 foreach (object Obj2 in A)
102 {
103 if (Obj2 is IEnumerable<KeyValuePair<string, object>> Obj3)
104 Identifiers.Add(new AcmeIdentifier(Client, Obj3));
105 }
106
107 this.identifiers = Identifiers.ToArray();
108 }
109 break;
110
111 case "authorizations":
112 if (P.Value is Array A2)
113 {
114 List<Uri> Authorizations = new List<Uri>();
115
116 foreach (object Obj2 in A2)
117 {
118 if (Obj2 is string s)
119 Authorizations.Add(new Uri(s));
120 }
121
122 this.authorizationUris = Authorizations.ToArray();
123 }
124 break;
125
126 case "finalize":
127 this.finalize = new Uri(P.Value as string);
128 break;
129
130 case "certificate":
131 this.certificate = new Uri(P.Value as string);
132 break;
133
134 case "error":
135 if (P.Value is IEnumerable<KeyValuePair<string, object>> ErrorObj)
136 this.error = AcmeClient.CreateException(ErrorObj, Response);
137 break;
138 }
139 }
140 }
141
145 public AcmeIdentifier[] Identifiers => this.identifiers;
146
151 public Uri[] AuthorizationUris => this.authorizationUris;
152
156 public AcmeOrderStatus Status => this.status;
157
161 public DateTime? Expires => this.expires;
162
166 public DateTime? NotBefore => this.notBefore;
167
171 public DateTime? NotAfter => this.notAfter;
172
176 public Uri Finalize => this.finalize;
177
181 public Uri Certificate => this.certificate;
182
186 public AcmeException Error => this.error;
187
192 public Task<AcmeOrder> Poll()
193 {
194 return this.Client.GetOrder(this.AccountLocation, this.Location);
195 }
196
201 public async Task<AcmeAuthorization[]> GetAuthorizations()
202 {
203 if (this.authorizations is null)
204 {
205 int i, c = this.authorizationUris.Length;
206 AcmeAuthorization[] Result = new AcmeAuthorization[c];
207
208 for (i = 0; i < c; i++)
209 {
210 Uri Location = this.authorizationUris[i];
211 Result[i] = new AcmeAuthorization(this.Client, this.AccountLocation, Location,
212 (await this.Client.POST_as_GET(Location, this.AccountLocation)).Payload);
213 }
214
215 this.authorizations = Result;
216 }
217
218 return this.authorizations;
219 }
220
224 public Task<AcmeAuthorization[]> Authorizations
225 {
226 get { return this.GetAuthorizations(); }
227 }
228
235 {
236 return this.Client.FinalizeOrder(this.AccountLocation, this.finalize, CertificateRequest);
237 }
238
243 public Task<X509Certificate2[]> DownloadCertificate()
244 {
245 if (this.certificate is null)
246 throw new Exception("No certificate URI available.");
247
248 return this.Client.DownloadCertificate(this.AccountLocation, this.certificate);
249 }
250 }
251}
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
Represents an ACME authorization.
Implements an ACME client for the generation of certificates using ACME-compliant certificate servers...
Definition: AcmeClient.cs:24
async Task< AcmeOrder > GetOrder(Uri AccountLocation, Uri OrderLocation)
Gets the state of an order.
Definition: AcmeClient.cs:589
async Task< AcmeOrder > FinalizeOrder(Uri AccountLocation, Uri FinalizeLocation, CertificateRequest CertificateRequest)
Finalize order.
Definition: AcmeClient.cs:708
async Task< X509Certificate2[]> DownloadCertificate(Uri AccountLocation, Uri CertificateLocation)
Downloads a certificate.
Definition: AcmeClient.cs:723
Represents an ACME problem report.
Represents an ACME identifier.
AcmeClient Client
ACME client.
Definition: AcmeObject.cs:26
Represents an ACME order.
Definition: AcmeOrder.cs:50
DateTime? Expires
The timestamp after which the server will consider this order invalid
Definition: AcmeOrder.cs:161
Task< AcmeOrder > Poll()
Gets the current state of the order.
Definition: AcmeOrder.cs:192
AcmeOrderStatus Status
The status of this order.
Definition: AcmeOrder.cs:156
Uri[] AuthorizationUris
For pending orders, the authorizations that the client needs to complete before the requested certifi...
Definition: AcmeOrder.cs:151
AcmeException Error
Any error, if available.
Definition: AcmeOrder.cs:186
Uri Certificate
A URL for the certificate that has been issued in response to this order.
Definition: AcmeOrder.cs:181
DateTime? NotBefore
The requested value of the notBefore field in the certificate
Definition: AcmeOrder.cs:166
async Task< AcmeAuthorization[]> GetAuthorizations()
Gets current authorization objects.
Definition: AcmeOrder.cs:201
DateTime? NotAfter
The requested value of the notAfter field in the certificate
Definition: AcmeOrder.cs:171
AcmeIdentifier[] Identifiers
An array of identifier objects that the order pertains to.
Definition: AcmeOrder.cs:145
Task< X509Certificate2[]> DownloadCertificate()
Downloads the certificate.
Definition: AcmeOrder.cs:243
Uri Finalize
A URL that a CSR must be POSTed to once all of the order's authorizations are satisfied to finalize t...
Definition: AcmeOrder.cs:176
Task< AcmeOrder > FinalizeOrder(CertificateRequest CertificateRequest)
Finalize order.
Definition: AcmeOrder.cs:234
Task< AcmeAuthorization[]> Authorizations
Curernt authorization objects.
Definition: AcmeOrder.cs:225
Abstract base class for all ACME resources.
Definition: AcmeResource.cs:11
Uri Location
Location of resource.
Definition: AcmeResource.cs:37
Uri AccountLocation
Account location.
Definition: AcmeResource.cs:31
Contains information about a Certificate Signing Request (CSR).
AcmeOrderStatus
ACME Order status enumeration
Definition: AcmeOrder.cs:15