Beispiel #1
0
from oppy.cell.varlen import VersionsCell

from oppy.connection.definitions import V3_KEY_BITS, OPENSSL_RSA_KEY_TYPE
from oppy.connection.handshake.exceptions import (
    BadHandshakeState,
    HandshakeFailed,
    ReceivedDestroyCell,
    UnexpectedCell,
)
from oppy.crypto import util as crypto_util
from oppy.util.tools import dispatch, enum

V3State = enum(
    INIT=0,
    EXPECT_VERSIONS=1,
    EXPECT_CERTS=2,
    EXPECT_AUTH_CHALLENGE=3,
    EXPECT_NETINFO=4,
    DONE=5,
)


class V3FSM(object):

    _response_map = {}

    def __init__(self, transport):
        '''
        :param transport transport: the transport for the associated
            connection. this is needed to get the transport's TLS cert
        '''
        # need the transport so we can call getPeerCertificate()
Beispiel #2
0
from oppy.cell.cell import Cell
from oppy.cell.definitions import PADDING_CMD_IDS
from oppy.cell.exceptions import NotEnoughBytes

from oppy.connection.handshake.v3 import V3FSM
from oppy.connection.handshake.exceptions import (
    BadHandshakeState,
    HandshakeFailed,
    UnexpectedCell,
)
from oppy.util.tools import enum


ConnState = enum(
    PENDING=0,
    OPEN=1,
)


class Connection(Protocol):
    '''A TLS connection to an entry node.'''

    def __init__(self, relay):
        '''
        :param stem.descriptor.server_descriptor.RelayDescriptor relay:
            relay we should create a connection to
        '''
        logging.debug('Creating connection to {0}'.format(relay.address))
        # map all circuits using this connections
        self._circuit_map = {}
        self._buffer = ''
Beispiel #3
0
    RelayExtended2Cell,
    RelayTruncatedCell,
    RelayDropCell,
    RelayResolvedCell,
    RelayExtended2Cell,
)
from oppy.util.tools import enum


CIRCUIT_WINDOW_THRESHOLD_INIT = 1000
SENDME_THRESHOLD = 900
WINDOW_SIZE = 100


CState = enum(
    OPEN=0,
    BUFFERING=1,
)


CircuitType = enum(
    IPv4=0,
    IPv6=1,
)


BACKWARD_CELL_TYPES = (
    DestroyCell,
    EncryptedCell,
)

Beispiel #4
0
IPv6 = "\x04"

# used for parsing incoming SOCKS data
VER_LEN = 1
NMETHODS_LEN = 1
CMD_LEN = 1
RSV_LEN = 1
ADDR_TYPE_LEN = 1
IPv4_LEN = 4
IPv6_LEN = 16
PORT_LEN = 2
REQUEST_HEADER_LEN = VER_LEN + CMD_LEN + RSV_LEN + ADDR_TYPE_LEN

State = enum(
    HANDSHAKE=0,
    REQUEST=1,
    FORWARDING=2,
)


class OppySOCKSProtocol(Protocol):
    '''Do SOCKS 5 handshake and forward local traffic to streams.'''
    def __init__(self, circuit_manager):
        self._circuit_manager = circuit_manager
        self.state = State.HANDSHAKE
        self.request = None
        # An `oppy.stream.stream` object over which the SOCKS client's data
        # will be forwarded. This will be set by the time that state has
        # become forwarding
        self.stream = None
Beispiel #5
0
    RelaySendMeCell,
    RelayExtendedCell,
    RelayExtended2Cell,
    RelayTruncatedCell,
    RelayDropCell,
    RelayResolvedCell,
    RelayExtended2Cell,
)
from oppy.util.tools import enum

CIRCUIT_WINDOW_THRESHOLD_INIT = 1000
SENDME_THRESHOLD = 900
WINDOW_SIZE = 100

CState = enum(
    OPEN=0,
    BUFFERING=1,
)

CircuitType = enum(
    IPv4=0,
    IPv6=1,
)

BACKWARD_CELL_TYPES = (
    DestroyCell,
    EncryptedCell,
)

