[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Adding support for '@type dir-key-certificate-3 1.0'



commit fa6ef6bca6e703e9b69a140ec5abe4c972122872
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Jan 18 09:24:11 2013 -0800

    Adding support for '@type dir-key-certificate-3 1.0'
    
    We already parsed key certificates for network status documents. I didn't know
    though that they had their own @type annotation.
    
    Test data is from...
    
    https://metrics.torproject.org/data/certs.tar.bz2
    https://trac.torproject.org/7987
---
 stem/descriptor/__init__.py             |    4 ++-
 test/integ/descriptor/data/metrics_cert |   34 ++++++++++++++++++++
 test/integ/descriptor/networkstatus.py  |   52 +++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 1 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index aec8632..7280222 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -68,7 +68,7 @@ def parse_file(descriptor_file, descriptor_type = None, path = None):
   extra-info 1.0                        :class:`~stem.descriptor.extrainfo_descriptor.RelayExtraInfoDescriptor`
   directory 1.0                         **unsupported**
   network-status-2 1.0                  :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV2` (with a :class:`~stem.descriptor.networkstatus.NetworkStatusDocumentV2`)
-  dir-key-certificate-3 1.0             **unsupported**
+  dir-key-certificate-3 1.0             :class:`~stem.descriptor.networkstatus.KeyCertificate`
   network-status-consensus-3 1.0        :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3` (with a :class:`~stem.descriptor.networkstatus.NetworkStatusDocumentV3`)
   network-status-vote-3 1.0             :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3` (with a :class:`~stem.descriptor.networkstatus.NetworkStatusDocumentV3`)
   network-status-microdesc-consensus-3  :class:`~stem.descriptor.router_status_entry.RouterStatusEntryMicroV3` (with a :class:`~stem.descriptor.networkstatus.NetworkStatusDocumentV3`)
@@ -168,6 +168,8 @@ def _parse_metrics_file(descriptor_type, major_version, minor_version, descripto
 
     for desc in stem.descriptor.networkstatus._parse_file(descriptor_file, document_type):
       yield desc
+  elif descriptor_type == "dir-key-certificate-3" and major_version == 1:
+    yield stem.descriptor.networkstatus.KeyCertificate(descriptor_file.read())
   elif descriptor_type in ("network-status-consensus-3", "network-status-vote-3") and major_version == 1:
     document_type = stem.descriptor.networkstatus.NetworkStatusDocumentV3
 
diff --git a/test/integ/descriptor/data/metrics_cert b/test/integ/descriptor/data/metrics_cert
new file mode 100644
index 0000000..510bfd8
--- /dev/null
+++ b/test/integ/descriptor/data/metrics_cert
@@ -0,0 +1,34 @@
+@type dir-key-certificate-3 1.0
+dir-key-certificate-version 3
+fingerprint 14C131DFC5C6F93646BE72FA1401C02A8DF2E8B4
+dir-key-published 2008-05-09 21:13:26
+dir-key-expires 2009-05-09 21:13:26
+dir-identity-key
+-----BEGIN RSA PUBLIC KEY-----
+MIIBigKCAYEA7cZXvDRxfjDYtr9/9UsQ852+6cmHMr8VVh8GkLwbq3RzqjkULwQ2
+R9mFvG4FnqMcMKXi62rYYA3fZL1afhT804cpvyp/D3dPM8QxW88fafFAgIFP4LiD
+0JYjnF8cva5qZ0nzlWnMXLb32IXSvsGSE2FRyAV0YN9a6k967LSgCfUnZ+IKMezW
+1vhL9YK4QIfsDowgtVsavg63GzGmA7JvZmn77+/J5wKz11vGr7Wttf8XABbH2taX
+O9j/KGBOX2OKhoF3mXfZSmUO2dV9NMwtkJ7zD///Ny6sfApWV6kVP4O9TdG3bAsl
++fHCoCKgF/jAAWzh6VckQTOPzQZaH5aMWfXrDlzFWg17MjonI+bBTD2Ex2pHczzJ
+bN7coDMRH2SuOXv8wFf27KdUxZ/GcrXSRGzlRLygxqlripUanjVGN2JvrVQVr0kz
+pjNjiZl2z8ZyZ5d4zQuBi074JPGgx62xAstP37v1mPw14sIWfLgY16ewYuS5bCxV
+lyS28jsPht9VAgMBAAE=
+-----END RSA PUBLIC KEY-----
+dir-signing-key
+-----BEGIN RSA PUBLIC KEY-----
+MIGJAoGBAOeE3Qr1Km97gTgiB3io0EU0fqHW2ESMXVHeQuNDtCWBa0XSCEG6gx4B
+ZkkHjfVWqGQ7TmmzjYP9L9uCgtoKfhSvJA2w9NUMtMl8sgZmF4lcGpXXvGY9a566
+Bn+3wP0lMhb/I8CPVPX+NWEjgl1noZxo1C59SO/iALGQOpxRYgmbAgMBAAE=
+-----END RSA PUBLIC KEY-----
+dir-key-certification
+-----BEGIN SIGNATURE-----
+asvWwaMq34OfHoWUhAwh4+JDOuEUZJVIHQnedOYfQH8asS2QvW3Ma93OhrwVOC6b
+FyKmTJmJsl0MJGiC7tcEOlL6knsKE4CsuIw/PEcu2Rnm+R9zWxQuMYiHvGQMoDxl
+giOhLLs4LlzAAJlbfbd3hjF4STVAtTwmxYuIjb1Mq/JfAsx/wH3TLXgVZwj32w9s
+zUd9KZwwLzFiiHpC+U7zh6+wRsZfo2tlpmcaP1dTSINgVbdzPJ/DOUlx9nwTCBsE
+AQpUx2DpAikwrpw0zDqpQvYulcQlNLWFN/y/PkmiK8mIJk0OBMiQA7JgqWamnnk4
+PwqaGv483LkBF+25JFGJmnUVve3RMc+s61+2kBcjfUMed4QaHkeCMHqlRqpfQVkk
+RY22NXCwrJvSMEwiy7acC8FGysqwHRyE356+Rw6TB43g3Tno9KaHEK7MHXjSHwNs
+GM9hAsAMRX9Ogqhq5UjDNqEsvDKuyVeyh7unSZEOip9Zr6K/+7VsVPNb8vfBRBjo
+-----END SIGNATURE-----
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index e34960a..c654158 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -148,6 +148,58 @@ class TestNetworkStatus(unittest.TestCase):
       self.assertEquals(443, router.or_port)
       self.assertEquals(None, router.dir_port)
 
+  def test_metrics_cert(self):
+    """
+    Checks if consensus documents from Metrics are parsed properly.
+    """
+
+    expected_identity_key = """-----BEGIN RSA PUBLIC KEY-----
+MIIBigKCAYEA7cZXvDRxfjDYtr9/9UsQ852+6cmHMr8VVh8GkLwbq3RzqjkULwQ2
+R9mFvG4FnqMcMKXi62rYYA3fZL1afhT804cpvyp/D3dPM8QxW88fafFAgIFP4LiD
+0JYjnF8cva5qZ0nzlWnMXLb32IXSvsGSE2FRyAV0YN9a6k967LSgCfUnZ+IKMezW
+1vhL9YK4QIfsDowgtVsavg63GzGmA7JvZmn77+/J5wKz11vGr7Wttf8XABbH2taX
+O9j/KGBOX2OKhoF3mXfZSmUO2dV9NMwtkJ7zD///Ny6sfApWV6kVP4O9TdG3bAsl
++fHCoCKgF/jAAWzh6VckQTOPzQZaH5aMWfXrDlzFWg17MjonI+bBTD2Ex2pHczzJ
+bN7coDMRH2SuOXv8wFf27KdUxZ/GcrXSRGzlRLygxqlripUanjVGN2JvrVQVr0kz
+pjNjiZl2z8ZyZ5d4zQuBi074JPGgx62xAstP37v1mPw14sIWfLgY16ewYuS5bCxV
+lyS28jsPht9VAgMBAAE=
+-----END RSA PUBLIC KEY-----"""
+
+    expected_signing_key = """-----BEGIN RSA PUBLIC KEY-----
+MIGJAoGBAOeE3Qr1Km97gTgiB3io0EU0fqHW2ESMXVHeQuNDtCWBa0XSCEG6gx4B
+ZkkHjfVWqGQ7TmmzjYP9L9uCgtoKfhSvJA2w9NUMtMl8sgZmF4lcGpXXvGY9a566
+Bn+3wP0lMhb/I8CPVPX+NWEjgl1noZxo1C59SO/iALGQOpxRYgmbAgMBAAE=
+-----END RSA PUBLIC KEY-----"""
+
+    expected_key_cert = """-----BEGIN SIGNATURE-----
+asvWwaMq34OfHoWUhAwh4+JDOuEUZJVIHQnedOYfQH8asS2QvW3Ma93OhrwVOC6b
+FyKmTJmJsl0MJGiC7tcEOlL6knsKE4CsuIw/PEcu2Rnm+R9zWxQuMYiHvGQMoDxl
+giOhLLs4LlzAAJlbfbd3hjF4STVAtTwmxYuIjb1Mq/JfAsx/wH3TLXgVZwj32w9s
+zUd9KZwwLzFiiHpC+U7zh6+wRsZfo2tlpmcaP1dTSINgVbdzPJ/DOUlx9nwTCBsE
+AQpUx2DpAikwrpw0zDqpQvYulcQlNLWFN/y/PkmiK8mIJk0OBMiQA7JgqWamnnk4
+PwqaGv483LkBF+25JFGJmnUVve3RMc+s61+2kBcjfUMed4QaHkeCMHqlRqpfQVkk
+RY22NXCwrJvSMEwiy7acC8FGysqwHRyE356+Rw6TB43g3Tno9KaHEK7MHXjSHwNs
+GM9hAsAMRX9Ogqhq5UjDNqEsvDKuyVeyh7unSZEOip9Zr6K/+7VsVPNb8vfBRBjo
+-----END SIGNATURE-----"""
+
+    cert_path = test.integ.descriptor.get_resource("metrics_cert")
+
+    with open(cert_path) as cert_file:
+      certs = stem.descriptor.parse_file(cert_file, path = cert_path)
+
+      cert = next(certs)
+      self.assertEquals(3, cert.version)
+      self.assertEquals(None, cert.address)
+      self.assertEquals(None, cert.dir_port)
+      self.assertEquals("14C131DFC5C6F93646BE72FA1401C02A8DF2E8B4", cert.fingerprint)
+      self.assertEquals(expected_identity_key, cert.identity_key)
+      self.assertEquals(datetime.datetime(2008, 5, 9, 21, 13, 26), cert.published)
+      self.assertEquals(datetime.datetime(2009, 5, 9, 21, 13, 26), cert.expires)
+      self.assertEquals(expected_signing_key, cert.signing_key)
+      self.assertEquals(None, cert.crosscert)
+      self.assertEquals(expected_key_cert, cert.certification)
+      self.assertEquals([], cert.get_unrecognized_lines())
+
   def test_consensus_v3(self):
     """
     Checks that version 3 consensus documents are properly parsed.

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits