Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libraries/acme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def acme_client
@client = Acme::Client.new(private_key: private_key, directory: directory)

if node['acme']['private_key'].nil?
acme_client.new_account(contact: contact, terms_of_service_agreed: true)
if new_resource.hmac_key.nil? || new_resource.kid.nil?
acme_client.new_account(contact: contact, terms_of_service_agreed: true)
else
acme_client.new_account(contact: contact, terms_of_service_agreed: true, external_account_binding: { kid: new_resource.kid, hmac_key: new_resource.hmac_key })
end
node.default['acme']['private_key'] = private_key.to_pem

# write key to disk for persistence
Expand Down
19 changes: 13 additions & 6 deletions resources/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
property :key_type, String, default: 'rsa', equal_to: %w(rsa ec)
property :ec_curve, String, default: lazy { node['acme']['ec_curve'] }, equal_to: %w(prime256v1 secp384r1 secp521r1)

property :hmac_key, [String, nil]
property :kid, [String, nil]

# From https://letsencrypt.org/docs/profiles/
property :profile, [String, nil], default: nil, equal_to: [nil] + %w(classic shortlived tlsclient tlsserver)

Expand Down Expand Up @@ -90,7 +93,9 @@
if mycert.nil? || mycert.not_after <= renew_at || names_changed?(mycert, names)
order = acme_order_certs_for(format_names(names), profile: new_resource.profile)
all_validations = []
if new_resource.install_authz_block.nil?
if !new_resource.hmac_key.nil? && !new_resource.kid.nil?
# Use the HMAC key and KID to validate the challenges
elsif new_resource.install_authz_block.nil?
order.authorizations.each do |authorization|
authz = install_http_validation(authorization, new_resource)
acme_validate(authz)
Expand All @@ -111,12 +116,14 @@

ruby_block "create certificate for #{new_resource.cn}" do
block do
unless (all_validations.map { |authz| authz.status == 'valid' }).all?
errors = all_validations.select { |authz| authz.status != 'valid' }.map do |authz|
"{url: #{authz.url}, status: #{authz.status}, error: #{authz.error}} "
end.reduce(:+)
if !new_resource.hmac_key.nil? && !new_resource.kid.nil?
unless (all_validations.map { |authz| authz.status == 'valid' }).all?
errors = all_validations.select { |authz| authz.status != 'valid' }.map do |authz|
"{url: #{authz.url}, status: #{authz.status}, error: #{authz.error}} "
end.reduce(:+)

raise "[#{new_resource.cn}] Validation failed, unable to request certificate, Errors: [#{errors}]"
raise "[#{new_resource.cn}] Validation failed, unable to request certificate, Errors: [#{errors}]"
end
end

begin
Expand Down