Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

TLS (Transport Layer Security) คืออะไร? ทำงานอย่างไร? และทำไมจึงสำคัญ

TLS (Transport Layer Security) คืออะไร?

TLS เป็นโปรโตคอลเข้ารหัสมาตรฐานสากล สำหรับ รักษาความปลอดภัยการสื่อสารผ่านอินเทอร์เน็ต เป็นผู้ kế thừaของ SSL (Secure Sockets Layer) ที่ Netscape พัฒนา (SSL 3.0 ปี 1996 → TLS 1.0 ปี 1999)

เป้าหมายหลัก 3 ประการ:

  1. Encryption (การเข้ารหัส): ข้อมูลถูกเข้ารหัส ไม่ให้ผู้ดักฟัง (Eavesdropper) อ่านเข้าใจ
  2. Authentication (การยืนยันตัวตน): ยืนยันว่า Server (และ Client บางกรณี) เป็นผู้ที่แท้จริง ผ่าน Digital Certificate
  3. Integrity (ความสมบูรณ์): ข้อมูลไม่ถูกแก้ไข/เสียหายระหว่างการส่ง (Message Authentication Code - MAC)

TLS ทำงานอย่างไร? (TLS Handshake แบบง่าย)

  1. Client Hello: Client ส่ง Supported Cipher Suites, TLS Version, Random Bytes, Extensions (SNI, ALPN)
  2. Server Hello: Server เลือก Cipher Suite, TLS Version, ส่ง Random Bytes, Certificate (Public Key + CA Signature)
  3. Certificate Verification: Client ตรวจ Certificate: ไม่หมดอายุ, Chain of Trust ถูกต้อง (Root CA ที่เชื่อถือ), Domain ตรง (SAN), ไม่ถูก Revoke (CRL/OCSP)
  4. Key Exchange: Client สร้าง Pre-Master Secret เข้ารหัสด้วย Public Key ของ Server ส่งไป (RSA) หรือทำ Key Exchange (ECDHE) ร่วมกัน
  5. Session Keys Derivation: ทั้งคู่สร้าง Symmetric Session Keys (Encryption Key + MAC Key) จาก Pre-Master Secret + Random Bytes
  6. Finished: ทั้งคู่ส่ง Encrypted "Finished" Message ยืนยัน Handshake สำเร็จ
  7. Application Data: สื่อสารด้วย Symmetric Encryption (AES-GCM, ChaCha20-Poly1305) เร็วและปลอดภัย

TLS Versions: ควรใช้อะไร?

VersionYearสถานะหมายเหตุ
SSL 2.01995🚫 Deprecated/Insecureช่องโหว่ร้ายแรง (DROWN, POODLE)
SSL 3.01996🚫 Deprecated/InsecurePOODLE Attack
TLS 1.01999🚫 DeprecatedBEAST, POODLE - PCI DSS ห้ามใช้
TLS 1.12006🚫 Deprecatedไม่มี AEAD, ช่องโหว่คล้าย 1.0
TLS 1.22008✅ Standard ปัจจุบันรองรับ AEAD (AES-GCM, ChaCha20-Poly1305), ยังใช้กันทั่วไป
TLS 1.32018🌟 แนะนำให้ใช้เร็วกว่า (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

  1. ✅ ใช้ TLS 1.3 (ปิด 1.0, 1.1, 1.2 ถ้า Client รองรับหมด)
  2. ✅ ใช้ ECDHE (Forward Secrecy) + AEAD Ciphers
  3. ✅ HSTS (Strict Transport Security) Header: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  4. ✅ OCSP Stapling ลด Latency/Privacy Issue
  5. ✅ Certificate Transparency (CT) Logs ตรวจสอบ Cert ที่ออกผิดกฎ
  6. ✅ Automate Renewal (ACME) อย่า Renew เองด้วยมือ
  7. ✅ ทดสอบด้วย SSL Labs Test (เป้าหมาย Grade A+)

สรุป

TLS เป็นรากฐานของความเชื่อมั่นบนอินเทอร์เน็ต ทุกคนใช้ทุกวัน (HTTPS, Email, VPN) การเข้าใจ Handshake, Versions, Ciphers, Certificates และ Best Practices จำเป็นสำหรับ Developer, SysAdmin, Security Engineer ทุกคน ย้ายไป TLS 1.3 ให้หมดแล้ว