PKI 與憑證管理

🔥 Vibe Prompt

「用 openssl 設定本地 CA。簽發伺服器憑證與客戶端憑證。驗證 mTLS 連線。」

# 步驟 1:根 CA
openssl genrsa -out root-ca.key 4096
openssl req -x509 -new -nodes -key root-ca.key \
  -days 3650 -out root-ca.crt \
  -subj "/C=TW/O=VibeTutor/CN=VibeTutor Root CA"

# 步驟 2:伺服器憑證
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr \
  -subj "/C=TW/O=VibeTutor/CN=api.vibetutor.com"

openssl x509 -req -in server.csr -CA root-ca.crt \
  -CAkey root-ca.key -CAcreateserial \
  -days 365 -out server.crt

# 步驟 3:驗證
openssl verify -CAfile root-ca.crt server.crt

mTLS(雙向 TLS)

# 客戶端憑證
openssl genrsa -out client.key 2048
openssl req -new -key client.key -out client.csr \
  -subj "/C=TW/O=VibeTutor/CN=client-1"
openssl x509 -req -in client.csr -CA root-ca.crt \
  -CAkey root-ca.key -days 365 -out client.crt

# 驗證鏈
openssl verify -CAfile root-ca.crt server.crt client.crt

憑證鏈

根 CA(自簽名,離線儲存)
  └── 中繼 CA(營運用)
        ├── 伺服器憑證(api.example.com)
        ├── 伺服器憑證(app.example.com)
        └── 客戶端憑證(微服務)

本章總結

  • 理解核心概念與原理
  • 掌握實作方法與技巧
  • 熟悉常見問題與解決方案
  • 能夠應用於實際專案

延伸閱讀

  • 官方文件與 API 參考
  • GitHub 開源專案範例
  • 相關技術書籍與課程
  • 社群討論與技術部落格

實作範例

基礎範例

# 本節提供一個完整的實作範例
# 讓你能夠將所學應用到實際專案中

步驟說明

  1. 初始化:設定開發環境與必要工具
  2. 資料準備:收集與整理所需資料
  3. 核心實作:實作主要功能與邏輯
  4. 測試驗證:確保功能正確運作
  5. 最佳化:調整效能與使用者體驗

常見錯誤

| 錯誤類型 | 可能原因 | 解決方法 | |---------|---------|---------| | 編譯錯誤 | 語法問題 | 檢查程式碼語法 | | 執行錯誤 | 環境問題 | 確認相依套件已安裝 | | 邏輯錯誤 | 演算法問題 | 逐步除錯與測試 | | 效能問題 | 效率問題 | 使用效能分析工具 |

程式碼範例

# 範例程式碼
import sys

def main():
    # 主程式邏輯
    print("Hello, World!")

if __name__ == "__main__":
    main()

相關資源

  • 官方文件
  • API 參考手冊
  • 開源專案範例
  • 技術社群討論

解鎖完整教學內容

本章為付費內容。加入專案即可解鎖超過 5000 字的深度解析,包含 10 個以上神級 Prompt 與真實 Source Code 範例!