1
0
Fork 0
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:
Christian Pointner 2017-07-13 15:42:48 +02:00 committed by ansibot
parent 5a20095b04
commit 34c0abd106

View file

@ -201,9 +201,7 @@ class CertificateSigningRequest(object):
if self.subjectAltName is None:
self.subjectAltName = 'DNS:%s' % self.subject['CN']
for (key, value) in self.subject.items():
if value is None:
del self.subject[key]
self.subject = dict((k, v) for k, v in self.subject.items() if v)
def generate(self, module):
'''Generate the certificate signing request.'''
@ -217,7 +215,7 @@ class CertificateSigningRequest(object):
setattr(subject, key, value)
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()
self.privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM, privatekey_content)
@ -227,7 +225,7 @@ class CertificateSigningRequest(object):
self.request = req
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.close()
except (IOError, OSError) as exc:
@ -286,6 +284,9 @@ def main():
required_one_of=[['commonName', 'subjectAltName']],
)
if not pyopenssl_found:
module.fail_json(msg='the python pyOpenSSL module is required')
path = module.params['path']
base_dir = os.path.dirname(module.params['path'])