summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2004-09-25 22:07:59 +0000
committerRobey Pointer <robey@lag.net>2004-09-25 22:07:59 +0000
commite1639180f99a381e879b29c2ca25cbe02fe09f02 (patch)
treec2bdc964797571c9433e6839a934a1217f7ee8aa /tests
parentec3df4cc0d04a62de33faa0c8e7bb0eb4be75289 (diff)
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-92]
add rsa/dss key object unit tests add tests for rsa/dss key objects -- yay!
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dss.key12
-rw-r--r--tests/test_pkey.py114
-rw-r--r--tests/test_rsa.key15
3 files changed, 141 insertions, 0 deletions
diff --git a/tests/test_dss.key b/tests/test_dss.key
new file mode 100644
index 00000000..e10807f1
--- /dev/null
+++ b/tests/test_dss.key
@@ -0,0 +1,12 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBuwIBAAKBgQDngaYDZ30c6/7cJgEEbtl8FgKdwhba1Z7oOrOn4MI/6C42G1bY
+wMuqZf4dBCglsdq39SHrcjbE8Vq54gPSOh3g4+uV9Rcg5IOoPLbwp2jQfF6f1FIb
+sx7hrDCIqUcQccPSxetPBKmXI9RN8rZLaFuQeTnI65BKM98Ruwvq6SI2LwIVAPDP
+hSeawaJI27mKqOfe5PPBSmyHAoGBAJMXxXmPD9sGaQ419DIpmZecJKBUAy9uXD8x
+gbgeDpwfDaFJP8owByCKREocPFfi86LjCuQkyUKOfjYMN6iHIf1oEZjB8uJAatUr
+FzI0ArXtUqOhwTLwTyFuUojE5own2WYsOAGByvgfyWjsGhvckYNhI4ODpNdPlxQ8
+ZamaPGPsAoGARmR7CCPjodxASvRbIyzaVpZoJ/Z6x7dAumV+ysrV1BVYd0lYukmn
+jO1kKBWApqpH1ve9XDQYN8zgxM4b16L21kpoWQnZtXrY3GZ4/it9kUgyB7+NwacI
+BlXa8cMDL7Q/69o0d54U0X/NeX5QxuYR6OMJlrkQB7oiW/P/1mwjQgECFGI9QPSc
+h9pT9XHqn+1rZ4bK+QGA
+-----END DSA PRIVATE KEY-----
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
new file mode 100644
index 00000000..6bbeb53d
--- /dev/null
+++ b/tests/test_pkey.py
@@ -0,0 +1,114 @@
+#!/usr/bin/python
+
+# Copyright (C) 2003-2004 Robey Pointer <robey@lag.net>
+#
+# This file is part of paramiko.
+#
+# Paramiko is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+"""
+Some unit tests for public/private key objects.
+"""
+
+import unittest
+from paramiko import RSAKey, DSSKey, Message, util, randpool
+
+# from openssh's ssh-keygen
+PUB_RSA = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA049W6geFpmsljTwfvI1UmKWWJPNFI74+vNKTk4dmzkQY2yAMs6FhlvhlI8ysU4oj71ZsRYMecHbBbxdN79+JRFVYTKaLqjwGENeTd+yv4q+V2PvZv3fLnzApI3l7EJCqhWwJUHJ1jAkZzqDx0tyOL4uoZpww3nmE0kb3y21tH4c='
+PUB_DSS = 'ssh-dss AAAAB3NzaC1kc3MAAACBAOeBpgNnfRzr/twmAQRu2XwWAp3CFtrVnug6s6fgwj/oLjYbVtjAy6pl/h0EKCWx2rf1IetyNsTxWrniA9I6HeDj65X1FyDkg6g8tvCnaNB8Xp/UUhuzHuGsMIipRxBxw9LF608EqZcj1E3ytktoW5B5OcjrkEoz3xG7C+rpIjYvAAAAFQDwz4UnmsGiSNu5iqjn3uTzwUpshwAAAIEAkxfFeY8P2wZpDjX0MimZl5wkoFQDL25cPzGBuB4OnB8NoUk/yjAHIIpEShw8V+LzouMK5CTJQo5+Ngw3qIch/WgRmMHy4kBq1SsXMjQCte1So6HBMvBPIW5SiMTmjCfZZiw4AYHK+B/JaOwaG9yRg2Ejg4Ok10+XFDxlqZo8Y+wAAACARmR7CCPjodxASvRbIyzaVpZoJ/Z6x7dAumV+ysrV1BVYd0lYukmnjO1kKBWApqpH1ve9XDQYN8zgxM4b16L21kpoWQnZtXrY3GZ4/it9kUgyB7+NwacIBlXa8cMDL7Q/69o0d54U0X/NeX5QxuYR6OMJlrkQB7oiW/P/1mwjQgE='
+FINGER_RSA = '1024 60:73:38:44:cb:51:86:65:7f:de:da:a2:2b:5a:57:d5'
+FINGER_DSS = '1024 44:78:f0:b9:a2:3c:c5:18:20:09:ff:75:5b:c1:d2:6c'
+SIGNED_RSA = '20:d7:8a:31:21:cb:f7:92:12:f2:a4:89:37:f5:78:af:e6:16:b6:25:b9:97:3d:a2:cd:5f:ca:20:21:73:4c:ad:34:73:8f:20:77:28:e2:94:15:08:d8:91:40:7a:85:83:bf:18:37:95:dc:54:1a:9b:88:29:6c:73:ca:38:b4:04:f1:56:b9:f2:42:9d:52:1b:29:29:b4:4f:fd:c9:2d:af:47:d2:40:76:30:f3:63:45:0c:d9:1d:43:86:0f:1c:70:e2:93:12:34:f3:ac:c5:0a:2f:14:50:66:59:f1:88:ee:c1:4a:e9:d1:9c:4e:46:f0:0e:47:6f:38:74:f1:44:a8'
+
+
+class KeyTest (unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_1_load_rsa(self):
+ key = RSAKey.from_private_key_file('tests/test_rsa.key')
+ self.assertEquals('ssh-rsa', key.get_name())
+ exp_rsa = FINGER_RSA.split()[1].replace(':', '')
+ my_rsa = util.hexify(key.get_fingerprint()).lower()
+ self.assertEquals(exp_rsa, my_rsa)
+ self.assertEquals(PUB_RSA.split()[1], key.get_base64())
+ self.assertEquals(1024, key.get_bits())
+
+ def test_2_load_dss(self):
+ key = DSSKey.from_private_key_file('tests/test_dss.key')
+ self.assertEquals('ssh-dss', key.get_name())
+ exp_dss = FINGER_DSS.split()[1].replace(':', '')
+ my_dss = util.hexify(key.get_fingerprint()).lower()
+ self.assertEquals(exp_dss, my_dss)
+ self.assertEquals(PUB_DSS.split()[1], key.get_base64())
+ self.assertEquals(1024, key.get_bits())
+
+ def test_3_compare_rsa(self):
+ # verify that the private & public keys compare equal
+ key = RSAKey.from_private_key_file('tests/test_rsa.key')
+ self.assertEquals(key, key)
+ pub = RSAKey(data=str(key))
+ self.assert_(key.can_sign())
+ self.assert_(not pub.can_sign())
+ self.assertEquals(key, pub)
+
+ def test_4_compare_dss(self):
+ # verify that the private & public keys compare equal
+ key = DSSKey.from_private_key_file('tests/test_dss.key')
+ self.assertEquals(key, key)
+ pub = DSSKey(data=str(key))
+ self.assert_(key.can_sign())
+ self.assert_(not pub.can_sign())
+ self.assertEquals(key, pub)
+
+ def test_5_sign_rsa(self):
+ # verify that the rsa private key can sign and verify
+ key = RSAKey.from_private_key_file('tests/test_rsa.key')
+ msg = key.sign_ssh_data(randpool, 'ice weasels')
+ self.assert_(type(msg) is Message)
+ self.assertEquals('ssh-rsa', msg.get_string())
+ sig = ''.join([chr(int(x, 16)) for x in SIGNED_RSA.split(':')])
+ self.assertEquals(sig, msg.get_string())
+ msg.rewind()
+ pub = RSAKey(data=str(key))
+ self.assert_(pub.verify_ssh_sig('ice weasels', msg))
+
+ def test_6_sign_dss(self):
+ # verify that the dss private key can sign and verify
+ key = DSSKey.from_private_key_file('tests/test_dss.key')
+ msg = key.sign_ssh_data(randpool, 'ice weasels')
+ self.assert_(type(msg) is Message)
+ self.assertEquals('ssh-dss', msg.get_string())
+ # can't do the same test as we do for RSA, because DSS signatures
+ # are usually different each time. but we can test verification
+ # anyway so it's ok.
+ self.assertEquals(40, len(msg.get_string()))
+ msg.rewind()
+ pub = DSSKey(data=str(key))
+ self.assert_(pub.verify_ssh_sig('ice weasels', msg))
+
+ def test_7_generate_rsa(self):
+ key = RSAKey.generate(1024)
+ msg = key.sign_ssh_data(randpool, 'jerri blank')
+ self.assert_(key.verify_ssh_sig('jerri blank', msg))
+
+ def test_8_generate_dss(self):
+ key = DSSKey.generate(1024)
+ msg = key.sign_ssh_data(randpool, 'jerri blank')
+ self.assert_(key.verify_ssh_sig('jerri blank', msg))
diff --git a/tests/test_rsa.key b/tests/test_rsa.key
new file mode 100644
index 00000000..f50e9c53
--- /dev/null
+++ b/tests/test_rsa.key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICWgIBAAKBgQDTj1bqB4WmayWNPB+8jVSYpZYk80Ujvj680pOTh2bORBjbIAyz
+oWGW+GUjzKxTiiPvVmxFgx5wdsFvF03v34lEVVhMpouqPAYQ15N37K/ir5XY+9m/
+d8ufMCkjeXsQkKqFbAlQcnWMCRnOoPHS3I4vi6hmnDDeeYTSRvfLbW0fhwIBIwKB
+gBIiOqZYaoqbeD9OS9z2K9KR2atlTxGxOJPXiP4ESqP3NVScWNwyZ3NXHpyrJLa0
+EbVtzsQhLn6rF+TzXnOlcipFvjsem3iYzCpuChfGQ6SovTcOjHV9z+hnpXvQ/fon
+soVRZY65wKnF7IAoUwTmJS9opqgrN6kRgCd3DASAMd1bAkEA96SBVWFt/fJBNJ9H
+tYnBKZGw0VeHOYmVYbvMSstssn8un+pQpUm9vlG/bp7Oxd/m+b9KWEh2xPfv6zqU
+avNwHwJBANqzGZa/EpzF4J8pGti7oIAPUIDGMtfIcmqNXVMckrmzQ2vTfqtkEZsA
+4rE1IERRyiJQx6EJsz21wJmGV9WJQ5kCQQDwkS0uXqVdFzgHO6S++tjmjYcxwr3g
+H0CoFYSgbddOT6miqRskOQF3DZVkJT3kyuBgU2zKygz52ukQZMqxCb1fAkASvuTv
+qfpH87Qq5kQhNKdbbwbmd2NxlNabazPijWuphGTdW0VfJdWfklyS2Kr+iqrs/5wV
+HhathJt636Eg7oIjAkA8ht3MQ+XSl9yIJIS8gVpbPxSw5OMfw0PjVE7tBdQruiSc
+nvuQES5C9BMHjF39LZiGH1iLQy7FgdHyoP+eodI7
+-----END RSA PRIVATE KEY-----