Commit de8257

2025-12-23 15:36:23 Cédric: -/-
/dev/null .. astuces openssl.md
@@ 0,0 1,93 @@
+ # Astuces Openssl
+
+ #### Request clef + csr :
+
+ ```bash
+ openssl req -new -newkey rsa:2048 -keyout XXX.key -out XXX.csr
+ ```
+
+ #### Clef privée déchiffrée :
+
+ ```bash
+ openssl rsa -in XXX.key -out XXX.unsecure.key
+ ```
+
+ #### Chiffrer une clef privée :
+
+ ```bash
+ openssl rsa -in maCle.pem -des3 -out maCle.pem
+ ```
+
+ #### Construire un pfx/pkcs12 :
+
+ ```bash
+ openssl pkcs12 -inkey privkey.pem -in chaine.pem -export -out fichier.pfx
+ ```
+
+ #### Utiliser le paramètre "Legacy" avec des vieux OS Windows :
+
+ ```bash
+ openssl pkcs12 -in <PKCS#12 Filename> -legacy -out <Encrypted PEM Filename>
+ openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in <Encrypted PEM Filename> -out <PKCS#12 Filename> -legacy -name "<Display Name>"
+ ```
+
+ #### Connexion direct d’un client TLS :
+
+ ```bash
+ openssl s_client -connect address.of.my.isp.com:587 -starttls smtp
+ ```
+
+ #### Connexion avec une clef privée :
+
+ ```bash
+ ssh -i clef.txt root@host
+ ```
+
+ #### Générer un id\_rsa.pub à partir d'une clef privée :
+
+ ```bash
+ ssh-keygen -y -f ~/.ssh/clef-privée > ~/.ssh/id_rsa.pub
+ # output d'une clef privée
+ ssh-keygen -l -f ~/.ssh/id_rsa
+ ```
+
+ #### Afficher le contenu d'un certificat .pem X509 :
+
+ ```bash
+ openssl x509 -in <fichier.pem> -noout -text | grep DNS
+ ```
+
+ #### Vérifier une chaine de certif :
+
+ ```bash
+ openssl verify -CAfile chaine.pem cert.pem
+ ```
+
+ #### Output d'un certificat SSL :
+
+ ```bash
+ openssl x509 -in cert.pem -text -noout
+ ```
+
+ #### Générer une mini CA et l'utiliser pour créer des certifs (serveur/client)
+
+ ```bash
+ # CREATION DE LA CA ET SON CERTIF ASSOCIE :
+ openssl genrsa -out ca-key.pem 4096
+ openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
+ # dans les réponse de la commande :common name : test-server.home.naoned.net
+
+ # CREATION DU CERTIFICAT SERVEUR :
+ openssl genrsa -out server-key.pem 4096
+ openssl req -subj "/CN=test-server.home.naoned.net" -sha256 -new -key server-key.pem -out server.csr
+ # créer un request CERTIF pour le nom du serveur ainsi que les fonctions d'auth étendue
+ echo "subjectAltName = DNS:test-server.home.naoned.net,IP:172.16.16.x;IP:127.0.0.1" >>extFile.cnf
+ echo "extendedKeyUsage = serverAuth" >>extfile.cnf
+ openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf
+ # ok le certificat du serveur est créé et validé via la CA ainsi qu'avec l'extension "serverAuth"
+ # on fait la même chose pour le client qui se connectera
+ openssl genrsa -out key.pem 4096
+ openssl req -subj "/CN=client" -new -key key.pem -out client.csr
+ echo "extendedKeyUsage = clientAuth" >>extfile-client.cnf
+ openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem -extfile extfile-client.cnf
+ ```
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9