summaryrefslogtreecommitdiffstats
path: root/nova/crypto.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-17 13:13:44 +0000
committerGerrit Code Review <review@openstack.org>2013-01-17 13:13:44 +0000
commitf966e0f7126864bbd782505348a7ddda340694b1 (patch)
tree5898c8e249db620016906cac0a22fc83db739bdd /nova/crypto.py
parentfc7edc1bf1ae4f392c0a566dc952a9b3674657f1 (diff)
parentdaa5db3f4e990185522f38d1011cfe37141298fe (diff)
downloadnova-f966e0f7126864bbd782505348a7ddda340694b1.tar.gz
nova-f966e0f7126864bbd782505348a7ddda340694b1.tar.xz
nova-f966e0f7126864bbd782505348a7ddda340694b1.zip
Merge "Add encryption method using an ssh public key."
Diffstat (limited to 'nova/crypto.py')
-rw-r--r--nova/crypto.py43
1 files changed, 37 insertions, 6 deletions
diff --git a/nova/crypto.py b/nova/crypto.py
index ff76a54d0..68d25e650 100644
--- a/nova/crypto.py
+++ b/nova/crypto.py
@@ -171,13 +171,44 @@ def decrypt_text(project_id, text):
raise exception.ProjectNotFound(project_id=project_id)
try:
dec, _err = utils.execute('openssl',
- 'rsautl',
- '-decrypt',
- '-inkey', '%s' % private_key,
- process_input=text)
+ 'rsautl',
+ '-decrypt',
+ '-inkey', '%s' % private_key,
+ process_input=text)
return dec
- except exception.ProcessExecutionError:
- raise exception.DecryptionFailure()
+ except exception.ProcessExecutionError as exc:
+ raise exception.DecryptionFailure(reason=exc.stderr)
+
+
+def ssh_encrypt_text(ssh_public_key, text):
+ """Encrypt text with an ssh public key.
+
+ Requires recent ssh-keygen binary in addition to openssl binary.
+ """
+ with utils.tempdir() as tmpdir:
+ sshkey = os.path.abspath(os.path.join(tmpdir, 'ssh.key'))
+ with open(sshkey, 'w') as f:
+ f.write(ssh_public_key)
+ sslkey = os.path.abspath(os.path.join(tmpdir, 'ssl.key'))
+ try:
+ # NOTE(vish): -P is to skip prompt on bad keys
+ out, _err = utils.execute('ssh-keygen',
+ '-P', '',
+ '-e',
+ '-f', sshkey,
+ '-m', 'PKCS8')
+ with open(sslkey, 'w') as f:
+ f.write(out)
+ enc, _err = utils.execute('openssl',
+ 'rsautl',
+ '-encrypt',
+ '-pubin',
+ '-inkey', sslkey,
+ '-keyform', 'PEM',
+ process_input=text)
+ return enc
+ except exception.ProcessExecutionError as exc:
+ raise exception.EncryptionFailure(reason=exc.stderr)
def revoke_cert(project_id, file_name):