class ApartmentAcmeClient::Encryption
Public Class Methods
new()
click to toggle source
# File lib/apartment_acme_client/encryption.rb, line 25 def initialize @certificate_storage = ApartmentAcmeClient::CertificateStorage::Proxy.singleton end
Public Instance Methods
csr_private_key_string()
click to toggle source
for use in order to store this on the machine for NGINX use
# File lib/apartment_acme_client/encryption.rb, line 200 def csr_private_key_string csr_private_key.to_s end
register_new(email)
click to toggle source
Largely based on github.com/unixcharles/acme-client documentation
# File lib/apartment_acme_client/encryption.rb, line 30 def register_new(email) raise StandardError.new('Private key already exists') unless @certificate_storage.private_key.nil? private_key = create_private_key # Initialize the client new_client = ApartmentAcmeClient::AcmeClient::Proxy.singleton( acme_client_private_key: private_key, csr_private_key: nil, # not needed for 'register' call ) new_client.register(email) @certificate_storage.save_private_key(private_key) end
request_certificate(common_name:, domains:, wildcard_domain: nil)
click to toggle source
Create an order, perform authorization for each domain, and then request the certificate.
-
common name is used so that there is continuity of requests over time
-
domains are the list of individual http-based domains to be authorized
-
wildcard_domain is an optional wildcard domain to be authorized via DNS Record
Returns the certificate
# File lib/apartment_acme_client/encryption.rb, line 178 def request_certificate(common_name:, domains:, wildcard_domain: nil) domain_names_requested = domains domain_names_requested += [wildcard_domain, "*.#{wildcard_domain}"] if wildcard_domain.present? order = client.new_order(identifiers: domain_names_requested) # Do the HTTP authorizations order.authorizations.each do |authorization| next if authorization.wildcard || authorization.http.nil? authorize_domain_with_http(authorization) end # Do the DNS (wildcard) authorizations if authorize_domains_with_dns(order.authorizations, wildcard_domain: wildcard_domain) client.request_certificate(common_name: common_name, names: domain_names_requested, order: order) else # error, not authorized nil end end
Private Instance Methods
acme_client_private_key()
click to toggle source
Returns a private key
# File lib/apartment_acme_client/encryption.rb, line 214 def acme_client_private_key private_key = @certificate_storage.private_key return nil unless private_key OpenSSL::PKey::RSA.new(private_key) end
client()
click to toggle source
# File lib/apartment_acme_client/encryption.rb, line 206 def client @client ||= ApartmentAcmeClient::AcmeClient::Proxy.singleton( acme_client_private_key: acme_client_private_key, csr_private_key: csr_private_key, ) end
create_private_key()
click to toggle source
# File lib/apartment_acme_client/encryption.rb, line 233 def create_private_key OpenSSL::PKey::RSA.new(4096) end
csr_private_key()
click to toggle source
# File lib/apartment_acme_client/encryption.rb, line 221 def csr_private_key private_key = @certificate_storage.csr_private_key # create a new private key if one is not found if private_key.nil? private_key = create_private_key @certificate_storage.save_csr_private_key(private_key) end OpenSSL::PKey::RSA.new(private_key) end