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

[tor-commits] [stem/master] Parse signing certificate field



commit 2a98ba70f1e8a0ba7b3e0b1141ad69cfec98fba5
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Aug 24 15:37:43 2019 -0700

    Parse signing certificate field
---
 stem/descriptor/hidden_service.py         | 10 +++++++---
 test/unit/descriptor/hidden_service_v3.py |  9 +++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index 4af40d46..84b8d5e7 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -183,7 +183,8 @@ _parse_publication_time_line = _parse_timestamp_line('publication-time', 'publis
 _parse_signature_line = _parse_key_block('signature', 'signature', 'SIGNATURE')
 
 _parse_v3_version_line = _parse_int_line('hs-descriptor', 'version', allow_negative = False)
-_parse_lifetime = _parse_int_line('descriptor-lifetime', 'lifetime', allow_negative = False)
+_parse_lifetime_line = _parse_int_line('descriptor-lifetime', 'lifetime', allow_negative = False)
+_parse_signing_key_line = _parse_key_block('descriptor-signing-key-cert', 'signing_cert', 'ED25519 CERT')
 
 
 class BaseHiddenServiceDescriptor(Descriptor):
@@ -462,6 +463,7 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
 
   :var int version: **\\*** hidden service descriptor version
   :var int lifetime: **\\*** minutes after publication this descriptor is valid
+  :var str signing_cert: **\\*** cross-certifier for the short-term descriptor signing key
 
   **\\*** attribute is either required when we're parsed with validation or has
   a default value, others are left as **None** if undefined
@@ -473,12 +475,14 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
 
   ATTRIBUTES = {
     'version': (None, _parse_v3_version_line),
-    'lifetime': (None, _parse_lifetime),
+    'lifetime': (None, _parse_lifetime_line),
+    'signing_cert': (None, _parse_signing_key_line),
   }
 
   PARSER_FOR_LINE = {
     'hs-descriptor': _parse_v3_version_line,
-    'descriptor-lifetime': _parse_lifetime,
+    'descriptor-lifetime': _parse_lifetime_line,
+    'descriptor-signing-key-cert': _parse_signing_key_line,
   }
 
   @classmethod
diff --git a/test/unit/descriptor/hidden_service_v3.py b/test/unit/descriptor/hidden_service_v3.py
index b7a23c86..07a8e32c 100644
--- a/test/unit/descriptor/hidden_service_v3.py
+++ b/test/unit/descriptor/hidden_service_v3.py
@@ -16,6 +16,14 @@ from test.unit.descriptor import (
 
 expect_invalid_attr = functools.partial(base_expect_invalid_attr, HiddenServiceDescriptorV3, 'version', 3)
 
+EXPECTED_SIGNING_CERT = """\
+-----BEGIN ED25519 CERT-----
+AQgABqKwAQVql1QZETyEwJjg+Cv6f2w/cp+c3juj01NPBaJqihboAQAgBACx+FKK
+oDrFE1+ztSxzN8sApKOb5UuDtoe/E03DxZU5+r/K5AV6G0hYn21V7Xbu2pZHvIkT
+2oVY4hypWNJE58eFBRFRzBA0J2h0GyFs1pIuRh5QDJuxB5j92V0aRCNZFgM=
+-----END ED25519 CERT-----\
+"""
+
 
 class TestHiddenServiceDescriptorV3(unittest.TestCase):
   def test_for_riseup(self):
@@ -30,6 +38,7 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
 
     self.assertEqual(3, desc.version)
     self.assertEqual(180, desc.lifetime)
+    self.assertEqual(EXPECTED_SIGNING_CERT, desc.signing_cert)
 
   def test_invalid_version(self):
     """



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