Skip to content

Instantly share code, notes, and snippets.

@mcr
Last active March 16, 2019 22:27
Show Gist options
  • Save mcr/96000bdfd516306dbedfadf16953733a to your computer and use it in GitHub Desktop.
Save mcr/96000bdfd516306dbedfadf16953733a to your computer and use it in GitHub Desktop.
ACME-Client and DNS-Update example
# something wrong with authenticating the SSL key for staging server.
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
# AcmeKeys is a local class that collects stuff including the key pair for authenticating and options,
# and which server to talk to, and DNS update options for my dasblinkenled.org zone.
puts "Server at: #{AcmeKeys.acme.server}"
client = Acme::Client.new(private_key: AcmeKeys.acme.acmeprivkey,
directory: AcmeKeys.acme.server)
account = client.new_account(contact: 'mailto:[email protected]',
terms_of_service_agreed: true)
zone = "ne34db3.r.dasblinkenled.org"
order = client.new_order(identifiers: [zone])
authorization = order.authorizations.first
challenge = authorization.dns
expect(challenge.record_name).to eq("_acme-challenge") # good check for sanity, but could change
dns = DnsUpdate::load AcmeKeys.acme.update_options
target = challenge.record_name + "." + zone
puts "Removing old challenge from #{target}"
dns.remove { |m|
m.type = :txt
m.zone = "dasblinkenled.org"
m.hostname = target
}
sleep(1)
puts "Adding #{challenge.token} challenge to #{target}"
dns.update { |m|
m.type = :txt
m.zone = "dasblinkenled.org"
m.hostname = target
m.data = challenge.record_content
}
sleep(30)
puts "NIC"
system("dig +short @nic.sandelman.ca #{target} txt")
puts "SNS"
system("dig +short @sns.cooperix.net #{target} txt")
sleep(30)
challenge.request_validation
while challenge.status == 'pending'
puts "Challenge waiting"
sleep(2)
challenge.reload
end
puts "Status: #{challenge.status}"
byebug
expect(challenge.status).to eq('valid')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment