การออกกใบรับรอง Digital Certificate จะออกโดย Certificate Authority (CA) ซึ่งเป็นหน่วยงานกลางที่ได้รับความน่าเชื่อถือ เช่น GlobalSign, DigiCert, GoDaddy, Let’s Encrypt หรือถ้าหน่วยงานที่มี Certificate Server ภายในไว้ออก digital certificate โดยมี Certificate Server เช่น Microsoft Certificate Services (Windows Server), Hashicorp Vault เป็นต้น
รูปแบบของ Certificate จะแบ่งเป็นลำดับชั้น (Chain) ดังนี้
Root CA├── Intermediate CA 1 (signed by Root CA)│ ├── End-entity certificate (signed by Intermediate CA 1)│ └── End-entity certificate (signed by Intermediate CA 1)└── Intermediate CA 2 (signed by Root CA) └── End-entity certificate (signed by Intermediate CA 2)
Root CA เป็น Top-level ของ Certificate hierarchy สำหรับ Public Key Infrastructure (PKI) มีความน่าเชื่อถือสูง และมักถูกเก็บไว้แบบ offline เพื่อความปลอดภัย เช่น trust store ของเบราว์เซอร์ต่างๆ และใช้เพื่อออก intermediate certificate หรือใบรับรองอื่นๆ
Intermediate CA เป็น CA ที่อยู่ระหว่าง root และ end-entity certificate ซึ่งใช้ในการออก certificate ให้กลับผู้ร้องขอของระบบย่อยลงไป หรือผู้ใช้งาน (end-entity certificate) เช่นเว็บไซต์ อีเมลล์ ช่วยลดความเสี่ยงในการถูกโจมตี เพราะหาก intermediate certificate ถูกโจมตี จะสามารถเพิกถอนได้ง่ายกว่า Root Certificate
Root Certificate จึงเป็นรากฐานของความน่าเชื่อถือในระบบ PKI (public key infrastructure) ในขณะที่ Intermediate Certificate ทำหน้าที่เป็นสะพานเชื่อระหว่าง Root Certificate และใบรับรองอื่นๆ ที่ใช้งานจริง
ขั้นตอนสร้าง Self-Sign ฉertificate จาการสร้าง CA เองมีขั้นตอนดังนี้
สร้าง CA key
openssl genrsa -out ca.key 4096
สร้าง CA Certificate จาก CA key ที่สร้างก่อนหน้า
openssl req -x509 -new -nodes -sha512 -days 3650 \-subj "/C=TH/ST=TH/L=BK/O=IT/OU=IT/CN=Corp-Internal-CA Root CA" \-key ca.key \-out ca.crt
สร้าง Server key หรือใบรับรองของผู้ร้องขอ Digital Certificate (end-entity certificate)
openssl genrsa -out app.key 4096
ทำการสร้าง CSR (Certificate Signing Requests) เพื่อส่งให้กับ CA ทำการ sign หรือออก Digital Certificate ให้
openssl req -sha512 -new \-subj "/C=TH/ST=TH/L=BK/O=IT/OU=IT/CN=*.app.corp.com" \-key app.key \-out app.csr
กระบวนการออก certificate ของ CA จะสร้างส่วนของ SAN เพื่อที่จะมีข้อมูลของ server เช่น server fqdn หรือ ip ในการระบุตัวตนที่ออกโดย CA
[~/repos/lab/test-secret] cat v3.extauthorityKeyIdentifier=keyid,issuerbasicConstraints=CA:FALSEkeyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEnciphermentextendedKeyUsage = serverAuthsubjectAltName = @alt_names[alt_names]DNS.0=app.corp.comDNS.0=*.app.corp.comIP.0=10.38.16.141
CA ทำการออก Digital Certificate โดยการ sign ด้วย Certificate ของ CA จาก Certificate Signing Request (CSR) ของผู้ร้องขอ Digital Certificate
openssl x509 -req -sha512 -days 3650 \-extfile v3.ext \-CA ca.crt -CAkey ca.key -CAcreateserial \-in app.csr \-out app.crtCertificate request self-signature oksubject=C=TH, ST=TH, L=BK, O=IT, OU=IT, CN=*.app.corp.com
จากนั้น CA จะส่ง Certificate ที่สร้างขึ้นส่งกลับไปยังผู้ร้องขอ ซึ่งก็คือ app.crt ตามตัวอย่างเพื่อใช้งานต่อไป เช่นไปใช้กับ kubernetes Ingress หรือ Application Server เป็นต้น
