acme-client 2.0.17 → 2.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +79 -0
- data/README.md +48 -2
- data/Rakefile +5 -0
- data/acme-client-2.0.32.gem +0 -0
- data/acme-client.gemspec +4 -1
- data/lib/acme/client/certificate_request.rb +19 -2
- data/lib/acme/client/error/rate_limited.rb +15 -0
- data/lib/acme/client/error.rb +77 -1
- data/lib/acme/client/http_client.rb +13 -1
- data/lib/acme/client/jwk/ecdsa.rb +4 -4
- data/lib/acme/client/problem.rb +135 -0
- data/lib/acme/client/resources/account.rb +4 -2
- data/lib/acme/client/resources/authorization.rb +13 -3
- data/lib/acme/client/resources/challenges/base.rb +16 -3
- data/lib/acme/client/resources/challenges/dns_account01.rb +30 -0
- data/lib/acme/client/resources/challenges.rb +3 -1
- data/lib/acme/client/resources/directory.rb +8 -2
- data/lib/acme/client/resources/order.rb +37 -4
- data/lib/acme/client/resources/renewal_info.rb +54 -0
- data/lib/acme/client/resources.rb +1 -0
- data/lib/acme/client/util.rb +55 -0
- data/lib/acme/client/version.rb +1 -1
- data/lib/acme/client.rb +45 -4
- metadata +52 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f38120a91d760cdaf3a37defaf5c100da771a656655bb9cf26276901371e89f3
|
|
4
|
+
data.tar.gz: 712b061ca7d441c0fcbb5554a21a44c1495bf0fa5a7b21010942f644f79d353b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d830b1206e60ae98a031de5237618c3a526fdd2f29ebaed5aa018352c15c3838e30015a104de622a850846ac56e5bbe94c06b94378bab854adb961031c8548ef
|
|
7
|
+
data.tar.gz: 741e5e8b735527b1f95b630564ce0cf1729880323cb3eae7696ce7a7738570de73ab2ce0aaf3bb0bf53c2b7418d3ad56240e2373f55414bf2e112f7802443dc2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
+
## `2.0.35`
|
|
2
|
+
|
|
3
|
+
* Expose the RFC 8555 order `error` field on `Resources::Order#error` and add `Order#typed_error`
|
|
4
|
+
|
|
5
|
+
## `2.0.34`
|
|
6
|
+
|
|
7
|
+
* Add badAttestationStatement error
|
|
8
|
+
|
|
9
|
+
## `2.0.33`
|
|
10
|
+
|
|
11
|
+
* Add `Acme::Client::Problem` for structured RFC 7807 / RFC 8555 ACME problem documents
|
|
12
|
+
* Expose `Acme::Client::Error#problem` and problem field accessors while keeping `#acme_error_body` behavior
|
|
13
|
+
* Add typed error mappings for all currently registered IANA ACME error types and verify them against IANA's CSV registry
|
|
14
|
+
|
|
15
|
+
## `2.0.32`
|
|
16
|
+
|
|
17
|
+
* Fix `valid_ip_address?` method definition. Was mistakenly defined on Object instead of `Acme::Client::CertificateRequest`
|
|
18
|
+
|
|
19
|
+
## `2.0.31`
|
|
20
|
+
|
|
21
|
+
* Expose Retry-After header on all
|
|
22
|
+
* ARI improvement
|
|
23
|
+
* Expose full error message on Error#acme_error_body
|
|
24
|
+
* Expose error subproblems (RFC7807) on Error#subproblems
|
|
25
|
+
|
|
26
|
+
## `2.0.30`
|
|
27
|
+
|
|
28
|
+
* Add a default message to RateLimited error
|
|
29
|
+
|
|
30
|
+
This fix avoid argument error on RateLimited object when stubbing without passing arguments.
|
|
31
|
+
|
|
32
|
+
## `2.0.29`
|
|
33
|
+
|
|
34
|
+
* IP support to the CertificateRequest helper
|
|
35
|
+
|
|
36
|
+
## `2.0.28`
|
|
37
|
+
|
|
38
|
+
* Make [Retry-After](https://datatracker.ietf.org/doc/html/rfc8555/#section-6.6) accessible from RateLimited#retry_after exceptions
|
|
39
|
+
|
|
40
|
+
## `2.0.27`
|
|
41
|
+
|
|
42
|
+
* Add support for Renewal Information (ARI) (RFC 9773)
|
|
43
|
+
|
|
44
|
+
## `2.0.26`
|
|
45
|
+
|
|
46
|
+
* Add support for dns-account-01 challenge (RFC draft-ietf-acme-dns-account-label-01)
|
|
47
|
+
|
|
48
|
+
## `2.0.25`
|
|
49
|
+
|
|
50
|
+
* Add support for profiles extension
|
|
51
|
+
|
|
52
|
+
## `2.0.24`
|
|
53
|
+
|
|
54
|
+
* Add support for account orders url attribute.
|
|
55
|
+
|
|
56
|
+
## `2.0.23`
|
|
57
|
+
|
|
58
|
+
* Allow Order to be create without url. Location is not always required in the specification.
|
|
59
|
+
|
|
60
|
+
## `2.0.22`
|
|
61
|
+
|
|
62
|
+
* Loosen base64 dependency constraint
|
|
63
|
+
|
|
64
|
+
## `2.0.21`
|
|
65
|
+
|
|
66
|
+
* Add validated attribute to challenges
|
|
67
|
+
|
|
68
|
+
## `2.0.20`
|
|
69
|
+
|
|
70
|
+
* Add OrderNotReady exception
|
|
71
|
+
|
|
72
|
+
## `2.0.19`
|
|
73
|
+
|
|
74
|
+
* Fix an issue CSR generation. Version should be set to zero according to the spec. It's causing issue with some ACME server implementation.
|
|
75
|
+
|
|
76
|
+
## `2.0.18`
|
|
77
|
+
|
|
78
|
+
* Fix an issue public key encoding. `OpenSSL::BN` cause keys with leading zero to fail.
|
|
79
|
+
|
|
1
80
|
## `2.0.17`
|
|
2
81
|
|
|
3
82
|
* Fix bug where depending on call order `jws` get generated with the wrong `kid`
|
data/README.md
CHANGED
|
@@ -120,9 +120,11 @@ To order a new certificate, the client must provide a list of identifiers.
|
|
|
120
120
|
|
|
121
121
|
The returned order will contain a list of `Authorization` that need to be completed in other to finalize the order, generally one per identifier.
|
|
122
122
|
|
|
123
|
-
Each authorization contains multiple challenges, typically a `dns-01` and a `http-01` challenge. The applicant is only required to complete one of the challenges.
|
|
123
|
+
Each authorization contains multiple challenges, typically a `dns-01`, `dns-account-01`, and a `http-01` challenge. The applicant is only required to complete one of the challenges.
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
The `dns-account-01` challenge prepends an account-specific label before `_acme-challenge`, producing a record name of the form `_<label>._acme-challenge` so different clients can validate the same domain concurrently.
|
|
126
|
+
|
|
127
|
+
You can access the challenge you wish to complete using the `#dns`, `#dns_account`, or `#http` methods.
|
|
126
128
|
|
|
127
129
|
```ruby
|
|
128
130
|
order = client.new_order(identifiers: ['example.com'])
|
|
@@ -165,6 +167,25 @@ dns_challenge.record_type # => 'TXT'
|
|
|
165
167
|
dns_challenge.record_content # => 'HRV3PS5sRDyV-ous4HJk4z24s5JjmUTjcCaUjFt28-8'
|
|
166
168
|
```
|
|
167
169
|
|
|
170
|
+
### Preparing for DNS-Account-01 challenge
|
|
171
|
+
|
|
172
|
+
To complete the DNS-Account-01 challenge, you must set a DNS TXT record using an account-specific name. This allows multiple ACME clients to validate the same domain concurrently without conflicts.
|
|
173
|
+
|
|
174
|
+
The DNSAccount01 object has utility methods to generate the required DNS record:
|
|
175
|
+
|
|
176
|
+
```ruby
|
|
177
|
+
dns_account_challenge = authorization.dns_account
|
|
178
|
+
|
|
179
|
+
dns_account_challenge.record_name # => '_ujmmovf2vn55tgye._acme-challenge'
|
|
180
|
+
dns_account_challenge.record_type # => 'TXT'
|
|
181
|
+
dns_account_challenge.record_content # => 'HRV3PS5sRDyV-ous4HJk4z24s5JjmUTjcCaUjFt28-8'
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The record name includes an account-specific label derived from your account URL, ensuring different clients can validate simultaneously:
|
|
185
|
+
|
|
186
|
+
- **DNS-01**: `_acme-challenge.example.com` (shared)
|
|
187
|
+
- **DNS-Account-01**: `_ujmmovf2vn55tgye._acme-challenge.example.com` (account-specific)
|
|
188
|
+
|
|
168
189
|
### Requesting a challenge verification
|
|
169
190
|
|
|
170
191
|
Once you are ready to complete the challenge, you can request the server perform the verification.
|
|
@@ -203,6 +224,15 @@ end
|
|
|
203
224
|
order.certificate # => PEM-formatted certificate
|
|
204
225
|
```
|
|
205
226
|
|
|
227
|
+
When the server fails issuance after accepting the finalize request, the order moves to `invalid` and carries a problem document explaining why.
|
|
228
|
+
|
|
229
|
+
```ruby
|
|
230
|
+
if order.status == 'invalid'
|
|
231
|
+
order.error # => { "type" => "urn:ietf:params:acme:error:rateLimited", "detail" => "..." }
|
|
232
|
+
order.typed_error # => Acme::Client::Error::RateLimited
|
|
233
|
+
end
|
|
234
|
+
```
|
|
235
|
+
|
|
206
236
|
### Ordering an alternative certificate
|
|
207
237
|
|
|
208
238
|
The provider may provide alternate certificate with different certificate chain. You can specify the required chain and the client will automatically download alternate certificate and match the chain by name.
|
|
@@ -244,6 +274,22 @@ new_private_key = OpenSSL::PKey::RSA.new(4096)
|
|
|
244
274
|
client.account_key_change(new_private_key: new_private_key)
|
|
245
275
|
```
|
|
246
276
|
|
|
277
|
+
### Profile Extension
|
|
278
|
+
|
|
279
|
+
Provide a CA profile when creating a new order:
|
|
280
|
+
|
|
281
|
+
```ruby
|
|
282
|
+
order = client.new_order(identifiers: ['example.com'], profile: 'shortlived')
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
ACME servers may list supported profiles in the directory endpoint:
|
|
286
|
+
|
|
287
|
+
```ruby
|
|
288
|
+
client.profiles => {"classic": "https://example.com/docs/classic", "shortlived": "https://example.com/docs/shortlived"}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
See the [RFC draft of certificate profiles](https://datatracker.ietf.org/doc/draft-aaron-acme-profiles/) for more info.
|
|
292
|
+
|
|
247
293
|
## Requirements
|
|
248
294
|
|
|
249
295
|
Ruby >= 3.0
|
data/Rakefile
CHANGED
|
@@ -3,4 +3,9 @@ require 'bundler/gem_tasks'
|
|
|
3
3
|
require 'rspec/core/rake_task'
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
|
5
5
|
|
|
6
|
+
desc 'Check the gem against the live IANA ACME error registry'
|
|
7
|
+
task :spec_iana_registry do
|
|
8
|
+
sh({ 'RUN_IANA_REGISTRY_SPEC' => '1' }, 'bundle exec rspec spec/iana_registry_spec.rb')
|
|
9
|
+
end
|
|
10
|
+
|
|
6
11
|
task default: [:spec]
|
|
Binary file
|
data/acme-client.gemspec
CHANGED
|
@@ -18,10 +18,13 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
|
|
19
19
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
20
20
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
|
21
|
-
spec.add_development_dependency 'vcr', '~>
|
|
21
|
+
spec.add_development_dependency 'vcr', '~> 6.0'
|
|
22
|
+
spec.add_development_dependency 'bigdecimal'
|
|
23
|
+
spec.add_development_dependency 'csv'
|
|
22
24
|
spec.add_development_dependency 'webmock', '~> 3.8'
|
|
23
25
|
spec.add_development_dependency 'webrick', '~> 1.7'
|
|
24
26
|
|
|
27
|
+
spec.add_runtime_dependency 'base64', '~> 0.2'
|
|
25
28
|
spec.add_runtime_dependency 'faraday', '>= 1.0', '< 3.0.0'
|
|
26
29
|
spec.add_runtime_dependency 'faraday-retry', '>= 1.0', '< 3.0.0'
|
|
27
30
|
end
|
|
@@ -89,7 +89,7 @@ class Acme::Client::CertificateRequest
|
|
|
89
89
|
end
|
|
90
90
|
csr.public_key = @private_key
|
|
91
91
|
csr.subject = generate_subject
|
|
92
|
-
csr.version =
|
|
92
|
+
csr.version = 0
|
|
93
93
|
add_extension(csr)
|
|
94
94
|
csr.sign @private_key, @digest
|
|
95
95
|
end
|
|
@@ -104,8 +104,15 @@ class Acme::Client::CertificateRequest
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def add_extension(csr)
|
|
107
|
+
san = @names.map do |name|
|
|
108
|
+
if valid_ip_address?(name)
|
|
109
|
+
"IP:#{name}"
|
|
110
|
+
else
|
|
111
|
+
"DNS:#{name}"
|
|
112
|
+
end
|
|
113
|
+
end
|
|
107
114
|
extension = OpenSSL::X509::ExtensionFactory.new.create_extension(
|
|
108
|
-
'subjectAltName',
|
|
115
|
+
'subjectAltName', san.join(', '), false
|
|
109
116
|
)
|
|
110
117
|
csr.add_attribute(
|
|
111
118
|
OpenSSL::X509::Attribute.new(
|
|
@@ -114,6 +121,16 @@ class Acme::Client::CertificateRequest
|
|
|
114
121
|
)
|
|
115
122
|
)
|
|
116
123
|
end
|
|
124
|
+
|
|
125
|
+
def valid_ip_address?(address)
|
|
126
|
+
require 'ipaddr'
|
|
127
|
+
begin
|
|
128
|
+
ip = IPAddr.new(address)
|
|
129
|
+
true
|
|
130
|
+
rescue IPAddr::InvalidAddressError, IPAddr::AddressFamilyError
|
|
131
|
+
false
|
|
132
|
+
end
|
|
133
|
+
end
|
|
117
134
|
end
|
|
118
135
|
|
|
119
136
|
require 'acme/client/certificate_request/ec_key_patch'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Acme::Client::Error::RateLimited < Acme::Client::Error::ServerError
|
|
2
|
+
DEFAULT_MESSAGE = 'Error message: urn:ietf:params:acme:error:rateLimited'
|
|
3
|
+
DEFAULT_RETRY_SECONDS = 10
|
|
4
|
+
|
|
5
|
+
def initialize(message = DEFAULT_MESSAGE, retry_after = nil, acme_error_body: nil, subproblems: nil, problem: nil)
|
|
6
|
+
retry_after_time = case retry_after
|
|
7
|
+
when Time then retry_after
|
|
8
|
+
when nil then Time.now + DEFAULT_RETRY_SECONDS
|
|
9
|
+
else Acme::Client::Util.parse_retry_after(retry_after) || Time.now + DEFAULT_RETRY_SECONDS
|
|
10
|
+
end
|
|
11
|
+
int_retry_after = retry_after.nil? ? DEFAULT_RETRY_SECONDS : [(retry_after_time - Time.now).ceil, 0].max
|
|
12
|
+
super(message, retry_after: int_retry_after, acme_error_body: acme_error_body, subproblems: subproblems, problem: problem)
|
|
13
|
+
@retry_after_time = retry_after_time
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/acme/client/error.rb
CHANGED
|
@@ -1,4 +1,59 @@
|
|
|
1
|
+
require 'acme/client/problem'
|
|
2
|
+
|
|
1
3
|
class Acme::Client::Error < StandardError
|
|
4
|
+
attr_reader :retry_after, :retry_after_time, :subproblems, :acme_error_body, :problem
|
|
5
|
+
|
|
6
|
+
Subproblem = Struct.new(:type, :detail, :identifier, keyword_init: true) do
|
|
7
|
+
def to_h
|
|
8
|
+
{ type: type, detail: detail, identifier: identifier }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(message = nil, retry_after: nil, acme_error_body: nil, subproblems: nil, problem: nil)
|
|
13
|
+
super(message)
|
|
14
|
+
@retry_after_time = Acme::Client::Util.parse_retry_after(retry_after)
|
|
15
|
+
@retry_after = @retry_after_time ? [(@retry_after_time - Time.now).ceil, 0].max : nil
|
|
16
|
+
@problem = Acme::Client::Problem.from(problem || acme_error_body)
|
|
17
|
+
@acme_error_body = acme_error_body || @problem&.to_h
|
|
18
|
+
@subproblems = parse_subproblems(subproblems || @problem&.raw_subproblems)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def parse_subproblems(raw)
|
|
24
|
+
return [] if raw.nil? || !raw.is_a?(Array)
|
|
25
|
+
|
|
26
|
+
raw.map do |sp|
|
|
27
|
+
Subproblem.new(
|
|
28
|
+
type: sp['type'],
|
|
29
|
+
detail: sp['detail'],
|
|
30
|
+
identifier: sp['identifier']
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
public
|
|
36
|
+
|
|
37
|
+
def type
|
|
38
|
+
problem&.type
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def code
|
|
42
|
+
problem&.code
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def detail
|
|
46
|
+
problem&.detail || message
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def status
|
|
50
|
+
problem&.status
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def identifier
|
|
54
|
+
problem&.identifier
|
|
55
|
+
end
|
|
56
|
+
|
|
2
57
|
class Timeout < Acme::Client::Error; end
|
|
3
58
|
|
|
4
59
|
class ClientError < Acme::Client::Error; end
|
|
@@ -8,8 +63,11 @@ class Acme::Client::Error < StandardError
|
|
|
8
63
|
class NotFound < ClientError; end
|
|
9
64
|
class CertificateNotReady < ClientError; end
|
|
10
65
|
class ForcedChainNotFound < ClientError; end
|
|
66
|
+
class OrderNotReady < ClientError; end
|
|
67
|
+
class OrderUrlNil < ClientError; end
|
|
11
68
|
|
|
12
69
|
class ServerError < Acme::Client::Error; end
|
|
70
|
+
class AlreadyReplaced < ServerError; end
|
|
13
71
|
class AlreadyRevoked < ServerError; end
|
|
14
72
|
class BadCSR < ServerError; end
|
|
15
73
|
class BadNonce < ServerError; end
|
|
@@ -28,12 +86,21 @@ class Acme::Client::Error < StandardError
|
|
|
28
86
|
class UserActionRequired < ServerError; end
|
|
29
87
|
class BadRevocationReason < ServerError; end
|
|
30
88
|
class Caa < ServerError; end
|
|
89
|
+
class Compound < ServerError; end
|
|
31
90
|
class Dns < ServerError; end
|
|
32
91
|
class Connection < ServerError; end
|
|
33
92
|
class Tls < ServerError; end
|
|
34
93
|
class IncorrectResponse < ServerError; end
|
|
94
|
+
class AutoRenewalCanceled < ServerError; end
|
|
95
|
+
class AutoRenewalExpired < ServerError; end
|
|
96
|
+
class AutoRenewalCancellationInvalid < ServerError; end
|
|
97
|
+
class AutoRenewalRevocationNotSupported < ServerError; end
|
|
98
|
+
class UnknownDelegation < ServerError; end
|
|
99
|
+
class OnionCAARequired < ServerError; end
|
|
100
|
+
class BadAttestationStatement < ServerError; end
|
|
35
101
|
|
|
36
102
|
ACME_ERRORS = {
|
|
103
|
+
'urn:ietf:params:acme:error:alreadyReplaced' => AlreadyReplaced,
|
|
37
104
|
'urn:ietf:params:acme:error:alreadyRevoked' => AlreadyRevoked,
|
|
38
105
|
'urn:ietf:params:acme:error:badCSR' => BadCSR,
|
|
39
106
|
'urn:ietf:params:acme:error:badNonce' => BadNonce,
|
|
@@ -44,6 +111,7 @@ class Acme::Client::Error < StandardError
|
|
|
44
111
|
'urn:ietf:params:acme:error:externalAccountRequired' => ExternalAccountRequired,
|
|
45
112
|
'urn:ietf:params:acme:error:accountDoesNotExist' => AccountDoesNotExist,
|
|
46
113
|
'urn:ietf:params:acme:error:malformed' => Malformed,
|
|
114
|
+
'urn:ietf:params:acme:error:orderNotReady' => OrderNotReady,
|
|
47
115
|
'urn:ietf:params:acme:error:rateLimited' => RateLimited,
|
|
48
116
|
'urn:ietf:params:acme:error:rejectedIdentifier' => RejectedIdentifier,
|
|
49
117
|
'urn:ietf:params:acme:error:serverInternal' => ServerInternal,
|
|
@@ -52,9 +120,17 @@ class Acme::Client::Error < StandardError
|
|
|
52
120
|
'urn:ietf:params:acme:error:userActionRequired' => UserActionRequired,
|
|
53
121
|
'urn:ietf:params:acme:error:badRevocationReason' => BadRevocationReason,
|
|
54
122
|
'urn:ietf:params:acme:error:caa' => Caa,
|
|
123
|
+
'urn:ietf:params:acme:error:compound' => Compound,
|
|
55
124
|
'urn:ietf:params:acme:error:dns' => Dns,
|
|
56
125
|
'urn:ietf:params:acme:error:connection' => Connection,
|
|
57
126
|
'urn:ietf:params:acme:error:tls' => Tls,
|
|
58
|
-
'urn:ietf:params:acme:error:incorrectResponse' => IncorrectResponse
|
|
127
|
+
'urn:ietf:params:acme:error:incorrectResponse' => IncorrectResponse,
|
|
128
|
+
'urn:ietf:params:acme:error:autoRenewalCanceled' => AutoRenewalCanceled,
|
|
129
|
+
'urn:ietf:params:acme:error:autoRenewalExpired' => AutoRenewalExpired,
|
|
130
|
+
'urn:ietf:params:acme:error:autoRenewalCancellationInvalid' => AutoRenewalCancellationInvalid,
|
|
131
|
+
'urn:ietf:params:acme:error:autoRenewalRevocationNotSupported' => AutoRenewalRevocationNotSupported,
|
|
132
|
+
'urn:ietf:params:acme:error:unknownDelegation' => UnknownDelegation,
|
|
133
|
+
'urn:ietf:params:acme:error:onionCAARequired' => OnionCAARequired,
|
|
134
|
+
'urn:ietf:params:acme:error:badAttestationStatement' => BadAttestationStatement,
|
|
59
135
|
}
|
|
60
136
|
end
|
|
@@ -101,7 +101,14 @@ module Acme::Client::HTTPClient
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
def raise_on_error!
|
|
104
|
-
|
|
104
|
+
retry_after = env.response_headers['retry-after']
|
|
105
|
+
body = env.body.is_a?(Hash) ? env.body : nil
|
|
106
|
+
problem = Acme::Client::Problem.from(body)
|
|
107
|
+
subproblems = error_subproblems
|
|
108
|
+
if error_class == Acme::Client::Error::RateLimited
|
|
109
|
+
raise error_class.new(error_message, retry_after, acme_error_body: body, subproblems: subproblems, problem: problem)
|
|
110
|
+
end
|
|
111
|
+
raise error_class.new(error_message, retry_after: retry_after, acme_error_body: body, subproblems: subproblems, problem: problem)
|
|
105
112
|
end
|
|
106
113
|
|
|
107
114
|
def error_message
|
|
@@ -122,6 +129,11 @@ module Acme::Client::HTTPClient
|
|
|
122
129
|
env.body['type']
|
|
123
130
|
end
|
|
124
131
|
|
|
132
|
+
def error_subproblems
|
|
133
|
+
return unless env.body.is_a?(Hash)
|
|
134
|
+
env.body['subproblems']
|
|
135
|
+
end
|
|
136
|
+
|
|
125
137
|
def decode_body
|
|
126
138
|
content_type = env.response_headers['Content-Type'].to_s
|
|
127
139
|
|
|
@@ -50,8 +50,8 @@ class Acme::Client::JWK::ECDSA < Acme::Client::JWK::Base
|
|
|
50
50
|
{
|
|
51
51
|
crv: @curve_params[:jwa_crv],
|
|
52
52
|
kty: 'EC',
|
|
53
|
-
x: Acme::Client::Util.urlsafe_base64(coordinates[:x]
|
|
54
|
-
y: Acme::Client::Util.urlsafe_base64(coordinates[:y]
|
|
53
|
+
x: Acme::Client::Util.urlsafe_base64(coordinates[:x]),
|
|
54
|
+
y: Acme::Client::Util.urlsafe_base64(coordinates[:y])
|
|
55
55
|
}
|
|
56
56
|
end
|
|
57
57
|
|
|
@@ -92,8 +92,8 @@ class Acme::Client::JWK::ECDSA < Acme::Client::JWK::Base
|
|
|
92
92
|
hex_y = hex[2 + data_len / 2, data_len / 2]
|
|
93
93
|
|
|
94
94
|
{
|
|
95
|
-
x:
|
|
96
|
-
y:
|
|
95
|
+
x: [hex_x].pack('H*'),
|
|
96
|
+
y: [hex_y].pack('H*')
|
|
97
97
|
}
|
|
98
98
|
end
|
|
99
99
|
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Acme; end
|
|
4
|
+
class Acme::Client; end
|
|
5
|
+
|
|
6
|
+
class Acme::Client::Problem
|
|
7
|
+
ERROR_PREFIX = 'urn:ietf:params:acme:error:'.freeze
|
|
8
|
+
|
|
9
|
+
# Registry descriptions for problem types, not fallback values for problem details.
|
|
10
|
+
REGISTERED_ERROR_TYPE_DESCRIPTIONS = {
|
|
11
|
+
'accountDoesNotExist' => 'The request specified an account that does not exist',
|
|
12
|
+
'alreadyRevoked' => 'The request specified a certificate to be revoked that has already been revoked',
|
|
13
|
+
'badCSR' => 'The CSR is unacceptable (e.g., due to a short key)',
|
|
14
|
+
'badNonce' => 'The client sent an unacceptable anti-replay nonce',
|
|
15
|
+
'badPublicKey' => 'The JWS was signed by a public key the server does not support',
|
|
16
|
+
'badRevocationReason' => 'The revocation reason provided is not allowed by the server',
|
|
17
|
+
'badSignatureAlgorithm' => 'The JWS was signed with an algorithm the server does not support',
|
|
18
|
+
'caa' => 'Certification Authority Authorization (CAA) records forbid the CA from issuing a certificate',
|
|
19
|
+
'compound' => 'Specific error conditions are indicated in the "subproblems" array',
|
|
20
|
+
'connection' => 'The server could not connect to validation target',
|
|
21
|
+
'dns' => 'There was a problem with a DNS query during identifier validation',
|
|
22
|
+
'externalAccountRequired' => 'The request must include a value for the "externalAccountBinding" field',
|
|
23
|
+
'incorrectResponse' => "Response received didn't match the challenge's requirements",
|
|
24
|
+
'invalidContact' => 'A contact URL for an account was invalid',
|
|
25
|
+
'malformed' => 'The request message was malformed',
|
|
26
|
+
'orderNotReady' => 'The request attempted to finalize an order that is not ready to be finalized',
|
|
27
|
+
'rateLimited' => 'The request exceeds a rate limit',
|
|
28
|
+
'rejectedIdentifier' => 'The server will not issue certificates for the identifier',
|
|
29
|
+
'serverInternal' => 'The server experienced an internal error',
|
|
30
|
+
'tls' => 'The server received a TLS error during validation',
|
|
31
|
+
'unauthorized' => 'The client lacks sufficient authorization',
|
|
32
|
+
'unsupportedContact' => 'A contact URL for an account used an unsupported protocol scheme',
|
|
33
|
+
'unsupportedIdentifier' => 'An identifier is of an unsupported type',
|
|
34
|
+
'userActionRequired' => 'Visit the "instance" URL and take actions specified there',
|
|
35
|
+
'autoRenewalCanceled' => 'The short-term certificate is no longer available because the auto-renewal Order has been explicitly canceled by the IdO',
|
|
36
|
+
'autoRenewalExpired' => 'The short-term certificate is no longer available because the auto-renewal Order has expired',
|
|
37
|
+
'autoRenewalCancellationInvalid' => 'A request to cancel an auto-renewal Order that is not in state "valid" has been received',
|
|
38
|
+
'autoRenewalRevocationNotSupported' => 'A request to revoke an auto-renewal Order has been received',
|
|
39
|
+
'unknownDelegation' => 'An unknown configuration is listed in the delegation attribute of the order request',
|
|
40
|
+
'onionCAARequired' => 'The CA only supports checking the CAA for Hidden Services in-band, but the client has not provided an in-band CAA',
|
|
41
|
+
'alreadyReplaced' => 'The request specified a predecessor certificate that has already been marked as replaced',
|
|
42
|
+
'badAttestationStatement' => 'The attestation statement is unacceptable (e.g. not signed by an attestation authority trusted by the CA)'
|
|
43
|
+
}.freeze
|
|
44
|
+
|
|
45
|
+
def self.from(value)
|
|
46
|
+
case value
|
|
47
|
+
when nil
|
|
48
|
+
nil
|
|
49
|
+
when Acme::Client::Problem
|
|
50
|
+
value
|
|
51
|
+
when Hash
|
|
52
|
+
new(value)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
attr_reader :raw
|
|
57
|
+
|
|
58
|
+
def initialize(raw = {})
|
|
59
|
+
@raw = raw || {}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def type
|
|
63
|
+
fetch('type')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def code
|
|
67
|
+
return unless type
|
|
68
|
+
return unless type.start_with?(ERROR_PREFIX)
|
|
69
|
+
|
|
70
|
+
type[ERROR_PREFIX.length..-1]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def title
|
|
74
|
+
fetch('title')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def detail
|
|
78
|
+
fetch('detail')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def status
|
|
82
|
+
fetch('status')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def instance
|
|
86
|
+
fetch('instance')
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def identifier
|
|
90
|
+
fetch('identifier')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def subproblems
|
|
94
|
+
return [] unless raw_subproblems.is_a?(Array)
|
|
95
|
+
|
|
96
|
+
raw_subproblems.map { |subproblem| self.class.new(subproblem) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def raw_subproblems
|
|
100
|
+
fetch('subproblems')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def registered?
|
|
104
|
+
REGISTERED_ERROR_TYPE_DESCRIPTIONS.key?(code)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
alias standard? registered?
|
|
108
|
+
|
|
109
|
+
def description
|
|
110
|
+
REGISTERED_ERROR_TYPE_DESCRIPTIONS[code]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def matches?(type_or_code)
|
|
114
|
+
candidate = type_or_code.to_s
|
|
115
|
+
candidate == type || candidate == code || "#{ERROR_PREFIX}#{candidate}" == type
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def message
|
|
119
|
+
detail || title || type
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def to_h
|
|
123
|
+
raw
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def as_json(*_arguments)
|
|
127
|
+
to_h
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
|
|
132
|
+
def fetch(key)
|
|
133
|
+
raw[key] || raw[key.to_sym]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -34,16 +34,18 @@ class Acme::Client::Resources::Account
|
|
|
34
34
|
url: url,
|
|
35
35
|
term_of_service: term_of_service,
|
|
36
36
|
status: status,
|
|
37
|
-
contact: contact
|
|
37
|
+
contact: contact,
|
|
38
|
+
orders: orders_url
|
|
38
39
|
}
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
private
|
|
42
43
|
|
|
43
|
-
def assign_attributes(url:, term_of_service:, status:, contact:)
|
|
44
|
+
def assign_attributes(url:, term_of_service:, status:, contact:, orders: nil)
|
|
44
45
|
@url = url
|
|
45
46
|
@term_of_service = term_of_service
|
|
46
47
|
@status = status
|
|
47
48
|
@contact = Array(contact)
|
|
49
|
+
@orders_url = orders
|
|
48
50
|
end
|
|
49
51
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Acme::Client::Resources::Authorization
|
|
4
|
-
attr_reader :url, :identifier, :domain, :expires, :status, :wildcard
|
|
4
|
+
attr_reader :url, :identifier, :domain, :expires, :status, :wildcard, :retry_after, :retry_after_time
|
|
5
5
|
|
|
6
6
|
def initialize(client, **arguments)
|
|
7
7
|
@client = client
|
|
@@ -38,6 +38,13 @@ class Acme::Client::Resources::Authorization
|
|
|
38
38
|
end
|
|
39
39
|
alias_method :dns, :dns01
|
|
40
40
|
|
|
41
|
+
def dns_account_01
|
|
42
|
+
@dns_account_01 ||= challenges.find { |challenge|
|
|
43
|
+
challenge.is_a?(Acme::Client::Resources::Challenges::DNSAccount01)
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
alias_method :dns_account, :dns_account_01
|
|
47
|
+
|
|
41
48
|
def to_h
|
|
42
49
|
{
|
|
43
50
|
url: url,
|
|
@@ -45,7 +52,8 @@ class Acme::Client::Resources::Authorization
|
|
|
45
52
|
status: status,
|
|
46
53
|
expires: expires,
|
|
47
54
|
challenges: @challenges,
|
|
48
|
-
wildcard: wildcard
|
|
55
|
+
wildcard: wildcard,
|
|
56
|
+
retry_after: retry_after
|
|
49
57
|
}
|
|
50
58
|
end
|
|
51
59
|
|
|
@@ -62,7 +70,7 @@ class Acme::Client::Resources::Authorization
|
|
|
62
70
|
Acme::Client::Resources::Challenges.new(@client, **arguments)
|
|
63
71
|
end
|
|
64
72
|
|
|
65
|
-
def assign_attributes(url:, status:, expires:, challenges:, identifier:, wildcard: false)
|
|
73
|
+
def assign_attributes(url:, status:, expires:, challenges:, identifier:, wildcard: false, retry_after: nil)
|
|
66
74
|
@url = url
|
|
67
75
|
@identifier = identifier
|
|
68
76
|
@domain = identifier.fetch('value')
|
|
@@ -70,5 +78,7 @@ class Acme::Client::Resources::Authorization
|
|
|
70
78
|
@expires = expires
|
|
71
79
|
@challenges = challenges
|
|
72
80
|
@wildcard = wildcard
|
|
81
|
+
@retry_after = retry_after
|
|
82
|
+
@retry_after_time = Acme::Client::Util.parse_retry_after(retry_after)
|
|
73
83
|
end
|
|
74
84
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Acme::Client::Resources::Challenges::Base
|
|
4
|
-
attr_reader :status, :url, :token, :error
|
|
4
|
+
attr_reader :status, :url, :token, :error, :validated, :retry_after, :retry_after_time
|
|
5
5
|
|
|
6
6
|
def initialize(client, **arguments)
|
|
7
7
|
@client = client
|
|
@@ -28,8 +28,18 @@ class Acme::Client::Resources::Challenges::Base
|
|
|
28
28
|
true
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def typed_error
|
|
32
|
+
return nil unless error
|
|
33
|
+
|
|
34
|
+
problem = Acme::Client::Problem.from(error)
|
|
35
|
+
error_type = problem&.type
|
|
36
|
+
error_detail = problem&.detail || 'Unknown error'
|
|
37
|
+
error_class = Acme::Client::Error::ACME_ERRORS.fetch(error_type, Acme::Client::Error)
|
|
38
|
+
error_class.new(error_detail, problem: problem)
|
|
39
|
+
end
|
|
40
|
+
|
|
31
41
|
def to_h
|
|
32
|
-
{ status: status, url: url, token: token, error: error }
|
|
42
|
+
{ status: status, url: url, token: token, error: error, validated: validated, retry_after: retry_after }
|
|
33
43
|
end
|
|
34
44
|
|
|
35
45
|
private
|
|
@@ -40,10 +50,13 @@ class Acme::Client::Resources::Challenges::Base
|
|
|
40
50
|
).to_h
|
|
41
51
|
end
|
|
42
52
|
|
|
43
|
-
def assign_attributes(status:, url:, token:, error: nil)
|
|
53
|
+
def assign_attributes(status:, url:, token:, error: nil, validated: nil, retry_after: nil)
|
|
44
54
|
@status = status
|
|
45
55
|
@url = url
|
|
46
56
|
@token = token
|
|
47
57
|
@error = error
|
|
58
|
+
@validated = validated
|
|
59
|
+
@retry_after = retry_after
|
|
60
|
+
@retry_after_time = Acme::Client::Util.parse_retry_after(retry_after)
|
|
48
61
|
end
|
|
49
62
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# DNS-Account-01 challenge following draft-ietf-acme-dns-account-label-01
|
|
4
|
+
# Enables multiple ACME clients to validate the same domain concurrently
|
|
5
|
+
class Acme::Client::Resources::Challenges::DNSAccount01 < Acme::Client::Resources::Challenges::Base
|
|
6
|
+
CHALLENGE_TYPE = 'dns-account-01'.freeze
|
|
7
|
+
RECORD_PREFIX = '_'.freeze
|
|
8
|
+
RECORD_SUFFIX = '._acme-challenge'.freeze
|
|
9
|
+
RECORD_TYPE = 'TXT'.freeze
|
|
10
|
+
DIGEST = OpenSSL::Digest::SHA256
|
|
11
|
+
BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567'.freeze # RFC 4648 lowercase alphabet
|
|
12
|
+
|
|
13
|
+
# Generates account-specific DNS record name using SHA256(account_url) + Base32
|
|
14
|
+
# Format: _<base32_label>._acme-challenge
|
|
15
|
+
def record_name
|
|
16
|
+
digest = DIGEST.digest(@client.kid)[0, 10] # First 10 octets for label
|
|
17
|
+
bits = digest.unpack1('B*')
|
|
18
|
+
label = bits.scan(/.{5}/).map { |chunk| BASE32_ALPHABET[chunk.to_i(2)] }.join
|
|
19
|
+
"#{RECORD_PREFIX}#{label}#{RECORD_SUFFIX}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def record_type
|
|
23
|
+
RECORD_TYPE
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def record_content
|
|
27
|
+
Acme::Client::Util.urlsafe_base64(DIGEST.digest(key_authorization))
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
@@ -4,11 +4,13 @@ module Acme::Client::Resources::Challenges
|
|
|
4
4
|
require 'acme/client/resources/challenges/base'
|
|
5
5
|
require 'acme/client/resources/challenges/http01'
|
|
6
6
|
require 'acme/client/resources/challenges/dns01'
|
|
7
|
+
require 'acme/client/resources/challenges/dns_account01'
|
|
7
8
|
require 'acme/client/resources/challenges/unsupported_challenge'
|
|
8
9
|
|
|
9
10
|
CHALLENGE_TYPES = {
|
|
10
11
|
'http-01' => Acme::Client::Resources::Challenges::HTTP01,
|
|
11
|
-
'dns-01' => Acme::Client::Resources::Challenges::DNS01
|
|
12
|
+
'dns-01' => Acme::Client::Resources::Challenges::DNS01,
|
|
13
|
+
'dns-account-01' => Acme::Client::Resources::Challenges::DNSAccount01
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
def self.new(client, type:, **arguments)
|
|
@@ -7,14 +7,16 @@ class Acme::Client::Resources::Directory
|
|
|
7
7
|
new_order: 'newOrder',
|
|
8
8
|
new_authz: 'newAuthz',
|
|
9
9
|
revoke_certificate: 'revokeCert',
|
|
10
|
-
key_change: 'keyChange'
|
|
10
|
+
key_change: 'keyChange',
|
|
11
|
+
renewal_info: 'renewalInfo'
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
DIRECTORY_META = {
|
|
14
15
|
terms_of_service: 'termsOfService',
|
|
15
16
|
website: 'website',
|
|
16
17
|
caa_identities: 'caaIdentities',
|
|
17
|
-
external_account_required: 'externalAccountRequired'
|
|
18
|
+
external_account_required: 'externalAccountRequired',
|
|
19
|
+
profiles: 'profiles'
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
def initialize(client, **arguments)
|
|
@@ -45,6 +47,10 @@ class Acme::Client::Resources::Directory
|
|
|
45
47
|
meta[DIRECTORY_META[:external_account_required]]
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
def profiles
|
|
51
|
+
meta[DIRECTORY_META[:profiles]]
|
|
52
|
+
end
|
|
53
|
+
|
|
48
54
|
def meta
|
|
49
55
|
@directory[:meta]
|
|
50
56
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Acme::Client::Resources::Order
|
|
4
|
-
attr_reader :url, :status, :contact, :finalize_url, :identifiers, :authorization_urls, :expires, :certificate_url
|
|
4
|
+
attr_reader :url, :status, :contact, :finalize_url, :identifiers, :authorization_urls, :expires, :certificate_url, :profile, :replaces, :error, :retry_after, :retry_after_time
|
|
5
5
|
|
|
6
6
|
def initialize(client, **arguments)
|
|
7
7
|
@client = client
|
|
@@ -9,6 +9,8 @@ class Acme::Client::Resources::Order
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def reload
|
|
12
|
+
raise Acme::Client::Error::OrderUrlNil, 'Cannot reload order with nil url.' if url.nil?
|
|
13
|
+
|
|
12
14
|
assign_attributes(**@client.order(url: url).to_h)
|
|
13
15
|
true
|
|
14
16
|
end
|
|
@@ -32,6 +34,28 @@ class Acme::Client::Resources::Order
|
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
37
|
+
def renew(replaces: nil, **arguments)
|
|
38
|
+
replaces ||= renewal_info.ari_id
|
|
39
|
+
|
|
40
|
+
@client.new_order(replaces: replaces, **to_h.slice(:identifiers, :profile).merge(arguments))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def renewal_info(certificate: nil, ari_id: nil)
|
|
44
|
+
certificate ||= self.certificate if ari_id.nil?
|
|
45
|
+
|
|
46
|
+
@client.renewal_info(certificate:, ari_id:)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def typed_error
|
|
50
|
+
return nil unless error
|
|
51
|
+
|
|
52
|
+
problem = Acme::Client::Problem.from(error)
|
|
53
|
+
error_type = problem&.type
|
|
54
|
+
error_detail = problem&.detail || 'Unknown error'
|
|
55
|
+
error_class = Acme::Client::Error::ACME_ERRORS.fetch(error_type, Acme::Client::Error)
|
|
56
|
+
error_class.new(error_detail, problem: problem)
|
|
57
|
+
end
|
|
58
|
+
|
|
35
59
|
def to_h
|
|
36
60
|
{
|
|
37
61
|
url: url,
|
|
@@ -40,19 +64,28 @@ class Acme::Client::Resources::Order
|
|
|
40
64
|
finalize_url: finalize_url,
|
|
41
65
|
authorization_urls: authorization_urls,
|
|
42
66
|
identifiers: identifiers,
|
|
43
|
-
certificate_url: certificate_url
|
|
67
|
+
certificate_url: certificate_url,
|
|
68
|
+
profile: profile,
|
|
69
|
+
replaces: replaces,
|
|
70
|
+
error: error,
|
|
71
|
+
retry_after: retry_after
|
|
44
72
|
}
|
|
45
73
|
end
|
|
46
74
|
|
|
47
75
|
private
|
|
48
76
|
|
|
49
|
-
def assign_attributes(url
|
|
50
|
-
@url = url
|
|
77
|
+
def assign_attributes(url: nil, status:, expires:, finalize_url:, authorization_urls:, identifiers:, certificate_url: nil, profile: nil, replaces: nil, error: nil, retry_after: nil) # rubocop:disable Layout/LineLength,Metrics/ParameterLists
|
|
78
|
+
@url = url unless url.nil?
|
|
51
79
|
@status = status
|
|
52
80
|
@expires = expires
|
|
53
81
|
@finalize_url = finalize_url
|
|
54
82
|
@authorization_urls = authorization_urls
|
|
55
83
|
@identifiers = identifiers
|
|
56
84
|
@certificate_url = certificate_url
|
|
85
|
+
@profile = profile
|
|
86
|
+
@replaces = replaces
|
|
87
|
+
@error = error
|
|
88
|
+
@retry_after = retry_after
|
|
89
|
+
@retry_after_time = Acme::Client::Util.parse_retry_after(retry_after)
|
|
57
90
|
end
|
|
58
91
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Acme::Client::Resources::RenewalInfo
|
|
4
|
+
attr_reader :ari_id, :suggested_window, :explanation_url, :retry_after, :retry_after_time
|
|
5
|
+
|
|
6
|
+
def initialize(client, **arguments)
|
|
7
|
+
@client = client
|
|
8
|
+
assign_attributes(**arguments)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def reload
|
|
12
|
+
assign_attributes(**@client.renewal_info(ari_id: ari_id).to_h)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def suggested_window_start
|
|
16
|
+
suggested_window&.fetch('start', nil)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def suggested_window_end
|
|
20
|
+
suggested_window&.fetch('end', nil)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def suggested_renewal_time
|
|
24
|
+
return nil unless suggested_window_start && suggested_window_end
|
|
25
|
+
|
|
26
|
+
start_time = DateTime.rfc3339(suggested_window_start).to_time
|
|
27
|
+
end_time = DateTime.rfc3339(suggested_window_end).to_time
|
|
28
|
+
window_duration = end_time - start_time
|
|
29
|
+
|
|
30
|
+
random_offset = rand(0.0..window_duration)
|
|
31
|
+
selected_time = start_time + random_offset
|
|
32
|
+
|
|
33
|
+
selected_time > Time.now ? selected_time : Time.now
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def to_h
|
|
37
|
+
{
|
|
38
|
+
ari_id: ari_id,
|
|
39
|
+
suggested_window: suggested_window,
|
|
40
|
+
explanation_url: explanation_url,
|
|
41
|
+
retry_after: retry_after
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def assign_attributes(ari_id:, suggested_window:, explanation_url: nil, retry_after: nil)
|
|
48
|
+
@ari_id = ari_id
|
|
49
|
+
@suggested_window = suggested_window
|
|
50
|
+
@explanation_url = explanation_url
|
|
51
|
+
@retry_after = retry_after
|
|
52
|
+
@retry_after_time = Acme::Client::Util.parse_retry_after(retry_after)
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/acme/client/util.rb
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
require 'time'
|
|
2
|
+
|
|
1
3
|
module Acme::Client::Util
|
|
2
4
|
extend self
|
|
3
5
|
|
|
6
|
+
# Parses a Retry-After header value into a Time.
|
|
7
|
+
# RFC 7231 §7.1.3: the value is either delay-seconds or an HTTP-date.
|
|
8
|
+
# Returns a Time, or nil if the value is nil or unparseable.
|
|
9
|
+
def parse_retry_after(value)
|
|
10
|
+
return nil if value.nil?
|
|
11
|
+
|
|
12
|
+
value = value.to_s
|
|
13
|
+
Integer(value, 10).then { |seconds| Time.now + seconds }
|
|
14
|
+
rescue ArgumentError, RangeError
|
|
15
|
+
begin
|
|
16
|
+
Time.httpdate(value)
|
|
17
|
+
rescue ArgumentError
|
|
18
|
+
nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
4
22
|
def urlsafe_base64(data)
|
|
5
23
|
Base64.urlsafe_encode64(data).sub(/[\s=]*\z/, '')
|
|
6
24
|
end
|
|
@@ -32,4 +50,41 @@ module Acme::Client::Util
|
|
|
32
50
|
raise ArgumentError, 'priv must be EC or RSA'
|
|
33
51
|
end
|
|
34
52
|
end
|
|
53
|
+
|
|
54
|
+
# Generates a certificate identifier for ACME Renewal Information (ARI) as per RFC 9773.
|
|
55
|
+
# The identifier is constructed by extracting the Authority Key Identifier (AKI) from
|
|
56
|
+
# the certificate extension, and the DER-encoded serial number (without tag and length bytes).
|
|
57
|
+
# Both values are base64url-encoded and concatenated with a period separator.
|
|
58
|
+
#
|
|
59
|
+
# certificate - An OpenSSL::X509::Certificate instance or PEM string.
|
|
60
|
+
#
|
|
61
|
+
# Returns a string in the format: base64url(AKI).base64url(serial)
|
|
62
|
+
def ari_certificate_identifier(certificate)
|
|
63
|
+
cert = if certificate.is_a?(OpenSSL::X509::Certificate)
|
|
64
|
+
certificate
|
|
65
|
+
else
|
|
66
|
+
OpenSSL::X509::Certificate.new(certificate)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
aki_ext = cert.extensions.find { |ext| ext.oid == 'authorityKeyIdentifier' }
|
|
70
|
+
raise ArgumentError, 'Certificate does not have an Authority Key Identifier extension' unless aki_ext
|
|
71
|
+
|
|
72
|
+
aki_value = aki_ext.value
|
|
73
|
+
hex_string = if aki_value =~ /keyid:([0-9A-Fa-f:]+)/
|
|
74
|
+
$1
|
|
75
|
+
elsif aki_value =~ /^[0-9A-Fa-f:]+$/
|
|
76
|
+
aki_value
|
|
77
|
+
else
|
|
78
|
+
raise ArgumentError, 'Could not parse Authority Key Identifier'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
key_identifier = hex_string.split(':').map { |hex| hex.to_i(16).chr }.join
|
|
82
|
+
serial_der = OpenSSL::ASN1::Integer.new(cert.serial).to_der
|
|
83
|
+
serial_value = OpenSSL::ASN1.decode(serial_der).value.to_s(2)
|
|
84
|
+
|
|
85
|
+
aki_b64 = urlsafe_base64(key_identifier)
|
|
86
|
+
serial_b64 = urlsafe_base64(serial_value)
|
|
87
|
+
|
|
88
|
+
"#{aki_b64}.#{serial_b64}"
|
|
89
|
+
end
|
|
35
90
|
end
|
data/lib/acme/client/version.rb
CHANGED
data/lib/acme/client.rb
CHANGED
|
@@ -14,12 +14,14 @@ module Acme; end
|
|
|
14
14
|
class Acme::Client; end
|
|
15
15
|
|
|
16
16
|
require 'acme/client/version'
|
|
17
|
+
require 'acme/client/problem'
|
|
17
18
|
require 'acme/client/http_client'
|
|
18
19
|
require 'acme/client/certificate_request'
|
|
19
20
|
require 'acme/client/self_sign_certificate'
|
|
20
21
|
require 'acme/client/resources'
|
|
21
22
|
require 'acme/client/jwk'
|
|
22
23
|
require 'acme/client/error'
|
|
24
|
+
require 'acme/client/error/rate_limited'
|
|
23
25
|
require 'acme/client/util'
|
|
24
26
|
require 'acme/client/chain_identifier'
|
|
25
27
|
|
|
@@ -135,11 +137,13 @@ class Acme::Client
|
|
|
135
137
|
@kid ||= account.kid
|
|
136
138
|
end
|
|
137
139
|
|
|
138
|
-
def new_order(identifiers:, not_before: nil, not_after: nil)
|
|
140
|
+
def new_order(identifiers:, not_before: nil, not_after: nil, profile: nil, replaces: nil)
|
|
139
141
|
payload = {}
|
|
140
142
|
payload['identifiers'] = prepare_order_identifiers(identifiers)
|
|
141
143
|
payload['notBefore'] = not_before if not_before
|
|
142
144
|
payload['notAfter'] = not_after if not_after
|
|
145
|
+
payload['profile'] = profile if profile
|
|
146
|
+
payload['replaces'] = replaces if replaces
|
|
143
147
|
|
|
144
148
|
response = post(endpoint_for(:new_order), payload: payload)
|
|
145
149
|
arguments = attributes_from_order_response(response)
|
|
@@ -222,6 +226,20 @@ class Acme::Client
|
|
|
222
226
|
response.success?
|
|
223
227
|
end
|
|
224
228
|
|
|
229
|
+
def renewal_info(certificate: nil, ari_id: nil)
|
|
230
|
+
if certificate.nil? && ari_id.nil?
|
|
231
|
+
raise ArgumentError, 'must specify certificate or ari_id'
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
ari_id ||= Acme::Client::Util.ari_certificate_identifier(certificate)
|
|
235
|
+
|
|
236
|
+
renewal_info_url = URI.join(endpoint_for(:renewal_info).to_s + '/', ari_id).to_s
|
|
237
|
+
|
|
238
|
+
response = get(renewal_info_url)
|
|
239
|
+
attributes = attributes_from_renewal_info_response(response)
|
|
240
|
+
Acme::Client::Resources::RenewalInfo.new(self, ari_id: ari_id, **attributes)
|
|
241
|
+
end
|
|
242
|
+
|
|
225
243
|
def get_nonce
|
|
226
244
|
http_client = Acme::Client::HTTPClient.new_connection(url: endpoint_for(:new_nonce), options: @connection_options)
|
|
227
245
|
response = http_client.head(nil, nil)
|
|
@@ -253,6 +271,10 @@ class Acme::Client
|
|
|
253
271
|
directory.external_account_required
|
|
254
272
|
end
|
|
255
273
|
|
|
274
|
+
def profiles
|
|
275
|
+
directory.profiles
|
|
276
|
+
end
|
|
277
|
+
|
|
256
278
|
private
|
|
257
279
|
|
|
258
280
|
def load_directory
|
|
@@ -286,6 +308,7 @@ class Acme::Client
|
|
|
286
308
|
response.body,
|
|
287
309
|
:status,
|
|
288
310
|
[:term_of_service, 'termsOfServiceAgreed'],
|
|
311
|
+
:orders,
|
|
289
312
|
:contact
|
|
290
313
|
)
|
|
291
314
|
end
|
|
@@ -298,19 +321,37 @@ class Acme::Client
|
|
|
298
321
|
[:finalize_url, 'finalize'],
|
|
299
322
|
[:authorization_urls, 'authorizations'],
|
|
300
323
|
[:certificate_url, 'certificate'],
|
|
301
|
-
:identifiers
|
|
324
|
+
:identifiers,
|
|
325
|
+
:profile,
|
|
326
|
+
:replaces,
|
|
327
|
+
:error
|
|
302
328
|
)
|
|
303
329
|
|
|
304
330
|
attributes[:url] = response.headers[:location] if response.headers[:location]
|
|
331
|
+
attributes[:retry_after] = response.headers['retry-after'] if response.headers['retry-after']
|
|
305
332
|
attributes
|
|
306
333
|
end
|
|
307
334
|
|
|
308
335
|
def attributes_from_authorization_response(response)
|
|
309
|
-
extract_attributes(response.body, :identifier, :status, :expires, :challenges, :wildcard)
|
|
336
|
+
attributes = extract_attributes(response.body, :identifier, :status, :expires, :challenges, :wildcard)
|
|
337
|
+
attributes[:retry_after] = response.headers['retry-after'] if response.headers['retry-after']
|
|
338
|
+
attributes
|
|
310
339
|
end
|
|
311
340
|
|
|
312
341
|
def attributes_from_challenge_response(response)
|
|
313
|
-
extract_attributes(response.body, :status, :url, :token, :type, :error)
|
|
342
|
+
attributes = extract_attributes(response.body, :status, :url, :token, :type, :error, :validated)
|
|
343
|
+
attributes[:retry_after] = response.headers['retry-after'] if response.headers['retry-after']
|
|
344
|
+
attributes
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def attributes_from_renewal_info_response(response)
|
|
348
|
+
attributes = extract_attributes(
|
|
349
|
+
response.body,
|
|
350
|
+
[:suggested_window, 'suggestedWindow'],
|
|
351
|
+
[:explanation_url, 'explanationURL']
|
|
352
|
+
)
|
|
353
|
+
attributes[:retry_after] = response.headers['retry-after'] if response.headers['retry-after']
|
|
354
|
+
attributes
|
|
314
355
|
end
|
|
315
356
|
|
|
316
357
|
def extract_attributes(input, *attributes)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acme-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.35
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Charles Barbier
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rake
|
|
@@ -44,14 +43,42 @@ dependencies:
|
|
|
44
43
|
requirements:
|
|
45
44
|
- - "~>"
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
46
|
+
version: '6.0'
|
|
48
47
|
type: :development
|
|
49
48
|
prerelease: false
|
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
50
|
requirements:
|
|
52
51
|
- - "~>"
|
|
53
52
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
53
|
+
version: '6.0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: bigdecimal
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: csv
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
55
82
|
- !ruby/object:Gem::Dependency
|
|
56
83
|
name: webmock
|
|
57
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,6 +107,20 @@ dependencies:
|
|
|
80
107
|
- - "~>"
|
|
81
108
|
- !ruby/object:Gem::Version
|
|
82
109
|
version: '1.7'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: base64
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0.2'
|
|
117
|
+
type: :runtime
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0.2'
|
|
83
124
|
- !ruby/object:Gem::Dependency
|
|
84
125
|
name: faraday
|
|
85
126
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -120,7 +161,6 @@ dependencies:
|
|
|
120
161
|
- - "<"
|
|
121
162
|
- !ruby/object:Gem::Version
|
|
122
163
|
version: 3.0.0
|
|
123
|
-
description:
|
|
124
164
|
email:
|
|
125
165
|
- unixcharles@gmail.com
|
|
126
166
|
executables: []
|
|
@@ -132,6 +172,7 @@ files:
|
|
|
132
172
|
- LICENSE.txt
|
|
133
173
|
- README.md
|
|
134
174
|
- Rakefile
|
|
175
|
+
- acme-client-2.0.32.gem
|
|
135
176
|
- acme-client.gemspec
|
|
136
177
|
- bin/console
|
|
137
178
|
- bin/generate_keystash
|
|
@@ -143,22 +184,26 @@ files:
|
|
|
143
184
|
- lib/acme/client/certificate_request/ec_key_patch.rb
|
|
144
185
|
- lib/acme/client/chain_identifier.rb
|
|
145
186
|
- lib/acme/client/error.rb
|
|
187
|
+
- lib/acme/client/error/rate_limited.rb
|
|
146
188
|
- lib/acme/client/http_client.rb
|
|
147
189
|
- lib/acme/client/jwk.rb
|
|
148
190
|
- lib/acme/client/jwk/base.rb
|
|
149
191
|
- lib/acme/client/jwk/ecdsa.rb
|
|
150
192
|
- lib/acme/client/jwk/hmac.rb
|
|
151
193
|
- lib/acme/client/jwk/rsa.rb
|
|
194
|
+
- lib/acme/client/problem.rb
|
|
152
195
|
- lib/acme/client/resources.rb
|
|
153
196
|
- lib/acme/client/resources/account.rb
|
|
154
197
|
- lib/acme/client/resources/authorization.rb
|
|
155
198
|
- lib/acme/client/resources/challenges.rb
|
|
156
199
|
- lib/acme/client/resources/challenges/base.rb
|
|
157
200
|
- lib/acme/client/resources/challenges/dns01.rb
|
|
201
|
+
- lib/acme/client/resources/challenges/dns_account01.rb
|
|
158
202
|
- lib/acme/client/resources/challenges/http01.rb
|
|
159
203
|
- lib/acme/client/resources/challenges/unsupported_challenge.rb
|
|
160
204
|
- lib/acme/client/resources/directory.rb
|
|
161
205
|
- lib/acme/client/resources/order.rb
|
|
206
|
+
- lib/acme/client/resources/renewal_info.rb
|
|
162
207
|
- lib/acme/client/self_sign_certificate.rb
|
|
163
208
|
- lib/acme/client/util.rb
|
|
164
209
|
- lib/acme/client/version.rb
|
|
@@ -166,7 +211,6 @@ homepage: http://github.com/unixcharles/acme-client
|
|
|
166
211
|
licenses:
|
|
167
212
|
- MIT
|
|
168
213
|
metadata: {}
|
|
169
|
-
post_install_message:
|
|
170
214
|
rdoc_options: []
|
|
171
215
|
require_paths:
|
|
172
216
|
- lib
|
|
@@ -181,8 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
181
225
|
- !ruby/object:Gem::Version
|
|
182
226
|
version: '0'
|
|
183
227
|
requirements: []
|
|
184
|
-
rubygems_version: 3.
|
|
185
|
-
signing_key:
|
|
228
|
+
rubygems_version: 3.6.9
|
|
186
229
|
specification_version: 4
|
|
187
230
|
summary: Client for the ACME protocol.
|
|
188
231
|
test_files: []
|