Package org.jivesoftware.smackx.bytestreams.socks5.packet

Examples of org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream


     */
    @After
    public void cleanup() {
        SmackConfiguration.setLocalSocks5ProxyEnabled(true);
        SmackConfiguration.setLocalSocks5ProxyPort(7777);
        Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
        try {
            String address = InetAddress.getLocalHost().getHostAddress();
            List<String> addresses = new ArrayList<String>();
            addresses.add(address);
            socks5Proxy.replaceLocalAddresses(addresses);
        }
        catch (UnknownHostException e) {
            // ignore
        }

        socks5Proxy.stop();
    }
View Full Code Here


        return stunResults;
    }

    synchronized public void setPublicIP(InetAddress privateIP,
        InetAddress publicIP) {
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();

        if (recentPublicIPs.containsKey(privateIP)) {
            proxy.removeLocalAddress(recentPublicIPs.get(privateIP)
                .getHostAddress());

            recentPublicIPs.remove(privateIP);
        }
View Full Code Here

                /*
                 * If a public IP was retrieved, add it to the local addresses
                 * of the Socks5 proxy for external clients to be able to
                 * connect to me.
                 */
                Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
                if (ip != null) {
                    // the local IP matches the retrieved IP address, so it is
                    // already the public IP. Store this fact for later.
                    if (ip.equals(localAddress)) {
                        aLocalIPisPublicIP = true;
                        return;
                    }

                    synchronized (stunResults) {
                        stunResults.add(di);
                    }

                    // Add public IP if its not already in the list
                    if (!proxy.getLocalAddresses()
                        .contains(ip.getHostAddress())) {
                        setPublicIP(localAddress, ip);
                        log.debug("Added WAN-IP: " + ip.getHostAddress()
                            + " (through " + localAddress.getHostAddress()
                            + ")");
View Full Code Here

         * TODO Fix in Smack: Either always start proxy when enabled in the
         * smack configuration or never start it automatically. Currently it
         * only starts after initiation the singleton on first access.
         */

        Socks5Proxy proxy = NetworkingUtils.getSocks5ProxySafe();

        if (proxyEnabled != SmackConfiguration.isLocalSocks5ProxyEnabled()) {
            settingsChanged = true;
            SmackConfiguration.setLocalSocks5ProxyEnabled(proxyEnabled);
        }

        // Note: The proxy gets restarted on port change, too.
        if (proxyPort != SmackConfiguration.getLocalSocks5ProxyPort()) {
            settingsChanged = true;
            portChanged = true;
            SmackConfiguration.setLocalSocks5ProxyPort(proxyPort);
        }

        // Get & set all (useful) internal and external IP addresses as
        // potential connect addresses
        if (proxyEnabled) {

            try {
                List<InetAddress> myAdresses = NetworkingUtils
                    .getAllNonLoopbackLocalIPAdresses(true);

                if (!myAdresses.isEmpty()) {
                    // convert to List of Strings
                    List<String> myAdressesStr = new LinkedList<String>();
                    for (InetAddress ip : myAdresses)
                        myAdressesStr.add(ip.getHostAddress());
                    proxy.replaceLocalAddresses(myAdressesStr);
                }

                // Perform public IP detection concurrently
                // Dont perform if we know a local IP is the WAN IP
                if (stunHelper != null && !stunHelper.isLocalIPthePublicIP())
                    stunHelper.startWANIPDetection(stunServer, stunPort, false);

            } catch (Exception e) {
                log.debug("Error while retrieving IP addresses", e);
            }
        }

        if (settingsChanged || proxy.isRunning() != proxyEnabled) {
            StringBuilder sb = new StringBuilder();
            if (settingsChanged)
                sb.append("Socks5Proxy properties changed. ");

            if (proxy.isRunning()) {
                proxy.stop();
                sb.append("Socks5Proxy stopped. ");
            }
            if (proxyEnabled) {
                proxy.start();
                sb.append("Socks5Proxy started on port " + proxy.getPort()
                    + "...");
            }
            log.debug(sb);

            if (upnpManager != null) {
View Full Code Here

    @Test
    public void shouldFailIfTargetIsNotConnectedToLocalSocks5Proxy() throws Exception {

        // start a local SOCKS5 proxy
        SmackConfiguration.setLocalSocks5ProxyPort(proxyPort);
        Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
        socks5Proxy.start();

        // build stream host information for local SOCKS5 proxy
        StreamHost streamHost = new StreamHost(connection.getUser(),
                        socks5Proxy.getLocalAddresses().get(0));
        streamHost.setPort(socks5Proxy.getPort());

        // create digest to get the socket opened by target
        String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

        Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
                        connection, sessionID, targetJID);

        try {
            socks5Client.getSocket(10000);

            fail("exception should be thrown");
        }
        catch (XMPPException e) {
            assertTrue(e.getMessage().contains("target is not connected to SOCKS5 proxy"));
            protocol.verifyAll(); // assert no XMPP messages were sent
        }

        socks5Proxy.stop();

    }
View Full Code Here

    @Test
    public void shouldSuccessfullyConnectThroughLocalSocks5Proxy() throws Exception {

        // start a local SOCKS5 proxy
        SmackConfiguration.setLocalSocks5ProxyPort(proxyPort);
        Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
        socks5Proxy.start();

        // test data
        final byte[] data = new byte[] { 1, 2, 3 };

        // create digest
        final String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

        // allow connection of target with this digest
        socks5Proxy.addTransfer(digest);

        // build stream host information
        final StreamHost streamHost = new StreamHost(connection.getUser(),
                        socks5Proxy.getLocalAddresses().get(0));
        streamHost.setPort(socks5Proxy.getPort());

        // target connects to local SOCKS5 proxy
        Thread targetThread = new Thread() {

            @Override
            public void run() {
                try {
                    Socks5Client targetClient = new Socks5Client(streamHost, digest);
                    Socket socket = targetClient.getSocket(10000);
                    socket.getOutputStream().write(data);
                }
                catch (Exception e) {
                    fail(e.getMessage());
                }
            }

        };
        targetThread.start();

        Thread.sleep(200);

        // initiator connects
        Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
                        connection, sessionID, targetJID);

        Socket socket = socks5Client.getSocket(10000);

        // verify test data
        InputStream in = socket.getInputStream();
        for (int i = 0; i < data.length; i++) {
            assertEquals(data[i], in.read());
        }

        targetThread.join();

        protocol.verifyAll(); // assert no XMPP messages were sent

        socks5Proxy.removeTransfer(digest);
        socks5Proxy.stop();

    }
View Full Code Here

    public void shouldFailIfRequestHasNoStreamHosts() throws Exception {

        try {

            // build SOCKS5 Bytestream initialization request with no SOCKS5 proxies
            Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
                            initiatorJID, targetJID, sessionID);

            // get SOCKS5 Bytestream manager for connection
            Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
View Full Code Here

    public void shouldFailIfRequestHasInvalidStreamHosts() throws Exception {

        try {

            // build SOCKS5 Bytestream initialization request
            Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
                            initiatorJID, targetJID, sessionID);
            // add proxy that is not running
            bytestreamInitialization.addStreamHost(proxyJID, proxyAddress, 7778);

            // get SOCKS5 Bytestream manager for connection
            Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);

            // build SOCKS5 Bytestream request with the bytestream initialization
View Full Code Here

     */
    @Test
    public void shouldBlacklistInvalidProxyAfter2Failures() throws Exception {

        // build SOCKS5 Bytestream initialization request
        Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
                        initiatorJID, targetJID, sessionID);
        bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);

        // get SOCKS5 Bytestream manager for connection
        Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);

        // try to connect several times
        for (int i = 0; i < 2; i++) {
            try {
                // build SOCKS5 Bytestream request with the bytestream initialization
                Socks5BytestreamRequest byteStreamRequest = new Socks5BytestreamRequest(
                                byteStreamManager, bytestreamInitialization);

                // set timeouts
                byteStreamRequest.setTotalConnectTimeout(600);
                byteStreamRequest.setMinimumConnectTimeout(300);

                // accept the stream (this is the call that is tested here)
                byteStreamRequest.accept();

                fail("exception should be thrown");
            }
            catch (XMPPException e) {
                assertTrue(e.getMessage().contains(
                                "Could not establish socket with any provided host"));
            }

            // verify targets response
            assertEquals(1, protocol.getRequests().size());
            Packet targetResponse = protocol.getRequests().remove(0);
            assertTrue(IQ.class.isInstance(targetResponse));
            assertEquals(initiatorJID, targetResponse.getTo());
            assertEquals(IQ.Type.ERROR, ((IQ) targetResponse).getType());
            assertEquals(XMPPError.Condition.item_not_found.toString(),
                            ((IQ) targetResponse).getError().getCondition());
        }

        // create test data for stream
        byte[] data = new byte[] { 1, 2, 3 };
        Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(7779);

        assertTrue(socks5Proxy.isRunning());

        // add a valid SOCKS5 proxy
        bytestreamInitialization.addStreamHost(proxyJID, proxyAddress, 7779);

        // build SOCKS5 Bytestream request with the bytestream initialization
        Socks5BytestreamRequest byteStreamRequest = new Socks5BytestreamRequest(byteStreamManager,
                        bytestreamInitialization);

View Full Code Here

        // disable blacklisting
        Socks5BytestreamRequest.setConnectFailureThreshold(0);

        // build SOCKS5 Bytestream initialization request
        Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
                        initiatorJID, targetJID, sessionID);
        bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);

        // get SOCKS5 Bytestream manager for connection
        Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);

        // try to connect several times
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.