RFC 2818 - HTTP sur TLS (HTTPS) - Exemples pratiques (Practical Examples)
Exemples pratiques (Practical Examples)
Connexion HTTPS complète (Complete HTTPS Connection)
Opérations du client :
1. Analyser l'URI : https://www.example.com/page.html
→ Nom d'hôte : www.example.com
→ Port : 443 (par défaut)
2. Connexion TCP à www.example.com:443
3. Négociation TLS :
ClientHello →
← ServerHello + Certificate
Vérifier le nom d'hôte dans le certificat
...négociation terminée...
4. Envoyer une requête HTTP chiffrée :
GET /page.html HTTP/1.1
Host: www.example.com
5. Recevoir une réponse HTTP chiffrée :
HTTP/1.1 200 OK
Content-Length: 1234
...
6. Fermer la connexion :
Envoyer closure_alert
Fermer la connexion TCP
Exemple de vérification de certificat (Certificate Verification Example)
# Exemple Python (conceptuel)
import ssl
import socket
# Créer un contexte SSL
context = ssl.create_default_context()
# Se connecter au serveur
sock = socket.create_connection(('www.example.com', 443))
ssock = context.wrap_socket(sock, server_hostname='www.example.com')
# wrap_socket vérifie automatiquement :
# 1. La chaîne de certificats est valide
# 2. Le nom d'hôte correspond
# 3. Le certificat n'est pas expiré
# Obtenir les informations du certificat
cert = ssock.getpeercert()
print(f"Subject: {cert['subject']}")
print(f"Issuer: {cert['issuer']}")
print(f"SANs: {cert.get('subjectAltName', [])}")
Gestion des erreurs courantes (Common Error Handling)
Erreur 1 : Non-correspondance du nom d'hôte du certificat (Certificate Hostname Mismatch)
- Certificat : *.example.com
- Accès : www.different.com
→ Terminer la connexion ou avertir l'utilisateur
Erreur 2 : Certificat expiré (Certificate Expired)
- Not After : 2023-12-31
- Current : 2024-01-01
→ Refuser la connexion
Erreur 3 : Certificat auto-signé (Self-Signed Certificate)
- Pas dans la liste des CA de confiance
→ Avertir l'utilisateur ou refuser
Erreur 4 : Chaîne de certificats incomplète (Incomplete Certificate Chain)
- Certificat intermédiaire manquant
→ Impossible de vérifier, refuser la connexion