From d548495e9e1ec2ad995060112308fbf8da79c809 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 21 Aug 2015 11:52:18 -0700 Subject: [PATCH] Port volume transfer to Python 3 Encode Unicode to UTF-8 for salt and authentication key when computing the crypt hash. Partially implements: blueprint cinder-python3 Change-Id: I19d337cf0d40d91378e1c42061bc51b6009970a2 --- cinder/transfer/api.py | 13 ++++++++++--- tox.ini | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cinder/transfer/api.py b/cinder/transfer/api.py index e29dee773..04d48cadc 100644 --- a/cinder/transfer/api.py +++ b/cinder/transfer/api.py @@ -25,6 +25,7 @@ import os from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils +import six from cinder.db import base from cinder import exception @@ -98,9 +99,15 @@ class API(base.Base): def _get_crypt_hash(self, salt, auth_key): """Generate a random hash based on the salt and the auth key.""" - return hmac.new(str(salt), - str(auth_key), - hashlib.sha1).hexdigest() + if not isinstance(salt, (six.binary_type, six.text_type)): + salt = str(salt) + if isinstance(salt, six.text_type): + salt = salt.encode('utf-8') + if not isinstance(auth_key, (six.binary_type, six.text_type)): + auth_key = str(auth_key) + if isinstance(auth_key, six.text_type): + auth_key = auth_key.encode('utf-8') + return hmac.new(salt, auth_key, hashlib.sha1).hexdigest() def create(self, context, volume_id, display_name): """Creates an entry in the transfers table.""" diff --git a/tox.ini b/tox.ini index b026e036b..11ad4736c 100644 --- a/tox.ini +++ b/tox.ini @@ -96,6 +96,7 @@ commands = cinder.tests.unit.test_volume_configuration \ cinder.tests.unit.test_volume_glance_metadata \ cinder.tests.unit.test_volume_rpcapi \ + cinder.tests.unit.test_volume_transfer \ cinder.tests.unit.test_volume_types \ cinder.tests.unit.test_volume_types_extra_specs \ cinder.tests.unit.test_volume_utils \ -- 2.45.2