tech:notes_ssl_tls_https_client_openssl
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:notes_ssl_tls_https_client_openssl [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:notes_ssl_tls_https_client_openssl [2026/06/10 12:16] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes SSL/TLS HTTPS client OpenSSL | ||
| + | |||
| + | Voir : | ||
| + | * [[notes_curl_wget]] | ||
| + | * [FeistyDuck - Bulletproof TLS Guide](https:// | ||
| + | * [FeistyDuck - OpenSSL Cookbook - 3rd Edition](https:// | ||
| + | |||
| + | Voir aussi : | ||
| + | * [Exemples de conf HTTPS / SSL / TLS pour plusieurs serveurs (nginx, apache, postfix](https:// | ||
| + | * [[openssl_proxy_http_proxy]] | ||
| + | |||
| + | |||
| + | Vérif cert | ||
| + | ~~~bash | ||
| + | openssl s_client -showcerts -CAfile ca.crt -connect 192.168.56.101: | ||
| + | ~~~ | ||
| + | |||
| + | Avoir des informations sur le certificat (info cert) | ||
| + | ~~~bash | ||
| + | openssl x509 -inform PEM -in mycertfile.pem -text -out certdata | ||
| + | ~~~ | ||
| + | |||
| + | Debug | ||
| + | ~~~bash | ||
| + | curl -v --insecure --show-error --verbose --cacert mycertfile.pem https:// | ||
| + | ~~~ | ||
| + | |||
| + | Install CA certificat - Debian | ||
| + | ~~~bash | ||
| + | mv cert.pem acme.fr.crt | ||
| + | cp acme.fr.crt / | ||
| + | #vim / | ||
| + | # | ||
| + | |||
| + | # RedHat | ||
| + | # update-ca-trust | ||
| + | |||
| + | # Debian | ||
| + | update-ca-certificates | ||
| + | ~~~ | ||
| + | |||
| + | Remove CA certificat - Debian | ||
| + | ~~~bash | ||
| + | rm / | ||
| + | |||
| + | |||
| + | # RedHat | ||
| + | # update-ca-trust | ||
| + | |||
| + | # Debian | ||
| + | # | ||
| + | |||
| + | update-ca-certificates -f | ||
| + | ~~~ | ||
| + | '' | ||
| + | |||
| + | |||
| + | Install CA certificat - RedHat | ||
| + | |||
| + | Voir : | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ~~~bash | ||
| + | cp ca.crt / | ||
| + | |||
| + | # Debian | ||
| + | # update-ca-certificates | ||
| + | |||
| + | # RedHat | ||
| + | update-ca-trust | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | Source : | ||
| + | cat / | ||
| + | |||
| + | Requette HTTP over SSL/TLS | ||
| + | ~~~bash | ||
| + | (echo -ne "GET / HTTP/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Test TLS HTTPS en ligne | ||
| + | |||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | ## Test TLS HTTPS hors ligne | ||
| + | |||
| + | [TestSSL.sh](https:// | ||
| + | |||
| + | ## Python | ||
| + | |||
| + | '' | ||
| + | ~~~python | ||
| + | """ | ||
| + | |||
| + | https:// | ||
| + | https:// | ||
| + | """ | ||
| + | from __future__ import print_function | ||
| + | |||
| + | import socket | ||
| + | import ssl | ||
| + | import sys | ||
| + | |||
| + | try: | ||
| + | from urllib2 import urlopen | ||
| + | except ImportError: | ||
| + | from urllib.request import urlopen | ||
| + | |||
| + | X509_V_FLAG_TRUSTED_FIRST = 0x8000 | ||
| + | URL = " | ||
| + | |||
| + | print(sys.version) | ||
| + | print(ssl.OPENSSL_VERSION) | ||
| + | print() | ||
| + | |||
| + | ctx = ssl.create_default_context() | ||
| + | assert ctx.verify_mode == ssl.CERT_REQUIRED | ||
| + | assert ctx.check_hostname == True | ||
| + | |||
| + | print(" | ||
| + | print(" | ||
| + | try: | ||
| + | urlopen(URL, | ||
| + | except Exception as e: | ||
| + | print(" | ||
| + | print(e) | ||
| + | else: | ||
| + | print(" | ||
| + | print() | ||
| + | |||
| + | print(" | ||
| + | ctx.verify_flags |= X509_V_FLAG_TRUSTED_FIRST | ||
| + | print(" | ||
| + | try: | ||
| + | urlopen(URL, | ||
| + | except Exception as e: | ||
| + | print(" | ||
| + | print(e) | ||
| + | else: | ||
| + | print(" | ||
| + | print() | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Le certificat téléchargé ne fonctionne pas | ||
| + | |||
| + | | | **Curl** | **Wget** | ||
| + | | ---------- | -------- | --------- | | ||
| + | | **Debian** | | ||
| + | | **RedHat** | | ||
| + | |||
| + | source : https:// | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | openssl s_client -showcerts -connect acme.fr:443 -servername acme.fr </ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | **OK** | ||
| + | **NOK** sous RedHat | ||
| + | ~~~bash | ||
| + | wget --ca-certificate=mycertfile.pem https:// | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | **NOK** sous Debian & RedHat | ||
| + | ~~~bash | ||
| + | curl --show-error --verbose --cacert mycertfile.pem https:// | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Utiliser '' | ||
| + | ~~~bash | ||
| + | openssl s_client -showcerts -verify 5 -connect 192.168.56.101: | ||
| + | ~~~ | ||
| + | |||
| + | Puis ne garder que la CA. | ||
| + | Note : si la CA existe, dans le cas d'un certificat auto-signé, | ||
| + | Pour Debian, il est possible d' | ||
| + | ~~~bash | ||
| + | vim mycertfile.pem | ||
| + | ~~~ | ||
| + | |||
| + | Voir https:// | ||
| + | |||
