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.0 | 1994 | ไม่เคยปล่อยใช้งาน | มีปัญหาด้านการออกแบบร้ายแรง |
| SSL 2.0 | 1995 | เลิกใช้แล้ว | ไม่ปลอดภัยและมีช่องโหว่หลายแบบ |
| SSL 3.0 | 1996 | เลิกใช้แล้ว | ถูกโจมตีได้ เช่น POODLE |
| TLS 1.0 | 1999 | เลิกใช้แล้ว | ไม่เหมาะกับมาตรฐานความปลอดภัยปัจจุบัน |
| TLS 1.1 | 2006 | เลิกใช้แล้ว | ถูกแทนที่ด้วย TLS เวอร์ชันใหม่กว่า |
| TLS 1.2 | 2008 | ยังรองรับ | ยังใช้แพร่หลายเมื่อ config อย่างปลอดภัย |
| TLS 1.3 | 2018 | แนะนำให้ใช้ | 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
| ประเภท | การตรวจสอบ | การใช้งานทั่วไป |
|---|---|---|
| DV | Domain Validation: พิสูจน์ว่าสามารถควบคุม domain ได้ | บล็อก แอป API เว็บไซต์ส่วนตัว และเว็บไซต์ส่วนใหญ่ |
| OV | Organization Validation: ตรวจ domain และข้อมูลองค์กร | บริษัทที่ต้องการให้มีข้อมูลองค์กรใน certificate |
| EV | Extended 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
- เลือก domain name ที่ต้องใช้ HTTPS รวมทั้ง www และ non-www
- สร้างหรือขอ certificate ผ่าน host, CDN หรือ certificate authority
- ยืนยันสิทธิ์ domain ด้วย DNS record, HTTP file หรือ email approval
- ติดตั้ง certificate และ private key บน server หรือ platform
- เปิด redirect จาก HTTP ไป HTTPS และต่ออายุ certificate ก่อนหมดอายุ
SSL/TLS Error ที่พบบ่อย
SSL/TLS error มักหมายถึง browser ไม่สามารถตรวจ certificate ได้อย่างปลอดภัย หรือสร้าง secure connection ไม่สำเร็จ
| Error | สาเหตุที่พบบ่อย | วิธีแก้ |
|---|---|---|
| Certificate expired | certificate หมดอายุแล้ว | ต่ออายุและติดตั้ง certificate ใหม่ |
| Name mismatch | certificate ไม่มี hostname ที่ผู้ใช้เปิด | ออก certificate ใหม่ให้มี SAN name ถูกต้อง |
| Untrusted issuer | certificate chain ไม่เชื่อมไปยัง root ที่เชื่อถือได้ | ติดตั้ง intermediate certificate หรือใช้ CA ที่เชื่อถือได้ |
| Mixed content | หน้า HTTPS โหลดรูป script หรือ CSS ผ่าน HTTP | เปลี่ยน resource ให้เป็น HTTPS |
| Old TLS version | server รองรับเฉพาะ 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