Blame
| de8257 | Cédric | 2025-12-23 15:36:23 | 1 | # Astuces Openssl |
| 2 | ||||
| 3 | #### Request clef + csr : |
|||
| 4 | ||||
| 5 | ```bash |
|||
| 6 | openssl req -new -newkey rsa:2048 -keyout XXX.key -out XXX.csr |
|||
| 7 | ``` |
|||
| 8 | ||||
| 9 | #### Clef privée déchiffrée : |
|||
| 10 | ||||
| 11 | ```bash |
|||
| 12 | openssl rsa -in XXX.key -out XXX.unsecure.key |
|||
| 13 | ``` |
|||
| 14 | ||||
| 15 | #### Chiffrer une clef privée : |
|||
| 16 | ||||
| 17 | ```bash |
|||
| 18 | openssl rsa -in maCle.pem -des3 -out maCle.pem |
|||
| 19 | ``` |
|||
| 20 | ||||
| 21 | #### Construire un pfx/pkcs12 : |
|||
| 22 | ||||
| 23 | ```bash |
|||
| 24 | openssl pkcs12 -inkey privkey.pem -in chaine.pem -export -out fichier.pfx |
|||
| 25 | ``` |
|||
| 26 | ||||
| 27 | #### Utiliser le paramètre "Legacy" avec des vieux OS Windows : |
|||
| 28 | ||||
| 29 | ```bash |
|||
| 30 | openssl pkcs12 -in <PKCS#12 Filename> -legacy -out <Encrypted PEM Filename> |
|||
| 31 | openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in <Encrypted PEM Filename> -out <PKCS#12 Filename> -legacy -name "<Display Name>" |
|||
| 32 | ``` |
|||
| 33 | ||||
| 34 | #### Connexion direct d’un client TLS : |
|||
| 35 | ||||
| 36 | ```bash |
|||
| 37 | openssl s_client -connect address.of.my.isp.com:587 -starttls smtp |
|||
| 38 | ``` |
|||
| 39 | ||||
| 40 | #### Connexion avec une clef privée : |
|||
| 41 | ||||
| 42 | ```bash |
|||
| 43 | ssh -i clef.txt root@host |
|||
| 44 | ``` |
|||
| 45 | ||||
| 46 | #### Générer un id\_rsa.pub à partir d'une clef privée : |
|||
| 47 | ||||
| 48 | ```bash |
|||
| 49 | ssh-keygen -y -f ~/.ssh/clef-privée > ~/.ssh/id_rsa.pub |
|||
| 50 | # output d'une clef privée |
|||
| 51 | ssh-keygen -l -f ~/.ssh/id_rsa |
|||
| 52 | ``` |
|||
| 53 | ||||
| 54 | #### Afficher le contenu d'un certificat .pem X509 : |
|||
| 55 | ||||
| 56 | ```bash |
|||
| 57 | openssl x509 -in <fichier.pem> -noout -text | grep DNS |
|||
| 58 | ``` |
|||
| 59 | ||||
| 60 | #### Vérifier une chaine de certif : |
|||
| 61 | ||||
| 62 | ```bash |
|||
| 63 | openssl verify -CAfile chaine.pem cert.pem |
|||
| 64 | ``` |
|||
| 65 | ||||
| 66 | #### Output d'un certificat SSL : |
|||
| 67 | ||||
| 68 | ```bash |
|||
| 69 | openssl x509 -in cert.pem -text -noout |
|||
| 70 | ``` |
|||
| 71 | ||||
| 72 | #### Générer une mini CA et l'utiliser pour créer des certifs (serveur/client) |
|||
| 73 | ||||
| 74 | ```bash |
|||
| 75 | # CREATION DE LA CA ET SON CERTIF ASSOCIE : |
|||
| 76 | openssl genrsa -out ca-key.pem 4096 |
|||
| 77 | openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem |
|||
| 78 | # dans les réponse de la commande :common name : test-server.home.naoned.net |
|||
| 79 | ||||
| 80 | # CREATION DU CERTIFICAT SERVEUR : |
|||
| 81 | openssl genrsa -out server-key.pem 4096 |
|||
| 82 | openssl req -subj "/CN=test-server.home.naoned.net" -sha256 -new -key server-key.pem -out server.csr |
|||
| 83 | # créer un request CERTIF pour le nom du serveur ainsi que les fonctions d'auth étendue |
|||
| 84 | echo "subjectAltName = DNS:test-server.home.naoned.net,IP:172.16.16.x;IP:127.0.0.1" >>extFile.cnf |
|||
| 85 | echo "extendedKeyUsage = serverAuth" >>extfile.cnf |
|||
| 86 | openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf |
|||
| 87 | # ok le certificat du serveur est créé et validé via la CA ainsi qu'avec l'extension "serverAuth" |
|||
| 88 | # on fait la même chose pour le client qui se connectera |
|||
| 89 | openssl genrsa -out key.pem 4096 |
|||
| 90 | openssl req -subj "/CN=client" -new -key key.pem -out client.csr |
|||
| 91 | echo "extendedKeyUsage = clientAuth" >>extfile-client.cnf |
|||
| 92 | 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 |
|||
| 93 | ``` |
