同事分享的案例,使用 openssl pkcs12 -export -out server.pfx -inkey server.key -in server.cer -certfile ca.cer 匯出 .pfx 檔,過程需要設定密碼(且需輸入兩次確認沒打錯字),但檔案拿到 Windows 要匯入時,密碼百敲不過,一直被抱怨密碼不正確。因有反覆重做三次,已排除手滑敲錯密碼的可能。(註:暫不考慮靈異事件或超自然現象)
【延伸閱讀】如何在收到 PFX 或 CER 憑證檔之後使用 OpenSSL 進行常見的格式轉換 by 保哥


(示意圖)

幸好這已算 FAQ,很快查到解法,指令加上 -certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES -nomac 參數改成 openssl pkcs12 -export -certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES -nomac -out server.pfx -inkey server.key -in server.cer -certfile ca.cer 後藥到病除。

整理茶包原委跟背景知識:

  1. 問題主要發生在 OpenSSL 3 + Windows 2012R2/Windows 2016 組合 (討論指出 OpenSSL 早期版本無此問題)
  2. PKCS12 產生 .pfx 時會使用 PBE (Password Based Encryption) 加密私鑰跟憑證,PBE 演算法有多種選擇
  3. openssl 預設使用 AES-256-CBC with PBKDF2 作為 PBE 演算法 參考
    檢查方式:openssl pkcs12 -noout -info -in some.pfx 參考
  4. Windows 2012R2/Windows 2016 不支援 .pfx 的 AES256-SHA256 演算法 參考
  5. 解法是使用 openssl 參數 -certpbe-keypbe 指定老 Windows 支援的加密演算法,另外有個 -legacy 參數會改用 RC2_CBC 或 3DES_CBC 應該也能解決問題。參考

This article discusses the common issue of a password error prompt when importing .pfx files exported using OpenSSL into Windows systems. By specifying certain encryption algorithm parameters, the problem can be addressed.


Comments

# by asd

sdasd

# by 樂透無名

筆記...

# by Dark

茶包到底是什麼意思? 網路上一查發現都是指男性的OO囊...

# by Jeffrey

to Dark, 是從 Trouble-Shooter 茶包射手來的,Trouble 翻成茶包源自一部老電影,可以試試關鍵字「秋天童話 茶包」

Post a comment