Skip to content

Commit

Permalink
Merge pull request #51324 from garethgreenaway/1257_something_somethi…
Browse files Browse the repository at this point in the history
…ng_bytes_argh_python2

 [2018.3] Fixes to x509 module and test
  • Loading branch information
s0undt3ch authored Jan 25, 2019
2 parents b44cd84 + bd7072f commit f62cc11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions salt/modules/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _passphrase_callback(passphrase):
Returns a callback function used to supply a passphrase for private keys
'''
def f(*args):
return salt.utils.stringutils.to_str(passphrase)
return salt.utils.stringutils.to_bytes(passphrase)
return f


Expand Down Expand Up @@ -961,7 +961,7 @@ def create_crl( # pylint: disable=too-many-arguments,too-many-locals

serial_number = rev_item['serial_number'].replace(':', '')
# OpenSSL bindings requires this to be a non-unicode string
serial_number = salt.utils.stringutils.to_str(serial_number)
serial_number = salt.utils.stringutils.to_bytes(serial_number)

if 'not_after' in rev_item and not include_expired:
not_after = datetime.datetime.strptime(
Expand All @@ -976,6 +976,7 @@ def create_crl( # pylint: disable=too-many-arguments,too-many-locals
rev_date = datetime.datetime.strptime(
rev_item['revocation_date'], '%Y-%m-%d %H:%M:%S')
rev_date = rev_date.strftime('%Y%m%d%H%M%SZ')
rev_date = salt.utils.stringutils.to_bytes(rev_date)

rev = OpenSSL.crypto.Revoked()
rev.set_serial(serial_number)
Expand Down Expand Up @@ -1005,7 +1006,7 @@ def create_crl( # pylint: disable=too-many-arguments,too-many-locals
'days': days_valid
}
if digest:
export_kwargs['digest'] = bytes(digest)
export_kwargs['digest'] = salt.utils.stringutils.to_bytes(digest)
else:
log.warning('No digest specified. The default md5 digest will be used.')

Expand Down Expand Up @@ -1573,7 +1574,7 @@ def create_certificate(
pem_type='CERTIFICATE'
)
else:
return cert.as_pem()
return salt.utils.stringutils.to_str(cert.as_pem())
# pylint: enable=too-many-locals


Expand Down
6 changes: 3 additions & 3 deletions tests/unit/modules/test_x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_create_key(self):
'''
ret = x509.create_private_key(text=True,
passphrase='super_secret_passphrase')
self.assertIn(b'BEGIN RSA PRIVATE KEY', ret)
self.assertIn('BEGIN RSA PRIVATE KEY', ret)

@skipIf(not HAS_M2CRYPTO, 'Skipping, M2Crypto is unavailble')
def test_create_certificate(self):
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_create_certificate(self):
authorityKeyIdentifier='keyid,issuer:always',
days_valid=3650,
days_remaining=0)
self.assertIn(b'BEGIN CERTIFICATE', ret)
self.assertIn('BEGIN CERTIFICATE', ret)

@skipIf(not HAS_M2CRYPTO, 'Skipping, M2Crypto is unavailble')
def test_create_crl(self):
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_create_crl(self):
os.remove(ca_crl_file.name)

# Ensure that a CRL was actually created
self.assertIn(b'BEGIN X509 CRL', crl)
self.assertIn('BEGIN X509 CRL', crl)

@skipIf(not HAS_M2CRYPTO, 'Skipping, M2Crypto is unavailble')
def test_revoke_certificate_with_crl(self):
Expand Down

0 comments on commit f62cc11

Please sign in to comment.