Esempio n. 1
0
 def _decrypt_basic(self, descriptor_cookie):
     assert self._crypted_data[0] == AuthType.Basic
     block_count = self._crypted_data[1]
     entries_len = block_count * self.REND_BASIC_AUTH_CLIENT_MULTIPLE * self.REND_BASIC_AUTH_CLIENT_ENTRY_LEN
     assert len(self._crypted_data) > 2 + entries_len + self.CIPHER_IV_LEN, 'Size of crypted data too small'
     iv = self._crypted_data[2 + entries_len:2 + entries_len + self.CIPHER_IV_LEN]
     client_id = sha1(descriptor_cookie + iv)[:4]
     session_key = self._get_session_key(self._crypted_data[2:2 + entries_len], descriptor_cookie, client_id)
     d = aes_ctr_decryptor(session_key, iv)
     data = self._crypted_data[2 + entries_len + self.CIPHER_IV_LEN:]
     return d.update(data)
Esempio n. 2
0
    def _get_secret_id(self, replica):
        """
        Get secret_id by replica number.

        rend-spec.txt
        1.3.

        "time-period" changes periodically as a function of time and
        "permanent-id". The current value for "time-period" can be calculated
        using the following formula:

          time-period = (current-time + permanent-id-byte * 86400 / 256)
                          / 86400
        """
        # tor ref: get_secret_id_part_bytes
        permanent_byte = self._permanent_id[0]
        time_period = int((int(time.time()) + (permanent_byte * 86400 / 256)) / 86400)
        if self._descriptor_cookie and self._auth_type == AuthType.Stealth:
            buff = struct.pack('!I16sB', time_period, self._descriptor_cookie, replica)
        else:
            buff = struct.pack('!IB', time_period, replica)
        return sha1(buff)
Esempio n. 3
0
 def _serialize_payload(self):
     #  PK_ID  Identifier for Bob's PK      [20 octets]
     return struct.pack('!20s', sha1(
         self.introduction_point.service_key)) + self.handshake_encrypted
Esempio n. 4
0
 def get_descriptor_id(self, replica):
     # tor ref: rend_compute_v2_desc_id
     # Calculate descriptor ID: H(permanent-id | secret-id-part)
     buff = self._permanent_id + self._get_secret_id(replica)
     return sha1(buff)
Esempio n. 5
0
def tor_digest(msg):
    return sha1(msg)