-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathAcmeChallenge.cs
More file actions
118 lines (102 loc) · 2.54 KB
/
AcmeChallenge.cs
File metadata and controls
118 lines (102 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Waher.Content.Xml;
namespace Waher.Security.ACME
{
/// <summary>
/// ACME Challenge status enumeration
/// </summary>
public enum AcmeChallengeStatus
{
/// <summary>
/// Challenge created
/// </summary>
pending,
/// <summary>
/// Challenge being processed
/// </summary>
processing,
/// <summary>
/// Challenge valid
/// </summary>
valid,
/// <summary>
/// Challenge invalid
/// </summary>
invalid
}
/// <summary>
/// Base class of all ACME challenges.
/// </summary>
public class AcmeChallenge : AcmeResource
{
private readonly AcmeChallengeStatus status;
private readonly string type;
private readonly string token;
private readonly DateTime? validated;
internal AcmeChallenge(AcmeClient Client, Uri AccountLocation, IEnumerable<KeyValuePair<string, object>> Obj)
: base(Client, AccountLocation, null)
{
foreach (KeyValuePair<string, object> P in Obj)
{
switch (P.Key)
{
case "status":
if (!Enum.TryParse(P.Value as string, out this.status))
throw new ArgumentException("Invalid ACME challenge status: " + P.Value.ToString(), "status");
break;
case "validated":
if (XML.TryParse(P.Value as string, out DateTime TP))
this.validated = TP;
else
throw new ArgumentException("Invalid date and time value.", "validated");
break;
case "url":
this.Location = new Uri(P.Value as string);
break;
case "type":
this.type = P.Value as string;
break;
case "token":
this.token = P.Value as string;
break;
}
}
}
/// <summary>
/// The status of this challenge.
/// </summary>
public AcmeChallengeStatus Status => this.status;
/// <summary>
/// When the challenge was validated.
/// </summary>
public DateTime? Validated => this.validated;
/// <summary>
/// Type of challenge.
/// </summary>
public string Type => this.type;
/// <summary>
/// Token
/// </summary>
public string Token => this.token;
/// <summary>
/// Key authorization string. Used as response to challenge.
/// </summary>
public virtual string KeyAuthorization
{
get
{
return this.token + "." + this.Client.JwkThumbprint;
}
}
/// <summary>
/// Acknowledges the challenge.
/// </summary>
/// <returns>Acknowledged challenge object.</returns>
public Task<AcmeChallenge> AcknowledgeChallenge()
{
return this.Client.AcknowledgeChallenge(this.AccountLocation, this.Location);
}
}
}