From 61e1d7a83bc357751c5eb081f537194565bc7e65 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 13 Nov 2018 15:49:49 +1100 Subject: [PATCH] certdb: validate certificate signatures When verifying a CA certificate, validate its signature. This causes FreeIPA to reject certificate chains with bad signatures, signatures using unacceptable algorithms, or certificates with unacceptable key sizes. The '-e' option to 'certutil -V' was the missing ingredient. An an example of a problem prevented by this change, a certifiate signed by a 1024-bit intermediate CA, would previously have been imported by ipa-cacert-manage, but would cause Dogtag startup failure due to failing self-test. With this change, ipa-cacert-manage will reject the certificate: # ipa-cacert-manage renew --external-cert-file /tmp/ipa.p7 Importing the renewed CA certificate, please wait CA certificate CN=Certificate Authority,O=IPA.LOCAL 201809261455 in /tmp/ipa.p7 is not valid: certutil: certificate is invalid: The certificate was signed using a signature algorithm that is disabled because it is not secure. Fixes: https://pagure.io/freeipa/issue/7761 Reviewed-By: Christian Heimes --- ipapython/certdb.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ipapython/certdb.py b/ipapython/certdb.py index ba7d0afe5..b84d7d3b7 100644 --- a/ipapython/certdb.py +++ b/ipapython/certdb.py @@ -933,8 +933,15 @@ class NSSDatabase: raise ValueError("subject key identifier must not be empty") try: - self.run_certutil(['-V', '-n', nickname, '-u', 'L'], - capture_output=True) + self.run_certutil( + [ + '-V', # check validity of cert and attrs + '-n', nickname, + '-u', 'L', # usage; 'L' means "SSL CA" + '-e', # check signature(s); this checks + # key sizes, sig algorithm, etc. + ], + capture_output=True) except ipautil.CalledProcessError as e: # certutil output in case of error is # 'certutil: certificate is invalid: \n'