summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2011-05-27 19:42:57 +0000
committerChris Behrens <cbehrens@codestud.com>2011-05-27 19:42:57 +0000
commit90280230c0ceebcea7db80c6a05ae0cef5599bc1 (patch)
tree10eab8b86e9c886a2cbeb8bfe117a51b669a9fe1
parenta92f2bcbbaa40458e81bad3f6cb21288161322f9 (diff)
parent60a291747eeded09ade608088eae47fdb300a56b (diff)
downloadnova-90280230c0ceebcea7db80c6a05ae0cef5599bc1.tar.gz
nova-90280230c0ceebcea7db80c6a05ae0cef5599bc1.tar.xz
nova-90280230c0ceebcea7db80c6a05ae0cef5599bc1.zip
Merged lp:~rackspace-titan/nova/lp788979
-rw-r--r--nova/tests/test_xenapi.py25
-rw-r--r--nova/virt/xenapi/vmops.py24
2 files changed, 28 insertions, 21 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 3ba37a762..9d56c1644 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -592,12 +592,29 @@ class XenAPIDiffieHellmanTestCase(test.TestCase):
bob_shared = self.bob.compute_shared(alice_pub)
self.assertEquals(alice_shared, bob_shared)
- def test_encryption(self):
- msg = "This is a top-secret message"
- enc = self.alice.encrypt(msg)
+ def _test_encryption(self, message):
+ enc = self.alice.encrypt(message)
self.assertFalse(enc.endswith('\n'))
dec = self.bob.decrypt(enc)
- self.assertEquals(dec, msg)
+ self.assertEquals(dec, message)
+
+ def test_encrypt_simple_message(self):
+ self._test_encryption('This is a simple message.')
+
+ def test_encrypt_message_with_newlines_at_end(self):
+ self._test_encryption('This message has a newline at the end.\n')
+
+ def test_encrypt_many_newlines_at_end(self):
+ self._test_encryption('Message with lotsa newlines.\n\n\n')
+
+ def test_encrypt_newlines_inside_message(self):
+ self._test_encryption('Message\nwith\ninterior\nnewlines.')
+
+ def test_encrypt_with_leading_newlines(self):
+ self._test_encryption('\n\nMessage with leading newlines.')
+
+ def test_encrypt_really_long_message(self):
+ self._test_encryption(''.join(['abcd' for i in xrange(1024)]))
def tearDown(self):
super(XenAPIDiffieHellmanTestCase, self).tearDown()
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 1d8678ce2..1fcaaeede 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -1190,30 +1190,20 @@ class SimpleDH(object):
mpi = M2Crypto.m2.bn_to_mpi(bn)
return mpi
- def _run_ssl(self, text, which):
- base_cmd = ('openssl enc -aes-128-cbc -a -pass pass:%(shared)s '
- '-nosalt %(dec_flag)s')
- if which.lower()[0] == 'd':
- dec_flag = ' -d'
- # When decoding base64, we need to make sure there's a
- # single '\n' at the end of the base64 encoded data.
- # It's kinda dumb that openssl wants to see a newline
- text = text.strip('\n') + '\n'
- else:
- dec_flag = ''
- shared = self._shared
- cmd = base_cmd % locals()
- proc = _runproc(cmd)
+ def _run_ssl(self, subcommand, text):
+ proc = _runproc('openssl %s' % subcommand)
proc.stdin.write(text)
proc.stdin.close()
proc.wait()
err = proc.stderr.read()
if err:
raise RuntimeError(_('OpenSSL error: %s') % err)
- return proc.stdout.read().strip('\n')
+ return proc.stdout.read()
def encrypt(self, text):
- return self._run_ssl(text, 'enc')
+ cmd = 'enc -aes-128-cbc -a -A -pass pass:%s -nosalt' % self._shared
+ return self._run_ssl(cmd, text).strip('\n')
def decrypt(self, text):
- return self._run_ssl(text, 'dec')
+ cmd = 'enc -aes-128-cbc -a -A -pass pass:%s -nosalt -d' % self._shared
+ return self._run_ssl(cmd, text)