Créer ou renouveler un certificat Let’s Encrypt avec la méthode DNS challenge

Certbot (Let’s Encrypt) a révolutionné et démocratisé l’utilisation du protocole HTTPS avec ses certificats gratuits. J’en avais déjà parlé notament dans l’article Renouveler un certificat SSL Let’s encrypt avec le plugin Webroot. La méthode utilisée dans l’article possède au moins un inconvénient en ce qui me concerne, si un des domaines ou sous-domaines n’a pas de document root – par exemple c’est un domaine redirigé – alors il n’est pas possible de renouveler le certificat car Certbot doit écrire à la racine de l’hébergement du domaine dans un répertoire .well-known, qui n’existe pas pour ce genre de cas.

La méthode DNS challenge

Pour palier à cela, je me suis penché sur la vérification par DNS que propose Certbot. Voici la syntaxe que j’utilise avec quelques options bien utiles :

certbot \
     --text \
     --agree-tos \
     --email postmaster@domaine.net \
     -d domaine.net \
     -d www.domaine.net \
     -d admin.domaine.net \
     -d outils.domaine.net \
     --manual \
     --preferred-challenges dns \
     --expand \
     --renew-by-default \
     --manual-public-ip-logging-ok \
     certonly

La première fois, Certbot va vous demander d’ajouter un ou plusieurs nouveaux enregistrements DNS de type TXT avec des messages de la sorte :

Please deploy a DNS TXT record under the name
_acme-challenge.www.domaine.net with the following value:

01q03R1jl4gen_8souu4Ki1kbnfEaJJ7JIjP_eG12nU

Before continuing, verify the record is deployed.

Lorsque c’est fait, il suffit d’appuyer sur entrée pour continuer et le renouvellement du certificat va se poursuivre.


Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.domaine.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.domaine.net/privkey.pem
   Your cert will expire on 2018-01-01. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le