mirror of
https://github.com/Mailu/Mailu.git
synced 2024-12-12 10:45:38 +02:00
Ensure we always send an ISRG root for DANE
This commit is contained in:
parent
a7cf68163a
commit
86adf07461
@ -330,8 +330,8 @@ mail {
|
||||
{% endif %}
|
||||
{% if TLS and not TLS_ERROR %}
|
||||
{% if TLS_FLAVOR in ['letsencrypt','mail-letsencrypt'] %}
|
||||
ssl_certificate /certs/letsencrypt/live/mailu/fullchain.pem;
|
||||
ssl_certificate /certs/letsencrypt/live/mailu-ecdsa/fullchain.pem;
|
||||
ssl_certificate /certs/letsencrypt/live/mailu/DANE-chain.pem;
|
||||
ssl_certificate /certs/letsencrypt/live/mailu-ecdsa/DANE-chain.pem;
|
||||
{% endif %}
|
||||
{% if TLS_PERMISSIVE %}
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
|
||||
|
@ -5,6 +5,60 @@ import logging as log
|
||||
import sys
|
||||
from socrate import system, conf
|
||||
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
|
||||
from cryptography.x509.verification import PolicyBuilder, Store, DNSName
|
||||
from cryptography.x509.oid import NameOID
|
||||
import hashlib
|
||||
|
||||
ISRG_ROOT_X1 = x509.load_pem_x509_certificate(b'''-----BEGIN CERTIFICATE-----
|
||||
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
||||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
||||
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
||||
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
||||
MTCCAiIwDQ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Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
|
||||
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
||||
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
||||
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
||||
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
||||
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
||||
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
||||
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
||||
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
||||
-----END CERTIFICATE-----
|
||||
''')
|
||||
ISRG_ROOT_X2 = x509.load_pem_x509_certificate(b'''-----BEGIN CERTIFICATE-----
|
||||
MIICGzCCAaGgAwIBAgIQQdKd0XLq7qeAwSxs6S+HUjAKBggqhkjOPQQDAzBPMQsw
|
||||
CQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2gg
|
||||
R3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMjAeFw0yMDA5MDQwMDAwMDBaFw00
|
||||
MDA5MTcxNjAwMDBaME8xCzAJBgNVBAYTAlVTMSkwJwYDVQQKEyBJbnRlcm5ldCBT
|
||||
ZWN1cml0eSBSZXNlYXJjaCBHcm91cDEVMBMGA1UEAxMMSVNSRyBSb290IFgyMHYw
|
||||
EAYHKoZIzj0CAQYFK4EEACIDYgAEzZvVn4CDCuwJSvMWSj5cz3es3mcFDR0HttwW
|
||||
+1qLFNvicWDEukWVEYmO6gbf9yoWHKS5xcUy4APgHoIYOIvXRdgKam7mAHf7AlF9
|
||||
ItgKbppbd9/w+kHsOdx1ymgHDB/qo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0T
|
||||
AQH/BAUwAwEB/zAdBgNVHQ4EFgQUfEKWrt5LSDv6kviejM9ti6lyN5UwCgYIKoZI
|
||||
zj0EAwMDaAAwZQIwe3lORlCEwkSHRhtFcP9Ymd70/aTSVaYgLXTWNLxBo1BfASdW
|
||||
tL4ndQavEi51mI38AjEAi/V3bNTIZargCyzuFJ0nN6T5U6VR5CmD1/iQMVtCnwr1
|
||||
/q4AaOeMSQ+2b1tbFfLn
|
||||
-----END CERTIFICATE-----
|
||||
''')
|
||||
|
||||
args = system.set_env()
|
||||
log.basicConfig(stream=sys.stderr, level=args.get("LOG_LEVEL", "WARNING"))
|
||||
|
||||
@ -29,21 +83,43 @@ args["TLS"] = {
|
||||
"notls": None
|
||||
}[args["TLS_FLAVOR"]]
|
||||
|
||||
def format_for_nginx(fullchain, output):
|
||||
def format_for_nginx(fullchain, output, strip_CA=args.get('LETSENCRYPT_SHORTCHAIN')):
|
||||
""" We may want to strip ISRG Root X1 out """
|
||||
if not os.path.exists(fullchain):
|
||||
return
|
||||
split = '-----END CERTIFICATE-----\n'
|
||||
with open(fullchain, 'r') as pem:
|
||||
certs = [f'{cert}{split}' for cert in pem.read().split(split) if cert]
|
||||
if len(certs)>2 and args.get('LETSENCRYPT_SHORTCHAIN'):
|
||||
del certs[-1]
|
||||
with open(output, 'w') as pem:
|
||||
pem.write(''.join(certs))
|
||||
chain=[]
|
||||
with open(fullchain, 'rb') as f:
|
||||
chain = x509.load_pem_x509_certificates(f.read())
|
||||
builder = PolicyBuilder().store(Store([ISRG_ROOT_X1, ISRG_ROOT_X2]))
|
||||
verifier = builder.build_server_verifier(DNSName(chain[0].subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value))
|
||||
valid_chain = verifier.verify(chain[0], chain[1:])
|
||||
log.info(f'The certificate chain looks as follows for {fullchain}:')
|
||||
indent = ' '
|
||||
has_found_PIN = False
|
||||
for cert in valid_chain:
|
||||
pubkey_der = cert.public_key().public_bytes(Encoding.DER, PublicFormat.SubjectPublicKeyInfo)
|
||||
digest = hashlib.sha256(pubkey_der).hexdigest()
|
||||
log.info(f'{indent}{cert.subject.rfc4514_string()} {digest}')
|
||||
indent += ' '
|
||||
if digest == '0b9fa5a59eed715c26c1020c711b4f6ec42d58b0015e14337a39dad301c5afc3': # ISRG Root X1
|
||||
log.info('ISRG X1 PIN FOUND!')
|
||||
has_found_PIN = True
|
||||
elif digest == '762195c225586ee6c0237456e2107dc54f1efc21f61a792ebd515913cce68332': # ISRG Root X2
|
||||
log.info('ISRG X2 PIN FOUND!')
|
||||
has_found_PIN = True
|
||||
if not has_found_PIN:
|
||||
log.error('Neither ISRG X1 nor ISRG X2 have been found in the certificate chain. Please check your DANE records.')
|
||||
with open(output, 'wt') as f:
|
||||
for cert in valid_chain:
|
||||
if strip_CA and (cert.subject.rfc4514_string() in ['CN=ISRG Root X1,O=Internet Security Research Group,C=US', 'CN=ISRG Root X2,O=Internet Security Research Group,C=US']):
|
||||
continue
|
||||
f.write(f'{cert.public_bytes(encoding=Encoding.PEM).decode("ascii").strip()}')
|
||||
|
||||
if args['TLS_FLAVOR'] in ['letsencrypt', 'mail-letsencrypt']:
|
||||
format_for_nginx('/certs/letsencrypt/live/mailu/fullchain.pem', '/certs/letsencrypt/live/mailu/nginx-chain.pem')
|
||||
format_for_nginx('/certs/letsencrypt/live/mailu/fullchain.pem', '/certs/letsencrypt/live/mailu/DANE-chain.pem', False)
|
||||
format_for_nginx('/certs/letsencrypt/live/mailu-ecdsa/fullchain.pem', '/certs/letsencrypt/live/mailu-ecdsa/nginx-chain.pem')
|
||||
format_for_nginx('/certs/letsencrypt/live/mailu-ecdsa/fullchain.pem', '/certs/letsencrypt/live/mailu-ecdsa/DANE-chain.pem', False)
|
||||
|
||||
if args["TLS"] and not all(os.path.exists(file_path) for file_path in args["TLS"]):
|
||||
print("Missing cert or key file, disabling TLS")
|
||||
|
@ -23,6 +23,7 @@ command = [
|
||||
"--keep-until-expiring",
|
||||
"--allow-subset-of-names",
|
||||
"--renew-with-new-domains",
|
||||
"--preferred-chain 'ISRG Root X1'",
|
||||
"--config-dir", "/certs/letsencrypt",
|
||||
"--post-hook", "/config.py"
|
||||
]
|
||||
@ -38,6 +39,7 @@ command2 = [
|
||||
"--allow-subset-of-names",
|
||||
"--key-type", "ecdsa",
|
||||
"--renew-with-new-domains",
|
||||
"--preferred-chain 'ISRG Root X1'",
|
||||
"--config-dir", "/certs/letsencrypt",
|
||||
"--post-hook", "/config.py"
|
||||
]
|
||||
|
1
towncrier/newsfragments/3187.bugfix
Normal file
1
towncrier/newsfragments/3187.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Ensure we always send ISRG_X1 root when LE is configured. Switch to the non-crossigned version as the other one will expire in September
|
Loading…
Reference in New Issue
Block a user