mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Openssl csr fixes (#26110)
* openssl_csr: fix for python3 * openssl_csr: actually check for existence of pyOpenSSL * pep8 compliance * fixes for python 2.6 and 3
This commit is contained in:
parent
5a20095b04
commit
34c0abd106
1 changed files with 6 additions and 5 deletions
|
@ -201,9 +201,7 @@ class CertificateSigningRequest(object):
|
||||||
if self.subjectAltName is None:
|
if self.subjectAltName is None:
|
||||||
self.subjectAltName = 'DNS:%s' % self.subject['CN']
|
self.subjectAltName = 'DNS:%s' % self.subject['CN']
|
||||||
|
|
||||||
for (key, value) in self.subject.items():
|
self.subject = dict((k, v) for k, v in self.subject.items() if v)
|
||||||
if value is None:
|
|
||||||
del self.subject[key]
|
|
||||||
|
|
||||||
def generate(self, module):
|
def generate(self, module):
|
||||||
'''Generate the certificate signing request.'''
|
'''Generate the certificate signing request.'''
|
||||||
|
@ -217,7 +215,7 @@ class CertificateSigningRequest(object):
|
||||||
setattr(subject, key, value)
|
setattr(subject, key, value)
|
||||||
|
|
||||||
if self.subjectAltName is not None:
|
if self.subjectAltName is not None:
|
||||||
req.add_extensions([crypto.X509Extension("subjectAltName", False, self.subjectAltName)])
|
req.add_extensions([crypto.X509Extension(b"subjectAltName", False, self.subjectAltName.encode('ascii'))])
|
||||||
|
|
||||||
privatekey_content = open(self.privatekey_path).read()
|
privatekey_content = open(self.privatekey_path).read()
|
||||||
self.privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM, privatekey_content)
|
self.privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM, privatekey_content)
|
||||||
|
@ -227,7 +225,7 @@ class CertificateSigningRequest(object):
|
||||||
self.request = req
|
self.request = req
|
||||||
|
|
||||||
try:
|
try:
|
||||||
csr_file = open(self.path, 'w')
|
csr_file = open(self.path, 'wb')
|
||||||
csr_file.write(crypto.dump_certificate_request(crypto.FILETYPE_PEM, self.request))
|
csr_file.write(crypto.dump_certificate_request(crypto.FILETYPE_PEM, self.request))
|
||||||
csr_file.close()
|
csr_file.close()
|
||||||
except (IOError, OSError) as exc:
|
except (IOError, OSError) as exc:
|
||||||
|
@ -286,6 +284,9 @@ def main():
|
||||||
required_one_of=[['commonName', 'subjectAltName']],
|
required_one_of=[['commonName', 'subjectAltName']],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not pyopenssl_found:
|
||||||
|
module.fail_json(msg='the python pyOpenSSL module is required')
|
||||||
|
|
||||||
path = module.params['path']
|
path = module.params['path']
|
||||||
base_dir = os.path.dirname(module.params['path'])
|
base_dir = os.path.dirname(module.params['path'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue