Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple domains or wildcard #146

Closed
tonymadbrain opened this issue Jun 27, 2018 · 9 comments
Closed

Multiple domains or wildcard #146

tonymadbrain opened this issue Jun 27, 2018 · 9 comments

Comments

@tonymadbrain
Copy link

Can't find how to deal with multiple domains in one certificate and wildcard certificates. Can you please describe steps with little code examples?

@gmarco
Copy link

gmarco commented Jul 7, 2018

order must contain all reqest domain
order = client.new_order(identifiers: ['domain1.de','*.domain1.de'])
order.authorizations.each do |authorization| # loop over all auth's

csr with:
csr = Acme::Client::CertificateRequest.new(private_key: a_different_private_key, subject: { common_name: 'domain1.de' } ,names: ["domain1.de","*.domain1.de"] )

this works so for, but the example with :

while challenge.status == 'pending' 
  sleep(5)
  challenge.reload
end

will never get over "pending", waiting for multiple minutes, an run again, shows that auth was done, but the reload never showed that. what is the problem here ?

@unixcharles
Copy link
Owner

Did you complete the required challenges?

@gmarco
Copy link

gmarco commented Jul 12, 2018

after many tries: yes.

the main thing was:
add DNS entry and wait for Entry to be seen in public server, then request the auth. After that the status goes to valid. If you put the DNS record and try to validate this (also with while loop after that) it will never get valid.

@weppos
Copy link
Contributor

weppos commented Aug 22, 2018

You explicitly need to request a validation from the CA. The CA will not attempt to perform any challenge validation until you are ready and you tell them to do so.

You are missing:

challenge.request_validation

The steps are:

  1. obtain the authorization and the challenge
  2. provision the challenge (e.g. the DNS record) and test it actually works as expected
  3. request the validation

Note that the validation is final. If the validation doesn't succeed (e.g. because the DNS record doesn't resolve) the status will go to invalid and you won't be able to request a new validation without re-starting a new order and a new challenge.

@unixcharles
Copy link
Owner

I didn't had too much time lately but I'll add instruction for wildcard whenever I have time.

To be honest, I've never tried this specific flow myself. I just implemented the spec and assumed it would work. I have had confirmation from pretty heavy users of the gem that it works.

@richardonrails
Copy link

It works. I have something like this...

Example: domains = ['example.com', '*.example.com', 'foo.example.net']

  def generate_cert(client, domains)
    order = client.new_order(identifiers: domains)
    authorizations = order.authorizations

    authorizations.each do |authorization|
      domain = authorization.domain

      if authorization.status == 'pending'

        if authorization.wildcard
          challenge = authorization.dns
          update_dns_record(domain, challenge.record_name, challenge.record_content)

          # You only get one shot for the DNS challenge. If you try to validate/verify
          # the challenge immediately it sees the old DNS record content and challenge 
          # status is 'invalid' you can't try again. So we just sleep long enough so that it works...
          sleep(10)
        else
          challenge = authorization.http
          create_file(challenge.filename, challenge.file_content)
        end

        challenge.request_validation

        while challenge.status == 'pending'
          sleep(0.25)
          challenge.reload
        end

        puts challenge.error unless challenge.status == 'valid'
      end
    end

    csr = Acme::Client::CertificateRequest.new(
      common_name: domains[0],
      names: domains
    )
    order.finalize(csr: csr)

    sleep(1) while order.status == 'processing'

    certificate = order.certificate

    return certificate, csr
  end

@mcr
Copy link

mcr commented Mar 17, 2019

Why would you attempt to validate the challenges one at a time? Wouldn't it be better to do all the file creations and DNS updates first, and then validate them all?

@weppos
Copy link
Contributor

weppos commented Mar 17, 2019

Why would you attempt to validate the challenges one at a time? Wouldn't it be better to do all the file creations and DNS updates first, and then validate them all?

You can't. Each challenge contains an unique token that is provided by Let's Encrypt that you must expose (e.g. via DNS) to prove the match with the challenge.

@mcr
Copy link

mcr commented Mar 17, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants