From a8ff22322622aff271d39ac849618f7372552619 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 26 May 2017 21:18:58 -0400 Subject: Support decrypting keys --- tests/test_pkey.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'tests/test_pkey.py') diff --git a/tests/test_pkey.py b/tests/test_pkey.py index 24d78c3e..74330b8d 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -27,7 +27,7 @@ from binascii import hexlify from hashlib import md5 import base64 -from paramiko import RSAKey, DSSKey, ECDSAKey, Message, util +from paramiko import RSAKey, DSSKey, ECDSAKey, Ed25519Key, Message, util from paramiko.py3compat import StringIO, byte_chr, b, bytes, PY2 from tests.util import test_path @@ -112,14 +112,7 @@ TEST_KEY_BYTESTR_2 = '\x00\x00\x00\x07ssh-rsa\x00\x00\x00\x01#\x00\x00\x00\x81\x TEST_KEY_BYTESTR_3 = '\x00\x00\x00\x07ssh-rsa\x00\x00\x00\x01#\x00\x00\x00\x00ӏV\x07k%<\x1fT$E#>ғfD\x18 \x0cae#̬S#VlE\x1epvo\x17M߉DUXL<\x06\x10דw\u2bd5ٿw˟0)#y{\x10l\tPru\t\x19Π\u070e/f0yFmm\x1f' -class KeyTest (unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - +class KeyTest(unittest.TestCase): def test_1_generate_key_bytes(self): key = util.generate_key_bytes(md5, x1234, 'happy birthday', 30) exp = b'\x61\xE1\xF2\x72\xF4\xC1\xC4\x56\x15\x86\xBD\x32\x24\x98\xC0\xE9\x24\x67\x27\x80\xF4\x7B\xB3\x7D\xDA\x7D\x54\x01\x9E\x64' @@ -436,3 +429,11 @@ class KeyTest (unittest.TestCase): key = RSAKey.from_private_key_file(test_path('test_rsa.key')) comparable = TEST_KEY_BYTESTR_2 if PY2 else TEST_KEY_BYTESTR_3 self.assertEqual(str(key), comparable) + + def test_ed25519(self): + key1 = Ed25519Key.from_private_key_file(test_path('test_ed25519.key')) + key2 = Ed25519Key.from_private_key_file( + test_path('test_ed25519_password.key'), 'abc123' + ) + + self.assertNotEqual(key1.asbytes(), key2.asbytes()) -- cgit v1.2.3 From 9b98d347ce2b1ba371e4689ea42c22962ed32e8e Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 26 May 2017 21:36:43 -0400 Subject: py3k --- paramiko/ed25519key.py | 12 ++++++------ tests/test_pkey.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/test_pkey.py') diff --git a/paramiko/ed25519key.py b/paramiko/ed25519key.py index 21c69305..3e447eb7 100644 --- a/paramiko/ed25519key.py +++ b/paramiko/ed25519key.py @@ -72,9 +72,9 @@ class Ed25519Key(PKey): if message.get_bytes(len(OPENSSH_AUTH_MAGIC)) != OPENSSH_AUTH_MAGIC: raise SSHException('Invalid key') - ciphername = message.get_string() - kdfname = message.get_string() - kdfoptions = message.get_string() + ciphername = message.get_text() + kdfname = message.get_text() + kdfoptions = message.get_binary() num_keys = message.get_int() if kdfname == "none": @@ -97,7 +97,7 @@ class Ed25519Key(PKey): public_keys = [] for _ in range(num_keys): pubkey = Message(message.get_binary()) - if pubkey.get_string() != 'ssh-ed25519': + if pubkey.get_text() != 'ssh-ed25519': raise SSHException('Invalid key') public_keys.append(pubkey.get_binary()) @@ -128,7 +128,7 @@ class Ed25519Key(PKey): signing_keys = [] for i in range(num_keys): - if message.get_string() != 'ssh-ed25519': + if message.get_text() != 'ssh-ed25519': raise SSHException('Invalid key') # A copy of the public key, again, ignore. public = message.get_binary() @@ -142,7 +142,7 @@ class Ed25519Key(PKey): ) signing_keys.append(signing_key) # Comment, ignore. - message.get_string() + message.get_binary() if len(signing_keys) != 1: raise SSHException('Invalid key') diff --git a/tests/test_pkey.py b/tests/test_pkey.py index 74330b8d..a26ff170 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -433,7 +433,7 @@ class KeyTest(unittest.TestCase): def test_ed25519(self): key1 = Ed25519Key.from_private_key_file(test_path('test_ed25519.key')) key2 = Ed25519Key.from_private_key_file( - test_path('test_ed25519_password.key'), 'abc123' + test_path('test_ed25519_password.key'), b'abc123' ) self.assertNotEqual(key1.asbytes(), key2.asbytes()) -- cgit v1.2.3