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

[tor-commits] [stem/master] HSv3 introductory point encoding



commit 0b7b6bb7a7d1b5daa5ca26c8339d9cb6b3f3d518
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Oct 30 15:55:03 2019 -0700

    HSv3 introductory point encoding
    
    Now that we have the building blocks it's a simple matter for us to encode HSv3
    introductory points back into strings.
---
 stem/descriptor/hidden_service.py         | 33 ++++++++++++++++++++++++++++++-
 test/unit/descriptor/hidden_service_v3.py |  8 ++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index 72fc9b2b..09030ca5 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -163,7 +163,7 @@ class IntroductionPointV3(collections.namedtuple('IntroductionPointV3', ['link_s
   :var str enc_key_raw: base64 introduction request encryption key
   :var stem.certificate.Ed25519Certificate enc_key_cert: cross-certifier of the signing key by the encryption key
   :var str legacy_key_raw: base64 legacy introduction point RSA public key
-  :var str legacy_key_cert: cross-certifier of the signing key by the legacy key
+  :var str legacy_key_cert: base64 cross-certifier of the signing key by the legacy key
   """
 
   @staticmethod
@@ -204,6 +204,37 @@ class IntroductionPointV3(collections.namedtuple('IntroductionPointV3', ['link_s
 
     return IntroductionPointV3(link_specifiers, onion_key, auth_key_cert, enc_key, enc_key_cert, legacy_key, legacy_key_cert)
 
+  def encode(self):
+    """
+    Descriptor representation of this introduction point.
+
+    :returns: **str** for our descriptor representation
+    """
+
+    lines = []
+
+    link_count = stem.client.datatype.Size.CHAR.pack(len(self.link_specifiers))
+    link_specifiers = link_count + ''.join([l.pack() for l in self.link_specifiers])
+    lines.append('introduction-point %s' % base64.b64encode(link_specifiers))
+
+    if self.onion_key_raw:
+      lines.append('onion-key ntor %s' % self.onion_key_raw)
+
+    lines.append('auth-key\n' + self.auth_key_cert.to_base64(pem = True))
+
+    if self.enc_key_raw:
+      lines.append('enc-key ntor %s' % self.enc_key_raw)
+
+    lines.append('enc-key-cert\n' + self.enc_key_cert.to_base64(pem = True))
+
+    if self.legacy_key_raw:
+      lines.append('legacy-key\n' + self.legacy_key_raw)
+
+    if self.legacy_key_cert:
+      lines.append('legacy-key-cert\n' + self.legacy_key_cert)
+
+    return '\n'.join(lines)
+
   def onion_key(self):
     """
     Provides our ntor introduction point public key.
diff --git a/test/unit/descriptor/hidden_service_v3.py b/test/unit/descriptor/hidden_service_v3.py
index 6f8ba69e..fb190211 100644
--- a/test/unit/descriptor/hidden_service_v3.py
+++ b/test/unit/descriptor/hidden_service_v3.py
@@ -284,6 +284,14 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
     self.assertTrue('JAoGBAMO3' in intro_point.legacy_key_raw)
     self.assertTrue('Ln1ITJ0qP' in intro_point.legacy_key_cert)
 
+  def test_intro_point_encode(self):
+    """
+    Encode an introduction point back into a string.
+    """
+
+    intro_point = IntroductionPointV3.parse(INTRO_POINT_STR)
+    self.assertEqual(INTRO_POINT_STR.rstrip(), intro_point.encode())
+
   @require_x25519
   @test.require.ed25519_support
   def test_intro_point_crypto(self):



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