
我一直在嘗試在 ubuntu 上使用新的 ssl 憑證來設定我的 dovecot imap 伺服器(版本 1.0.10 - 在此階段無法升級),如下所示:
$ grep ^ssl /etc/dovecot/dovecot.conf
ssl_disable = no
ssl_cert_file = /etc/ssl/certs/mydomain.com.crt.20120904
ssl_key_file = /etc/ssl/private/mydomain.com.key.20120904
$ /etc/init.t/dovecot stop
$ sudo dovecot -p
$ [i enter the ssl password here]
它沒有顯示任何錯誤,當我運行時ps aux | grep dovecot
我得到
root 21368 0.0 0.0 12452 688 ? Ss 15:19 0:00 dovecot -p
root 21369 0.0 0.0 71772 2940 ? S 15:19 0:00 dovecot-auth
dovecot 21370 0.0 0.0 14140 1904 ? S 15:19 0:00 pop3-login
dovecot 21371 0.0 0.0 14140 1900 ? S 15:19 0:00 pop3-login
dovecot 21372 0.0 0.0 14140 1904 ? S 15:19 0:00 pop3-login
dovecot 21381 0.0 0.0 14280 2140 ? S 15:19 0:00 imap-login
dovecot 21497 0.0 0.0 14280 2116 ? S 15:29 0:00 imap-login
dovecot 21791 0.0 0.0 14148 1908 ? S 15:48 0:00 imap-login
dovecot 21835 0.0 0.0 14148 1908 ? S 15:53 0:00 imap-login
dovecot 21931 0.0 0.0 14148 1904 ? S 16:00 0:00 imap-login
me 21953 0.0 0.0 5168 944 pts/0 S+ 16:02 0:00 grep --color=auto dovecot
看起來一切都運作良好。然後我測試一下是否可以遠端登入 dovecot 伺服器,這運作正常:
$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK Dovecot ready.
但是當我測試 dovecot 是否正確配置了 ssl 憑證時,它似乎失敗了:
$ sudo openssl s_client -connect localhost:143 -starttls imap
CONNECTED(00000003)
depth=0 /description=xxxxxxxxxxxxxxxxx/C=AU/ST=xxxxxxxx/L=xxxx/O=xxxxxx/CN=*.mydomain.com/[email protected]
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /description=xxxxxxxxxxx/C=AU/ST=xxxxxx/L=xxxx/O=xxxx/CN=*.mydomain.com/[email protected]
verify error:num=27:certificate not trusted
verify return:1
depth=0 /description=xxxxxxxx/C=AU/ST=xxxxxxxxxx/L=xxxx/O=xxxxx/CN=*.mydomain.com/[email protected]
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
0 s:/description=xxxxxxxxxxxx/C=AU/ST=xxxxxxxxxx/L=xxxxxxxx/O=xxxxxxx/CN=*.mydomain.com/[email protected]
i:/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Class 2 Primary Intermediate Server CA
---
Server certificate
-----BEGIN CERTIFICATE-----
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx
.
.
.
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx==
-----END CERTIFICATE-----
subject=/description=xxxxxxxxxx/C=AU/ST=xxxxxxxxx/L=xxxxxxx/O=xxxxxx/CN=*.mydomain.com/[email protected]
issuer=/C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Class 2 Primary Intermediate Server CA
---
No client certificate CA names sent
---
SSL handshake has read 2831 bytes and written 342 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 2048 bit
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : DHE-RSA-AES256-SHA
Session-ID: xxxxxxxxxxxxxxxxxxxx
Session-ID-ctx:
Master-Key: xxxxxxxxxxxxxxxxxx
Key-Arg : None
Start Time: 1351661960
Timeout : 300 (sec)
Verify return code: 21 (unable to verify the first certificate)
---
. OK Capability completed.
至少,我假設這是一個失敗?
答案1
問題出在 openssl 上,而不是 dovecot 上。
有一個錯誤-CApath
在 openssl 中,它會阻止它尋找預設 CApath,因此您需要透過新增到命令列來告訴它在哪裡可以找到根 CA 憑證清單。例如:
sudo openssl s_client -connect localhost:143 -starttls imap -CApath /dev/null
如果您尚未填充 certs 資料夾並且您精通計算機,請按照本教程從 Mozilla 下載 certdata.txt 並產生必要的 PEM 檔案和符號連結。如果您無權存取 /bin,則可能需要修改腳本,並且需要建立符號連結 ln -s ca-bundle.crt cert.pem。
(指定 /dev/null 強制 openssl 使用 openssl 目錄中 cert.pem 的預設路徑。要尋找 openssl 目錄所在的位置,請鍵入openssl version -d
)。
由於您使用的是 StartSSL,因此您可能需要連接您的憑證及其 dovecot 的中間證書,在您的情況下為 StartCom Class 2 主中間伺服器 CA。他們的免費憑證使用 StartCom Class 1 Primary Intermediate Server CA
答案2
您可以verbose_ssl = yes
在 dovecot 配置中使用來產生額外的日誌輸出。
在我的設定(dovecot 2.0)中,我使用以下語句:
ssl_cert = </etc/ssl/certs/mydomain.com.crt.20120904
ssl_key = </etc/ssl/private/mydomain.com.key.20120904
答案3
舊問題 - 新問題(這次讓我們加密證書):
“驗證回傳碼:21(無法驗證第一個憑證)“
(表示未找到/用於驗證中間憑證(鏈))
這是我在過去 24 小時內經過多次嘗試和錯誤後找到的解決方案。
首先讓我介紹一下我用於測試的內容:我在另一台電子郵件伺服器(Ubuntu 18.xx)上有 Dovecot,並且除了使用的網域/憑證之外,
它具有相同的 Dovecot設定。local.conf
兩者都使用 Letscrypt 證書,並且昨天都更新了。
Ubuntu 18 上的 Dovecot(版本 2.2.33.2)運作良好。
使用時沒有錯誤代碼openssl s_client測試電子郵件連接埠:993/IMAP 或:995/POP。
但是,在另一台機器(顯示錯誤的機器)上我使用:
作業系統:Ubuntu 20.04.2
Dovecot(Ubuntu 預設/儲存庫版本):2.3.7.2 (3c910f64b)
OpenSSL(Ubuntu 預設/儲存庫版本):1.1.1f 31 Mar 2020
在一位客戶抱怨將電子郵件帳戶新增至 Android 手機(Google/Gmail 預設電子郵件應用程式)後,我注意到了這個錯誤:
“證書不可信。”
如果我使用 web 或 smtp 的證書,openssl 測試可以正常工作並進行驗證。
這讓我相信問題出在 Ubuntu 20 的 Dovecot 上。
Thunderbird 和 Outlook 等其他電子郵件用戶端也可以正常運作。
我立即決定使用“openssl s_client”進行測試,錯誤最終將我帶到了這裡。
我的配置在損壞的和工作的 dovecot 機器上都是這樣的:
ssl_ca = </etc/letsencrypt/live/{CertName}/fullchain.pem
ssl_cert = </etc/letsencrypt/live/{CertName}/cert.pem
ssl_key = </etc/letsencrypt/live/{CertName}/privkey.pem
我還沒有確定是什麼軟體導致了錯誤,但我已經清除了錯誤。 Android 手機現在完全信任該憑證。進去後我知道這個錯誤可能是缺乏憑證鏈/CA的驗證所造成的。
解決方案/TL;DR:
使用全鏈.pem作為您的證書條目 ( ssl_cert =
)。它包含您的 LE 憑證和鏈。
您的 SSL Dovecot 配置應如下所示(顯然,將 {CertName} 替換為您自己的):
ssl_ca = </etc/letsencrypt/live/{CertName}/chain.pem (or 'fullchain' should work)
ssl_cert = </etc/letsencrypt/live/{CertName}/fullchain.pem
ssl_key = </etc/letsencrypt/live/{CertName}/privkey.pem
在測試過程中您不應該再看到錯誤:
Verify return code: 0 (ok)
我不需要在沒有顯示錯誤的機器上更改任何內容(Ubuntu 18) - 所以我沒有。
更新:
目前與 Ubuntu 20 儲存庫/apt 一起使用的 Dovecot 受到了影響。
錯誤參考:https://dovecot.org/pipermail/dovecot/2021-April/121884.html