Différences
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 | ||
| openssl:accueil [2021/04/04 17:01] – modification externe 127.0.0.1 | openssl:accueil [2025/12/07 20:09] (Version actuelle) – [Gérer sa propre PKI] add how to use certbot with smallstep phsw | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | |||
| + | ==== Ajouter un certificat au système ==== | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt install libnss3-tools | ||
| + | |||
| + | sudo cp homelab.crt / | ||
| + | sudo update-ca-certificates | ||
| + | sudo chmod a+r / | ||
| + | </ | ||
| + | |||
| + | Pour que le certificat soit aussi reconnu dans Firefox et Thunderbird, | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt install libnss3-tools | ||
| + | |||
| + | readonly certificateFile="/ | ||
| + | readonly certificateName=" | ||
| + | |||
| + | find ~/.mozilla* ~/ | ||
| + | do | ||
| + | certDir=$(dirname " | ||
| + | echo " | ||
| + | certutil -A -n " | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | |||
| ==== Générer un certificat auto-signé ==== | ==== Générer un certificat auto-signé ==== | ||
| + | |||
| + | |||
| + | * [[https:// | ||
| === Générer une clé privée RSA === | === Générer une clé privée RSA === | ||
| Ligne 32: | Ligne 66: | ||
| - | ----- | + | |
| ==== Lancer un serveur HTTPS ==== | ==== Lancer un serveur HTTPS ==== | ||
| + | |||
| <code bash> | <code bash> | ||
| sudo openssl s_server -accept 443 -cert server.pem | sudo openssl s_server -accept 443 -cert server.pem | ||
| Ligne 43: | Ligne 78: | ||
| - | ------ | + | |
| ==== Se connecter à un serveur HTTPS ==== | ==== Se connecter à un serveur HTTPS ==== | ||
| Ligne 54: | Ligne 89: | ||
| - | ----- | + | |
| ==== Connaître les dates d'un certificat ==== | ==== Connaître les dates d'un certificat ==== | ||
| Ligne 62: | Ligne 97: | ||
| <code bash> | <code bash> | ||
| openssl x509 -noout -dates -in cert.pem | openssl x509 -noout -dates -in cert.pem | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ==== Gérer sa propre PKI ==== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | |||
| + | === Avec Smallstep === | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | <code bash> | ||
| + | sudo curl -fsSL https:// | ||
| + | echo 'deb [signed-by=/ | ||
| + | | sudo tee / | ||
| + | sudo apt update | ||
| + | sudo apt install step-ca step-cli | ||
| + | |||
| + | step ca init | ||
| + | |||
| + | sudo step-ca $(step path)/ | ||
| + | |||
| + | step ca provisioner add acme --type ACME --x509-default-dur=$((30*24))h | ||
| + | |||
| + | sudo useradd --user-group --system --home / | ||
| + | sudo setcap CAP_NET_BIND_SERVICE=+eip $(which step-ca) | ||
| + | sudo mv $(step path) / | ||
| + | # put password in / | ||
| + | sudo chmod 400 / | ||
| + | # edit and adapt paths in / | ||
| + | # edit and adapt paths in / | ||
| + | sudo chown -R step:step / | ||
| + | # create the service in / | ||
| + | sudo systemctl daemon-reload | ||
| + | sudo systemctl status step-ca | ||
| + | sudo systemctl enable --now step-ca | ||
| + | sudo journalctl --follow --unit=step-ca | ||
| + | </ | ||
| + | |||
| + | |||
| + | === Utiliser Certbot pour récupérer un certificat === | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | Ici, on utilise Certbot pour automatiser la récupération d'un certificat pour l' | ||
| + | <code bash> | ||
| + | sudo apt install certbot | ||
| + | |||
| + | sudo certbot certonly -n --standalone -d pihole.homelab --server https:// | ||
| + | |||
| + | sudo cat / | ||
| + | sudo service pihole-FTL restart | ||
| + | </ | ||
| + | |||
| + | Après la commande, Certbot va automatiquement créer un timer Systemd pour deux fois par jour renouveler les certificats. Pour que le certificat renouvelé soit pris en compte par PiHole, créer le script ''/ | ||
| + | <code bash> | ||
| + | #!/bin/sh -eu | ||
| + | |||
| + | found=0 | ||
| + | for domain in $RENEWED_DOMAINS | ||
| + | do | ||
| + | if [ " | ||
| + | then | ||
| + | found=1 | ||
| + | fi | ||
| + | done | ||
| + | if [ " | ||
| + | then | ||
| + | exit 0 | ||
| + | fi | ||
| + | |||
| + | cp / | ||
| + | cat / | ||
| + | |||
| + | service pihole-FTL restart | ||
| + | </ | ||
| + | |||
| + | Un bug dans la version 4.0.0 de Certbot considère que '' | ||
| + | < | ||
| + | renew_before_expiry = 10 days | ||
| </ | </ | ||