diff --git a/changelogs/fragments/481-fix-excluded_subtrees-must-be-a-non-empty-list-or-None.yml b/changelogs/fragments/481-fix-excluded_subtrees-must-be-a-non-empty-list-or-None.yml new file mode 100644 index 00000000..0e38d035 --- /dev/null +++ b/changelogs/fragments/481-fix-excluded_subtrees-must-be-a-non-empty-list-or-None.yml @@ -0,0 +1,2 @@ +bugfixes: + - "openssl_csr - the module no longer crashes with 'permitted_subtrees/excluded_subtrees must be a non-empty list or None' if only one of ``name_constraints_permitted`` and ``name_constraints_excluded`` is provided (https://github.com/ansible-collections/community.crypto/issues/481)." diff --git a/plugins/module_utils/crypto/module_backends/csr.py b/plugins/module_utils/crypto/module_backends/csr.py index 4da3b97e..9d8fa6f1 100644 --- a/plugins/module_utils/crypto/module_backends/csr.py +++ b/plugins/module_utils/crypto/module_backends/csr.py @@ -528,8 +528,8 @@ class CertificateSigningRequestCryptographyBackend(CertificateSigningRequestBack if self.name_constraints_permitted or self.name_constraints_excluded: try: csr = csr.add_extension(cryptography.x509.NameConstraints( - [cryptography_get_name(name, 'name constraints permitted') for name in self.name_constraints_permitted], - [cryptography_get_name(name, 'name constraints excluded') for name in self.name_constraints_excluded], + [cryptography_get_name(name, 'name constraints permitted') for name in self.name_constraints_permitted] or None, + [cryptography_get_name(name, 'name constraints excluded') for name in self.name_constraints_excluded] or None, ), critical=self.name_constraints_critical) except TypeError as e: raise OpenSSLObjectError('Error while parsing name constraint: {0}'.format(e)) @@ -678,8 +678,8 @@ class CertificateSigningRequestCryptographyBackend(CertificateSigningRequestBack def _check_nameConstraints(extensions): current_nc_ext = _find_extension(extensions, cryptography.x509.NameConstraints) - current_nc_perm = [to_text(altname) for altname in current_nc_ext.value.permitted_subtrees] if current_nc_ext else [] - current_nc_excl = [to_text(altname) for altname in current_nc_ext.value.excluded_subtrees] if current_nc_ext else [] + current_nc_perm = [to_text(altname) for altname in current_nc_ext.value.permitted_subtrees or []] if current_nc_ext else [] + current_nc_excl = [to_text(altname) for altname in current_nc_ext.value.excluded_subtrees or []] if current_nc_ext else [] nc_perm = [to_text(cryptography_get_name(altname, 'name constraints permitted')) for altname in self.name_constraints_permitted] nc_excl = [to_text(cryptography_get_name(altname, 'name constraints excluded')) for altname in self.name_constraints_excluded] if set(nc_perm) != set(current_nc_perm) or set(nc_excl) != set(current_nc_excl):