Example #1
0
    def test_deriveExtend2CellSecrets_DestroyCell(self, conn):
        self.circuit._conn = conn
        response = DestroyCell.make(ID)

        self.assertRaises(ValueError, self.circuit._deriveExtend2CellSecrets,
                          response, mock.Mock())
        self.assertEqual(self.circuit._conn.send.call_count, 0)
Example #2
0
    def _sendDestroyCell(self):
        '''Send a destroy cell.

        .. note:: reason NONE is always used when sending forward destroy
            cells to avoid leaking version information.
        '''
        cell = DestroyCell.make(self.circuit_id)
        self._connection.send(cell)
Example #3
0
    def _sendDestroyCell(self):
        '''Send a destroy cell.

        .. note:: reason NONE is always used when sending forward destroy
            cells to avoid leaking version information.
        '''
        cell = DestroyCell.make(self.circuit_id)
        self._connection.send(cell)
Example #4
0
    def test_deriveExtend2CellSecrets_DestroyCell(self, conn):
        self.circuit._conn = conn
        response = DestroyCell.make(ID)

        self.assertRaises(ValueError,
                          self.circuit._deriveExtend2CellSecrets,
                          response,
                          mock.Mock())
        self.assertEqual(self.circuit._conn.send.call_count, 0)
Example #5
0
    def test_deriveCreate2CellSecrets_DestroyCell(self, conn):
        self.circuit._conn = conn
        self.circuit._hs = mock.Mock()
        self.circuit._hs.deriveRelayCrypto.return_value = 'test'

        cell = DestroyCell.make(ID)

        self.assertRaises(ValueError, self.circuit._deriveCreate2CellSecrets,
                          cell, mock.Mock())
        self.assertEqual(self.circuit._conn.send.call_count, 0)
Example #6
0
    def test_deriveCreate2CellSecrets_DestroyCell(self, conn):
        self.circuit._conn = conn
        self.circuit._hs = mock.Mock()
        self.circuit._hs.deriveRelayCrypto.return_value = 'test'

        cell = DestroyCell.make(ID)

        self.assertRaises(ValueError,
                          self.circuit._deriveCreate2CellSecrets,
                          cell,
                          mock.Mock())
        self.assertEqual(self.circuit._conn.send.call_count, 0)
Example #7
0
    def test_recvCell_destroy_cell(self):
        self.circuit._recvRelayCell = mock.Mock()
        self.circuit._pollReadQueue = mock.Mock()
        self.circuit._sendDestroyCell = mock.Mock()
        self.circuit._closeCircuit = mock.Mock()
        cell = DestroyCell.make(ID)

        self.circuit._recvCell(cell)

        self.assertEqual(self.circuit._sendDestroyCell.call_count, 0)
        self.assertEqual(self.circuit._closeCircuit.call_count, 1)
        self.assertEqual(self.circuit._recvRelayCell.call_count, 0)
        self.assertEqual(self.circuit._pollReadQueue.call_count, 0)
Example #8
0
    def test_recvCell_destroy_cell(self):
        self.circuit._recvRelayCell = mock.Mock()
        self.circuit._pollReadQueue = mock.Mock()
        self.circuit._sendDestroyCell = mock.Mock()
        self.circuit._closeCircuit = mock.Mock()
        cell = DestroyCell.make(ID)

        self.circuit._recvCell(cell)

        self.assertEqual(self.circuit._sendDestroyCell.call_count, 0)
        self.assertEqual(self.circuit._closeCircuit.call_count, 1)
        self.assertEqual(self.circuit._recvRelayCell.call_count, 0)
        self.assertEqual(self.circuit._pollReadQueue.call_count, 0)
Example #9
0
    def _deriveCreate2CellSecrets(self, response, path_node):
        if isinstance(response, DestroyCell):
            msg = "DestroyCell received from {}.".format(path_node.router_status_entry.fingerprint)
            raise ValueError(msg)
        if not isinstance(response, Created2Cell):
            msg = "Unexpected cell {} received from {}.".format(response, path_node.router_status_entry.fingerprint)
            destroy = DestroyCell.make(self.circuit_id)
            self._conn.send(destroy)
            raise ValueError(msg)

        self._crypt_path.append(ntor.deriveRelayCrypto(self._hs_state, response))
        # TODO: implement this
        # self._hs_state.memwipe()
        self._hs_state = None
Example #10
0
    def _deriveCreate2CellSecrets(self, response, path_node):
        if isinstance(response, DestroyCell):
            msg = ("DestroyCell received from {}.".format(
                path_node.router_status_entry.fingerprint))
            raise ValueError(msg)
        if not isinstance(response, Created2Cell):
            msg = ("Unexpected cell {} received from {}.".format(
                response, path_node.router_status_entry.fingerprint))
            destroy = DestroyCell.make(self.circuit_id)
            self._conn.send(destroy)
            raise ValueError(msg)

        self._crypt_path.append(
            ntor.deriveRelayCrypto(self._hs_state, response))
        # TODO: implement this
        #self._hs_state.memwipe()
        self._hs_state = None
Example #11
0
    def _deriveExtend2CellSecrets(self, response, path_node):
        if isinstance(response, DestroyCell):
            msg = "Destroy cell received from {} on pending circuit {}.".format(
                path_node.router_status_entry.fingerprint, self.circuit_id
            )
            raise ValueError(msg)

        cell, _ = crypto.decryptCell(response, self._crypt_path)

        if not isinstance(cell, RelayExtended2Cell):
            msg = "CircuitBuildTask {} received an unexpected cell: {}. " "Destroying the circuit.".format(
                self.circuit_id, type(cell)
            )
            destroy = DestroyCell.make(self.circuit_id)
            self._conn.send(destroy)
            raise ValueError(msg)

        self._crypt_path.append(ntor.deriveRelayCrypto(self._hs_state, cell))
        # TODO: implement this
        # self._hs_state.memwipe()
        self._hs = None
Example #12
0
    def _deriveExtend2CellSecrets(self, response, path_node):
        if isinstance(response, DestroyCell):
            msg = (
                "Destroy cell received from {} on pending circuit {}.".format(
                    path_node.router_status_entry.fingerprint,
                    self.circuit_id))
            raise ValueError(msg)

        cell, _ = crypto.decryptCell(response, self._crypt_path)

        if not isinstance(cell, RelayExtended2Cell):
            msg = ("CircuitBuildTask {} received an unexpected cell: {}. "
                   "Destroying the circuit.".format(self.circuit_id,
                                                    type(cell)))
            destroy = DestroyCell.make(self.circuit_id)
            self._conn.send(destroy)
            raise ValueError(msg)

        self._crypt_path.append(ntor.deriveRelayCrypto(self._hs_state, cell))
        # TODO: implement this
        #self._hs_state.memwipe()
        self._hs = None