Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ansible/modules/crypto/openssl_certificate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_relative_time_option(input_string, input_name):
if result.startswith("+") or result.startswith("-"):
return crypto_utils.convert_relative_to_datetime(result)
if result is None:
raise crypto_utils.CertificateError(
raise crypto_utils.OpenSSLObjectError(
'The timespec "%s" for %s is not valid' %
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']:
Expand All @@ -293,7 +293,7 @@ def get_relative_time_option(input_string, input_name):
pass

if not isinstance(result, datetime.datetime):
raise crypto_utils.CertificateError(
raise crypto_utils.OpenSSLObjectError(
'The time spec "%s" for %s is invalid' %
(input_string, input_name)
)
Expand Down
5 changes: 2 additions & 3 deletions lib/ansible/modules/crypto/openssl_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def _check_signature(csr):
return False

try:
csr = crypto_utils.load_certificate_request(self.path)
csr = crypto_utils.load_certificate_request(self.path, backend='pyopenssl')
except Exception as dummy:
return False

Expand Down Expand Up @@ -819,8 +819,7 @@ def _check_signature(csr):
return key_a == key_b

try:
with open(self.path, 'rb') as f:
csr = cryptography.x509.load_pem_x509_csr(f.read(), self.cryptography_backend)
csr = crypto_utils.load_certificate_request(self.path, backend='cryptography')
except Exception as dummy:
return False

Expand Down