BACKWARD_RELAY_CELL_TYPES = (
    RelayDataCell,
    RelayEndCell,
Beispiel #6
0
# used for parsing incoming SOCKS data
VER_LEN = 1
NMETHODS_LEN = 1
CMD_LEN = 1
RSV_LEN = 1
ADDR_TYPE_LEN = 1
IPv4_LEN = 4
IPv6_LEN = 16
PORT_LEN = 2
REQUEST_HEADER_LEN = VER_LEN+CMD_LEN+RSV_LEN+ADDR_TYPE_LEN


State = enum(
    HANDSHAKE=0,
    REQUEST=1,
    FORWARDING=2,
)


class OppySOCKSProtocol(Protocol):
    '''Do SOCKS 5 handshake and forward local traffic to streams.'''

    def __init__(self, circuit_manager):
        self._circuit_manager = circuit_manager
        self.state = State.HANDSHAKE
        self.request = None
        # An `oppy.stream.stream` object over which the SOCKS client's data
        # will be forwarded. This will be set by the time that state has
        # become forwarding
        self.stream = None
Beispiel #7
0
from oppy.cell.relay import RelayDataCell
from oppy.cell.relay import RelayEndCell
from oppy.cell.relay import RelaySendMeCell

from oppy.circuit.handshake.ntorfsm import NTorFSM
from oppy.crypto.exceptions import KeyDerivationFailed, UnrecognizedCell
from oppy.path.path import PathSelector
from oppy.util.tools import dispatch, enum

CIRCUIT_WINDOW_THRESHOLD_INIT = 1000
SENDME_THRESHOLD = 900
WINDOW_SIZE = 100

CState = enum(
    PENDING=0,
    OPEN=1,
    BUFFERING=2,
)

CType = enum(
    IPv4=0,
    IPv6=1,
)


class Circuit(object):

    # dispatch table used to lookup handler functions for incoming cells
    # filled in with the `dispatch` decorator
    _response_table = {}
Beispiel #8
0
 def test_enum(self):
     e = tools.enum(OPEN=0, CLOSED=1)
     self.assertEqual(e.OPEN, 0)
     self.assertEqual(e.CLOSED, 1)
Beispiel #9
0
from oppy.cell.relay import RelaySendMeCell

from oppy.circuit.handshake.ntorfsm import NTorFSM
from oppy.crypto.exceptions import KeyDerivationFailed, UnrecognizedCell
from oppy.path.path import PathSelector
from oppy.util.tools import dispatch, enum


CIRCUIT_WINDOW_THRESHOLD_INIT = 1000
SENDME_THRESHOLD = 900
WINDOW_SIZE = 100


CState = enum(
    PENDING=0,
    OPEN=1,
    BUFFERING=2,
)


CType = enum(
    IPv4=0,
    IPv6=1,
)


class Circuit(object):

    # dispatch table used to lookup handler functions for incoming cells
    # filled in with the `dispatch` decorator
    _response_table = {}
Beispiel #10
0
from oppy.cell.util import LinkSpecifier
from oppy.circuit.handshake.exceptions import (
    BadHandshakeState,
    HandshakeFailed,
    ReceivedDestroyCell,
    UnexpectedCell,
)
from oppy.crypto.exceptions import UnrecognizedCell
from oppy.crypto.ntorhandshake import NTorHandshake
import oppy.crypto.util as crypto
from oppy.util.tools import dispatch, enum

State = enum(
    INIT=0,
    EXPECT_CREATED2=1,
    EXPECT_FIRST_EXTENDED2=2,
    EXPECT_SECOND_EXTENDED2=3,
    DONE=4,
)


class NTorFSM(object):
    '''Finite state machine to step through an ntor handshake with relays
    on a circuit's path.
    '''

    _response_map = {}

    def __init__(self, circuit_id, path, crypt_path):
        '''
        :param int circuit_id: id of the circuit for this ntor fsm
Beispiel #11
0
from oppy.circuit.handshake.exceptions import (
    BadHandshakeState,
    HandshakeFailed,
    ReceivedDestroyCell,
    UnexpectedCell,
)
from oppy.crypto.exceptions import UnrecognizedCell
from oppy.crypto.ntorhandshake import NTorHandshake
import oppy.crypto.util as crypto
from oppy.util.tools import dispatch, enum


State = enum(
    INIT=0,
    EXPECT_CREATED2=1,
    EXPECT_FIRST_EXTENDED2=2,
    EXPECT_SECOND_EXTENDED2=3,
    DONE=4,
)


class NTorFSM(object):
    '''Finite state machine to step through an ntor handshake with relays
    on a circuit's path.
    '''

    _response_map = {}

    def __init__(self, circuit_id, path, crypt_path):
        '''
        :param int circuit_id: id of the circuit for this ntor fsm
Beispiel #12
0
from twisted.internet.protocol import Protocol

from oppy.cell.cell import Cell
from oppy.cell.definitions import PADDING_CMD_IDS
from oppy.cell.exceptions import NotEnoughBytes

from oppy.connection.handshake.v3 import V3FSM
from oppy.connection.handshake.exceptions import (
    BadHandshakeState,
    HandshakeFailed,
    UnexpectedCell,
)
from oppy.util.tools import enum

ConnState = enum(
    PENDING=0,
    OPEN=1,
)


class Connection(Protocol):
    '''A TLS connection to an entry node.'''
    def __init__(self, relay):
        '''
        :param stem.descriptor.server_descriptor.RelayDescriptor relay:
            relay we should create a connection to
        '''
        logging.debug('Creating connection to {0}'.format(relay.address))
        # map all circuits using this connections
        self._circuit_map = {}
        self._buffer = ''
        self._relay = relay