DNS challenge - get TXT payload programmatically

Hello,
we're developing product which renews certificates in our company, we use certbot and need to use DNS challenge.
We call certbot from python using
process = Popen(call, stdout=PIPE, stderr=STDOUT) where "call" is the certbot command.

My very first test certbot command is:
certbot certonly --manual --preferred-challenges=dns -d acmetest.mydomain.com

How can we programmatically get payload for the TXT record? Our certbot cannot contact DNS server directly, we have to contact it from the python layer. But when I tested certbot I noticed it returns string for the TXT record in the response text and additionally it expects me to hit enter to continue. Is there some way to, for example, save payload of TXT record to file? Like we do with "--webroot" when we use certbot for HTTP challenged SSL certificates.

Thank you
Zdenek

1 Like

The TXT RR value is provided to a separate script which is called/specified with the --manual-auth-hook. See User Guide — Certbot 2.11.0 documentation for more info.

That said, I'm not sure if integrating Certbot with subprocess.Popen is the most sensible thing to do. The output is far from machine readable, interfacing with challenges like this is difficult if not almost impossible et c.

It's probably better to integrate a library into your Python script. There is a Certbot API at API Documentation — Certbot 2.12.0.dev0 documentation but I don't think that's very helpful. Certbot internally uses the acme library (certbot/acme at master · certbot/certbot · GitHub / acme · PyPI) but I can't seem to find the API documentation of that library at all. If it even exists.

The ACME Client Implementations - Let's Encrypt page lists another Python library called "txacme", which is an ACME library for Twisted, something I'm not familiar with at all.. :man_shrugging:t2:

5 Likes

I second @Osiris recommendation. Specifically, I suggest writing two small scripts -- one which takes the token as input via environment variable and sets the appropriate DNS TXT record, and another which cleans up the record -- and passing these scripts to certbot with the --manual-auth-hook and --manual-cleanup-hook flags.

7 Likes

Hello,
yes this is exactly what i am going to do. Thank you both for your answers, I really like the forum here.
Have a nice day
Zdenek

5 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.