|อ่าน 13 นาที

SSL/TLS คืออะไร? HTTPS, Encryption และ Certificate ทำงานอย่างไร

SSL/TLS คือชั้นความปลอดภัยเบื้องหลัง HTTPS ทำหน้าที่เข้ารหัสข้อมูลระหว่าง browser กับเว็บไซต์ ตรวจสอบตัวตนของ server และปกป้องข้อมูลอย่างรหัสผ่าน cookie ฟอร์ม และข้อมูลชำระเงินไม่ให้ถูกอ่านหรือแก้ไขระหว่างทาง

SSL/TLS คืออะไร?

SSL ย่อมาจาก Secure Sockets Layer ส่วน TLS ย่อมาจาก Transport Layer Security ปัจจุบัน TLS คือ protocol ที่ใช้งานจริง แต่หลายคนยังเรียกว่า SSL certificate ตามความคุ้นเคย

เมื่อเว็บไซต์ใช้ TLS URL จะขึ้นต้นด้วย https:// และ browser อาจแสดงไอคอนแม่กุญแจหรือตัวบ่งชี้ความปลอดภัยตามรูปแบบของแต่ละ browser

TLS ปกป้องการเชื่อมต่อ ไม่ได้การันตีว่าเนื้อหาหรือธุรกิจนั้นปลอดภัยเสมอ เว็บไซต์อันตรายก็อาจใช้ HTTPS ได้ ดังนั้นแม่กุญแจหมายถึง connection ถูกเข้ารหัสและ certificate ตรงกับ domain ไม่ใช่การรับรองว่าเว็บไซต์น่าเชื่อถือทุกอย่าง

SSL/TLS provides:

1. Encryption
   Data is scrambled so eavesdroppers cannot read it.

2. Authentication
   The certificate helps prove the server is the real site.

3. Integrity
   The connection can detect tampering during transit.

Without HTTPS:
  Browser -> "password123" -> Wi-Fi -> ISP -> Website
  Anyone on the path may be able to read or alter traffic.

With HTTPS:
  Browser -> encrypted TLS data -> Wi-Fi -> ISP -> Website
  Interceptors see unreadable encrypted traffic.

SSL กับ TLS ต่างกันอย่างไร?

SSL และ TLS มักถูกใช้แทนกัน แต่ในทางเทคนิค SSL เลิกใช้แล้ว ส่วน TLS คือ protocol ที่ browser และ server สมัยใหม่ใช้จริง

Protocolปีสถานะหมายเหตุ
SSL 1.01994ไม่เคยปล่อยใช้งานมีปัญหาด้านการออกแบบร้ายแรง
SSL 2.01995เลิกใช้แล้วไม่ปลอดภัยและมีช่องโหว่หลายแบบ
SSL 3.01996เลิกใช้แล้วถูกโจมตีได้ เช่น POODLE
TLS 1.01999เลิกใช้แล้วไม่เหมาะกับมาตรฐานความปลอดภัยปัจจุบัน
TLS 1.12006เลิกใช้แล้วถูกแทนที่ด้วย TLS เวอร์ชันใหม่กว่า
TLS 1.22008ยังรองรับยังใช้แพร่หลายเมื่อ config อย่างปลอดภัย
TLS 1.32018แนะนำให้ใช้handshake เร็วขึ้นและค่าเริ่มต้นปลอดภัยกว่า

HTTPS ทำงานอย่างไร

HTTPS คือ HTTP ที่ทำงานอยู่ภายใน TLS browser ยังส่ง HTTP request ตามปกติ แต่ request เหล่านั้นจะถูกเข้ารหัสก่อนออกจากอุปกรณ์ของคุณ

อธิบาย TLS Handshake

ก่อนเริ่มส่งข้อมูลเว็บแบบเข้ารหัส browser และ server จะทำ handshake เพื่อเลือกค่าความปลอดภัย ตรวจ certificate และสร้าง key สำหรับเข้ารหัสร่วมกัน

Simplified TLS handshake:

1. ClientHello
   Browser sends supported TLS versions, cipher suites, and random data.

2. ServerHello
   Server chooses TLS settings and sends its certificate.

3. Certificate validation
   Browser checks domain name, issuer, chain, signature, and expiration.

4. Key exchange
   Browser and server agree on shared session keys.

5. Finished messages
   Both sides confirm the handshake was not tampered with.

6. Encrypted HTTP
   Normal HTTP requests and responses now travel inside TLS.

SSL Certificate มีอะไรอยู่ข้างใน?

SSL certificate คือเอกสารดิจิทัลที่ผูก domain name เข้ากับ public key และระบุผู้ออก certificate browser ใช้ certificate นี้เพื่อตรวจว่า server มีสิทธิ์แทน domain นั้นจริง

A certificate usually contains:

Subject:        www.example.com
Issuer:         Example Certificate Authority
Valid from:     2026-01-01
Valid until:    2026-04-01
Public key:     RSA or ECDSA public key
SAN entries:    example.com, www.example.com
Signature:      CA signature over the certificate data
Serial number:  Unique identifier from the CA

ประเภท Certificate: DV, OV และ EV

ประเภท certificate ต่างกันหลัก ๆ ที่ระดับการตรวจสอบตัวตนที่ certificate authority ทำก่อนออก certificate

