Unverified Commit 7d42052b authored by ANURADHAJHA99's avatar ANURADHAJHA99 Committed by teor
Browse files

Added function in TorNet.py to make chutney check for relay microdescriptors before verifying

parent 65f4b301
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import signal
import subprocess
import sys
import time
import base64

from chutney.Debug import debug_flag, debug

@@ -684,6 +685,7 @@ class LocalNodeBuilder(NodeBuilder):
            self._genAuthorityKey()
        if self._env['relay']:
            self._genRouterKey()
            self._setEd25519Id()
        if self._env['hs']:
            self._makeHiddenServiceDir()
            
@@ -781,6 +783,31 @@ class LocalNodeBuilder(NodeBuilder):
            sys.exit(1)
        self._env['fingerprint'] = fingerprint
       
    def _setEd25519Id(self):
        """Read the ed25519 identity key for this router, and set up the 'ed25519-id' entry in the Environ"""
        datadir = self._env['dir']
        key_file = os.path.join(datadir, 'keys', "ed25519_master_id_public_key")
        EXPECTED_ED25519_FILE_SIZE = 64
        CURRENT_FILE_SIZE = os.stat(key_file).st_size
        if not os.path.exists(key_file):
            print("File {} does not exist. Are you running a very old tor version?".format(key_file))
            return
        elif CURRENT_FILE_SIZE != EXPECTED_ED25519_FILE_SIZE:
            raise ValueError("The current size of the file is {} bytes, which is not matching the expected value of {} bytes".format(CURRENT_FILE_SIZE, EXPECTED_ED25519_FILE_SIZE))
        else:
            with open(key_file, 'rb') as f:
                ED25519_KEY_POSITION = 32
                f.seek(ED25519_KEY_POSITION)
                rest_file = f.read()
                encoded_value = base64.b64encode(rest_file)
                ed25519_id = encoded_value.decode('utf-8').replace('=', '')
                EXPECTED_ED25519_BASE64_KEY_SIZE = 43
                CURRENT_ED25519_BASE64_KEY_SIZE = len(ed25519_id)
                if CURRENT_ED25519_BASE64_KEY_SIZE != EXPECTED_ED25519_BASE64_KEY_SIZE:
                    raise ValueError("The current length of the key is {}, which is not matching the expected length of {}".format(CURRENT_ED25519_BASE64_KEY_SIZE, EXPECTED_ED25519_BASE64_KEY_SIZE))
                else:
                    self._env['ed25519-id'] = ed25519_id
            
    def _getAltAuthLines(self, hasbridgeauth=False):
        """Return a combination of AlternateDirAuthority,
        and AlternateBridgeAuthority lines for