Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
linux:ssl [08-12-2016 17:28] edmc73 |
linux:ssl [17-12-2023 10:35] (Version actuelle) edmc73 |
||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
Ou comment avoir un **https** pour son site. | Ou comment avoir un **https** pour son site. | ||
+ | Cette page est à réorganiser car il y a eu beaucoup de test et certaines infos sont obsolètes. Voici quelques liens : | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
- | ===== Avec StartSSL ===== | ||
- | Aller sur ce site => http:// | ||
- | Vous devrez valider votre email et nom de domaine en cliquant sur **Validations Wizard** | ||
- | Toujours dans **Validations Wizard** vous devez faire vérifier votre nom de domaine en choisissant **Domain Name Validation** | + | ===== Avec Let's Encrypt ===== |
- | Un mail de vérification sera envoyé à l'une (que vous choisissez) des adresses email renseigné pour votre nom de domaine. | + | **MAJ 2024** |
+ | En résumé sur une fresh debian 11 | ||
- | Ensuite, cliquez sur **Certificates Wizard**, choisissez **Web Server SSL/TLS Certificate** dans la liste et fournissez un mot de passe pour la clé privé. | + | apt install certbot python3-certbot-apache |
+ | |||
+ | < | ||
+ | # certbot --apache -d edmc73.com | ||
+ | Saving debug log to /var/ | ||
+ | Plugins selected: Authenticator apache, Installer apache | ||
+ | Enter email address (used for urgent renewal and security notices) | ||
+ | | ||
- | Copier/coller la clé sur votre serveur. Suivez les indications. | + | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
+ | Please read the Terms of Service at | ||
+ | https:// | ||
+ | agree in order to register with the ACME server. Do you agree? | ||
+ | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
+ | (Y)es/(N)o: Y | ||
- | openssl rsa -in ssl.key -out ssl.key | + | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
- | + | Would you be willing, once your first certificate is successfully issued, to | |
- | Cliquez sur **Continue** et choisissez votre nom de domaine. | + | share your email address with the Electronic Frontier Foundation, a founding |
+ | partner of the Let's Encrypt project and the non-profit organization that | ||
+ | develops Certbot? We'd like to send you email about our work encrypting the web, | ||
+ | EFF news, campaigns, and ways to support digital freedom. | ||
+ | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
+ | (Y)es/(N)o: Y | ||
+ | Account registered. | ||
+ | Requesting a certificate for edmc73.com | ||
+ | Performing the following challenges: | ||
+ | http-01 challenge for edmc73.com | ||
+ | Enabled Apache rewrite module | ||
+ | Waiting for verification... | ||
+ | Cleaning up challenges | ||
+ | Created an SSL vhost at / | ||
+ | Enabled Apache socache_shmcb module | ||
+ | Enabled Apache ssl module | ||
+ | Deploying Certificate to VirtualHost / | ||
+ | Enabling available site: / | ||
+ | Enabled Apache rewrite module | ||
+ | Redirecting vhost in / | ||
- | A la fin vous devez avoir 4 fichiers | + | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
- | ca.pem ssl.crt | + | Congratulations! You have successfully enabled https:// |
+ | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
+ | Subscribe to the EFF mailing list (email: toto@toto.com). | ||
- | Configurer ensuite apache dans ce style | + | IMPORTANT NOTES: |
- | < | + | - Congratulations! Your certificate and chain have been saved at: |
- | < | + | /etc/letsencrypt/live/edmc73.com/fullchain.pem |
- | DocumentRoot | + | Your key file has been saved at: |
- | | + | /etc/letsencrypt/live/edmc73.com/privkey.pem |
- | TransferLog | + | Your certificate will expire |
- | SSLEngine | + | tweaked version of this certificate in the future, simply run |
- | SSLProtocol | + | |
- | SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA: | + | renew *all* of your certificates, |
+ | - If you like Certbot, please consider supporting our work by: | ||
+ | |||
+ | Donating to ISRG / Let's Encrypt: https:// | ||
+ | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \" | ||
- | </ | ||
</ | </ | ||
+ | On se retrouve donc avec un nouveau fichier de config dans apache tout configuré pour que ça fonctionne en https. | ||
+ | |||
+ | ------------------------- | ||
+ | |||
- | ===== Avec Let's Encrypt ===== | ||
Let's Encrypt a bien évolué depuis sa version beta, je vais maintenant mettre mes scripts à jour et détailler le fonctionnement sur Debian 7 et Apache | Let's Encrypt a bien évolué depuis sa version beta, je vais maintenant mettre mes scripts à jour et détailler le fonctionnement sur Debian 7 et Apache | ||
Ligne 59: | Ligne 96: | ||
< | < | ||
# apt update | # apt update | ||
- | # apt install certbot | + | # apt install certbot |
+ | </ | ||
- | et la PAF !! | + | Pour émettre un certificat, letsencrypt doit s’assurer que vous avez bien la main sur les ressources à certifier. Letsencrypt propose 3 types de challenge : |
- | Les paquets supplémentaires suivants seront installés : | + | * HTTP-01 : challenge par requête http, le plus couramment utilisé pour les certificats simples |
- | dialog python-acme python-certbot python-cffi-backend python-configargparse python-configobj python-cryptography python-dialog python-dnspython python-enum34 python-funcsigs | + | |
- | python-idna python-ipaddress python-mock python-ndg-httpsclient python-openssl python-parsedatetime python-pbr python-pkg-resources python-psutil python-pyasn1 python-pyicu | + | |
- | python-requests python-rfc3339 python-setuptools python-six python-tz python-urllib3 python-zope.component python-zope.event python-zope.interface | + | |
- | Paquets suggérés : | + | |
- | | + | |
- | python-openssl-doc python-openssl-dbg python-psutil-doc doc-base python-socks python-setuptools-doc python-ntlm | + | |
- | Paquets recommandés : | + | |
- | letsencrypt | + | |
- | Les NOUVEAUX paquets suivants seront installés : | + | |
- | certbot dialog python-acme python-certbot python-cffi-backend python-configargparse python-configobj python-cryptography python-dialog python-dnspython python-enum34 python-funcsigs | + | |
- | python-idna python-ipaddress python-mock python-ndg-httpsclient python-openssl python-parsedatetime python-pbr python-psutil python-pyasn1 python-pyicu python-requests python-rfc3339 | + | |
- | python-setuptools python-tz python-urllib3 python-zope.component python-zope.event python-zope.interface | + | |
- | Les paquets suivants seront mis à jour : | + | |
- | | + | |
- | 2 mis à jour, 30 nouvellement installés, 0 à enlever et 101 non mis à jour. | + | |
- | Il est nécessaire de prendre 2 308 ko dans les archives. | + | |
- | Après cette opération, 11,8 Mo d' | + | |
- | </ | + | |
+ | Si dans le cas d’un site web, cette validation se résume généralement à vérifier que vous avez la main sur le serveur web, dans le cas d’un certificat wildcard il faut prouver que vous avez la main sur l’ensemble du domaine. Aussi, seul le challenge DNS-01 est possible pour des certificats wildcard letsencrypt, | ||
Je décide d' | Je décide d' | ||
Ligne 102: | Ligne 125: | ||
</ | </ | ||
+ | |||
+ | Dans le cas d'un wildcard avec authentification par DNS | ||
+ | |||
+ | < | ||
+ | # certbot certonly --manual -d ' | ||
+ | Saving debug log to / | ||
+ | Plugins selected: Authenticator manual, Installer None | ||
+ | Obtaining a new certificate | ||
+ | Performing the following challenges: | ||
+ | dns-01 challenge for edmc73.com | ||
+ | |||
+ | ------------------------------------------------------------------------------- | ||
+ | NOTE: The IP of this machine will be publicly logged as having requested this | ||
+ | certificate. If you're running certbot in manual mode on a machine that is not | ||
+ | your server, please ensure you're okay with that. | ||
+ | |||
+ | Are you OK with your IP being logged? | ||
+ | ------------------------------------------------------------------------------- | ||
+ | (Y)es/(N)o: y | ||
+ | |||
+ | ------------------------------------------------------------------------------- | ||
+ | Please deploy a DNS TXT record under the name | ||
+ | _acme-challenge.edmc73.com with the following value: | ||
+ | |||
+ | 6CmoURMbv3F14hJdzR8zqXrhcYJeKWJEhT8xZcz4gUY | ||
+ | |||
+ | Before continuing, verify the record is deployed. | ||
+ | ------------------------------------------------------------------------------- | ||
+ | Press Enter to Continue | ||
+ | </ | ||
+ | C'est à ce moment la que vous allez ajouter une entrée DNS sur votre nom de domaine. Ensuite pressez Enter :) | ||
+ | |||
+ | < | ||
+ | Waiting for verification... | ||
+ | Cleaning up challenges | ||
+ | |||
+ | IMPORTANT NOTES: | ||
+ | - Congratulations! Your certificate and chain have been saved at: | ||
+ | / | ||
+ | Your key file has been saved at: | ||
+ | / | ||
+ | Your cert will expire on 2033-06-13. To obtain a new or tweaked | ||
+ | | ||
+ | | ||
+ | | ||
+ | - If you like Certbot, please consider supporting our work by: | ||
+ | |||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | Vous devrez retaper la commande suivante pour renouveler le certificat à la main. | ||
+ | # certbot certonly --manual -d *.edmc73.com | ||
+ | |||
+ | Voir la doc: https:// | ||
+ | Et un tuto pour automatiser avec l'api ovh: https:// | ||
+ | </ | ||
Tous les fichiers sont dans **/ | Tous les fichiers sont dans **/ | ||
Ligne 119: | Ligne 201: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | ou bien, variante fourni par letsencrypt | ||
+ | |||
+ | < | ||
+ | < | ||
+ | # Baseline setting to Include for SSL sites | ||
+ | |||
+ | SSLEngine on | ||
+ | | ||
+ | # Intermediate configuration, | ||
+ | SSLProtocol | ||
+ | SSLCipherSuite | ||
+ | SSLHonorCipherOrder | ||
+ | SSLCompression | ||
+ | |||
+ | SSLOptions +StrictRequire | ||
+ | |||
+ | # Add vhost name to log entries: | ||
+ | LogFormat "%h %l %u %t \" | ||
+ | LogFormat "%v %h %l %u %t \" | ||
+ | |||
+ | #CustomLog / | ||
+ | #LogLevel warn | ||
+ | #ErrorLog / | ||
+ | |||
+ | # Always ensure Cookies have " | ||
+ | #Header edit Set-Cookie (? | ||
+ | |||
+ | SSLCipherSuite ALL: | ||
+ | SSLCertificateFile | ||
+ | SSLCertificateKeyFile | ||
+ | SSLCertificateChainFile / | ||
+ | SSLCACertificateFile | ||
+ | SetEnvIf User-Agent “.*MSIE.*” nokeepalive ssl-unclean-shutdown | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
On reload apache | On reload apache | ||
Ligne 175: | Ligne 297: | ||
- | <note warning> | + | ==== module apache ==== |
- | Après avoir demandé une invitation pour tester en avant première ce nouveau service de certificat ssl gratuit, j'ai reçu un mail avec quelques commandes à taper. | + | |
- | 1ère chose, récupérer | + | Dans le cas d'un site web en python ou autre animal du genre ou on doit utiliser un proxy et donc bref, ça devient chiant. |
- | git clone https:// | + | |
- | | + | |
- | Je me dit, chouette un script tout prêt à l' | + | |
- | ./ | + | Ce module va écrire une config temporaire dans apache pour que letsencrypt |
- | Cette commande lance l' | ||
- | Tout ça pour lancer un script dans un environnement virtuel de python qui se résume par un échec. | ||
< | < | ||
- | Running with virtualenv: sudo /home/user/.local/share/letsencrypt/bin/ | + | certbot_apache._internal.http_01: |
- | The apache plugin is not working; there may be problems with your existing configuration. | + | |
- | The error was: PluginError(' | + | certbot_apache._internal.http_01: |
+ | |||
+ | RewriteEngine on | ||
+ | RewriteRule ^/\.well-known/acme-challenge/([A-Za-z0-9-_=]+)$ | ||
+ | |||
+ | certbot_apache._internal.http_01: | ||
+ | < | ||
+ | Require all granted | ||
+ | </ | ||
+ | < | ||
+ | | ||
+ | </ | ||
+ | |||
+ | certbot.reverter:Creating backup of / | ||
+ | |||
</ | </ | ||
- | Bien que tous les efforts ont été fait pour nous simplifier la vie, je n'aime pas vraiment ça, surtout pour installer un certificat ssl qui ne demande qu'à copier 3-4 fichiers et écrire quelques lignes de config dans apache. | ||
- | J'ai l' | ||
- | ./ | ||
- | --server https:// | ||
- | Ce qui nous sort toutes les commandes à taper en root sur le serveur web | + | ==== Commandes ==== |
- | <code> | + | <note> |
- | Make sure your web server displays the following content at | + | La commande qui va bien, pensez bien à associer le certificat pour le nom de domaine + le www. |
- | http:// | + | |
- | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | + | # ./ |
- | Content-Type header MUST be set to text/plain. | + | Ne pas oublié un reload d' |
+ | service apache2 reload | ||
- | If you don't have HTTP server configured, you can run the following | + | Pour voir la liste des certificats installés sur le système |
- | command on the target server (as root): | + | |
- | mkdir -p / | + | Ensuite pour supprimer un certificat du système |
- | cd / | + | ./certbot-auto delete |
- | printf " | + | |
- | # run only once per server: | + | |
- | $(command | + | |
- | " | + | |
- | SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map = {'': | + | |
- | s = BaseHTTPServer.HTTPServer(('', | + | |
- | s.serve_forever()" | + | |
- | </ | + | |
- | Alors ok, on voit mieux ce qui se passe, mais ça me parait encore trop lourd, je décide de tester | + | Si vous changer le path dans votre config apache, vous pouvez modifier la config letsencrypt à la main dans **/ |
+ | certbot renew --dry-run | ||
+ | |||
+ | ===== Avec certbot de debian ===== | ||
- | ./ | + | Maintenant certbot est directement intégré à debian 8 Jessie |
- | --server https:// | + | |
- | et la magie opère | + | La tache renew est maintenant un peu plus complexe car elle utilise systemd mais aussi le cron au cas ou systemd serait absent.. |
- | < | + | |
- | Updating letsencrypt and virtual environment dependencies....... | + | |
- | Running with virtualenv: sudo / | + | |
- | IMPORTANT NOTES: | + | Bref, pour continuer de recevoir un mail à chaque renouvellement, |
- | - Congratulations! Your certificate and chain have been saved at | + | |
- | /etc/letsencrypt/live/forum.p2pfr.com/fullchain.pem. Your cert will | + | |
- | | + | |
- | the future, simply run Let's Encrypt again. | + | |
- | </ | + | |
- | Maintenant nous avons 4 fichiers prêt à l' | + | < |
- | < | + | [Unit] |
- | < | + | Description=Certbot |
- | | + | Documentation=file:///usr/share/doc/ |
- | SSLProtocol all -SSLv2 | + | Documentation=https: |
- | | + | [Service] |
- | SSLCertificateFile | + | Type=oneshot |
- | | + | ExecStartPre=/usr/bin/perl -e 'sleep int(rand(3600))' |
- | SSLCertificateChainFile | + | ExecStart=/usr/bin/certbot -q renew --no-self-upgrade |
- | | + | PrivateTmp=true |
- | SetEnvIf User-Agent “.*MSIE.*” nokeepalive ssl-unclean-shutdown | + | |
- | </ | + | |
</ | </ | ||
- | On reload | + | ===== Config |
- | service apache2 reload | + | |
- | et voici le résultat | + | En mode certonly, letsencrypt crée un répertoire à la racine de votre site web **.well-known/ |
- | {{: | + | |
- | Pour renouveler le certificat, il suffit de relancer la même dernière commande. | + | Nous allons créer une config apache qui va centraliser toutes ces demandes dans un répertoire unique, par exemple **/ |
- | Le certificat est valide 90 jours, donc on peut lancer cette commande en automatique tous les 88 jours par exemple via le cron. | + | Créez |
+ | mkdir / | ||
- | Le cron ne permet pas d’exécuter un script tous les 88 jours, je propose donc un petit script que vous exécuterez tous les jours par le cron et qui fera un test sur la date du certificat pour savoir si il est plus vieux que 88 jours, et dans ce cas il exécutera le script | + | Créez |
+ | <code apache> | ||
+ | Alias / | ||
+ | < | ||
+ | Options -Indexes | ||
+ | AllowOverride all | ||
+ | Require all granted | ||
+ | </ | ||
+ | </ | ||
- | N' | + | a2enconf letsencrypt |
- | <code bash> | + | |
- | #!/bin/bash | + | |
- | if test `find /etc/ | + | et maintenant la commande certbot a utiliser |
- | then | + | certbot certonly --webroot -w /var/www/ |
- | /home/user/ | + | Ce sera le même répertoire pour tous les domaines de votre serveur. |
- | fi | + | |
+ | Si vous utilisez un proxy pass, attention à exclure le chemin de letsencrypt comme ceci | ||
+ | |||
+ | <code apache> | ||
+ | | ||
+ | ProxyPass | ||
+ | ProxyPassReverse / http://127.0.0.1:6000/ | ||
</ | </ | ||
- | Pour avoir un peu d'aide | ||
- | ./ | ||
+ | ===== Alternative à certbot ===== | ||
- | ====== Retour d'expérience ====== | + | Si comme moi vous trouvez un peu relou l'installation |
- | Après 90 jours, c'est donc le moment fatidique | + | |
- | En lançant la commande | + | |
- | / | + | |
- | J' | + | https:// |
- | Updating letsencrypt and virtual environment dependencies...You are using pip version 7.1.2, however version 8.0.2 is available. | + | |
- | You should consider upgrading via the 'pip install --upgrade pip' command. | + | |
- | ..Could not open requirements file: [Errno 2] No such file or directory: ' | + | |
+ | An ACME protocol client written purely in Shell (Unix shell) language. | ||
+ | Full ACME protocol implementation. | ||
+ | Simple, powerful and very easy to use. You only need 3 minutes to learn it. | ||
+ | Bash, dash and sh compatible. | ||
+ | Simplest shell script for Let's Encrypt free certificate client. | ||
+ | Purely written in Shell with no dependencies on python or the official Let's Encrypt client. | ||
+ | Just one script to issue, renew and install your certificates automatically. | ||
+ | DOES NOT require root/sudoer access. | ||
+ | It's probably the easiest& | ||
- | Je lance le script tout seul | + | Pas encore encore testé, mais recommandé par proxmox ( https://pve.proxmox.com/wiki/HTTPS_Certificate_Configuration_(Version_4.x_and_newer)# |
- | ./letsencrypt-auto | + | |
- | Updating letsencrypt and virtual environment dependencies....... | + | |
- | Running with virtualenv: | + | |
- | No installers seem to be present and working on your system; fix that or try running letsencrypt with the " | + | |
- | Je lance avec le " | ||
- | < | ||
- | Updating letsencrypt and virtual environment dependencies....... | ||
- | Running with virtualenv: / | ||
- | Use of --agree-dev-preview is deprecated. | ||
- | IMPORTANT NOTES: | + | ===== Let' |
- | - Congratulations! Your certificate and chain have been saved at | + | |
- | / | + | |
- | | + | |
- | the future, simply run Let' | + | |
- | - If you like Let's Encrypt, please consider supporting our work by: | + | |
- | | + | en gros suivre ce guide officiel => https://certbot.eff.org/lets-encrypt/centosrhel7-nginx |
- | | + | |
- | </code> | + | |
- | Par contre il faut quand même recharger apache | + | yum install python2-certbot-nginx |
- | service apache2 reload | + | |
- | Sinon le nouveau certificat n'est pas disponible | + | |
- | ===== 2ème retour ===== | + | Pour ne pas toucher à ma conf nginx j'ai lancé la commande suivante |
- | let's encrypt a changé | + | |
+ | Cela permet d'ajouter temporairement une config nginx juste pour vérifier que le nom de domaine pointe bien sur notre serveur et de tout remettre comme avant. | ||
- | Après avoir réinstallé leur nouveau script **certbot**, | + | Les certificats se trouvent dans /etc/ |
- | < | + | |
- | # ./certbot-auto certonly --webroot -w / | + | |
- | Checking for new version... | + | |
- | Requesting root privileges to run certbot... | + | |
- | / | + | |
- | IMPORTANT NOTES: | + | Pour vérifier, lancez simplement la commande |
- | - Congratulations! Your certificate and chain have been saved at | + | |
- | / | + | |
- | | + | |
- | the future, simply run Certbot again. | + | |
- | - If you like Certbot, please consider supporting our work by: | + | |
- | | + | Exemple de conf nginx |
- | Donating to EFF: | + | <code nginx> |
+ | server | ||
+ | | ||
+ | | ||
+ | # pour forcer le site en https | ||
+ | | ||
+ | } | ||
+ | server { | ||
+ | | ||
+ | | ||
+ | ssl on; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | La première fois, un email vous sera demandé ainsi qu'une validation de la licence, des infos seront stocké dans / | ||
- | Ne pas oublié un reload d' | + | ===== Avec StartSSL ===== |
- | service apache2 reload | + | |
+ | Aller sur ce site => http:// | ||
+ | |||
+ | Vous devrez valider votre email et nom de domaine en cliquant sur **Validations Wizard** | ||
+ | |||
+ | Toujours dans **Validations Wizard** vous devez faire vérifier votre nom de domaine en choisissant **Domain Name Validation** | ||
+ | |||
+ | Un mail de vérification sera envoyé à l'une (que vous choisissez) des adresses email renseigné pour votre nom de domaine. | ||
+ | |||
+ | Ensuite, cliquez sur **Certificates Wizard**, choisissez **Web Server SSL/TLS Certificate** dans la liste et fournissez un mot de passe pour la clé privé. | ||
+ | |||
+ | Copier/ | ||
+ | |||
+ | openssl rsa -in ssl.key -out ssl.key | ||
+ | | ||
+ | Cliquez sur **Continue** et choisissez votre nom de domaine. | ||
+ | |||
+ | A la fin vous devez avoir 4 fichiers | ||
+ | ca.pem | ||
+ | |||
+ | Configurer ensuite apache dans ce style | ||
+ | < | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \" | ||
+ | </ | ||
+ | </ |