Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AcmeAccount.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using Waher.Content;
6
8{
13 {
17 valid,
18
22 deactivated,
23
27 revoked
28 };
29
34 {
35 private readonly AcmeAccountStatus status;
36 private readonly string[] contact = null;
37 private readonly string initialIp = null;
38 private readonly Uri orders = null;
39 private readonly DateTime? createdAt = null;
40 private readonly bool? termsOfServiceAgreed = null;
41
42 internal AcmeAccount(AcmeClient Client, Uri Location, IEnumerable<KeyValuePair<string, object>> Obj)
43 : base(Client, Location, Location)
44 {
45 foreach (KeyValuePair<string, object> P in Obj)
46 {
47 switch (P.Key)
48 {
49 case "status":
50 if (!Enum.TryParse(P.Value as string, out this.status))
51 throw new ArgumentException("Invalid ACME account status: " + P.Value.ToString(), "status");
52 break;
53
54 case "contact":
55 if (P.Value is Array A)
56 {
57 List<string> Contact = new List<string>();
58
59 foreach (object Obj2 in A)
60 {
61 if (Obj2 is string s)
62 Contact.Add(s);
63 }
64
65 this.contact = Contact.ToArray();
66 }
67 break;
68
69 case "termsOfServiceAgreed":
70 if (CommonTypes.TryParse(P.Value as string, out bool b))
71 this.termsOfServiceAgreed = b;
72 else
73 throw new ArgumentException("Invalid boolean value.", "termsOfServiceAgreed");
74 break;
75
76 case "orders":
77 this.orders = new Uri(P.Value as string);
78 break;
79
80 case "initialIp":
81 this.initialIp = P.Value as string;
82 break;
83
84 case "createdAt":
85 if (XML.TryParse(P.Value as string, out DateTime TP))
86 this.createdAt = TP;
87 else
88 throw new ArgumentException("Invalid date and time value.", "createdAt");
89 break;
90 }
91 }
92 }
93
98 public string[] Contact => this.contact;
99
103 public AcmeAccountStatus Status => this.status;
104
109 public bool? TermsOfServiceAgreed => this.termsOfServiceAgreed;
110
114 public Uri Orders => this.orders;
115
119 public string InitialIp => this.initialIp;
120
124 public DateTime? CreatedAt => this.createdAt;
125
131 public Task<AcmeAccount> Update(string[] Contact)
132 {
133 return this.Client.UpdateAccount(this.Location, Contact);
134 }
135
140 public Task<AcmeAccount> Deactivate()
141 {
142 return this.Client.DeactivateAccount(this.Location);
143 }
144
149 public Task<AcmeAccount> NewKey()
150 {
151 return this.Client.NewKey(this.Location);
152 }
153
161 public Task<AcmeOrder> OrderCertificate(string[] Domains, DateTime? NotBefore, DateTime? NotAfter)
162 {
163 int i, c = Domains.Length;
164 AcmeIdentifier[] Identifiers = new AcmeIdentifier[c];
165
166 for (i = 0; i < c; i++)
167 Identifiers[i] = new AcmeIdentifier(this.Client, "dns", Domains[i]);
168
169 return this.OrderCertificate(Identifiers, NotBefore, NotAfter);
170 }
171
179 public Task<AcmeOrder> OrderCertificate(string Domain, DateTime? NotBefore, DateTime? NotAfter)
180 {
181 return this.OrderCertificate("dns", Domain, NotBefore, NotAfter);
182 }
183
192 public Task<AcmeOrder> OrderCertificate(string Type, string Value, DateTime? NotBefore, DateTime? NotAfter)
193 {
194 return this.OrderCertificate(new AcmeIdentifier(this.Client, Type, Value), NotBefore, NotAfter);
195 }
196
204 public Task<AcmeOrder> OrderCertificate(AcmeIdentifier Identifier,
205 DateTime? NotBefore, DateTime? NotAfter)
206 {
207 return this.OrderCertificate(new AcmeIdentifier[] { Identifier }, NotBefore, NotAfter);
208 }
209
217 public Task<AcmeOrder> OrderCertificate(AcmeIdentifier[] Identifiers,
218 DateTime? NotBefore, DateTime? NotAfter)
219 {
220 return this.Client.OrderCertificate(this.Location, Identifiers, NotBefore, NotAfter);
221 }
222
226 public Task<AcmeOrder[]> GetOrders()
227 {
228 if (this.orders is null)
229 throw new Exception("Account object did not report a URI for the list of orders.");
230
231 return this.Client.GetOrders(this.Location, this.orders);
232 }
233 }
234}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
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 account.
Definition: AcmeAccount.cs:34
Task< AcmeOrder > OrderCertificate(string Domain, DateTime? NotBefore, DateTime? NotAfter)
Orders certificate.
Definition: AcmeAccount.cs:179
Task< AcmeAccount > NewKey()
Creates a new key for the account.
Definition: AcmeAccount.cs:149
Task< AcmeOrder > OrderCertificate(string[] Domains, DateTime? NotBefore, DateTime? NotAfter)
Orders certificate.
Definition: AcmeAccount.cs:161
string[] Contact
Optional array of URLs that the server can use to contact the client for issues related to this accou...
Definition: AcmeAccount.cs:98
Uri Orders
A URL from which a list of orders submitted by this account can be fetched via a GET request
Definition: AcmeAccount.cs:114
DateTime? CreatedAt
Date and time of creation, if available.
Definition: AcmeAccount.cs:124
Task< AcmeAccount > Update(string[] Contact)
Updates the account.
Definition: AcmeAccount.cs:131
bool? TermsOfServiceAgreed
Including this field in a new-account request, with a value of true, indicates the client's agreement...
Definition: AcmeAccount.cs:109
string InitialIp
Initial IP address.
Definition: AcmeAccount.cs:119
AcmeAccountStatus Status
The status of this account.
Definition: AcmeAccount.cs:103
Task< AcmeOrder > OrderCertificate(AcmeIdentifier Identifier, DateTime? NotBefore, DateTime? NotAfter)
Orders certificate.
Definition: AcmeAccount.cs:204
Task< AcmeOrder > OrderCertificate(AcmeIdentifier[] Identifiers, DateTime? NotBefore, DateTime? NotAfter)
Orders certificate.
Definition: AcmeAccount.cs:217
Task< AcmeOrder[]> GetOrders()
Gets the list of current orders.
Definition: AcmeAccount.cs:226
Task< AcmeOrder > OrderCertificate(string Type, string Value, DateTime? NotBefore, DateTime? NotAfter)
Orders certificate.
Definition: AcmeAccount.cs:192
Task< AcmeAccount > Deactivate()
Deactivates the account.
Definition: AcmeAccount.cs:140
Implements an ACME client for the generation of certificates using ACME-compliant certificate servers...
Definition: AcmeClient.cs:24
async Task< AcmeAccount > NewKey(Uri AccountLocation)
Generates a new key for the account. (Account keys are managed by the CSP.)
Definition: AcmeClient.cs:497
async Task< AcmeOrder > OrderCertificate(Uri AccountLocation, AcmeIdentifier[] Identifiers, DateTime? NotBefore, DateTime? NotAfter)
Orders certificate.
Definition: AcmeClient.cs:549
async Task< AcmeAccount > UpdateAccount(Uri AccountLocation, string[] Contact)
Updates an account.
Definition: AcmeClient.cs:466
async Task< AcmeOrder[]> GetOrders(Uri AccountLocation, Uri OrdersLocation)
Gets the list of current orders for an account.
Definition: AcmeClient.cs:601
async Task< AcmeAccount > DeactivateAccount(Uri AccountLocation)
Deactivates an account.
Definition: AcmeClient.cs:482
Represents an ACME identifier.
AcmeClient Client
ACME client.
Definition: AcmeObject.cs:26
Abstract base class for all ACME resources.
Definition: AcmeResource.cs:11
Uri Location
Location of resource.
Definition: AcmeResource.cs:37
AcmeAccountStatus
ACME Account status enumeration
Definition: AcmeAccount.cs:13