openssl_certificate_info, openssl_csr: fix wrong exception, and little refactoring (#54922)

* Fix wrong exception name.

* Use crypto_utils.load_certificate_request() to load CSRs with both backends.
pull/54934/head
Felix Fontein 5 years ago committed by ansibot
parent dafdcf286a
commit c5991b970f

@ -282,7 +282,7 @@ def get_relative_time_option(input_string, input_name):
if result.startswith("+") or result.startswith("-"): if result.startswith("+") or result.startswith("-"):
return crypto_utils.convert_relative_to_datetime(result) return crypto_utils.convert_relative_to_datetime(result)
if result is None: if result is None:
raise crypto_utils.CertificateError( raise crypto_utils.OpenSSLObjectError(
'The timespec "%s" for %s is not valid' % 'The timespec "%s" for %s is not valid' %
input_string, input_name) input_string, input_name)
for date_fmt in ['%Y%m%d%H%M%SZ', '%Y%m%d%H%MZ', '%Y%m%d%H%M%S%z', '%Y%m%d%H%M%z']: for date_fmt in ['%Y%m%d%H%M%SZ', '%Y%m%d%H%MZ', '%Y%m%d%H%M%S%z', '%Y%m%d%H%M%z']:
@ -293,7 +293,7 @@ def get_relative_time_option(input_string, input_name):
pass pass
if not isinstance(result, datetime.datetime): if not isinstance(result, datetime.datetime):
raise crypto_utils.CertificateError( raise crypto_utils.OpenSSLObjectError(
'The time spec "%s" for %s is invalid' % 'The time spec "%s" for %s is invalid' %
(input_string, input_name) (input_string, input_name)
) )

@ -632,7 +632,7 @@ class CertificateSigningRequestPyOpenSSL(CertificateSigningRequestBase):
return False return False
try: try:
csr = crypto_utils.load_certificate_request(self.path) csr = crypto_utils.load_certificate_request(self.path, backend='pyopenssl')
except Exception as dummy: except Exception as dummy:
return False return False
@ -819,8 +819,7 @@ class CertificateSigningRequestCryptography(CertificateSigningRequestBase):
return key_a == key_b return key_a == key_b
try: try:
with open(self.path, 'rb') as f: csr = crypto_utils.load_certificate_request(self.path, backend='cryptography')
csr = cryptography.x509.load_pem_x509_csr(f.read(), self.cryptography_backend)
except Exception as dummy: except Exception as dummy:
return False return False

Loading…
Cancel
Save