Score:1

Dovecot problems wit SSL Cert: Verify return code: 2 (unable to get issuer certificate)

my flag

sry for that, but i am a newcomer at ssl and what do i wrong? i try to change the dovecot imap login to imaps but something goes wrong with the ssl cert check. The ssl cert works for the https apache server and its the same what i try to use for dovecot. i tried to understand the answere from dave thomson https://stackoverflow.com/questions/47108886/openssl-s-client-error-verify-errornum-2unable-to-get-issuer-certificate but it's hard for an newcomer. maybe you have an easier way. thx and br

openssl s_client -connect <my-domain>:993 -servername <my-domain> -CAfile /etc/apache2/ssl/cert_2021.ca-bundle

output:

CONNECTED(00000003)
depth=2 C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
verify error:num=2:unable to get issuer certificate
issuer= C = GB, ST = Greater Manchester, L = Salford, O = Comodo CA Limited, CN = AAA Certificate Services
verify return:1
depth=1 C = GB, ST = Greater Manchester, L = Salford, O = Sectigo Limited, CN = Sectigo RSA Domain Validation Secure Server CA
issuer= C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
verify return:1
depth=0 CN = <my-domain>
issuer= C = GB, ST = Greater Manchester, L = Salford, O = Sectigo Limited, CN = Sectigo RSA Domain Validation Secure Server CA
verify return:1
---
Certificate chain
0 s:CN = <my-domain>
i:C = GB, ST = Greater Manchester, L = Salford, O = Sectigo Limited, CN = Sectigo RSA Domain Validation Secure Server CA
---
Server certificate
-----BEGIN CERTIFICATE-----
...gJaprVUs
-----END CERTIFICATE-----
subject=CN = <my-domain>

issuer=C = GB, ST = Greater Manchester, L = Salford, O = Sectigo Limited, CN = Sectigo RSA Domain Validation Secure Server CA

---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 2192 bytes and written 397 bytes
Verification error: unable to get issuer certificate
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 2048 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 2 (unable to get issuer certificate)
---
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol  : TLSv1.3
Cipher    : TLS_AES_256_GCM_SHA384
Session-ID: 3B8DCD9A603FF577C1E77F40C5D3BCE2B9BAE026EF430566359B0D82353CE1E5
Session-ID-ctx:
Resumption PSK: 69E09...34D1
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 97 86 ca 30 d9 1e 13 95-51 b3 06 87 9d 9f fe ec   ...0....Q.......
...
00d0 - 26 69 ba 7b 58 58 2c da-18 90 c9 8b 9f e2 3f be   &i.{XX,.......?.

Start Time: 1651046361
Timeout   : 7200 (sec)
Verify return code: 2 (unable to get issuer certificate)
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol  : TLSv1.3
Cipher    : TLS_AES_256_GCM_SHA384
Session-ID: F834...EE6E
Session-ID-ctx:
Resumption PSK: A6FBE...23BF
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket lifetime hint: 7200 (seconds)
TLS session ticket:
0000 - 97 86 ca 30 d9 1e 13 95-51 b3 06 87 9d 9f fe ec   ...0....Q.......
...
00d0 - a9 74 d9 44 c8 40 43 11-48 32 1e e2 2a 8f b9 bb   [email protected]..*...

Start Time: 1651046361
Timeout   : 7200 (sec)
Verify return code: 2 (unable to get issuer certificate)
Extended master secret: no
Max Early Data: 0
---
read R BLOCK
* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN] Dovecot (Raspbian) ready.
* BYE Disconnected for inactivity.
closed

for other tries

openssl s_client -connect <my-domain>:993 -servername <my-domain> -CApath /etc/ssl/certs/ | grep 'returncode'

i get the same output:

depth=0 CN = <my-domain>
verify error:num=20:unable to get local issuer certificate
...
..
.
Start Time: 1651049986
Timeout   : 7200 (sec)
Verify return code: 21 (unable to verify the first certificate)
Extended master secret: no
Max Early Data: 0

my

/etc/dovecot/conf.d/10-ssl.conf

has the minimum cfg

ssl = required
ssl_cert = </etc/apache2/ssl/cert_2021.crt
ssl_key = </etc/apache2/ssl/cert_2021.key
ssl_client_ca_file = /etc/apache2/ssl/cert_2021.ca-bundle
ssl_dh = </usr/share/dovecot/dh.pem

UPDATE:

After your input anx i throw all the stuff in on single file. mean the crt, key and ca-bundle information nicely and smooth with copy + paste. saved unter /etc/dovecot/private without any symlink. under /etc/dovecot/conf.d/10-ssl.conf i set

