Web Application Security Fundamentals #09: HTTPS, TLS, & Certificate Security
Memahami HTTPS, TLS handshake, certificate management, HSTS, certificate pinning, dan testing TLS configuration.
HTTPS (HTTP Secure) = HTTP + TLS encryption. Melindungi confidentiality (eavesdropping), integrity (tampering), dan authenticity (impersonation) data in transit.
Tujuan Pembelajaran
- Memahami TLS 1.2 vs 1.3 (handshake, cipher suites)
- Certificate management (self-signed, CA-signed, renewal)
- HSTS (HTTP Strict Transport Security)
- Certificate pinning
- Testing TLS configuration
HTTPS Setup
Self-Signed Certificate (Development)
# Generate private key + certificate
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
# Start HTTPS server
python3 -m http.server 8443 --certificate cert.pem --key key.pem
CA-Signed Certificate (Production)
# Generate Certificate Signing Request (CSR)
openssl req -new -key key.pem -out csr.pem
# Submit to CA (Let's Encrypt, GlobalSign, etc)
# Receive certificate signed by trusted CA
# Configure server:
# nginx config
server {
listen 443 ssl http2;
server_name api.example.com;
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
# TLS 1.2+
ssl_protocols TLSv1.2 TLSv1.3;
# Strong ciphers
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# HSTS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Redirect HTTP to HTTPS
if ($scheme != "https") {
return 301 https://$server_name$request_uri;
}
# ... rest of config
}
Certificate Validation
# ❌ VULNERABLE - No certificate validation
import requests
response = requests.get('https://api.example.com', verify=False)
# ✅ SECURE - Validate certificate
response = requests.get('https://api.example.com', verify=True)
# verify=True (default) checks:
# - Certificate chain validity
# - Hostname match
# - Not expired
HSTS (HTTP Strict Transport Security)
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
max-age=31536000 : 1 year (browser remember)
includeSubDomains : Apply to subdomains too
preload : Include dalam HSTS preload list
Impact:
- Browser automatically upgrade HTTP → HTTPS
- No insecure redirects
- Prevent session cookie theft via network downgrade
Certificate Pinning
Hardcode expected certificate pub key di app. Mencegah MITM via rogue CA:
// iOS certificate pinning
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard let cert = challenge.protectionSpace.serverTrust else {
completionHandler(.cancelAuthenticationChallenge, nil)
return
}
let pubKey = SecCertificateCopyPublicKey(SecTrustGetCertificateAtIndex(cert, 0)!)
let expectedKey = "my-pinned-public-key-base64" // Hardcoded
if publicKeyMatches(pubKey, expectedKey) {
completionHandler(.useCredential, URLCredential(trust: cert))
} else {
completionHandler(.cancelAuthenticationChallenge, nil)
}
}
Testing TLS Configuration
# Check TLS version
curl -I --tlsv1.2 https://api.example.com
# Should work for TLS 1.2+
# Check ciphers
echo | openssl s_client -connect api.example.com:443 2>&1 | grep "Cipher"
# Test for vulnerabilities
nmap --script ssl-enum-ciphers -p 443 api.example.com
# Online tool
https://www.ssllabs.com/ssltest/
Checklist
- [ ] HTTPS untuk all endpoints
- [ ] HTTP redirects to HTTPS
- [ ] Valid certificate (not self-signed in production)
- [ ] HSTS header set (max-age ≥ 31536000)
- [ ] TLS 1.2+ (disable older protocols)
- [ ] Strong cipher suites
- [ ] Certificate renewed before expiry
- [ ] No pinning issues on certificate renewal
Kesimpulan
HTTPS adalah table stakes. Tanpa TLS, semua data di-transmit plaintext → attackers dapat intercept, modify, forge.
Modul berikutnya (#10) membahas Security Headers.
Next: #10 - Security Headers (CSP, X-Frame-Options, etc)
Post Terkait
Malware Analysis Fundamentals #08: Bukti Digital yang Wajib Dikumpulkan Saat Analisis Malware
Checklist lengkap bukti digital yang wajib dikumpulkan saat analisis malware: hash, IOC jaringan (domain, IP, sertifikat...
Malware Analysis Fundamentals #07: Membangun Lab Analisis Malware yang Aman
Panduan membangun lab analisis malware yang aman: isolated VM, snapshot, jaringan host-only/simulasi, mematikan shared c...
Malware Analysis Fundamentals #06: Behavioral & Memory Analysis — Mengamati Perilaku Malware Secara Langsung
Tutorial behavioral & memory analysis malware: mengamati process tree, perubahan file/registry, persistence, trafik C2,...