Back
+15 XP
Concept

SSL/TLS Encryption with the ssl Module

Raw sockets transmit unencrypted cleartext. The standard `ssl` module wraps sockets in TLS/SSL encryption layers, verifying certificates and protecting payloads 🔐.

python
import ssl, socket

context = ssl.create_default_context()
# Encrypts socket and verifies CA certificates:
print(f"TLS Verify Mode: {context.verify_mode == ssl.CERT_REQUIRED} 🔐")
print(f"Check hostname: {context.check_hostname} 🛡️")

# 78. SSL/TLS Encryption with the ssl Module Raw sockets transmit unencrypted cleartext. The standard `ssl` module wraps sockets in TLS/SSL encryption layers, verifying certificates and protecting payloads 🔐. ```python import ssl, socket context = ssl.create_default_context() # Encrypts socket and verifies CA certificates: print(f"TLS Verify Mode: {context.verify_mode == ssl.CERT_REQUIRED} 🔐") print(f"Check hostname: {context.check_hostname} 🛡️") ``` `ssl.create_default_context()` automatically loads system trusted CA root certificates and enforces modern secure cipher suites! 🔐 --- ### Question What does `ssl.create_default_context()` configure by default for security? 🧠 - [ ] a. Enforces certificate validation and hostname checking with secure TLS defaults 🔐 - [ ] b. Disables all encryption for faster streaming - [ ] c. Allows self-signed certificates without verification - [ ] d. Permits deprecated SSLv2 protocol handshakes --- ### Challenge Import `ssl`. Create `ctx = ssl.create_default_context()`. Print whether `ctx.check_hostname` is `True`. 🎯 <details> <summary>Solution</summary> ```python import ssl ctx = ssl.create_default_context() print(ctx.check_hostname) ``` </details>

Checkpoint

What does `ssl.create_default_context()` configure by default for security? 🧠

Practice

Import `ssl`. Create `ctx = ssl.create_default_context()`. Print whether `ctx.check_hostname` is `True`. 🎯

Terminal
01
Tap code blocks below to assemble
Available Blocks