问题原文
原帖链接 · Timor · CC BY-SA 4.0
Okay, this is gonna be a long one, I fear. Please bear with me.
setting
I have an OpenLDAP 2.4.50 server running on Alpine 3.12.1. It's serving LDAPS only with a let's encrypt staging certificate (at the moment, but prod environment will be no different, certificate-wise). Specifically it uses cert.pem referenced by olcTLSCertificateFile in cn=config. Everything works fine, I can connect and work with it using ApacheDirectoryStudio (acknowledging that I trust the host, though the cert seems smelly). Connecting with any OpenLDAP clients, such as ldapsearch or ldapmodify, needs a TLS_CACERT-entry in /etc/openldap/ldap.conf that consists of cat intermediate.pem root.pem > rootchain.pem. And this is where things get funny.
As those of you who have worked with let's encrypt know, let's encrypt (or rather certbot) usually provides us with the following:
privkey.pem- the private keycert.pem- the server's certificatechain.pem- the intermediate certificate between out server certificate and the CAfullchain.pem- the chain form our server certificate to the root certificate without root, aka.cat cert.pem chain.pem > fullchain.pem
No root.pem and no root-chain.pem, the latter being cat chain.pem root.pem > rootchain.pem.
People throughout the webz state, that web browsers do some black magic if they don't get provided with the intermediate certificate but know of the root certificate and somehow retrieve the intermediate then, which I might be tempted to believe by own experience. These people say: for "normal" servers, just provide a certificate chain to the CA without the actual CA certificate as your certificate to your server software (e. g. Get your certificate chain right). After having had a more thorough look into all this, this totally makes sense, as rfc 4346, section 7.4.2 states
"certificate_list
This is a sequence (chain) of X.509v3 certificates. The sender's certificate must come first in the list. Each following certificate must directly certify the one preceding it."
According to this I should be able to provide fullChain.pem (which is cat cert.pem chain.pem > fullchain.pem) to olcTLSCertificateFile in cn=config and the root certificate to clients in /etc/openldap/ldap.conf as TLS_CACERT and every client should just run properly. Simply put, nope, they don't.
fun fact
openssl verify -CAfile root.pem somechain.pem only succeeds, if somechain.pem is cat chain.pem cert.pem > somechain.pem which should be wrong according to the rfc... ?!
conclusion
So to conclude all this:
- Is providing a chained PEM of the form
cat server.pem intermediate_lowest.pem intermediat_mid.pem intermediate-highest.pemas a server certificate the correct way? - If so or if not, how am I doing this correctly with OpenLDAP?
As requested in the comments, here comes the output of openssl s_client -connect for both, with root certificate only and with a chain of intermediate certificate followed by the root certificate. At the time of the requests, slapd is configured to use fullchain.pem aka. cert.pem followed by chain.pem.
- root certificate only
openssl s_client -showcerts -CAfile fakelerootx1.pem -connect directory.domain.tld:636 < /dev/null > with-rootcert.log 2>&1
depth=0 CN = *.domain.tld
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 CN = *.domain.tld
verify error:num=21:unable to verify the first certificate
verify return:1
CONNECTED(00000003)
---
Certificate chain
0 s:CN = *.domain.tld
i:CN = Fake LE Intermediate X1
-----BEGIN CERTIFICATE-----
[ cert data removed, it is the single cert.pem from lets encrypt ]
-----END CERTIFICATE-----
---
Server certificate
subject=CN = *.domain.tld
issuer=CN = Fake LE Intermediate X1
---
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 1899 bytes and written 401 bytes
Verification error: unable to verify the first 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: 21 (unable to verify the first certificate)
---
DONE
- chain made of intermediate followed by root
openssl s_client -showcerts -CAfile fakerootchain.pem -connect directory.domain.tld:636 < /dev/null > with-root_and_intermediate_cert.log 2>&1
depth=2 CN = Fake LE Root X1
verify return:1
depth=1 CN = Fake LE Intermediate X1
verify return:1
depth=0 CN = *.domain.tld
verify return:1
CONNECTED(00000003)
---
Certificate chain
0 s:CN = *.domain.tld
i:CN = Fake LE Intermediate X1
-----BEGIN CERTIFICATE-----
[ cert data removed, it is the single cert.pem from lets encrypt, again ]
-----END CERTIFICATE-----
---
Server certificate
subject=CN = *.domain.tld
issuer=CN = Fake LE Intermediate X1
---
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 1899 bytes and written 401 bytes
Verification: OK
---
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: 0 (ok)
---
DONE
已采纳解答
原帖链接 · Timor · CC BY-SA 4.0
OpenLDAP's slapd simply does not send the certificate chain to clients when TLS handshaking, even if a bundle of server certificate, intermediate certificate has been provided to it as its certificate.
The only suitable work-around without turning certificate validation off on the clients is the following.
- create a certificate bundle from intermediate certificate, root certificate
- make the client use this bundle as a trusted CA certificate, so it can factor the complete chain and validate; this works at least with software that's compiled against OpenLDAP libraries
- OpenLDAP command line clients as
ldapmodify,ldapsearch:
addTLS_CACERT imedrootbundle.pemto either~/.ldaprcor the system-wide/etc/openldap/ldap.conf - dovecot:
addtls_ca_cert_file = imedrootbundle.pemto your/etc/dovecot/dovecot-ldap.conf.extfile - postfix:
addtls_ca_cert_file = imedrootbundle.pemto all of yourcffiles, that you use as postfix dictionaries to query your directory
- OpenLDAP command line clients as
Keep in mind though, that the root certificate is not provided by let's encrypt's certbot and may change in the future thus rendering your intermediate certificate, root certificate useless. I set up a hook script with certbot that checks the intermediate certificate's issuer and tries to select the correct root certificate based on those that I know of. It complains if it can't find one. This at least breaks everything in a controlled manner early in the process.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
