From bd8c6a3c47386b798fd68a44277e11e8ec4914f5 Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Fri, 15 Nov 2013 12:23:43 +0200 Subject: [PATCH] Fixes SSH key format issue --- cloudbaseinit/utils/crypt.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cloudbaseinit/utils/crypt.py b/cloudbaseinit/utils/crypt.py index 96b1d3aa..1eee7c14 100644 --- a/cloudbaseinit/utils/crypt.py +++ b/cloudbaseinit/utils/crypt.py @@ -141,8 +141,15 @@ class CryptManager(object): def load_ssh_rsa_public_key(self, ssh_pub_key): ssh_rsa_prefix = "ssh-rsa " + if not ssh_pub_key.startswith(ssh_rsa_prefix): + raise CryptException('Invalid SSH key') + s = ssh_pub_key[len(ssh_rsa_prefix):] - b64_pub_key = s[:s.index(' ')] + idx = s.find(' ') + if idx >= 0: + b64_pub_key = s[:idx] + else: + b64_pub_key = s pub_key = base64.b64decode(b64_pub_key)