publishlab / node-acme-client

Simple and unopinionated ACME client for Node.js
MIT License
272 stars 54 forks source link

How to customize the dns validation resolution address? #91

Open jiayisheji opened 3 months ago

jiayisheji commented 3 months ago

I need to apply for two certificates for example.com and *.example.com. example.com can pass DNS resolution authentication successfully, but *.example.com always gets the error Authorization not found in DNS TXT record: _acme-challenge.example.com. When I debug the code, the recordValues ​​array value in the verify.js#verifyDnsChallenge function is always the keyAuthorization of example.com. The reason for the failure is that I cannot modify the DNS server resolution by myself using the dns.setServers method. If I want to customize the DNS server address, how can I do it?

wmantly commented 3 months ago

I just delt with doing wildcards, if you log what TXT records are requested to be added, they both will be _acme-challenge.example.com with 2 different keys to be added. Both need to be added to _acme-challenge.example.com

Are you using the sample code from https://github.com/publishlab/node-acme-client/blob/master/examples/dns-01/dns-01.js ? This works perfectly.

jiayisheji commented 3 months ago

@wmantly I useing https://github.com/publishlab/node-acme-client/blob/master/examples/api.js.

I add useNameserversResolveDnsRecord() method,execute it first.

async useNameserversResolveDnsRecord(domain: string, nameservers: string[], logger: AcmeClientLogger) {
      const originalServers = getServers();
      logger.info(`[${domain}] Original Servers: ${originalServers.join(', ')}`);

      setServers(nameservers);
      logger.info(`[${domain}] Restart Servers: ${getServers().join(', ')}`);

      return () => {
        setServers(originalServers);
        logger.info(`[${domain}] Restore Servers: ${getServers().join(', ')}`);
      }
}

I look at the source code, you use nodejs dns module resolution, so I'm simple and rough implementation.