TLS (Transport Layer Security) คืออะไร?
TLS เป็นโปรโตคอลเข้ารหัสมาตรฐานสากล สำหรับ รักษาความปลอดภัยการสื่อสารผ่านอินเทอร์เน็ต เป็นผู้ kế thừaของ SSL (Secure Sockets Layer) ที่ Netscape พัฒนา (SSL 3.0 ปี 1996 → TLS 1.0 ปี 1999)
เป้าหมายหลัก 3 ประการ:
- Encryption (การเข้ารหัส): ข้อมูลถูกเข้ารหัส ไม่ให้ผู้ดักฟัง (Eavesdropper) อ่านเข้าใจ
- Authentication (การยืนยันตัวตน): ยืนยันว่า Server (และ Client บางกรณี) เป็นผู้ที่แท้จริง ผ่าน Digital Certificate
- Integrity (ความสมบูรณ์): ข้อมูลไม่ถูกแก้ไข/เสียหายระหว่างการส่ง (Message Authentication Code - MAC)
TLS ทำงานอย่างไร? (TLS Handshake แบบง่าย)
- Client Hello: Client ส่ง Supported Cipher Suites, TLS Version, Random Bytes, Extensions (SNI, ALPN)
- Server Hello: Server เลือก Cipher Suite, TLS Version, ส่ง Random Bytes, Certificate (Public Key + CA Signature)
- Certificate Verification: Client ตรวจ Certificate: ไม่หมดอายุ, Chain of Trust ถูกต้อง (Root CA ที่เชื่อถือ), Domain ตรง (SAN), ไม่ถูก Revoke (CRL/OCSP)
- Key Exchange: Client สร้าง Pre-Master Secret เข้ารหัสด้วย Public Key ของ Server ส่งไป (RSA) หรือทำ Key Exchange (ECDHE) ร่วมกัน
- Session Keys Derivation: ทั้งคู่สร้าง Symmetric Session Keys (Encryption Key + MAC Key) จาก Pre-Master Secret + Random Bytes
- Finished: ทั้งคู่ส่ง Encrypted "Finished" Message ยืนยัน Handshake สำเร็จ
- Application Data: สื่อสารด้วย Symmetric Encryption (AES-GCM, ChaCha20-Poly1305) เร็วและปลอดภัย
TLS Versions: ควรใช้อะไร?
| Version | Year | สถานะ | หมายเหตุ |
|---|---|---|---|
| SSL 2.0 | 1995 | 🚫 Deprecated/Insecure | ช่องโหว่ร้ายแรง (DROWN, POODLE) |
| SSL 3.0 | 1996 | 🚫 Deprecated/Insecure | POODLE Attack |
| TLS 1.0 | 1999 | 🚫 Deprecated | BEAST, POODLE - PCI DSS ห้ามใช้ |
| TLS 1.1 | 2006 | 🚫 Deprecated | ไม่มี AEAD, ช่องโหว่คล้าย 1.0 |
| TLS 1.2 | 2008 | ✅ Standard ปัจจุบัน | รองรับ AEAD (AES-GCM, ChaCha20-Poly1305), ยังใช้กันทั่วไป |
| TLS 1.3 | 2018 | 🌟 แนะนำให้ใช้ | เร็วกว่า (1-RTT/0-RTT), ตัด Cipher อันตรายออก, Forward Secrecy บังคับ, เรียบง่ายกว่า |
Cipher Suites แนะนำ (TLS 1.2/1.3)
- TLS 1.3 (มาตรฐาน บังคับ AEAD):
TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256 - TLS 1.2 (เลือกเฉพาะ AEAD + Forward Secrecy):
ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384,ECDHE-ECDSA-CHACHA20-POLY1305,ECDHE-RSA-CHACHA20-POLY1305 - 🚫 ห้ามใช้: RC4, DES, 3DES, MD5, SHA1, CBC Mode (Lucky13, BEAST), RSA Key Exchange (No Forward Secrecy), EXPORT, NULL, ANON
TLS ใช้ที่ไหนบ้าง? (Use Cases)
- HTTPS (HTTP over TLS): เว็บไซต์, API, Web Apps - ใช้ Port 443
- Email: SMTP (STARTTLS Port 587/25), IMAPS (993), POP3S (995)
- VPN: OpenVPN, SSTP, WireGuard (Noise Protocol แทน TLS)
- VoIP/SIP: SIPS (TLS for Signaling), SRTP (Media Encryption)
- Messaging: XMPP (STARTTLS), Matrix (HTTPS)
- Database: PostgreSQL (SSL), MySQL (TLS), MongoDB (TLS)
- IoT/MQTT: MQTTS (Port 8883)
- DevOps: Docker Registry, Kubernetes API, Git HTTPS
Certificate (ใบรับรองดิจิทัล) และ PKI
- Public Key Infrastructure (PKI): ระบบจัดการ Certificate
- Certificate Authority (CA): องค์กรออก Certificate (Let's Encrypt, DigiCert, GlobalSign, Google Trust Services, AWS ACM)
- Certificate Chain: Leaf Cert → Intermediate CA → Root CA (Trusted Root Store ใน OS/Browser)
- Validation Levels: DV (Domain Validation - ฟรี/เร็ว), OV (Organization Validation), EV (Extended Validation - แถบสีเขียวเก่า)
- Automation: ACME Protocol (Let's Encrypt, ZeroSSL, Buypass) + Certbot, acme.sh, Caddy, Traefik - อัตโนมัติทุก 60-90 วัน
Best Practices สำหรับ Server Admin
- ✅ ใช้ TLS 1.3 (ปิด 1.0, 1.1, 1.2 ถ้า Client รองรับหมด)
- ✅ ใช้ ECDHE (Forward Secrecy) + AEAD Ciphers
- ✅ HSTS (Strict Transport Security) Header:
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload - ✅ OCSP Stapling ลด Latency/Privacy Issue
- ✅ Certificate Transparency (CT) Logs ตรวจสอบ Cert ที่ออกผิดกฎ
- ✅ Automate Renewal (ACME) อย่า Renew เองด้วยมือ
- ✅ ทดสอบด้วย SSL Labs Test (เป้าหมาย Grade A+)
สรุป
TLS เป็นรากฐานของความเชื่อมั่นบนอินเทอร์เน็ต ทุกคนใช้ทุกวัน (HTTPS, Email, VPN) การเข้าใจ Handshake, Versions, Ciphers, Certificates และ Best Practices จำเป็นสำหรับ Developer, SysAdmin, Security Engineer ทุกคน ย้ายไป TLS 1.3 ให้หมดแล้ว