Example #1
0
 def test_real_ep(self):
     proxy_ep = FakeHostnameEndpoint(reactor, "localhost", 8080)
     h = socks.socks_endpoint(proxy_ep)
     ep, host = h.hint_to_endpoint("tcp:example.com:1234", reactor,
                                   discard_status)
     self.assertIsInstance(ep, SOCKS5ClientEndpoint)
     self.assertEqual(host, "example.com")
Example #2
0
 def test_real_ep(self):
     proxy_ep = endpoints.HostnameEndpoint(reactor, "localhost", 8080)
     h = socks.socks_endpoint(proxy_ep)
     ep, host = h.hint_to_endpoint("tcp:example.com:1234", reactor,
                                   discard_status)
     self.assertIsInstance(ep, SOCKS5ClientEndpoint)
     self.assertEqual(host, "example.com")
Example #3
0
    def test_ep(self, scep):
        proxy_ep = endpoints.HostnameEndpoint(reactor, "localhost", 8080)
        h = socks.socks_endpoint(proxy_ep)

        rv = scep.return_value = mock.Mock()
        ep, host = h.hint_to_endpoint("tor:example.com:1234", reactor)
        self.assertEqual(scep.mock_calls,
                         [mock.call("example.com", 1234, proxy_ep)])
        self.assertIdentical(ep, rv)
        self.assertEqual(host, "example.com")
Example #4
0
 def test_bad_hint(self):
     proxy_ep = endpoints.HostnameEndpoint(reactor, "localhost", 8080)
     h = socks.socks_endpoint(proxy_ep)
     # legacy hints will be upgraded before the connection handler is
     # invoked, so the handler should not handle them
     self.assertRaises(ipb.InvalidHintError,
                       h.hint_to_endpoint, "example.com:1234", reactor)
     self.assertRaises(ipb.InvalidHintError,
                       h.hint_to_endpoint, "tcp:example.com:noport", reactor)
     self.assertRaises(ipb.InvalidHintError,
                       h.hint_to_endpoint, "tcp:@:1234", reactor)
Example #5
0
 def test_bad_hint(self):
     proxy_ep = FakeHostnameEndpoint(reactor, "localhost", 8080)
     h = socks.socks_endpoint(proxy_ep)
     # legacy hints will be upgraded before the connection handler is
     # invoked, so the handler should not handle them
     self.assertRaises(ipb.InvalidHintError, h.hint_to_endpoint,
                       "example.com:1234", reactor, discard_status)
     self.assertRaises(ipb.InvalidHintError, h.hint_to_endpoint,
                       "tcp:example.com:noport", reactor, discard_status)
     self.assertRaises(ipb.InvalidHintError, h.hint_to_endpoint,
                       "tcp:@:1234", reactor, discard_status)
Example #6
0
    def test_ep(self, scep):
        proxy_ep = FakeHostnameEndpoint(reactor, "localhost", 8080)
        h = socks.socks_endpoint(proxy_ep)

        rv = scep.return_value = mock.Mock()
        ep, host = h.hint_to_endpoint("tor:example.com:1234", reactor,
                                      discard_status)
        self.assertEqual(scep.mock_calls,
                         [mock.call("example.com", 1234, proxy_ep)])
        self.assertIdentical(ep, rv)
        self.assertEqual(host, "example.com")
from foolscap.api import Referenceable, Tub


tub = Tub()

which = sys.argv[1] if len(sys.argv) > 1 else None
if which == "tcp":
    furl = "pb://%s@tcp:%s:%d/calculator" % (TUBID, HOSTNAME, LOCALPORT)
elif which == "socks":
    # "slogin -D 8013 HOSTNAME" starts a SOCKS server on localhost 8013, for
    # which connections will emerge from the other end. Check the server logs
    # to see the peer address of each addObserver call to verify that it is
    # coming from 127.0.0.1 rather than the client host.
    from foolscap.connections import socks

    h = socks.socks_endpoint(HostnameEndpoint(reactor, "localhost", 8013))
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("tcp", h)
    furl = "pb://%s@tcp:localhost:%d/calculator" % (TUBID, LOCALPORT)
elif which in ("tor-default", "tor-socks", "tor-control", "tor-launch"):
    from foolscap.connections import tor

    if which == "tor-default":
        h = tor.default_socks()
    elif which == "tor-socks":
        h = tor.socks_port(int(sys.argv[2]))
    elif which == "tor-control":
        control_ep = clientFromString(reactor, sys.argv[2])
        h = tor.control_endpoint(control_ep)
    elif which == "tor-launch":
        data_directory = None
from twisted.internet.defer import inlineCallbacks
from twisted.internet.endpoints import HostnameEndpoint, clientFromString
from foolscap.api import Referenceable, Tub

tub = Tub()

which = sys.argv[1] if len(sys.argv) > 1 else None
if which == "tcp":
    furl = "pb://%s@tcp:%s:%d/calculator" % (TUBID, HOSTNAME, LOCALPORT)
elif which == "socks":
    # "slogin -D 8013 HOSTNAME" starts a SOCKS server on localhost 8013, for
    # which connections will emerge from the other end. Check the server logs
    # to see the peer address of each addObserver call to verify that it is
    # coming from 127.0.0.1 rather than the client host.
    from foolscap.connections import socks
    h = socks.socks_endpoint(HostnameEndpoint(reactor, "localhost", 8013))
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("tcp", h)
    furl = "pb://%s@tcp:localhost:%d/calculator" % (TUBID, LOCALPORT)
elif which in ("tor-default", "tor-socks", "tor-control", "tor-launch"):
    from foolscap.connections import tor
    if which == "tor-default":
        h = tor.default_socks()
    elif which == "tor-socks":
        h = tor.socks_port(int(sys.argv[2]))
    elif which == "tor-control":
        control_ep = clientFromString(reactor, sys.argv[2])
        h = tor.control_endpoint(control_ep)
    elif which == "tor-launch":
        data_directory = None
        if len(sys.argv) > 2: