Certificate Tools
Concept
Public Key and Private Key Pair: How it Works

source: https://comodosslstore.com/blog/public-key-and-private-key-pair-how-it-works.html
Digital Signature and Public Key as Identities

source: https://zhaohuabing.medium.com/digital-signature-and-public-key-as-identities-94f8ecac2a24
Certificates format
- The PEM format is the most common format used for certificates. Extensions used for PEM certificates are
cer,crt, andpem. They are Base64 encoded ASCII files. - The DER format is the binary form of the certificate. DER formatted certificates do not contain the "BEGIN CERTIFICATE/END CERTIFICATE" statements. DER formatted certificates most often use the
.derextension.
Generate P12 Keystore
Example
ใช้ OpenSSL เพื่อสร้าง self-signed ECC SSL Certificate
san.conf
- สร้างคีย์ส่วนตัว (Private Key)
- สร้าง Certificate Signing Request (CSR)
- สร้าง Self-Signed Certificate
Tools
View certificate chain
Certificate chain bundle
การ bundle (หรือรวม) CA certificate กับ intermediate certificate ไว้ในไฟล์เดียวกัน มักทำเพื่อใช้กับเว็บเซิร์ฟเวอร์ (เช่น Apache หรือ Nginx) เพื่อให้สามารถตรวจสอบ certificate chain ได้อย่างถูกต้อง กระบวนการนี้มักจะเรียกว่า "certificate chain bundle" หรือ "full chain."
ในการ bundle CA certificate กับ intermediate certificate สามารถทำได้โดยการต่อเนื้อหาของไฟล์ใบรับรองเหล่านี้เข้าด้วยกันในไฟล์เดียว โดยเริ่มจาก intermediate certificate แล้วตามด้วย CA certificate
ขั้นตอน:
- เตรียมไฟล์
intermediate.crtซึ่งเป็นใบรับรอง intermediate certificate - เตรียมไฟล์
ca.crtซึ่งเป็น CA certificate - ใช้คำสั่ง
catเพื่อรวมไฟล์ทั้งสองเข้าด้วยกัน
ตัวอย่างการรวมไฟล์:
คำอธิบาย:
intermediate.crt: เป็นไฟล์ที่เก็บใบรับรองของ intermediate certificate (หรือใบรับรองของผู้ที่ออกใบรับรองให้โดเมนของคุณ)ca.crt: เป็นใบรับรองของ Root Certificate Authority (CA)- ไฟล์
bundle.crt: ไฟล์ผลลัพธ์ที่ประกอบด้วยทั้ง intermediate และ CA certificate ซึ่งสามารถใช้สำหรับการตั้งค่าเว็บเซิร์ฟเวอร์หรือ application อื่นๆ
หลังจากที่ทำการ bundle แล้ว คุณสามารถนำไฟล์ bundle.crt นี้ไปใช้ในการตั้งค่าเว็บเซิร์ฟเวอร์หรือบริการอื่นๆ ได้เพื่อให้ทำงานร่วมกับ SSL/TLS ได้อย่างถูกต้อง
References
- https://www.misterpki.com/pkcs12/
- How to convert a certificate into the appropriate format
- What are the differences between .pem, .cer and .der?
- PEM, DER, CRT, and CER: X.509 Encodings and Conversions
Notes
อธิบาย concept เรื่อง trust ดังนี้ครับ
client อยากแลกเปลี่ยนข้อมูลกับ server สมมติชื่อ domainA
แต่ client ก็ไม่มีทางรู้ได้ว่าคนที่ตัวเองคุยด้วยอยู่ใช่ตัวจริงไหม หรือโดนดักปลอมระหว่างทาง
client จะเชื่อ public CA เสมอ
ดังนั้นถ้า public CA รับรองว่า server คือ domainA จริง
client ก็จึงจะคุยด้วยต่อ แต่ถ้าไม่ใช่ ก็เลิกคุย
สิ่งที่ใช้ในการรับรองคือ certificate (ใบรับรองพร้อมลายเซ็น)
บนเครื่อง client จะมี (trusted) root cert ของ public CA อยู่
root cert เอาไปตรวจได้ว่า intermediate cert ถูกออกและรับรอง(sign)โดย public CA จริง
แล้ว intermediate เอาไปตรวจต่อว่า server cert ถูก sign โดย intermediate ที่ตรวจสอบแล้วหรือไม่
สรุปแล้วฝั่ง server ต้อง provide intermediate cert & server cert ส่วน private key ไม่ได้ส่งไป แต่ต้องใส่ไว้ใน config ระบบเพื่อเอาไว้ถอดรหัสช่วงแลกkey
ฝั่ง client ไม่ต้องทำอะไร
แต่ถ้า cert ไม่ได้ออกโดย public CA ก็ต้องเอา server cert (กรณี self-signed) หรือ private CA cert(กรณีทำ private CA) ไปใส่ในส่วน trust ของทุกclientที่จะเชื่อมต่อ server