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 Dernière révision Les deux révisions suivantes | ||
linux:ssl [14-05-2016 22:21] edmc73 |
linux:ssl [11-01-2023 11:10] 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 170: | Ligne 230: | ||
- | <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> | + | systemctl reload apache2 |
- | #!/bin/bash | + | |
+ | et maintenant la commande certbot a utiliser | ||
+ | certbot certonly | ||
+ | Ce sera le même répertoire pour tous les domaines de votre serveur. | ||
- | if test `find /etc/letsencrypt/ | + | Si vous utilisez un proxy pass, attention à exclure le chemin de letsencrypt |
- | then | + | |
- | /home/user/letsencrypt/ | + | <code apache> |
- | fi | + | ProxyPass |
+ | | ||
+ | ProxyPassReverse | ||
</ | </ | ||
- | 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 \" | ||
+ | </ | ||
+ | </ |