~dan-prince/nova/cleanup_test_libvirt_inst_path

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/vmops.py

  • Committer: Tarmac
  • Author(s): Mark Washenberger, Chris Behrens
  • Date: 2011-05-27 21:15:49 UTC
  • mfrom: (1116.2.5 lp788979)
  • Revision ID: tarmac-20110527211549-qgi85dwqenjm65cm
When encrypting passwords in xenapi's SimpleDH(), we shouldn't send a final newline to openssl, as it'll use that as encryption data.  However, we do need to make sure there's a newline on the end when we write the base64 string for decoding..  Made these changes and updated the test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1190
1190
        mpi = M2Crypto.m2.bn_to_mpi(bn)
1191
1191
        return mpi
1192
1192
 
1193
 
    def _run_ssl(self, text, which):
1194
 
        base_cmd = ('openssl enc -aes-128-cbc -a -pass pass:%(shared)s '
1195
 
                '-nosalt %(dec_flag)s')
1196
 
        if which.lower()[0] == 'd':
1197
 
            dec_flag = ' -d'
1198
 
        else:
1199
 
            dec_flag = ''
1200
 
        shared = self._shared
1201
 
        cmd = base_cmd % locals()
1202
 
        proc = _runproc(cmd)
1203
 
        proc.stdin.write(text + '\n')
 
1193
    def _run_ssl(self, text, extra_args=None):
 
1194
        if not extra_args:
 
1195
            extra_args = ''
 
1196
        cmd = 'enc -aes-128-cbc -A -a -pass pass:%s -nosalt %s' % (
 
1197
                self._shared, extra_args)
 
1198
        proc = _runproc('openssl %s' % cmd)
 
1199
        proc.stdin.write(text)
1204
1200
        proc.stdin.close()
1205
1201
        proc.wait()
1206
1202
        err = proc.stderr.read()
1207
1203
        if err:
1208
1204
            raise RuntimeError(_('OpenSSL error: %s') % err)
1209
 
        return proc.stdout.read().strip('\n')
 
1205
        return proc.stdout.read()
1210
1206
 
1211
1207
    def encrypt(self, text):
1212
 
        return self._run_ssl(text, 'enc')
 
1208
        return self._run_ssl(text).strip('\n')
1213
1209
 
1214
1210
    def decrypt(self, text):
1215
 
        return self._run_ssl(text, 'dec')
 
1211
        return self._run_ssl(text, '-d')