Class: Acme::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/acme-client.rb,
lib/acme/client.rb,
lib/acme/client/version.rb
Defined Under Namespace
Modules: Resources
Classes: Certificate, CertificateRequest, Crypto, Error, FaradayMiddleware
Constant Summary
collapse
- DEFAULT_ENDPOINT =
'http://127.0.0.1:4000'
- DIRECTORY_DEFAULT =
{
'new-authz' => '/acme/new-authz',
'new-cert' => '/acme/new-cert',
'new-reg' => '/acme/new-reg',
'revoke-cert' => '/acme/revoke-cert'
}
- VERSION =
'0.2.3'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(private_key:, endpoint: DEFAULT_ENDPOINT, directory_uri: nil) ⇒ Client
Returns a new instance of Client.
12
13
14
15
16
|
# File 'lib/acme/client.rb', line 12
def initialize(private_key:, endpoint: DEFAULT_ENDPOINT, directory_uri: nil)
@endpoint, @private_key, @directory_uri = endpoint, private_key, directory_uri
@nonces ||= []
load_directory!
end
|
Instance Attribute Details
#nonces ⇒ Object
Returns the value of attribute nonces.
18
19
20
|
# File 'lib/acme/client.rb', line 18
def nonces
@nonces
end
|
#operation_endpoints ⇒ Object
Returns the value of attribute operation_endpoints.
18
19
20
|
# File 'lib/acme/client.rb', line 18
def operation_endpoints
@operation_endpoints
end
|
#private_key ⇒ Object
Returns the value of attribute private_key.
18
19
20
|
# File 'lib/acme/client.rb', line 18
def private_key
@private_key
end
|
Class Method Details
.revoke_certificate(certificate, *arguments) ⇒ Object
59
60
61
62
|
# File 'lib/acme/client.rb', line 59
def self.revoke_certificate(certificate, *arguments)
client = new(*arguments)
client.revoke_certificate(certificate)
end
|
Instance Method Details
#authorize(domain:) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/acme/client.rb', line 29
def authorize(domain:)
payload = {
resource: 'new-authz',
identifier: {
type: 'dns',
value: domain
}
}
response = connection.post(@operation_endpoints.fetch('new-authz'), payload)
::Acme::Client::Resources::Authorization.new(self, response)
end
|
#connection ⇒ Object
64
65
66
67
68
69
|
# File 'lib/acme/client.rb', line 64
def connection
@connection ||= Faraday.new(@endpoint) do |configuration|
configuration.use Acme::Client::FaradayMiddleware, client: self
configuration.adapter Faraday.default_adapter
end
end
|
#new_certificate(csr) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/acme/client.rb', line 42
def new_certificate(csr)
payload = {
resource: 'new-cert',
csr: Base64.urlsafe_encode64(csr.to_der)
}
response = connection.post(@operation_endpoints.fetch('new-cert'), payload)
::Acme::Client::Certificate.new(OpenSSL::X509::Certificate.new(response.body), fetch_chain(response), csr)
end
|
#register(contact:) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/acme/client.rb', line 20
def register(contact:)
payload = {
resource: 'new-reg', contact: Array(contact)
}
response = connection.post(@operation_endpoints.fetch('new-reg'), payload)
::Acme::Client::Resources::Registration.new(self, response)
end
|
#revoke_certificate(certificate) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/acme/client.rb', line 52
def revoke_certificate(certificate)
payload = { resource: 'revoke-cert', certificate: Base64.urlsafe_encode64(certificate.to_der) }
endpoint = @operation_endpoints.fetch('revoke-cert')
response = connection.post(endpoint, payload)
response.success?
end
|