ประเภทการตรวจสอบการใช้งานทั่วไป
DVDomain Validation: พิสูจน์ว่าสามารถควบคุม domain ได้บล็อก แอป API เว็บไซต์ส่วนตัว และเว็บไซต์ส่วนใหญ่
OVOrganization Validation: ตรวจ domain และข้อมูลองค์กรบริษัทที่ต้องการให้มีข้อมูลองค์กรใน certificate
EVExtended Validation: ตรวจข้อมูลองค์กรเข้มงวดกว่าบางเว็บไซต์ด้านการเงิน องค์กร และงาน compliance
Wildcardครอบคลุม subdomain หนึ่งระดับ เช่น *.example.comหลาย subdomain ภายใต้ domain เดียว
SAN / Multi-domainใส่หลายชื่อไว้ใน certificate เดียวหลาย domain หรือ hostname ในบริการเดียว

Certificate Chain of Trust

Browser ไม่ได้เชื่อถือ certificate ของทุกเว็บไซต์โดยตรง แต่เชื่อถือ root certificate authority หาก certificate chain ถูกต้อง จะเชื่อม website certificate กลับไปยัง root ที่ browser เชื่อถือได้

Certificate chain:

Root CA
  -> Intermediate CA
    -> Website certificate

Your browser already trusts many root CAs.
The website sends its certificate and usually the intermediate certificate.
The browser builds a chain back to a trusted root.

วิธีขอ SSL Certificate

เว็บไซต์ส่วนใหญ่ออก certificate ผ่าน hosting provider, CDN, managed platform หรือ certificate authority หลายกรณีใช้ certificate ฟรีและต่ออายุอัตโนมัติได้ เช่น Let’s Encrypt

  1. เลือก domain name ที่ต้องใช้ HTTPS รวมทั้ง www และ non-www
  2. สร้างหรือขอ certificate ผ่าน host, CDN หรือ certificate authority
  3. ยืนยันสิทธิ์ domain ด้วย DNS record, HTTP file หรือ email approval
  4. ติดตั้ง certificate และ private key บน server หรือ platform
  5. เปิด redirect จาก HTTP ไป HTTPS และต่ออายุ certificate ก่อนหมดอายุ

SSL/TLS Error ที่พบบ่อย

SSL/TLS error มักหมายถึง browser ไม่สามารถตรวจ certificate ได้อย่างปลอดภัย หรือสร้าง secure connection ไม่สำเร็จ

Errorสาเหตุที่พบบ่อยวิธีแก้
Certificate expiredcertificate หมดอายุแล้วต่ออายุและติดตั้ง certificate ใหม่
Name mismatchcertificate ไม่มี hostname ที่ผู้ใช้เปิดออก certificate ใหม่ให้มี SAN name ถูกต้อง
Untrusted issuercertificate chain ไม่เชื่อมไปยัง root ที่เชื่อถือได้ติดตั้ง intermediate certificate หรือใช้ CA ที่เชื่อถือได้
Mixed contentหน้า HTTPS โหลดรูป script หรือ CSS ผ่าน HTTPเปลี่ยน resource ให้เป็น HTTPS
Old TLS versionserver รองรับเฉพาะ protocol เก่าเปิด TLS 1.2 และ TLS 1.3
Clock wrongวันเวลาของเครื่องผู้ใช้ผิดแก้ system clock ให้ถูกต้อง

แนวทางปฏิบัติที่ดีสำหรับ SSL/TLS

การมี certificate ที่ถูกต้องเป็นเพียงส่วนหนึ่งของ HTTPS security การตั้งค่าก็สำคัญมากเช่นกัน

แนวทางเหตุผล
ใช้ TLS 1.2 และ TLS 1.3ปิด SSLv2, SSLv3, TLS 1.0 และ TLS 1.1
ต่ออายุอัตโนมัติป้องกันเว็บล่มจาก certificate หมดอายุ
Redirect HTTP ไป HTTPSให้ผู้ใช้อยู่บนหน้าเข้ารหัสเสมอ
เปิด HSTS อย่างระมัดระวังสั่ง browser ให้ใช้ HTTPS กับ domain ของคุณเสมอ
หลีกเลี่ยง mixed contentโหลด script, style, font, image และ API ผ่าน HTTPS
ปกป้อง private keyอย่า commit key ลง source control หรือแชร์โดยไม่จำเป็น

วิธีตรวจ SSL Certificate

การตรวจ certificate ช่วยยืนยันวันหมดอายุ issuer hostname ที่ครอบคลุม ความถูกต้องของ chain และ TLS version ที่รองรับ

Check a certificate from the terminal:

openssl s_client -connect example.com:443 -servername example.com

Show certificate dates:

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null \
  | openssl x509 -noout -dates -issuer -subject

ตรวจ SSL Certificate

ใช้เครื่องมือ SSL Checker ฟรีของเราเพื่อตรวจ validity, issuer, วันหมดอายุ, hostname coverage และปัญหา HTTPS configuration ที่พบบ่อย

เปิด SSL Checker

แหล่งอ้างอิง

  • RFC 8446 - The Transport Layer Security (TLS) Protocol Version 1.3
  • RFC 5246 - The Transport Layer Security (TLS) Protocol Version 1.2
  • CA/Browser Forum Baseline Requirements
  • Mozilla Server Side TLS recommendations
  • Let’s Encrypt documentation
USTHJP