6.03 TLS Basics (certificate based authentication)
1οΈβ£ Why TLS Exists
Without encryption:
- Credentials are sent in plain text
- Attackers can sniff traffic
- Sensitive data is exposed
Danger
Sending passwords over plain HTTP is insecure.
Always use HTTPS (TLS) for production systems.
TLS ensures:
- π Encryption (confidentiality)
- β Server identity verification
- π‘ Protection against man-in-the-middle attacks
2οΈβ£ Encryption Basics
πΉ Symmetric Encryption
- One shared key
- Same key encrypts and decrypts
- Fast and efficient
Problem: - Key must be shared securely - If intercepted β communication compromised
Warning
Symmetric encryption alone is not enough for secure internet communication.
πΉ Asymmetric Encryption (Public/Private Keys)
Uses a key pair:
- π Private Key (kept secret)
- π Public Key (shared openly)
Key Principle:
- Data encrypted with one key can only be decrypted with the other.
- You cannot encrypt and decrypt with the same key.
Note
If you encrypt with the public key β only the private key can decrypt.
If you encrypt with the private key β anyone with the public key can decrypt.
3οΈβ£ SSH Key Authentication (Asymmetric in Action)
Used for secure server access.
Key Generation
Generates:
| File | Purpose |
|---|---|
id_rsa |
Private Key (keep secret) |
id_rsa.pub |
Public Key |
Public key is added to:
Success
You can copy the same public key to multiple servers and use one private key to access all securely.
SSH Production Best Practices
β DO
Success
- Disable password authentication
- Use 4096-bit RSA or Ed25519 keys
- Protect private keys with passphrases
- Restrict SSH by IP if possible
- Rotate keys periodically
β DON'T
Danger
- Do NOT share private keys
- Do NOT store private keys in Git
- Do NOT use weak key sizes
- Do NOT allow root login over SSH
4οΈβ£ TLS Handshake (How HTTPS Works)
TLS combines both encryption types.
Step-by-Step Flow
- Client connects via HTTPS
- Server sends its certificate (contains public key)
- Client validates certificate
- Client generates symmetric key
- Client encrypts symmetric key using server's public key
- Server decrypts using private key
- Communication continues using symmetric encryption
Success
Asymmetric encryption secures key exchange.
Symmetric encryption secures ongoing communication.
5οΈβ£ What Is a Certificate?
A certificate contains:
- Server identity (CN / SAN)
- Public key
- Issuer (CA)
- Expiry date
- Digital signature
Common extensions:
| Type | Example |
|---|---|
| Certificate (Public Key) | .crt, .pem |
| Private Key | .key, *-key.pem |
Tip
If filename contains "key", it is usually a private key.
6οΈβ£ Self-Signed vs CA-Signed Certificates
πΉ Self-Signed
- Signed by itself
- Not trusted by browsers
- Used for labs/internal testing
Warning
Never use self-signed certificates for public production websites.
πΉ CA-Signed Certificate
Signed by trusted Certificate Authority.
Browsers trust these CAs because:
- CA public keys are built into browsers
- CA signs server certificate with its private key
- Browser verifies signature using CA public key
7οΈβ£ Certificate Signing Process
Step 1: Generate Private Key
Step 2: Generate CSR
Step 3: CA Signs Certificate
- CA validates domain ownership
- Signs certificate
- Sends back signed certificate
Success
The signed certificate proves your server identity.
8οΈβ£ Man-in-the-Middle Protection
Without CA validation:
- User connects securely to attacker
- Communication encrypted β but wrong server
With CA validation:
- Browser checks certificate issuer
- Invalid signature β browser warning
Danger
TLS without certificate validation does NOT guarantee identity.
9οΈβ£ Mutual TLS (mTLS)
Server validates client certificate.
Used in:
- Kubernetes API authentication
- Service mesh (Istio, Linkerd)
- Zero-trust architectures
Tip
mTLS provides identity verification on both sides.
π Production Best Practices
β DO
Success
- Always use HTTPS
- Use 2048-bit+ RSA or ECDSA
- Use trusted CA
- Enable HSTS
- Use strong cipher suites
- Rotate certificates before expiry
- Protect private keys with strict file permissions (600)
- Use automated renewal (cert-manager, Let's Encrypt)
β DON'T
Danger
- Do NOT expose private keys
- Do NOT disable certificate validation
- Do NOT use expired certificates
- Do NOT use weak TLS versions (TLS 1.0/1.1)
- Do NOT hardcode private keys in containers
- Do NOT commit certificates to Git
π― Summary
- Asymmetric encryption secures key exchange
- Symmetric encryption secures data transfer
- Certificates prove server identity
- Certificate Authorities establish trust
- TLS protects against eavesdropping and impersonation
Quote
Encryption protects data.
Certificates protect identity.
Proper key management protects everything.