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 Prochaine révision Les deux révisions suivantes | ||
linux:ssl [14-05-2016 01:16] edmc73 |
linux:ssl [24-06-2021 16:20] 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. | + | 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 |
- | Ensuite, cliquez sur **Certificates Wizard**, choisissez **Web Server SSL/TLS Certificate** dans la liste et fournissez un mot de passe pour la clé privé. | + | Le script s' |
- | Copier/ | ||
- | openssl rsa -in ssl.key -out ssl.key | + | Le site suivant permet de faciliter l' |
- | + | ||
- | Cliquez sur **Continue** et choisissez votre nom de domaine. | + | |
- | A la fin vous devez avoir 4 fichiers | + | >Sinon il y a toujours le script standalone => https://dl.eff.org/ |
- | ca.pem ssl.crt ssl.key sub.class1.server.ca.pem | + | |
- | Configurer ensuite apache | + | **certbot** est dispo dans le dépôt backport de debian. Il suffit d' |
- | < | + | deb http://ftp.debian.org/debian jessie-backports main |
- | < | + | |
- | | + | |
- | ErrorLog | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | SSLCertificateKeyFile / | + | < |
- | SSLCertificateChainFile / | + | # apt update |
- | CustomLog / | + | # apt install certbot |
- | "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \" | + | |
- | </ | + | |
</ | </ | ||
- | ===== Avec Let's Encrypt ===== | + | Pour émettre un certificat, letsencrypt doit s’assurer que vous avez bien la main sur les ressources |
- | Let's Encrypt a bien évolué depuis sa version beta, je vais maintenant mettre mes scripts | + | |
- | Le script s' | + | |
+ | | ||
+ | | ||
+ | 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, | ||
- | Le site suivant | + | Je décide d' |
- | Il propose un script | + | < |
+ | |||
+ | La première fois que vous lancerez ce script, | ||
- | J' | ||
< | < | ||
- | # wget https://dl.eff.org/certbot-auto | + | IMPORTANT NOTES: |
- | # chmod +x certbot-auto | + | - Congratulations! Your certificate and chain have been saved at |
- | # ./certbot-auto | + | /etc/letsencrypt/ |
- | Checking for new version... | + | expire on 2016-08-11. To obtain a new version |
- | Creating virtual environment... | + | the future, simply run Certbot again. |
- | Installing Python packages... | + | - If you like Certbot, please consider supporting our work by: |
- | Installation succeeded. | + | |
- | Requesting root privileges | + | Donating |
- | /root/.local/share/letsencrypt/bin/letsencrypt | + | |
- | No installers seem to be present and working on your system; fix that or try running certbot with the " | + | |
</ | </ | ||
- | Bon, ça n'a pas l'air gagné, je tente la commande pour apache | + | |
+ | |||
+ | Dans le cas d'un wildcard avec authentification par DNS | ||
< | < | ||
- | # ./certbot-auto --apache | + | # certbot |
- | Checking for new version... | + | Saving debug log to /var/log/ |
- | Requesting root privileges | + | Plugins selected: Authenticator manual, Installer None |
- | /root/.local/ | + | Obtaining a new certificate |
- | The apache plugin is not working; there may be problems with your existing configuration. | + | Performing the following challenges: |
- | The error was: NotSupportedError(' | + | dns-01 challenge for edmc73.com |
- | </ | + | |
- | Ça me rappel un peu la version beta. | + | ------------------------------------------------------------------------------- |
+ | 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. | ||
- | Je décide d' | + | Are you OK with your IP being logged? |
+ | ------------------------------------------------------------------------------- | ||
+ | (Y)es/(N)o: y | ||
- | < | + | ------------------------------------------------------------------------------- |
- | Checking for new version... | + | Please deploy a DNS TXT record under the name |
- | Requesting root privileges to run certbot... | + | _acme-challenge.edmc73.com with the following value: |
- | /root/.local/ | + | |
+ | 6CmoURMbv3F14hJdzR8zqXrhcYJeKWJEhT8xZcz4gUY | ||
+ | |||
+ | Before continuing, verify the record is deployed. | ||
+ | ------------------------------------------------------------------------------- | ||
+ | Press Enter to Continue | ||
+ | </code> | ||
+ | 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: | IMPORTANT NOTES: | ||
- | - Congratulations! Your certificate and chain have been saved at | + | - Congratulations! Your certificate and chain have been saved at: |
- | / | + | / |
- | expire on 2016-08-11. To obtain a new version of the certificate in | + | Your key file has been saved at: |
- | the future, simply run Certbot | + | / |
+ | Your cert will expire on 2033-06-13. To obtain a new or tweaked | ||
+ | version of this certificate in the future, simply run | ||
+ | | ||
+ | | ||
- If you like Certbot, please consider supporting our work by: | - If you like Certbot, please consider supporting our work by: | ||
Ligne 96: | Ligne 109: | ||
</ | </ | ||
- | La première fois que vous lancerez ce script, il vous sera demander | + | <note warning> |
+ | |||
+ | Vous devrez retaper | ||
+ | # 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 114: | Ligne 134: | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | 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 163: | Ligne 223: | ||
</ | </ | ||
+ | Voici mon cron qui permet dans le cas où un certificat est renouvelé de recharger apache et d' | ||
+ | |||
+ | 13 5,17 * * * / | ||
Et voila, vous n' | Et voila, vous n' | ||
- | <note warning> | ||
- | 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 le script | ||
- | git clone https:// | ||
- | If you're running Apache on a recent Debian-based OS, you can try the Apache plugin, which automates both obtaining and installing certs: | ||
- | Je me dit, chouette un script tout prêt à l' | ||
- | ./ | ||
- | 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 / | ||
- | The apache plugin is not working; there may be problems with your existing configuration. | ||
- | The error was: PluginError(' | ||
- | </ | ||
- | 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' | + | ==== Commandes ==== |
+ | < | ||
+ | La commande qui va bien, pensez bien à associer le certificat pour le nom de domaine + le www. | ||
- | ./letsencrypt-auto certonly -a manual | + | |
- | | + | |
- | Ce qui nous sort toutes les commandes à taper en root sur le serveur web | + | Ne pas oublié un reload d' |
- | < | + | |
- | Make sure your web server displays the following content at | + | |
- | http:// | + | |
- | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | + | Pour voir la liste des certificats installés sur le système |
+ | ./ | ||
- | Content-Type header MUST be set to text/plain. | + | Ensuite pour supprimer un certificat du système |
+ | ./certbot-auto delete --cert-name p2pfr.com | ||
- | If you don't have HTTP server configured, you can run the following | + | Si vous changer le path dans votre config apache, vous pouvez modifier la config letsencrypt à la main dans **/ |
- | command on the target server (as root): | + | certbot renew --dry-run |
+ | |||
+ | ===== Avec certbot de debian ===== | ||
- | mkdir -p /tmp/letsencrypt/public_html/.well-known/acme-challenge | + | Maintenant certbot est directement intégré à debian 8 Jessie |
- | cd /tmp/letsencrypt/public_html | + | |
- | printf " | + | La tache renew est maintenant un peu plus complexe car elle utilise systemd mais aussi le cron au cas ou systemd serait absent.. |
- | # run only once per server: | + | |
- | $(command -v python2 || command -v python2.7 || command -v python2.6) -c \ | + | Bref, pour continuer de recevoir un mail à chaque renouvellement, |
- | " | + | |
- | SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map | + | <code bash> |
- | s = BaseHTTPServer.HTTPServer(('', | + | [Unit] |
- | s.serve_forever()" | + | Description=Certbot |
+ | Documentation=file: | ||
+ | Documentation=https:// | ||
+ | [Service] | ||
+ | Type=oneshot | ||
+ | ExecStartPre=/ | ||
+ | ExecStart=/ | ||
+ | PrivateTmp=true | ||
</ | </ | ||
- | Alors ok, on voit mieux ce qui se passe, mais ça me parait encore trop lourd, je décide de tester la méthode **webroot** où l'on définit sur le serveur web où se trouve le site que l'on veut mettre en https et il gère le reste | + | ===== Config apache pour centraliser les acme-challenge ===== |
- | ./letsencrypt-auto certonly -a webroot --webroot-path / | + | En mode certonly, |
- | --server https://acme-v01.api.letsencrypt.org/ | + | |
- | et la magie opère | + | Nous allons créer une config apache qui va centraliser toutes ces demandes dans un répertoire unique, par exemple **/var/www/ |
- | < | + | |
- | Updating letsencrypt and virtual environment dependencies....... | + | |
- | Running with virtualenv: sudo /home/user/ | + | |
- | IMPORTANT NOTES: | + | Créez le répertoire **/var/www/ |
- | - Congratulations! Your certificate and chain have been saved at | + | mkdir /var/www/letsencrypt |
- | /etc/ | + | |
- | | + | |
- | the future, simply run Let's Encrypt again. | + | |
- | </ | + | |
- | Maintenant nous avons 4 fichiers prêt à l' | + | Créez le fichier **/ |
- | < | + | < |
- | < | + | Alias /.well-known/acme-challenge |
- | SSLEngine on | + | < |
- | SSLProtocol all -SSLv2 | + | |
- | SSLCipherSuite ALL: | + | |
- | SSLCertificateFile | + | Require all granted |
- | SSLCertificateKeyFile | + | </Directory> |
- | | + | |
- | | + | |
- | | + | |
- | </IfModule> | + | |
</ | </ | ||
- | On reload apache | + | a2enconf letsencrypt |
- | | + | |
- | et voici le résultat | + | et maintenant la commande certbot a utiliser |
- | {{: | + | |
+ | Ce sera le même répertoire pour tous les domaines de votre serveur. | ||
- | Pour renouveler le certificat, il suffit | + | Si vous utilisez un proxy pass, attention à exclure le chemin |
- | Le certificat est valide 90 jours, donc on peut lancer cette commande en automatique tous les 88 jours par exemple via le cron. | + | <code apache> |
+ | ProxyPass /.well-known/ | ||
+ | ProxyPass / http:// | ||
+ | ProxyPassReverse / http:// | ||
+ | </ | ||
- | 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 letsencrypt pour renouveler le certificat. | ||
- | N' | + | ===== Alternative à certbot ===== |
- | <code bash> | + | |
- | #!/bin/bash | + | |
- | if test `find / | + | Si comme moi vous trouvez un peu relou l' |
- | then | + | |
- | / | + | |
- | fi | + | |
- | </ | + | |
- | Pour avoir un peu d' | + | https:// |
- | | + | |
+ | 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& | ||
- | ====== Retour d' | + | Pas encore encore testé, mais recommandé par proxmox ( https://pve.proxmox.com/wiki/HTTPS_Certificate_Configuration_(Version_4.x_and_newer)# |
- | Après 90 jours, c'est donc le moment fatidique de mettre à jour le certificat. Pour info nous recevons un mail de notification d' | + | |
- | En lançant la commande | + | |
- | | + | |
- | J' | ||
- | 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: ' | ||
+ | ===== Let's encrypt sur centos avec nginx en reverse proxy ===== | ||
- | Je lance le script tout seul | + | en gros suivre ce guide officiel => https://certbot.eff.org/lets-encrypt/centosrhel7-nginx |
- | ./ | + | |
- | Updating letsencrypt and virtual environment dependencies....... | + | |
- | Running with virtualenv: /root/.local/share/letsencrypt/ | + | |
- | No installers seem to be present and working on your system; fix that or try running letsencrypt with the " | + | |
- | Je lance avec le " | + | yum install python2-certbot-nginx |
- | < | + | |
- | Updating letsencrypt and virtual environment dependencies....... | + | |
- | Running with virtualenv: / | + | |
- | Use of --agree-dev-preview is deprecated. | + | |
- | IMPORTANT NOTES: | + | Pour ne pas toucher à ma conf nginx j'ai lancé la commande suivante |
- | | + | |
- | / | + | 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. |
- | | + | |
- | the future, simply run Let's Encrypt again. | + | |
- | - If you like Let's Encrypt, please consider supporting our work by: | + | |
- | | + | Les certificats se trouvent dans /etc/ |
- | Donating to EFF: https://eff.org/donate-le | + | |
+ | Pour vérifier, lancez simplement la commande | ||
+ | certbot certificates | ||
+ | |||
+ | Exemple de conf nginx | ||
+ | <code nginx> | ||
+ | server | ||
+ | | ||
+ | | ||
+ | # pour forcer le site en https | ||
+ | | ||
+ | } | ||
+ | |||
+ | server { | ||
+ | | ||
+ | | ||
+ | ssl on; | ||
+ | | ||
+ | ssl_certificate_key | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | Par contre il faut quand même recharger apache | ||
- | service apache2 reload | ||
- | Sinon le nouveau certificat n'est pas disponible | ||
- | ===== 2ème retour | + | ===== Avec StartSSL |
- | let's encrypt a changé de script. | + | |
- | Après avoir réinstallé leur nouveau script **certbot**, | + | Aller sur ce site => http://www.startssl.com/ et créez-vous un compte. Il faudra ensuite installer le certificat qu'il vous fournirons pour vous identifier. |
- | <code> | + | |
- | # ./certbot-auto certonly --webroot -w /home/ | + | |
- | Checking for new version... | + | |
- | Requesting root privileges to run certbot... | + | |
- | /root/ | + | |
- | IMPORTANT NOTES: | + | Vous devrez valider votre email et nom de domaine en cliquant sur **Validations Wizard** |
- | - 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: | + | |
- | | + | 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. |
- | La première fois, un email vous sera demandé ainsi qu'une validation | + | Ensuite, cliquez sur **Certificates Wizard**, choisissez **Web Server SSL/TLS Certificate** dans la liste et fournissez |
- | Ne pas oublié un reload d' | + | Copier/ |
- | service apache2 reload | + | |
+ | 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 \" | ||
+ | </ | ||
+ | </ |