diff --git a/build_and_verify_pki.sh b/build_and_verify_pki.sh index ff2fb0b..ef68122 100644 --- a/build_and_verify_pki.sh +++ b/build_and_verify_pki.sh @@ -25,20 +25,23 @@ echo 1000 > /root/ca-intermediaire/crlnumber mkdir -p /root/server/{certs,csr,private} ## II - Mise en place des fichiers de configuration +# Installation de curl +if ! dpkg -l | grep -q curl; then + apt install -y curl +fi # Création des fichiers de configuration curl https://git.yh.genj.fr/polaire/IRSS010-Public_Keys_Infrastructure/raw/branch/main/ca/openssl.conf > /root/ca/openssl.cnf curl https://git.yh.genj.fr/polaire/IRSS010-Public_Keys_Infrastructure/raw/branch/main/ca-intermediaire/openssl.cnf > /root/ca-intermediaire/openssl.cnf - ## III - Mise en place de l'autorité de certification racine # Création de la paire de clés openssl genpkey -algorithm RSA -out /root/ca/private/racine.key -aes256 -pass pass:yourpassword # Création du certificat racine -openssl req -config /root/ca/openssl.cnf -key /root/ca/private/racine.key -new -x509 -days 3650 -sha512 -extensions v3_ca -out /root/ca/racine.cert -subj "/C=FR/ST=Haute-Garone/L=Toulouse/O=Igensia/OU=IPI/CN=Root CA" +openssl req -config /root/ca/openssl.cnf -key /root/ca/private/racine.key -new -x509 -days 3650 -sha512 -extensions v3_ca -out /root/ca/certs/racine.cert -passin pass:yourpassword -subj "/C=FR/ST=Haute-Garone/L=Toulouse/O=Igensia/OU=IPI/CN=Root CA" # Afficher le certificat racine -openssl x509 -in /root/ca/racine.cert -text > ./pki_checks/racine.cert.txt -# Vérifier le certificat -openssl verify -CAfile /root/ca/racine.cert /root/ca/racine.cert > ./pki_checks/verify.txt +openssl x509 -in /root/ca/certs/racine.cert -text > ./pki_checks/racine.cert.txt +# Vérifier le certificat racine et incrémentation du fichier verify.txt +openssl verify -CAfile /root/ca/certs/racine.cert /root/ca/certs/racine.cert > ./pki_checks/verify.txt ## IV - Mise en place de l'autorité de certification intermédiaire # Création de la paire de clés @@ -46,21 +49,21 @@ openssl genpkey -algorithm RSA -out /root/ca-intermediaire/private/intermediate. # Création de la demande de certificat de l'autorité intermédiaire (CSR) openssl req -config /root/ca-intermediaire/openssl.cnf -new -key /root/ca-intermediaire/private/intermediate.key -out /root/ca-intermediaire/csr/intermediate.csr -passin pass:yourpassword2 -subj "/C=FR/ST=Paca/L=Marseille/O=Igensia/OU=ISCPA/CN=Intermediate CA" # Signature du certificat par la CA Root -openssl ca -config /root/ca/openssl.cnf -extensions v3_ca_intermediaire -days 365 -notext -md sha512 -in /root/ca-intermediaire/csr/intermediate.csr -out /root/ca-intermediaire/certs/intermediate.cert -passin pass:yourpassword +openssl ca -batch -config /root/ca/openssl.cnf -extensions v3_ca_intermediaire -days 365 -notext -md sha512 -in /root/ca-intermediaire/csr/intermediate.csr -out /root/ca-intermediaire/certs/intermediate.cert -passin pass:yourpassword # Afficher le certificat intermédiaire -openssl x509 -in /root/ca-intermediaire/certs/intermediate.cert > ./pki_checks/intermediate.cert.txt -# Vérifier le certificat intermédiaire -openssl verify -CAfile /root/ca/racine.cert /root/ca-intermediaire/certs/intermediate.cert >> ./pki_checks/verify.txt +openssl x509 -in /root/ca-intermediaire/certs/intermediate.cert -text > ./pki_checks/intermediate.cert.txt +# Vérifier le certificat intermédiaire et incrémentation du fichier index.txt +openssl verify -CAfile /root/ca/certs/racine.cert /root/ca-intermediaire/certs/intermediate.cert >> ./pki_checks/verify.txt # Création de la chaîne de certification -cat /root/ca-intermediaire/certs/intermediate.cert /root/ca/racine.cert > /root/ca-intermediaire/certs/chain.cert +cat /root/ca-intermediaire/certs/intermediate.cert /root/ca/certs/racine.cert > /root/ca-intermediaire/certs/chain.cert ## V - Mise en place du certificat serveur à révoquer # Création de la paire de clés -openssl genpkey -algorithm RSA -out /root/server/private/server.key +openssl genpkey -algorithm RSA -out /root/server/private/server.key -aes256 -pass pass:yourpassword2 # Création de la CSR openssl req -config /root/ca-intermediaire/openssl.cnf -new -key /root/server/private/server.key -out /root/server/csr/server.csr -passin pass:yourpassword2 -subj "/C=FR/ST=Haute-Garone/L=Toulouse/O=Igensia/OU=IPI/CN=maquette.ipi" #Signature du certificat par la CA intermédiaire -openssl ca -config /root/ca-intermediaire/openssl.cnf -extensions server_cert -days 30 -notext -md sha512 -in /root/server/csr/server.csr -out /root/server/certs/server.cert -cert /root/ca-intermediaire/certs/intermediate.cert -passin pass:yourpassword2 -keyfile /root/ca-intermediaire/private/intermediate.key +openssl ca -batch -config /root/ca-intermediaire/openssl.cnf -extensions server_cert -days 30 -notext -md sha512 -in /root/server/csr/server.csr -out /root/server/certs/server.cert -cert /root/ca-intermediaire/certs/intermediate.cert -passin pass:yourpassword2 -keyfile /root/ca-intermediaire/private/intermediate.key # Afficher le certificat du serveur openssl x509 -in /root/server/certs/server.cert -text -noout > ./pki_checks/server.cert.txt # Vérifier le certificat du serveur @@ -74,23 +77,25 @@ openssl ca -config /root/ca-intermediaire/openssl.cnf -revoke /root/server/certs # Génération d'une nouvelle CRL après révocation openssl ca -config /root/ca-intermediaire/openssl.cnf -gencrl -out /root/ca-intermediaire/crl/crl.pem -passin pass:yourpassword2 # Vérification de la révocation d'un certificat -openssl verify -crl_check -CAfile /root/ca-intermediaire/chain.cert -CRLfile /root/ca-intermediaire/crl/crl.pem /root/server/certs/server.cert > ./pki_checks/verify_crl.txt +openssl verify -crl_check -CAfile /root/ca-intermediaire/certs/chain.cert -CRLfile /root/ca-intermediaire/crl/crl.pem /root/server/certs/server.cert > ./pki_checks/verify_crl.txt 2>&1 ## VII - Création du certificat serveur avec SAN # Mise à jour du fichier de configuration de la CA intermédiaire -curl https://git.yh.genj.fr/polaire/IRSS010-Public_Keys_Infrastructure/raw/branch/main/ca-intermediaire/openssl_san.cnf > /root/ca-intermediaire/openssl.cnf +curl https://git.yh.genj.fr/polaire/IRSS010-Public_Keys_Infrastructure/raw/branch/main/ca-intermediaire/openssl-san.cnf > /root/ca-intermediaire/openssl.cnf # Création de la paire de clés -openssl genpkey -algorithm RSA -out /root/server/private/server_san.key +openssl genpkey -algorithm RSA -out /root/server/private/server_san.key # Création de la CSR openssl req -config /root/ca-intermediaire/openssl.cnf -new -key /root/server/private/server_san.key -out /root/server/csr/server_san.csr -passin pass:yourpassword2 -subj "/C=FR/ST=Haute-Garone/L=Toulouse/O=Igensia/OU=IPI/CN=maquette.igensia" # Signature du certificat par la CA intermédiaire -openssl ca -config /root/ca-intermediaire/openssl.cnf -extensions server_cert -days 30 -notext -md sha512 -in /root/server/csr/server_san.csr -out /root/server/certs/server_san.cert -cert /root/ca-intermediaire/certs/intermediate.cert -passin pass:yourpassword2 -keyfile /root/ca-intermediaire/private/intermediate.key +openssl ca -batch -config /root/ca-intermediaire/openssl.cnf -extensions server_cert -days 30 -notext -md sha512 -in /root/server/csr/server_san.csr -out /root/server/certs/server_san.cert -cert /root/ca-intermediaire/certs/intermediate.cert -passin pass:yourpassword2 -keyfile /root/ca-intermediaire/private/intermediate.key # Vérification du certificat du serveur avec SAN openssl x509 -in /root/server/certs/server_san.cert -text > ./pki_checks/server_san.cert.txt +# Vérifier le certificat du serveur +openssl verify -CAfile /root/ca-intermediaire/certs/chain.cert /root/server/certs/server_san.cert >> ./pki_checks/verify.txt ## VIII - Installation et configuration d'Apache if ! dpkg -l | grep -q apache2; then - apt install -y apache2 + apt install -y apache2 fi curl https://git.yh.genj.fr/polaire/IRSS010-Public_Keys_Infrastructure/raw/branch/main/default-ssl.conf > /etc/apache2/sites-available/default-ssl.conf a2enmod ssl @@ -101,8 +106,9 @@ systemctl restart apache2 # Copie du fichier chain.cert dans le répertoire courant pour qu'il puisse être importé dans Firefox. cp /root/ca-intermediaire/certs/chain.cert ./chain.cert # Affichage des messages d'information +echo "" +echo "" echo "La PKI est en place. Pour tester HTTPS, récupérez ./chain.cert et importez-le dans Firefox." echo "Vous trouverez les certificats et leurs informations associés sous ./pki_checks/" echo "Vous pouvez consulter la sortie pour la CRL sous ./pki_checks/verify_crl.txt" -echo "Le fichier ./pki_checks/verify.txt contient les vérifications pour l'ensemble des certificats" - +echo "Le fichier ./pki_checks/verify.txt contient les vérifications pour l'ensemble des certificats" \ No newline at end of file