Utilisé principalement pour identifier et authentifier une personne physique ou morale, mais aussi pour chiffrer des échanges.
Le certificat est une clé publique signée par une CA (Autorité de certification) qui certifie que la clé publique est bien celle de l'entreprise E.
Extension .pfx, .p12
Fichier binaire chiffré. Utilisé sur Windows pour l'import et l'export des certificats.
Possibilité de convertir MonCertificat.p12 → MonCertificat.cer, puis de diviser se dernier en CACertificat.cer et PrivateKey.key
certbot certonly --email admin@domain.fr --webroot --webroot-path /usr/share/webapps/monsite --domains www.domain.fr --agree-tos --rsa-key-size 4096
# avec cette méthode le site doit être accessible sur le port 80 avec le même nom de server# l'url http://monsite.domain.fr/.well-known doit être accessiblemkdir -p /var/lib/letsencrypt/.well-known
chgrp http /var/lib/letsencrypt
chmod g+s /var/lib/letsencrypt
#### méthode manuelle ####
certbot certonly --email moi@domain.fr --manual --domains www.domain.fr --agree-tos --rsa-key-size 4096
cd /usr/share/webapp/monsite
mkdir -p .well-known/acme-challenge
printf"%s" xxx.yyy > .well-known/acme-challenge/xxx
# vérifier que le fichier est accessible par Let's Encrypt validation server; +https://www.letsencrypt.org# supprimer le dossier une fois la validation terminéerm -r .well-known/acme-challenge
# display information about a certificat
openssl x509 -text -noout -in /etc/letsencrypt/live/domain.fr/cert.pem
4 fichiers sont créés dans /etc/letsencrypt/live/www.domain.fr
cert.pem
chain.pem
fullchain.pem
certificat et chain
privkey.pem
clé
1 fichier est créé dans /etc/letsencrypt/csr
xxxx_csr-letsencrypt.pem
/etc/nginx/nginx.conf
server {
listen80;
server_name monsite.domain.fr;
return301 https://$server_name$request_uri;
}
server {
listen443 ssl http2;
listen [::]:443 ssl http2; # Listen on IPv6ssl_certificate /etc/letsencrypt/live/www.domain.fr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.fr/privkey.pem;
include letsencrypt.conf;
Les certificats Let's Encrypt ont une durée de validité de 90 jours.
La commande renew les renouvelle s'ils expirent dans moins de 30 jours.
When run with a set of domains corresponding to an existing certificate, the certonly command attempts to renew that specific certificate. (Renewing certificates)
Une fois le certificat renouvelé, redémarrer le serveur web.
Cron
crontab
# try to renew let's encrypt certificates if needed every day at 00h01
1 0 * * * /path/scripts/renew-certificates.sh
renew-certificates.sh
#!/bin/bashset -u
set -e
set -o pipefail
# renew for multiple domains
/usr/local/bin/certbot certonly \
--dns-ovh \ # Obtain certificates using a DNS TXT record
--dns-ovh-credentials /root/.ovh-api.ini \ # OVH credentials INI file
--non-interactive \ # Run without ever asking for user input
--agree-tos \ # Agree to the ACME Subscriber Agreement
--email admin@domain.fr \ # Email used for registration and recovery contact
--domains 'domain.fr,*.domain.fr'# Domain names to apply# --dry-run # Perform a test run of the client, obtaining test (invalid) certificates but not saving them to disk
Any executable files found in /etc/letsencrypt/renewal-hooks/deploy will be run only after a successful renewal.
#!/bin/bashset -e
set -o pipefail
set -u
# restart apache
systemctl restart apache2
# Warning: The unit file, source configuration file or drop-ins of apache2.service changed on disk.# Run 'systemctl daemon-reload' to reload units.
systemctl daemon-reload
Timer et Service
Voici un Timer units qui permet de renouveler les certificats tous les mois.
# with snap to get the latest version on Ubuntu
sudo snap install certbot --classic
sudo snap set certbot trust-plugin-with-root=ok # needed to allow the 2 snaps to communicate
sudo snap install certbot-dns-ovh
# APT
sudo apt install python3-certbot-dns-ovh
# si le paquet n'est pas disponible
sudo apt install python3-pip
# avec root sans sudo
pip3 install certbot # installer la version pip et désinstaller la version système si elle n'est pas compatible
pip3 install certbot-dns-ovh
Cert not yet due for renewal
Keeping the existing certificate
Certificate not yet due for renewal; no action taken.
Erreurs
The currently selected ACME CA endpoint does not support issuing wildcard certificates
# add this to the command line to use the ACME v2 API that supports Wildcard certificates.
--server https://acme-v02.api.letsencrypt.org/directory
Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA
Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.
You may need to use an authenticator plugin that can do challenges over DNS.
Dans le cas d'une demande de certificat contenant un wildcard, il faut utiliser la v2 de l'API.
Ce qui oblige à utiliser le challenge DNS, qui n'est accessible qu'en manual ou avec les plugins DNS. Changing the ACME Server
# use manual
sudo certbot certonly --manual -d 'domain.fr,*.domain.fr'
Achat d'un certificat
Génération du CSR
La CA va utiliser le CSR pour créer le certificat. Elle n'a pas besoin de la clé privée.
Une clé privée est générée en même temps que le CSR.
Il est important de générer le CSR et la clé privée sur le serveur sur lequel on installera le certificat.
# générer le CSR et la clé privée
openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
# générer un CSR depuis une clé privée existante
openssl req -out CSR.csr -key privateKey.key -new
# générer un CSR depuis un certificat existant
openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key
# décoder le CSR
openssl req -in server.csr -noout -text