summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorPaul Kapp <paullkapp+radssh@gmail.com>2017-08-22 06:31:47 -0400
committerPaul Kapp <paullkapp+radssh@gmail.com>2017-08-22 06:31:47 -0400
commit7229597ce0925ee8dafe97544f42dcc193fbad8f (patch)
treed0578884ddc4d79aad3699298600dd5fd8d0fd83 /tests
parent08f503740182608570ac87661225fe2e11914d8f (diff)
Generic certificate support
Roll agnostic certificate support into PKey, and tweak publickey authentication to use it only if set. Requires explicit call to PKey.load_certificate() in order to alter the authentication behavior.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pkey.py24
-rw-r--r--tests/test_rsa.key-cert.pub1
-rw-r--r--tests/test_rsa.key.pub1
3 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
index 9bb3c44c..034331a2 100644
--- a/tests/test_pkey.py
+++ b/tests/test_pkey.py
@@ -480,3 +480,27 @@ class KeyTest(unittest.TestCase):
self.assert_keyfile_is_encrypted(newfile)
finally:
os.remove(newfile)
+
+ def test_certificates(self):
+ # PKey.load_certificate
+ key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
+ self.assertTrue(key.public_blob is None)
+ key.load_certificate(pubkey_filename=test_path('test_rsa.key-cert.pub'))
+ self.assertTrue(key.public_blob is not None)
+ self.assertEqual(key.public_blob.key_type, 'ssh-rsa-cert-v01@openssh.com')
+ self.assertEqual(key.public_blob.comment, 'test_rsa.key.pub')
+ # Delve into blob contents, for test purposes
+ msg = Message(key.public_blob.key_blob)
+ self.assertEqual(msg.get_string(), 'ssh-rsa-cert-v01@openssh.com')
+ nonce = msg.get_string()
+ e = msg.get_mpint()
+ n = msg.get_mpint()
+ self.assertEqual(e, key.public_numbers.e)
+ self.assertEqual(n, key.public_numbers.n)
+ # Serial number
+ self.assertEqual(msg.get_int64(), 1234)
+
+ # Prevented from loading certificate that doesn't match
+ key1 = Ed25519Key.from_private_key_file(test_path('test_ed25519.key'))
+ self.assertRaises(ValueError, key1.load_certificate,
+ pubkey_filename=test_path('test_rsa.key-cert.pub'))
diff --git a/tests/test_rsa.key-cert.pub b/tests/test_rsa.key-cert.pub
new file mode 100644
index 00000000..7487ab66
--- /dev/null
+++ b/tests/test_rsa.key-cert.pub
@@ -0,0 +1 @@
+ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgsZlXTd5NE4uzGAn6TyAqQj+IPbsTEFGap2x5pTRwQR8AAAABIwAAAIEA049W6geFpmsljTwfvI1UmKWWJPNFI74+vNKTk4dmzkQY2yAMs6FhlvhlI8ysU4oj71ZsRYMecHbBbxdN79+JRFVYTKaLqjwGENeTd+yv4q+V2PvZv3fLnzApI3l7EJCqhWwJUHJ1jAkZzqDx0tyOL4uoZpww3nmE0kb3y21tH4cAAAAAAAAE0gAAAAEAAAAmU2FtcGxlIHNlbGYtc2lnbmVkIE9wZW5TU0ggY2VydGlmaWNhdGUAAAASAAAABXVzZXIxAAAABXVzZXIyAAAAAAAAAAD//////////wAAAAAAAACCAAAAFXBlcm1pdC1YMTEtZm9yd2FyZGluZwAAAAAAAAAXcGVybWl0LWFnZW50LWZvcndhcmRpbmcAAAAAAAAAFnBlcm1pdC1wb3J0LWZvcndhcmRpbmcAAAAAAAAACnBlcm1pdC1wdHkAAAAAAAAADnBlcm1pdC11c2VyLXJjAAAAAAAAAAAAAACVAAAAB3NzaC1yc2EAAAABIwAAAIEA049W6geFpmsljTwfvI1UmKWWJPNFI74+vNKTk4dmzkQY2yAMs6FhlvhlI8ysU4oj71ZsRYMecHbBbxdN79+JRFVYTKaLqjwGENeTd+yv4q+V2PvZv3fLnzApI3l7EJCqhWwJUHJ1jAkZzqDx0tyOL4uoZpww3nmE0kb3y21tH4cAAACPAAAAB3NzaC1yc2EAAACATFHFsARDgQevc6YLxNnDNjsFtZ08KPMyYVx0w5xm95IVZHVWSOc5w+ccjqN9HRwxV3kP7IvL91qx0Uc3MJdB9g/O6HkAP+rpxTVoTb2EAMekwp5+i8nQJW4CN2BSsbQY1M6r7OBZ5nmF4hOW/5Pu4l22lXe2ydy8kEXOEuRpUeQ= test_rsa.key.pub
diff --git a/tests/test_rsa.key.pub b/tests/test_rsa.key.pub
new file mode 100644
index 00000000..bfa1e150
--- /dev/null
+++ b/tests/test_rsa.key.pub
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA049W6geFpmsljTwfvI1UmKWWJPNFI74+vNKTk4dmzkQY2yAMs6FhlvhlI8ysU4oj71ZsRYMecHbBbxdN79+JRFVYTKaLqjwGENeTd+yv4q+V2PvZv3fLnzApI3l7EJCqhWwJUHJ1jAkZzqDx0tyOL4uoZpww3nmE0kb3y21tH4c=