Certificats SSL

Bon je vous l'accorde, la gestion des certificats c'est parfois simple mais cela tourne souvent au compliqué. Un grand merci quand même a let's encrypt qui a bien évolué au fil du temps et nous simplifie bien la vie ; parce qu'avoir un lien sécurisé vers son site web ou autre c'est quand même plus propre.

Dans mes pratiques c'était bien mais un peu compliqué puisque la récupération de certificats étaient liés à la mise à disposition du port 80, mais dans les faits et surtout chez soi avec un routeur et plusieurs serveurs proposant des interfaces web, difficile de dupliquer ce port. Alors en mode bricolage, un serveur frontal avec dns extérieur qui pointe dessus et un site bidon mais avec le bon nom dns, puis après la création/récupération du certificat, transfert vers le bon serveur web, renommage des certificats pour avoir les bons index de fichiers relancer le service web et tranquille pour 3 mois. Depuis peut j'ai découvert que l'on pouvait faire une demande de certificat et de ne pas utiliser le Défi HTTP-01 qui impose l'utilisation du port 80 mais de passer en Défi DNS-01. C'est un peu plus long, cela demande des manipulations sur les enregistrements DNS, mais c'est la solution à mes problèmes alors on fonce.

Mise en place

Maintenant beaucoup plus simple, un seul paquet à installer qui est certbot.

Description: automatically configure HTTPS using Let's Encrypt The objective of Certbot, Let's Encrypt, and the ACME (Automated Certificate Management Environment) protocol is to make it possible to set up an HTTPS server and have it automatically obtain a browser-trusted certificate, without any human intervention. This is accomplished by running a certificate management agent on the web server. . This agent is used to: .

  • Automatically prove to the Let's Encrypt CA that you control the website
  • Obtain a browser-trusted certificate and set it up on your web server
  • Keep track of when your certificate is going to expire, and renew it
  • Help you revoke the certificate if that ever becomes necessary. . This package contains the main application, including the standalone and the manual authenticators.

Connexion ssh sur le serveur web, installation de certbot avec module apache

apt install certbot python3-certbot-apache

Demande de certificat

Petit préalable pour apache et dans la même mesure tout autre serveur http Il faut bien sur sous apache2 que le module ssl et rewrite soient actifs:

apachectl -M

Loaded Modules: ... rewrite_module (shared) ssl_module (shared) ... Syntax OK

Sinon exécutez en fonction :

a2enmod ssl

et / ou

a2enmod rewrite

Puis un petit restart s'impose

service apache2 restart

http challenge Port 80 disponible

Sur le serveur web les ports sont déjà effectif et bien redirigé depuis l'extérieur avec une redirection des ports 80 et 443 vers les mêmes en interne depuis la freebox. Dans la mesure ou votre paramétrage web ( hostname ) et dns (dns pihole) est effectif, lancer cerbot depuis une session ssh sur le serveur web.

cerbot

sélectionner le bon site web et voilà.

Il est toujours utile de prendre le temp de lire les retours écran, il y a bien eu le changement de configuration avec apache pour activer le site en ssl et le nouveau fichier de configuration ainsi que la redirection http vers https.

Created an SSL vhost at /etc/apache2/sites-available/grav-le-ssl.conf Deploying Certificate to VirtualHost /etc/apache2/sites-available/grav-le-ssl.conf Enabling available site: /etc/apache2/sites-available/grav-le-ssl.conf Redirecting vhost in /etc/apache2/sites-enabled/grav.conf to ssl vhost in /etc/apache2/sites-available/grav-le-ssl.conf

Sur la fin du fichier, on à la confirmation que le certificat est bien obtenu et les commande pour dans 3 mois.

Congratulations! You have successfully enabled https://www.7ici.website


IMPORTANT NOTES:

  • Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/www.7ici.website/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/www.7ici.website/privkey.pem Your cert will expire on 2021-03-13. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew all of your certificates, run "certbot renew"

Que c'est bon quand l'informatique est aussi simple de cela !.

dns challange Port 80 pas disponible

Pour ma démo ce sera un serveur domotique jeedom qui n'est pas accessible depuis l'extérieur sur son port 80 mais est NATé sur un autre port. Donc depuis une connexion ssh utiliser la commande suivante (certbot est déjà installé) :

certbot --text --agree-tos --email monmail@7ici.website -d jeedom.7ici.website --manual --preferred-challenges dns --expand --renew-by-default --manual-public-ip-logging-ok certonly

email parce qu'avoir un retour quand le certificat va expirer c'est mieux. FQDN du serveur jeedom.7ici.website et surtout le mode challenge dns.

Un p'tit tour sur gandi pour mon cas et ajout du champ txt demandé par la console.

Obtaining a new certificate Performing the following challenges: dns-01 challenge for jeedom.7ici.website


Please deploy a DNS TXT record under the name _acme-challenge.jeedom.7ici.website with the following value:

LXuvfgdfhggfhgfhgfhghjhgjghjhgjkghjghjhgjghjaX-4

Before continuing, verify the record is deployed.


Vérifier la propagation du champ TXT dns avec l'outil de google :

https://toolbox.googleapps.com

valider depuis la console ssh.

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:

  • Congratulations! Your certificate and chain have been saved at:
    /etc/letsencrypt/live/jeedom.7ici.website/fullchain.pem
    Your key file has been saved at:
    /etc/letsencrypt/live/jeedom.7ici.website/privkey.pem
    Your cert will expire on 2091-13-36. 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"
  • Your account credentials have been saved in your Certbot
    configuration directory at /etc/letsencrypt. You should make a
    secure backup of this folder now. This configuration directory will
    also contain certificates and private keys obtained by Certbot so
    making regular backups of this folder is ideal.
  • 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

  • We were unable to subscribe you the EFF mailing list because your
    e-mail address appears to be invalid. You can try again later by
    visiting https://act.eff.org.

Un peu de bricolage dans les fichiers de configuration d'apache et le tour est joué.

ssl-diag

Fichier pour apache en mode http :

<VirtualHost *:80>  
DocumentRoot "/var/www/monsite"  
ServerName monsite.mondomaine 

ErrorLog ${APACHE_LOG_DIR}/monsite.error  
CustomLog ${APACHE_LOG_DIR}/monsite.access combined  

<Directory /var/www/monsite/>  
    Require all granted  
    Options FollowSymlinks MultiViews  
    AllowOverride All  
    SetEnv HOME /var/www/monsite  
    SetEnv HTTP_HOME /var/www/monsite  
    Satisfy Any  
</Directory>  

RewriteEngine on  
RewriteCond %{SERVER_NAME} =monsite.mondomaine  
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]  
</VirtualHost>

Fichier pour apache en mode https :

<IfModule mod_ssl.c>  
<VirtualHost *:443>  
DocumentRoot "/var/www/monsite"  
ServerName monsite.mondomaine  

ErrorLog ${APACHE_LOG_DIR}/monsite.error  
CustomLog ${APACHE_LOG_DIR}/monsite.access combined  

<Directory /var/www/monsite/>  
    Require all granted  
    Options FollowSymlinks MultiViews  
    AllowOverride All  
    SetEnv HOME /var/www/monsite  
    SetEnv HTTP_HOME /var/www/monsite  
    Satisfy Any  
</Directory>  

SSLCertificateFile /etc/letsencrypt/live/monsite.mondomaine/fullchain.pem  
SSLCertificateKeyFile /etc/letsencrypt/live/monsite.mondomaine/privkey.pem  
Include /etc/letsencrypt/options-ssl-apache.conf  
</VirtualHost>  
</IfModule>

Enjoy !

Next Post Previous Post