為什麼 openssl pkcs12 匯出添加額外的根錨點證書,在 Mac OS X 上複製伺服器證書

為什麼 openssl pkcs12 匯出添加額外的根錨點證書,在 Mac OS X 上複製伺服器證書

[起初發佈在 Slack Overflow 上,但評論區抱怨場地不合適。

我們正在努力從 StartCom SSL 憑證切換到 Let's Encrypt,並嘗試將其設定為自動與 macOS 伺服器 + Apache HTTPD 配合使用。從命令列工具 ( security import) 中,macOS 伺服器不接受直接.pem文件 - 您必須給它一個.p12文件,它會從中提取.pem文件以在 Apache 中進行配置。令人煩惱且毫無意義,但這是我們現在必須忍受的。

為了創建這個.p12文件,我們必須執行這個命令:

openssl pkcs12 -export \
-inkey /etc/letsencrypt/live/example.com/privkey.pem \
-in /etc/letsencrypt/live/example.com/cert.pem \
-certfile /etc/letsencrypt/live/example.com/chain.pem \
-out /etc/letsencrypt/live/example.com/example.com.p12

這就是事情變得奇怪的地方。輸出example.com.p12文件有example.com證書兩次,然後是 Let's Encrypt 中間 CA 證書,然後是不必要的自簽名 DST Root CA X3 錨證書(所有瀏覽器都預設安裝了該證書),最後是私鑰。結果是 Apache SSL 握手包含兩次伺服器憑證、中間 CA 憑證和根憑證(不應發送),這會導致 Qualys SSL Labs 測試器發出警告。

我們查看了裡面cert.pem,它只包含伺服器憑證(並且只包含一次)。chain.pem僅包含中間 CA 憑證(不是根錨點或伺服器憑證)。privkey.pem僅包含私鑰。openssl pkcs12 -export複製伺服器證書,然後執行查找根錨點證書並添加它的額外步驟也是如此。

如果我們在 openSUSE Linux 上執行相同的命令,輸出.p12檔案僅包含伺服器憑證(一次)、中間 CA 憑證和私鑰。無根錨。

我們嘗試了以下變體,但沒有發現輸出有任何差異:

openssl pkcs12 -export \
-inkey /etc/letsencrypt/live/example.com/privkey.pem \
-in /etc/letsencrypt/live/example.com/fullchain.pem \
-out /etc/letsencrypt/live/example.com/example.com.p12

openssl pkcs12 -export \
-inkey /etc/letsencrypt/live/example.com/privkey.pem \
-certfile /etc/letsencrypt/live/example.com/fullchain.pem \
-out /etc/letsencrypt/live/example.com/example.com.p12

我可以在 Linux 電腦上複製不正確的雙倍伺服器憑證行為的唯一方法是執行以下操作(但它仍然不包括根錨點):

openssl pkcs12 -export \
-inkey /etc/letsencrypt/live/example.com/privkey.pem \
-in /etc/letsencrypt/live/example.com/cert.pem \
-certfile /etc/letsencrypt/live/example.com/fullchain.pem \
-out /etc/letsencrypt/live/example.com/example.com.p12

(請注意,使用fullchain.pem代替而不是chain.pem與 ... 一起使用cert.pem,這完全有道理為什麼伺服器憑證會被重複,但這不是我們在 Mac OS X 上使用的命令。)

知道如何openssl pkcs12 -export在這裡做正確的事嗎?

相關內容