ssl_cert = </etc/dovecot/private/all_certs_in_one.txt
#ssl_client_ca_file = /etc/apache2/ssl/es_2021.ca-bundle

and i tried the command

openssl s_client -showcerts 6-connect <my-domain>:993 -servername <my-domain>

i get that output, what is definitly more then the last one...

CONNECTED(00000003)
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 
322 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---

UPDATE - with half SOLUTION

nano mkcert.sh

#!/bin/sh
# Generates a self-signed certificate.
# Edit dovecot-openssl.cnf before running this.
umask 077
OPENSSL=${OPENSSL-openssl}
SSLDIR=${SSLDIR-/etc/ssl}
OPENSSLCONFIG=${OPENSSLCONFIG-dovecot-openssl.cnf}

CERTDIR=$SSLDIR/certs
KEYDIR=$SSLDIR/private

CERTFILE=$CERTDIR/dovecot.pem
KEYFILE=$KEYDIR/dovecot.pem

if [ ! -d $CERTDIR ]; then
  echo "$SSLDIR/certs directory doesn't exist"
  exit 1
fi

if [ ! -d $KEYDIR ]; then
  echo "$SSLDIR/private directory doesn't exist"
  exit 1
fi

if [ -f $CERTFILE ]; then
  echo "$CERTFILE already exists, won't overwrite"
  exit 1
fi

if [ -f $KEYFILE ]; then
  echo "$KEYFILE already exists, won't overwrite"
  exit 1
fi

$OPENSSL req -new -x509 -nodes -config $OPENSSLCONFIG -out $CERTFILE -keyout $KEYFILE -days 3650 || exit 2
chmod 0600 $KEYFILE
echo
$OPENSSL x509 -subject -fingerprint -noout -in $CERTFILE || exit 2

nano dovecot-openssl.cnf

[ req ]
default_bits = 2048
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
# country (2 letter code)
#C=FI

# State or Province Name (full name)
#ST=

# Locality Name (eg. city)
#L=Helsinki

# Organization (eg. company)
O=<MY FIRM NAME>

# Organizational Unit Name (eg. section)
OU=IMAP server

# Common Name (*.example.com is also possible)
CN=mail.<YOUR DOMAIN NAME>

# E-mail contact [email protected] 
emailAddress=support@<YOUR DOMAIN NAME>

[ cert_type ]
nsCertType = server

create symlinks:

ln -s /etc/ssl/certs/dovecot.pem /etc/dovecot/private/dovecot_pem_sym.pem
ln -s /etc/ssl/private/dovecot.pem /etc/dovecot/private/dovecot_pem_sym.key

nano /etc/dovecot/conf.d/10-ssl.conf

ssl = required
ssl_cert = </etc/dovecot/private/dovecot_pem_sym.pem
ssl_key = </etc/dovecot/private/dovecot_pem_sym.key
#ssl_client_ca_dir = /etc/ssl/certs
#ssl_client_ca_file =
#ssl_dh = </usr/share/dovecot/dh.pem 

restart

systemctl restart dovecot

test

openssl s_client -showcerts -connect <YOUR mail.DOMAIN>:993 -servername <YOUR mail.DOMAIN>

errorcode is

Verify return code: 18 (self signed certificate)

but thats better then nothing =/ my apache cert doenst works but yeah. seams that we cant have everything working =(

btw. dont forget to set in outlook as example @cfg method to SSL/TLS not authomatic

in flag
Most probably your certificate file is missing the other certificates from the chain.
Score:0
fr flag
anx

You likely used the ssl_client_ca_file setting in error. It is used when Dovecot makes outgoing connections in a client role (in case, say, it is proxying to MTA/IMAP destination where the systems default CA is inappropriate). This is completely separate from configuration of Dovecot handling incoming connections in a server role, such as providing IMAP service via TLS.

Leave that unset, and instead concatenate your server and intermediate certificates into one combined file to be used in ssl_cert=</path/to/file.

Mind the order, in your case I believe that would be your server certificate, then Sectigo, then Usertrust. As you are currently pointing to apache2-used files, take care not to modify files you have configured elsewhere (with the expectation that they only contain either server cert or chain).

trash2 avatar
my flag
hi. first thx for your input i tried something (see UPDATE above) but now i got other kind of error. i cant see what i do wrong. for any input i will thx a lot. the outlook login on port 993 goes hand in hand with that working cert right? btw. if i use the ubuntu standarf snakeoil certs i get an good output but the outlook login still doenst works. the auth- error does not exist for the login try
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.