Files
106_105_181_70/ssl_deploy_guide.md
Timmy e747efe9ee docs: 新增 SSL 憑證部署指南
GCA G3 新憑證部署流程,含金鑰配對檢查、fullchain 組合、NPM 部署步驟

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 10:13:58 +08:00

101 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SSL 憑證部署指南 - tpesupporter.tpech.gov.tw
## 前置確認
新憑證GCA G3與舊私鑰HiPKI**不匹配**,需要找到申請 GCA 憑證時產生的私鑰。
### 確認金鑰配對
```bash
# 私鑰 modulus
openssl rsa -in privkey.pem -modulus -noout | md5sum
# 憑證 modulus
openssl x509 -in 952453E16C4AD7E7F6845225F3468EDA.cer -modulus -noout | md5sum
# 兩者 md5 必須一致才是配對的
```
## 部署步驟
### 1. 準備檔案
需要三個檔案:
- `privkey.pem` — 私鑰(申請 GCA 憑證時產生的)
- `952453E16C4AD7E7F6845225F3468EDA.cer` — 伺服器憑證
- `GCA_G3_intermediate.crt` — GCA G3 中繼憑證
### 2. 下載 GCA G3 中繼憑證
```bash
# 政府憑證管理中心 G3 中繼憑證
curl -o GCA_G3_intermediate.crt https://gca.nat.gov.tw/download/GCA_OCA.crt
```
> 如上述連結失效,請至 https://gca.nat.gov.tw 下載「GCA 憑證鏈」
### 3. 組合 fullchain.pem
```bash
# 將伺服器憑證轉為 PEM如果是 DER 格式)
openssl x509 -in 952453E16C4AD7E7F6845225F3468EDA.cer -inform DER -out server.pem 2>/dev/null \
|| cp 952453E16C4AD7E7F6845225F3468EDA.cer server.pem
# 合併成 fullchain順序伺服器憑證 → 中繼憑證)
cat server.pem GCA_G3_intermediate.crt > fullchain.pem
```
### 4. 備份舊憑證
```bash
ssh hospital_web "sudo cp -r /opt/php/data/custom_ssl/npm-1 /opt/php/data/custom_ssl/npm-1.bak.$(date +%Y%m%d)"
```
### 5. 上傳新憑證至伺服器
```bash
# 上傳 fullchain.pem 和 privkey.pem
scp fullchain.pem hospital_web:/tmp/
scp privkey.pem hospital_web:/tmp/
# 替換
ssh hospital_web "sudo cp /tmp/fullchain.pem /opt/php/data/custom_ssl/npm-1/fullchain.pem"
ssh hospital_web "sudo cp /tmp/privkey.pem /opt/php/data/custom_ssl/npm-1/privkey.pem"
# 清理
ssh hospital_web "rm /tmp/fullchain.pem /tmp/privkey.pem"
```
### 6. 重啟 NPM
```bash
ssh hospital_web "cd /opt/php && sudo docker compose restart app"
```
### 7. 驗證
```bash
ssh hospital_web "echo | openssl s_client -connect localhost:443 -servername tpesupporter.tpech.gov.tw 2>/dev/null | openssl x509 -noout -dates -subject -issuer"
```
預期結果:
- issuer 應為「政府憑證管理中心 - G3」
- notAfter 應為 2028-04-01
## 或者:透過 NPM 管理後台上傳
1. SSH 連線 `ssh hospital_web`(會自動建立 port forwarding
2. 瀏覽器開啟 `http://localhost:8181`
3. SSL Certificates → Add SSL Certificate → Custom
4. 貼上 fullchain.pem 內容Certificate
5. 貼上 privkey.pem 內容Certificate Key
6. 儲存後套用至對應的 Proxy Host
## 目前憑證狀態
| 項目 | 舊憑證(目前使用中) | 新憑證(待部署) |
|---|---|---|
| 簽發者 | HiPKI OV TLS CA - G1中華電信 | 政府憑證管理中心 - G3GCA |
| 有效期迄 | 2026-04-23 | 2028-04-01 |
| 私鑰位置 | /opt/php/data/custom_ssl/npm-1/privkey.pem | **待確認** |