summaryrefslogtreecommitdiff
path: root/keystoneclient/common
diff options
context:
space:
mode:
authorAdam Young <ayoung@redhat.com>2014-03-10 15:12:15 -0400
committerAdam Young <ayoung@redhat.com>2014-04-21 21:36:59 -0400
commit6c3cbab1a8e19f085c152a062b753bb2696b8964 (patch)
tree122742c293ebacbe76c8a0169ac959b6f58cb389 /keystoneclient/common
parent7e1700c565fb0a7fda7eb6fe573aff4f87de81fe (diff)
downloadpython-keystoneclient-6c3cbab1a8e19f085c152a062b753bb2696b8964.tar.gz
remove universal_newlines
Need to make sure that binary and text are both handled correctly for cms calls. Blueprint: compress-tokens Change-Id: If3ed5f339b53942d4ed6d6b2d9fc4eebd7180b0a
Diffstat (limited to 'keystoneclient/common')
-rw-r--r--keystoneclient/common/cms.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/keystoneclient/common/cms.py b/keystoneclient/common/cms.py
index ea10275..96f8b61 100644
--- a/keystoneclient/common/cms.py
+++ b/keystoneclient/common/cms.py
@@ -72,11 +72,11 @@ def _check_files_accessible(files):
return err
-def _process_communicate_handle_oserror(process, text, files):
+def _process_communicate_handle_oserror(process, data, files):
"""Wrapper around process.communicate that checks for OSError."""
try:
- output, err = process.communicate(text)
+ output, err = process.communicate(data)
except OSError as e:
if e.errno != errno.EPIPE:
raise
@@ -87,12 +87,14 @@ def _process_communicate_handle_oserror(process, text, files):
# able to read an input file, so check ourselves if can't read a file.
err = _check_files_accessible(files)
if process.stderr:
- err += process.stderr.read()
-
+ msg = process.stderr.read()
+ err = err + msg.decode('utf-8')
output = ''
retcode = -1
else:
retcode = process.poll()
+ if err is not None:
+ err = err.decode('utf-8')
return output, err, retcode
@@ -104,6 +106,7 @@ def cms_verify(formatted, signing_cert_file_name, ca_file_name):
:raises: CertificateConfigError if certificate is not configured properly.
"""
_ensure_subprocess()
+ data = bytearray(formatted, encoding='utf-8')
process = subprocess.Popen(['openssl', 'cms', '-verify',
'-certfile', signing_cert_file_name,
'-CAfile', ca_file_name,
@@ -112,10 +115,9 @@ def cms_verify(formatted, signing_cert_file_name, ca_file_name):
'-nocerts', '-noattr'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- universal_newlines=True)
+ stderr=subprocess.PIPE)
output, err, retcode = _process_communicate_handle_oserror(
- process, formatted, (signing_cert_file_name, ca_file_name))
+ process, data, (signing_cert_file_name, ca_file_name))
# Do not log errors, as some happen in the positive thread
# instead, catch them in the calling code and log them there.
@@ -230,6 +232,7 @@ def cms_sign_text(text, signing_cert_file_name, signing_key_file_name):
http://en.wikipedia.org/wiki/Cryptographic_Message_Syntax
"""
_ensure_subprocess()
+ data = bytearray(text, encoding='utf-8')
process = subprocess.Popen(['openssl', 'cms', '-sign',
'-signer', signing_cert_file_name,
'-inkey', signing_key_file_name,
@@ -238,16 +241,15 @@ def cms_sign_text(text, signing_cert_file_name, signing_key_file_name):
'-nocerts', '-noattr'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- universal_newlines=True)
+ stderr=subprocess.PIPE)
output, err, retcode = _process_communicate_handle_oserror(
- process, text, (signing_cert_file_name, signing_key_file_name))
+ process, data, (signing_cert_file_name, signing_key_file_name))
- if retcode or 'Error' in err:
+ if retcode or ('Error' in err):
LOG.error('Signing error: %s' % err)
raise subprocess.CalledProcessError(retcode, 'openssl')
- return output
+ return output.decode('utf-8')
def cms_sign_token(text, signing_cert_file_name, signing_key_file_name):